as-object
TypeScript icon, indicating that this package has built-in type declarations

0.1.3 • Public • Published

AS-OBJECT

AssemblyScript WebAssembly

Object API implementation for AssemblyScript with additional features.

Setup

npm install as-object
npm install visitor-as

Add the transform to your asc command

--transform json-as/transform

Alternatively, add it to your asconfig.json (e.g. in package.json)

{
  "options": {
    "transform": ["json-as/transform"]
  }
}

Usage

import { Object } from "as-object/assembly";
// Must import as-variant or it will not work
import { Variant } from "as-variant/assembly";
@object
class Vec3 {
    x!: f32;
    y!: f32;
    z!: f32;
}

const vec: Vec3 = {
    x: 3.4,
    y: 1.2,
    z: 8.3
}

console.log("[" + Object.keys(vec).map<string>(v => `"${v}"`).join(", ") + "]");
// ["x", "y", "z"]
console.log(Object.types(vec).join(", "));
// f32, f32, f32
console.log(Object.name(vec));
// Vec3
console.log("[" + Object.values(vec).map<f32>(v => v.get<f32>()).join(",") + "]");
// [3.4000000953674318,1.2000000476837159,8.300000190734864]

Readme

Keywords

Package Sidebar

Install

npm i as-object

Weekly Downloads

1

Version

0.1.3

License

MIT

Unpacked Size

20.1 kB

Total Files

16

Last publish

Collaborators

  • slicewire-dev
  • jairussw