From f13eba4361fba6662d8271cc04a7ddd3f03d4dbe Mon Sep 17 00:00:00 2001 From: Aaron Turner Date: Mon, 18 Jan 2021 07:37:12 -0800 Subject: [PATCH 01/10] Added Prettier for code formatting (#105) * Moved to eslint and used suggested linting and formatting * Updated node version to stable and LTS * chore: removed and added TS required comments Also replaced `this` with namespace to make tsc happy Co-authored-by: Willem Wyndham --- .eslintrc.js | 197 +++++ .travis.yml | 5 +- README.md | 7 +- as-pect.config.js | 2 +- assembly/JSON.ts | 55 +- assembly/__tests__/as-pect.d.ts | 642 +--------------- assembly/__tests__/roundtrip.spec.ts | 42 +- assembly/decoder.ts | 161 ++-- assembly/encoder.ts | 239 +++--- assembly/index.ts | 2 +- assembly/tsconfig.json | 4 +- assembly/util/index.ts | 44 +- index.js | 8 +- package.json | 14 +- yarn.lock | 1046 +++++++++++++++++++++++++- 15 files changed, 1528 insertions(+), 940 deletions(-) create mode 100644 .eslintrc.js diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000..dd3a174 --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,197 @@ +module.exports = { + root: true, + parser: "@typescript-eslint/parser", + plugins: [ + "@typescript-eslint", + ], + extends: [ + "eslint:recommended", + "plugin:@typescript-eslint/eslint-recommended", + "plugin:@typescript-eslint/recommended", + ], + parserOptions: { + ecmaVersion: 2020, + sourceType: "module", + ecmaFeatures: {} + }, + + // === General rules ========================================================= + + rules: { + // Omitted semicolons are hugely popular, yet within the compiler it makes + // sense to be better safe than sorry. + "semi": "error", + + // Our code bases uses 2 spaces for indentation, and we enforce it here so + // files don't mix spaces, tabs or different indentation levels. + "indent": ["error", 2, { + "SwitchCase": 1, + "VariableDeclarator": "first", + "offsetTernaryExpressions": true, + "ignoredNodes": [ // FIXME: something's odd here + "ConditionalExpression > *", + "ConditionalExpression > * > *", + "ConditionalExpression > * > * > *" + ] + }], + + // This is mostly visual style, making comments look uniform. + "spaced-comment": ["error", "always", { + "markers": ["/"], // triple-slash + "exceptions": ["/"] // all slashes + }], + + // This tends to be annoying as it encourages developers to make everything + // that is never reassigned a 'const', sometimes semantically incorrect so, + // typically leading to huge diffs in follow-up PRs modifying affected code. + "prefer-const": "off", + + // It is perfectly fine to declare top-level variables with `var`, yet this + // rule doesn't provide configuration options that would help. + "no-var": "off", + + // Quite often, dealing with multiple related cases at once or otherwise + // falling through is exactly the point of using a switch. + "no-fallthrough": "off", + + // Typical false-positives here are `do { ... } while (true)` statements or + // similar, but the only option provided here is not checking any loops. + "no-constant-condition": ["error", { checkLoops: false }], + + // Functions are nested in blocks occasionally, and there haven't been any + // problems with this so far, so turning the check off. + "no-inner-declarations": "off", + + // Quite common in scenarios where an iteration starts at `current = this`. + "@typescript-eslint/no-this-alias": "off", + + // Disabled here, but enabled again for JavaScript files. + "no-unused-vars": "off", + + // Disabled here, but enabled again for TypeScript files. + "@typescript-eslint/no-unused-vars": "off", + + // Allow emptry functions for some of our base classes + "@typescript-eslint/no-empty-function": "off" + }, + overrides: [ + + // === TypeScript rules ==================================================== + + { + files: [ + "**/assembly/**/*.ts" + ], + rules: { + // Enforcing to remove function parameters on stubs makes code less + // maintainable, so we instead allow unused function parameters. + "@typescript-eslint/no-unused-vars": [ + "warn", { + "vars": "local", + "varsIgnorePattern": "^_|^[A-Z](?:From|To)?$", // ignore type params + "args": "none", + "ignoreRestSiblings": false + } + ], + + // Namespaces are quite useful in AssemblyScript + "@typescript-eslint/no-namespace": "off", + + // There is actually codegen difference here + "@typescript-eslint/no-array-constructor": "off", + + // Sometimes it can't be avoided to add a @ts-ignore + "@typescript-eslint/ban-ts-comment": "off", + + // Utilized to achieve portability in some cases + "@typescript-eslint/no-non-null-assertion": "off", + } + }, + + // === Compiler rules (extends AssemblyScript rules) ======================= + + { + files: [ + "**/assembly/**/*.ts" + ], + rules: { + // There is an actual codegen difference here - TODO: revisit + "no-cond-assign": "off", + + // Not all types can be omitted in AS yet - TODO: revisit + "@typescript-eslint/no-inferrable-types": "off", + + // Used rarely to reference internals that are not user-visible + "@typescript-eslint/triple-slash-reference": "off", + + // The compiler has its own `Function` class for example + "no-shadow-restricted-names": "off", + "@typescript-eslint/ban-types": "off" + } + }, + + // === Standard Library rules (extends AssemblyScript rules) =============== + + { + files: [ + "**/assembly/**/*.ts" + ], + rules: { + // We are implementing with --noLib, so we shadow all the time + "no-shadow-restricted-names": "off", + + // Similarly, sometimes we need the return type to be String, not string + "@typescript-eslint/ban-types": "off" + } + }, + + // === Standard Definition rules (extends TypeScript rules) ================ + + { + files: [ + "**/assembly/**/*.d.ts" + ], + rules: { + // Often required to achieve compatibility with TypeScript + "@typescript-eslint/no-explicit-any": "off", + + // Interfaces can be stubs here, i.e. not yet fully implemented + "@typescript-eslint/no-empty-interface": "off", + + // Definitions make use of `object` to model rather unusual constraints + "@typescript-eslint/ban-types": "off" + } + }, + + + + // === Test rules (extends TypeScript rules) =============================== + + { + files: [ + "**/assembly/__tests__/**/*.ts" + ], + rules: { + // Tests typically include unusual code patterns on purpose. This is + // very likely not an extensive list, but covers what's there so far. + "no-empty": "off", + "no-cond-assign": "off", + "no-compare-neg-zero": "off", + "no-inner-declarations": "off", + "no-constant-condition": "off", + "use-isnan": "off", + "@typescript-eslint/no-namespace": "off", + "@typescript-eslint/no-unused-vars": "off", + "@typescript-eslint/no-empty-function": "off", + "@typescript-eslint/no-non-null-assertion": "off", + "@typescript-eslint/no-extra-semi": "off", + "@typescript-eslint/no-inferrable-types": "off", + "@typescript-eslint/ban-types": "off", + "@typescript-eslint/triple-slash-reference": "off", + "@typescript-eslint/ban-ts-comment": "off", + "@typescript-eslint/no-extra-non-null-assertion": "off", + "@typescript-eslint/no-empty-interface": "off" + } + }, + ] +}; diff --git a/.travis.yml b/.travis.yml index e30727d..5e530bf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,7 @@ language: node_js node_js: - - "10" - - "11" - - "12" + - "node" + - "lts/*" script: - yarn test diff --git a/README.md b/README.md index 5f2b0da..cb9526b 100644 --- a/README.md +++ b/README.md @@ -8,12 +8,12 @@ Special thanks to https://github.com/MaxGraey/bignum.wasm for basic unit testing This is developed for use in smart contracts written in AssemblyScript for https://github.com/nearprotocol/nearcore. This imposes such limitations: + - Float numbers not supported - We assume that memory never needs to be deallocated (cause these contracts are short-lived). Note that this mostly just defines the way it's currently implemented. Contributors are welcome to fix limitations. - # Usage ## Encoding JSON @@ -38,7 +38,6 @@ let json: Uint8Array = encoder.serialize(); // Or get serialized data as string let jsonString: String = encoder.toString(); - ``` ## Parsing JSON @@ -114,7 +113,7 @@ let jsonObj: JSON.Object = JSON.parse(`{"hello": "world"}`); let world = jsonObj.getString("hello"); // If you don't know what the type of the value -let unknown = jsonObj.getValue("hello") +let unknown = jsonObj.getValue("hello"); -unknown.isString // true; +unknown.isString; // true; ``` diff --git a/as-pect.config.js b/as-pect.config.js index 7599de7..cd5904f 100644 --- a/as-pect.config.js +++ b/as-pect.config.js @@ -17,7 +17,7 @@ module.exports = { /** To enable wat file output, use the following flag. The filename is ignored, but required by the compiler. */ "--textFile": ["output.wat"], "--runtime": ["stub"], // Acceptable values are: full, half, stub (arena), and none, - "--baseDir": process.cwd() + "--baseDir": process.cwd(), // "--runPasses": ["dce"] }, /** diff --git a/assembly/JSON.ts b/assembly/JSON.ts index ae929c8..5bab23e 100644 --- a/assembly/JSON.ts +++ b/assembly/JSON.ts @@ -39,7 +39,7 @@ class Handler { if (this.stack.length == 0) { this.stack.push(obj); } else { - this.addValue(name, obj) + this.addValue(name, obj); this.stack.push(obj); } return true; @@ -71,33 +71,38 @@ class Handler { } if (this.peek instanceof JSON.Obj) { (this.peek as JSON.Obj).set(name, obj); - } - else if (this.peek instanceof JSON.Arr) { + } else if (this.peek instanceof JSON.Arr) { (this.peek).push(obj); } } } namespace _JSON { - @lazy export const handler: Handler = new Handler(); - @lazy export const decoder: JSONDecoder = new JSONDecoder(_JSON.handler); - + // @ts-ignore decorator is valid + @lazy + export const handler: Handler = new Handler(); + // @ts-ignore decorator is valid + @lazy + export const decoder: JSONDecoder = new JSONDecoder( + _JSON.handler + ); + /** Parses a string or Uint8Array and returns a Json Value. */ export function parse(str: T): JSON.Value { var arr: Uint8Array; - if (isString(str)){ + if (isString(str)) { arr = Buffer.fromString(str); } else { arr = changetype(str); } - this.decoder.deserialize(arr); - const res = this.decoder.handler.peek; - this.decoder.handler.reset(); + _JSON.decoder.deserialize(arr); + const res = _JSON.decoder.handler.peek; + _JSON.decoder.handler.reset(); return res; } } -//@ts-ignore +// @ts-ignore @global export namespace JSON { export abstract class Value { @@ -149,7 +154,7 @@ export namespace JSON { } toString(): string { - return "\"" + this._str + "\""; + return '"' + this._str + '"'; } } @@ -172,7 +177,7 @@ export namespace JSON { return "null"; } } - + export class Bool extends Value { constructor(public _bool: bool) { super(); @@ -195,7 +200,15 @@ export namespace JSON { } toString(): string { - return "[" + this._arr.map((val: Value,i: i32,_arr: Value[]): string => val.toString()).join(",") + "]"; + return ( + "[" + + this._arr + .map((val: Value, i: i32, _arr: Value[]): string => + val.toString() + ) + .join(",") + + "]" + ); } } @@ -210,14 +223,13 @@ export namespace JSON { } set(key: string, value: T): void { - if (isReference(value)){ + if (isReference(value)) { if (value instanceof Value) { this._set(key, value); return; } } this._set(key, from(value)); - } private _set(key: string, value: Value): void { if (!this._obj.has(key)) { @@ -236,7 +248,9 @@ export namespace JSON { toString(): string { const objs: string[] = []; for (let i: i32 = 0; i < this.keys.length; i++) { - objs.push("\"" + this.keys[i] + "\":" + this._obj.get(this.keys[i]).toString()); + objs.push( + '"' + this.keys[i] + '":' + this._obj.get(this.keys[i]).toString() + ); } return "{" + objs.join(",") + "}"; } @@ -246,7 +260,6 @@ export namespace JSON { } } - export function from(val: T): Value { if (isBoolean(val)) { return Value.Bool(val); @@ -263,7 +276,7 @@ export namespace JSON { if (isArrayLike(val)) { const arr = Value.Array(); for (let i: i32 = 0; i < val.length; i++) { - //@ts-ignore + // @ts-ignore arr.push(from>(val[i])); } return arr; @@ -273,11 +286,11 @@ export namespace JSON { */ return Value.Object(); } - //@ts-ignore + + // @ts-ignore @inline /** Parses a string or Uint8Array and returns a Json Value. */ export function parse(str: T): Value { return _JSON.parse(str); } } - diff --git a/assembly/__tests__/as-pect.d.ts b/assembly/__tests__/as-pect.d.ts index 11bf4f9..6101ea2 100644 --- a/assembly/__tests__/as-pect.d.ts +++ b/assembly/__tests__/as-pect.d.ts @@ -1,641 +1 @@ -/** - * This function creates a test group in the test loader. - * - * @param {string} description - This is the name of the test group. - * @param {() => void} callback - A function that contains all of the closures for this test group. - * - * @example - * describe("my test suite", (): void => { - * // put your tests here - * }); - */ - declare function describe(description: string, callback: () => void): void; - - /** - * This function creates a test inside the given test group. It must be placed inside a describe - * block. - * - * @param {string} description - This is the name of the test, and should describe a behavior. - * @param {() => void} callback - A function that contains a set of expectations for this test. - * - * @example - * describe("the meaning of life", (): void => { - * it("should be 42", (): void => { - * // put your expectations here - * expect(29 + 13).toBe(42); - * }); - * }); - */ - declare function it(description: string, callback: () => void): void; - - /** - * A test that does not run, and is longhand equivalent to using todo function without a - * callback. This test does not get run and is reported like a todo. - * - * @param {string} description - This is the name of the test, and should describe a behavior. - * @param {() => void} callback - A function that contains a set of expectations for this test. - */ - declare function xit(description: string, callback: () => void): void; - - /** - * A test that does not run, and is longhand equivalent to using todo function without a - * callback. This test does not get run and is reported like a todo. - * - * @param {string} description - This is the name of the test, and should describe a behavior. - * @param {() => void} callback - A function that contains a set of expectations for this test. - */ - declare function xtest(description: string, callback: () => void): void; - - /** - * This function creates a test inside the given test group. It must be placed inside a describe - * block. - * - * @param {string} description - This is the name of the test, and should describe a behavior. - * @param {() => void} callback - A function that contains a set of expectations for this test. - * - * @example - * describe("the meaning of life", (): void => { - * test("the value should be 42", (): void => { - * // put your expectations here - * expect(29 + 13).toBe(42); - * }); - * }); - */ - declare function test(description: string, callback: () => void): void; - - /** - * This function creates a test that is expected to fail. This is useful to verify if a given - * behavior is expected to throw. - * - * @param {string} description - This is the name of the test, and should describe a behavior. - * @param {() => void} callback - A function that contains a set of expectations for this test. - * @param {string?} message - A message that describes why the test should fail. - * @example - * describe("the meaning of life", (): void => { - * throws("the value should be 42", (): void => { - * // put your expectations here - * expect(29 + 13).toBe(42); - * }); - * }); - */ - declare function throws(description: string, callback: () => void, message?: string): void; - - - /** - * This function creates a test that is expected to fail. This is useful to verify if a given - * behavior is expected to throw. - * - * @param {string} description - This is the name of the test, and should describe a behavior. - * @param {() => void} callback - A function that contains a set of expectations for this test. - * @param {string?} message - A message that describes why the test should fail. - * @example - * describe("the meaning of life", (): void => { - * itThrows("when the value should be 42", (): void => { - * // put your expectations here - * expect(29 + 13).not.toBe(42); - * }, "The value is actually 42."); - * }); - */ - declare function itThrows(description: string, callback: () => void, message?: string): void; - - /** - * This function creates a callback that is called before each individual test is run in this test - * group. - * - * @param {function} callback - The function to be run before each test in the current test group. - * - * @example - * // create a global - * var cat: Cat = new Cat(); - * - * describe("cats", (): void => { - * beforeEach((): void => { - * cat.meow(1); // meow once per test - * }); - * }); - */ - declare function beforeEach(callback: () => void): void; - - /** - * This function creates a callback that is called before the whole test group is run, and only - * once. - * - * @param {function} callback - The function to be run before each test in the current test group. - * - * @example - * // create a global - * var dog: Dog = null; - * describe("dogs", (): void => { - * beforeAll((): void => { - * dog = new Dog(); // create a single dog once before the tests start - * }); - * }); - */ - declare function beforeAll(callback: () => void): void; - - /** - * This function creates a callback that is called after each individual test is run in this test - * group. - * - * @param {function} callback - The function to be run after each test in the current test group. - * - * @example - * // create a global - * var cat: Cat = new Cat(); - * - * describe("cats", (): void => { - * afterEach((): void => { - * cat.sleep(12); // cats sleep a lot - * }); - * }); - */ - declare function afterEach(callback: () => void): void; - - /** - * This function creates a callback that is called after the whole test group is run, and only - * once. - * - * @param {function} callback - The function to be run after each test in the current test group. - * - * @example - * // create a global - * var dog: Dog = null; - * describe("dogs", (): void => { - * afterAll((): void => { - * memory.free(changetype(dog)); // free some memory - * }); - * }); - */ - declare function afterAll(callback: () => void): void; - - /** - * Describes a value and returns an expectation to test the value. - * - * @type {T} - The test's type - * @param {T} actual - The value being tested. - * - * @example - * expect(42).not.toBe(-1, "42 should not be -1"); - * expect(19 + 23).toBe(42, "19 + 23 should equal 42"); - */ - declare function expect(actual: T | null): Expectation; - - /** - * Describes a function and returns an expectation to test the function. - * - * @param {() => void} callback - The callback being tested. - * - * @example - * expectFn((): void => unreachable()).toThrow("unreachables do not throw"); - * expectFn((): void => { - * cat.meow(); - * }).not.toThrow("Uhoh, cats can't meow!");; - */ - declare function expectFn(cb: () => void): Expectation<() => void>; - - /** - * Describes a test that needs to be written. - * - * @param {string} description - The description of the test that needs to be written. - */ - declare function todo(description: string): void; - - /** - * Logs a single value to the logger, and is stringified. It works for references, values, and - * strings. - * - * @type {T} - The type to be logged. - * @param {T | null} value - The value to be logged. - * @example - * log("This is a logged value."); - * log(42); - * log(new Vec(1, 2, 3)); - * log(null); - */ - declare function log(value: T | null): void; - - /** - * An expectation for a value. - */ - declare class Expectation { - - /** - * Create a new expectation. - * - * @param {T | null} actual - The actual value of the expectation. - */ - constructor(actual: T | null); - - /** - * This expectation performs a strict equality on value types and reference types. - * - * @param {T | null} expected - The value to be compared. - * @param {string} message - The optional message that describes the expectation. - * - * @example - * expect(42).not.toBe(-1, "42 should not be -1"); - * expect(19 + 23).toBe(42, "19 + 23 should equal 42"); - */ - toBe(expected: T | null, message?: string): void; - - /** - * This expectation performs a strict equality on value types and performs a memcompare on - * reference types. If the reference type `T` has reference types as properties, the comparison does - * not perform property traversal. It will only compare the pointer values in the memory block, and - * only compare `offsetof()` bytes, regardless of the allocated block size. - * - * @param {T | null} expected - The value to be compared. - * @param {string} message - The optional message that describes the expectation. - * - * @example - * expect(new Vec3(1, 2, 3)).toStrictEqual(new Vec(1, 2, 3), "Vectors of the same shape should be equal"); - */ - toStrictEqual(expected: T | null, message?: string): void; - - /** - * This expectation performs a strict memory block equality based on the allocated block sizes. - * - * @param {T | null} expected - The value to be compared. - * @param {string} message - The optional message that describes the expectation. - * - * @example - * expect(new Vec3(1, 2, 3)).toBlockEqual(new Vec(1, 2, 3), "Vectors of the same shape should be equal"); - */ - toBlockEqual(expected: T | null, message?: string): void; - - /** - * If the value is callable, it calls the function, and fails the expectation if it throws, or hits - * an unreachable(). - * - * @param {string} message - The optional message that describes the expectation. - * - * @example - * expectFn((): void => unreachable()).toThrow("unreachable() should throw."); - * expectFn((): void => { - * cat.sleep(100); // cats can sleep quite a lot - * }).not.toThrow("cats should sleep, not throw"); - */ - toThrow(message?: string): void; - - /** - * This expecation asserts that the value is truthy, like in javascript. If the value is a string, - * then strings of length 0 are not truthy. - * - * @param {string} message - The optional message that describes the expectation. - * - * @example - * expect(true).toBeTruthy("true is truthy."); - * expect(1).toBeTruthy("numeric values that are not 0 are truthy."); - * expect(new Vec3(1, 2, 3)).toBeTruthy("reference types that aren't null are truthy."); - * expect(false).not.toBeTruthy("false is not truthy."); - * expect(0).not.toBeTruthy("0 is not truthy."); - * expect(null).not.toBeTruthy("null is not truthy."); - */ - toBeTruthy(message?: string): void; - - /** - * This expectation tests the value to see if it is null. If the value is a value type, it is - * never null. If the value is a reference type, it performs a strict null comparison. - * - * @param {string} message - The optional message that describes the expectation. - * - * @example - * expect(0).not.toBeNull("numbers are never null"); - * expect(null).toBeNull("null reference types are null."); - */ - toBeNull(message?: string): void; - - /** - * This expecation assert that the value is falsy, like in javascript. If the value is a string, - * then strings of length 0 are falsy. - * - * @param {string} message - The optional message that describes the expectation. - * - * @example - * expect(false).toBeFalsy("false is falsy."); - * expect(0).toBeFalsy("0 is falsy."); - * expect(null).toBeFalsy("null is falsy."); - * expect(true).not.toBeFalsy("true is not falsy."); - * expect(1).not.toBeFalsy("numeric values that are not 0 are not falsy."); - * expect(new Vec3(1, 2, 3)).not.toBeFalsy("reference types that aren't null are not falsy."); - */ - toBeFalsy(message?: string): void; - - /** - * This expectation asserts that the value is greater than the expected value. Since operators can - * be overloaded in assemblyscript, it's possible for this to work on reference types. - * - * @param {T | null} expected - The expected value that the actual value should be greater than. - * @param {string} message - The optional message that describes this expectation. - * - * @example - * expect(10).toBeGreaterThan(4); - * expect(12).not.toBeGreaterThan(42); - */ - toBeGreaterThan(expected: T | null, message?: string): void; - - /** - * This expectation asserts that the value is less than the expected value. Since operators can - * be overloaded in assemblyscript, it's possible for this to work on reference types. - * - * @param {T | null} value - The expected value that the actual value should be less than. - * @param {string} message - The optional message that describes this expectation. - * - * @example - * expect(10).not.toBeLessThan(4); - * expect(12).toBeLessThan(42); - */ - toBeLessThan(expected: T | null, message?: string): void; - - /** - * This expectation asserts that the value is greater than or equal to the expected value. Since - * operators can be overloaded in assemblyscript, it's possible for this to work on reference - * types. - * - * @param {T | null} value - The expected value that the actual value should be greater than or - * equal to. - * @param {string} message - The optional message that describes this expectation. - * - * @example - * expect(42).toBeGreaterThanOrEqualTo(42); - * expect(10).toBeGreaterThanOrEqualTo(4); - * expect(12).not.toBeGreaterThanOrEqualTo(42); - */ - toBeGreaterThanOrEqualTo(expected: T | null, message?: string): void; - - /** - * This expectation asserts that the value is less than or equal to the expected value. Since - * operators can be overloaded in assemblyscript, it's possible for this to work on reference - * types. - * - * @param {T | null} value - The expected value that the actual value should be less than or equal - * to. - * @param {string} message - The optional message that describes this expectation. - * - * @example - * expect(42).toBeLessThanOrEqualTo(42); - * expect(10).not.toBeLessThanOrEqualTo(4); - * expect(12).toBeLessThanOrEqualTo(42); - */ - toBeLessThanOrEqualTo(expected: T | null, message?: string): void; - - /** - * This expectation asserts that the value is close to another value. Both numbers must be finite, - * and T must extend f64 or f32. - * - * @param {T extends f64 | f32} value - The expected value to be close to. - * @param {i32} decimalPlaces - The number of decimal places used to calculate epsilon. Default is - * 2. - * @param {string} message - The optional message that describes this expectation. - */ - toBeCloseTo(expected: T, decimalPlaces?: number, message?: string): void; - - /** - * This function asserts the float type value is NaN. - * - * @param {string} message - The optional message the describes this expectation. - * @example - * expect(NaN).toBeNaN(); - * expect(42).not.toBeNaN(); - */ - toBeNaN(message?: string): void; - - /** - * This function asserts a float is finite. - * - * @param {string} message - The optional message the describes this expectation. - * @example - * expect(42).toBeFinite(); - * expect(Infinity).not.toBeFinite(); - */ - toBeFinite(message?: string): void; - - /** - * This method asserts the item has the expected length. - * - * @param {i32} expected - The expected length. - * @param {string} message - The optional message the describes this expectation. - */ - toHaveLength(expected: i32, message?: string): void; - - /** - * This method asserts that a given T that extends Array has a value/reference included. - * - * @param {i32} expected - The expected item to be included in the Array. - * @param {string} message - The optional message the describes this expectation. - */ - toInclude(expected: U, message?: string): void; - - - /** - * This method asserts that a given T that extends Array has a value/reference included and - * compared via memory.compare(). - * - * @param {i32} expected - The expected item to be included in the Array. - * @param {string} message - The optional message the describes this expectation. - */ - toIncludeEqual(expected: U, message?: string): void; - - /** - * This computed property is chainable, and negates the existing expectation. It returns itself. - * - * @param {U} expected - The expected item. - * @param {string} message - The optional message the describes this expectation. - * @type {Expectation} - */ - not: Expectation; - - /** - * The actual value of the expectation. - */ - actual: T | null; - private _not: boolean; - } - - /** - * This is called to stop the debugger. e.g. `node --inspect-brk asp`. - */ - declare function debug(): void; - - /** - * This function call enables performance statistics gathering for the following test. - * - * @param {bool} enabled - The bool to indicate if performance statistics should be gathered. - */ - declare function performanceEnabled(enabled: bool): void; - - /** - * This function call sets the maximum number of samples to complete the following test. - * - * @param {f64} count - The maximum number of samples required. - */ - declare function maxSamples(count: f64): void; - - /** - * This function call sets the number of decimal places to round to for the following test. - * - * @param {i32} deicmalPlaces - The number of decimal places to round to - */ - declare function roundDecimalPlaces(count: i32): void; - - /** - * This function call will set the maximum amount of time that should pass before it can stop - * gathering samples for the following test. - * - * @param {f64} time - The ammount of time in milliseconds. - */ - declare function maxTestRunTime(time: f64): void; - - /** - * This function call enables gathering the average/mean run time of each sample for the following - * test. - * - * @param {bool} enabled - The bool to indicate if the average/mean should be gathered. - */ - declare function reportAverage(enabled: bool): void; - - /** - * This function call enables gathering the median run time of each sample for the following test. - * - * @param {bool} enabled - The bool to indicate if the median should be gathered. - */ - declare function reportMedian(value: bool): void; - - /** - * This function call enables gathering the standard deviation of the run times of the samples - * collected for the following test. - * - * @param {bool} enabled - The bool to indicate if the standard deviation should be gathered. - */ - declare function reportStdDev(value: bool): void; - - /** - * This function call enables gathering the largest run time of the samples collected for the - * following test. - * - * @param {bool} enabled - The bool to indicate if the max should be gathered. - */ - declare function reportMax(value: bool): void; - - /** - * This function call enables gathering the smallest run time of the samples collected for the - * following test. - * - * @param {bool} enabled - The bool to indicate if the min should be gathered. - */ - declare function reportMin(value: bool): void; - - /** - * This function call enables gathering the varaince of the samples collected for the following test. - * - * @param {bool} enabled - The bool to indicate if the variance should be calculated. - */ - declare function reportVariance(value: bool): void; - - /** - * This static class contains a few conveince methods for developers to test the current number of - * blocks allocated on the heap. - */ - declare class RTrace { - /** - * This bool indicates if `RTrace` should call into JavaScript to obtain reference counts. - */ - public static enabled: bool; - - /** - * This method returns the current number of active references on the heap. - */ - public static count(): i32; - - /** - * This method starts a new refcounting group, and causes the next call to `RTrace.end(label)` to - * return a delta in reference counts on the heap. - * - * @param {i32} label - The numeric label for this refcounting group. - */ - public static start(label: i32): void; - - /** - * This method returns a delta of how many new (positive) or collected (negative) are on the heap. - * - * @param {i32} label - The numeric label for this refcounting group. - */ - public static end(label: i32): i32; - - /** - * This method returns the number of increments that have occurred over the course of a test - * file. - */ - public static increments(): i32; - - /** - * This method returns the number of decrements that have occurred over the course of a test - * file. - */ - public static decrements(): i32; - - /** - * This method returns the number of increments that have occurred over the course of a test - * group. - */ - public static groupIncrements(): i32; - - /** - * This method returns the number of decrements that have occurred over the course of a test - * group. - */ - public static groupDecrements(): i32; - - /** - * This method returns the number of increments that have occurred over the course of a test - * group. - */ - public static testIncrements(): i32; - - /** - * This method returns the number of decrements that have occurred over the course of a test - * group. - */ - public static testDecrements(): i32; - - /** - * This method returns the number of allocations that have occurred over the course of a test - * file. - */ - public static allocations(): i32; - - /** - * This method returns the number of frees that have occurred over the course of a test - * file. - */ - public static frees(): i32; - - /** - * This method returns the number of allocations that have occurred over the course of a test - * group. - */ - public static groupAllocations(): i32; - - /** - * This method returns the number of frees that have occurred over the course of a test - * group. - */ - public static groupFrees(): i32; - - /** - * This method returns the number of allocations that have occurred over the course of a test - * group. - */ - public static testAllocations(): i32; - - /** - * This method returns the number of frees that have occurred over the course of a test - * group. - */ - public static testFrees(): i32; - - /** - * This method triggers a garbage collection. - */ - public static collect(): void; - } \ No newline at end of file +/// diff --git a/assembly/__tests__/roundtrip.spec.ts b/assembly/__tests__/roundtrip.spec.ts index 8b5bb07..4cec3a9 100644 --- a/assembly/__tests__/roundtrip.spec.ts +++ b/assembly/__tests__/roundtrip.spec.ts @@ -3,8 +3,7 @@ import { JSONEncoder } from "../encoder"; import { Buffer } from "../util"; import { JSON } from "../JSON"; - -function roundtripTest(jsonString: string, _expectedString: string = ""): void { +function roundtripTest(jsonString: string, _expectedString: string = ""): void { const expectedString = _expectedString == "" ? jsonString : _expectedString; let buffer: Uint8Array = Buffer.fromString(jsonString); let handler = new JSONEncoder(); @@ -25,7 +24,7 @@ describe("Round trip", () => { }); it("should handle empty object with whitespace", () => { - roundtripTest("{ }", "{}") + roundtripTest("{ }", "{}"); }); it("should handle int32", () => { @@ -54,10 +53,7 @@ describe("Round trip", () => { }); it("should handle string escaped", () => { - roundtripTest( - '"\\"\\\\\\/\\n\\t\\b\\r\\t"', - '"\\"\\\\/\\n\\t\\b\\r\\t"' - ); + roundtripTest('"\\"\\\\\\/\\n\\t\\b\\r\\t"', '"\\"\\\\/\\n\\t\\b\\r\\t"'); }); it("should handle string unicode escaped simple", () => { @@ -65,11 +61,10 @@ describe("Round trip", () => { }); it("should handle string unicode escaped", () => { - roundtripTest( + roundtripTest( '"\\u041f\\u043e\\u043b\\u0442\\u043e\\u0440\\u0430 \\u0417\\u0435\\u043c\\u043b\\u0435\\u043a\\u043e\\u043f\\u0430"', '"Полтора Землекопа"' ); - }); it("should multiple keys", () => { @@ -111,7 +106,7 @@ function parseToString(input: string): string { return JSON.parse(input).toString(); } -describe("JSON.parse", () => { +describe("JSON.parse", () => { beforeAll(() => { primObj = JSON.Value.Object(); primArr = JSON.from([42]); @@ -122,11 +117,15 @@ describe("JSON.parse", () => { describe("Primitive Values", () => { it("should handle numbers", () => { - expect((JSON.parse("123456789"))._num).toStrictEqual((JSON.from(123456789))._num); + expect((JSON.parse("123456789"))._num).toStrictEqual( + (JSON.from(123456789))._num + ); }); it("should handle strings", () => { - expect(parseToString("\"hello\"")).toStrictEqual(JSON.from("hello").toString()); + expect(parseToString('"hello"')).toStrictEqual( + JSON.from("hello").toString() + ); }); it("should handle booleans", () => { @@ -134,7 +133,7 @@ describe("JSON.parse", () => { expect(parseToString("false")).toStrictEqual(JSON.from(false).toString()); }); - //TODO: JSON.from(null) should equal JSON.NUll(); + // TODO: JSON.from(null) should equal JSON.NUll(); it("should handle null", () => { expect(parseToString("null")).toStrictEqual("null"); }); @@ -142,11 +141,12 @@ describe("JSON.parse", () => { describe("Arrays", () => { it("should handle empty ones", () => { - expect(parseToString("[]")).toStrictEqual(JSON.from([]).toString()); + expect(parseToString("[]")).toStrictEqual( + JSON.from([]).toString() + ); }); it("should handle non-empty ones", () => { - expect(parseToString("[42]")).toStrictEqual(primArr.toString()); }); @@ -156,7 +156,7 @@ describe("JSON.parse", () => { expect(parseToString("[[42]]")).toStrictEqual(outterArr.toString()); }); }); - + describe("Objects", () => { it("should handle empty objects", () => { expect(parseToString("{}")).toStrictEqual(JSON.Value.Object().toString()); @@ -168,7 +168,8 @@ describe("JSON.parse", () => { "number": 42, "boolean": true, "string": "Hello" - }`)).toStrictEqual(primObj.toString()); + }`) + ).toStrictEqual(primObj.toString()); }); it("should handle nested objects", () => { @@ -181,15 +182,14 @@ describe("JSON.parse", () => { "boolean": true, "string": "Hello" } - }`)).toStrictEqual(outerObj); + }`) + ).toStrictEqual(outerObj); }); - + it("should handle arrays", () => { const obj = JSON.Value.Object(); obj.set("arr", primArr); expect(parseToString('{"arr": [42]}')).toStrictEqual(obj.toString()); }); - }); - }); diff --git a/assembly/decoder.ts b/assembly/decoder.ts index 70b8c37..5926596 100644 --- a/assembly/decoder.ts +++ b/assembly/decoder.ts @@ -32,56 +32,62 @@ export abstract class JSONHandler { * to allow easier validation of input. */ export class ThrowingJSONHandler extends JSONHandler { - setString(name: string, value: string): void { - assert(false, 'Unexpected string field ' + name + ' : "' + value + '"'); - } + setString(name: string, value: string): void { + assert(false, "Unexpected string field " + name + ' : "' + value + '"'); + } - setBoolean(name: string, value: bool): void { - assert(false, 'Unexpected bool field ' + name + ' : ' + (value ? 'true' : 'false')); - } + setBoolean(name: string, value: bool): void { + assert( + false, + "Unexpected bool field " + name + " : " + (value ? "true" : "false") + ); + } - setNull(name: string): void { - assert(false, 'Unexpected null field ' + name); - } + setNull(name: string): void { + assert(false, "Unexpected null field " + name); + } - setInteger(name: string, value: i64): void { - //@ts-ignore integer does have toString - assert(false, 'Unexpected integer field ' + name + ' : ' + value.toString()); - } + setInteger(name: string, value: i64): void { + // @ts-ignore integer does have toString + assert( + false, + "Unexpected integer field " + name + " : " + value.toString() + ); + } - pushArray(name: string): bool { - assert(false, 'Unexpected array field ' + name); - return true; - } + pushArray(name: string): bool { + assert(false, "Unexpected array field " + name); + return true; + } - pushObject(name: string): bool { - assert(false, 'Unexpected object field ' + name); - return true; - } + pushObject(name: string): bool { + assert(false, "Unexpected object field " + name); + return true; + } } -//@ts-ignore: decorator +// @ts-ignore: decorator @lazy const TRUE_STR = "true"; -//@ts-ignore: decorator +// @ts-ignore: decorator @lazy const FALSE_STR = "false"; -//@ts-ignore: decorator +// @ts-ignore: decorator @lazy const NULL_STR = "null"; -//@ts-ignore: decorator -@lazy const CHAR_0: i32 = 48; //"0".charCodeAt(0); -//@ts-ignore: decorator -@lazy const CHAR_9: i32 = 57; //"9".charCodeAt(0); -//@ts-ignore: decorator -@lazy const CHAR_A: i32 = 65; //"A".charCodeAt(0); -//@ts-ignore: decorator -@lazy const CHAR_A_LOWER: i32 = 97; //"a".charCodeAt(0); +// @ts-ignore: decorator +@lazy const CHAR_0: i32 = 48; // "0".charCodeAt(0); +// @ts-ignore: decorator +@lazy const CHAR_9: i32 = 57; // "9".charCodeAt(0); +// @ts-ignore: decorator +@lazy const CHAR_A: i32 = 65; // "A".charCodeAt(0); +// @ts-ignore: decorator +@lazy const CHAR_A_LOWER: i32 = 97; // "a".charCodeAt(0); export class DecoderState { lastKey: string = ""; readIndex: i32 = 0; - constructor(public buffer: Uint8Array){} + constructor(public buffer: Uint8Array) {} get ptr(): usize { - return Buffer.getDataPtr(this.buffer); + return Buffer.getDataPtr(this.buffer); } readString(start: usize, end: usize = this.readIndex): string { @@ -94,7 +100,7 @@ export class JSONDecoder { _state: DecoderState | null = null; constructor(handler: JSONHandlerT) { - this.handler = handler; + this.handler = handler; } get state(): DecoderState { @@ -105,10 +111,13 @@ export class JSONDecoder { this._state = state; } - deserialize(buffer: Uint8Array, decoderState: DecoderState | null = null): void { - if (decoderState != null) { - this.state = decoderState; - } else { + deserialize( + buffer: Uint8Array, + decoderState: DecoderState | null = null + ): void { + if (decoderState != null) { + this.state = decoderState; + } else { this.state = new DecoderState(buffer); } @@ -121,31 +130,35 @@ export class JSONDecoder { return -1; } return this.state.buffer[this.state.readIndex]; - } + } - private readChar(): i32 { - assert(this.state.readIndex < this.state.buffer.length, "Unexpected input end"); - return this.state.buffer[this.state.readIndex++]; - } + private readChar(): i32 { + assert( + this.state.readIndex < this.state.buffer.length, + "Unexpected input end" + ); + return this.state.buffer[this.state.readIndex++]; + } - private parseValue(): bool { - this.skipWhitespace(); - let result = this.parseObject() - || this.parseArray() - || this.parseString() - || this.parseBoolean() - || this.parseNumber() - || this.parseNull() - this.skipWhitespace(); - return result; - } + private parseValue(): bool { + this.skipWhitespace(); + let result = + this.parseObject() || + this.parseArray() || + this.parseString() || + this.parseBoolean() || + this.parseNumber() || + this.parseNull(); + this.skipWhitespace(); + return result; + } private parseObject(): bool { if (this.peekChar() != "{".charCodeAt(0)) { return false; } let key = this.state.lastKey; - //@ts-ignore can be null + // @ts-ignore can be null this.state.lastKey = ""; if (this.handler.pushObject(key)) { this.readChar(); @@ -179,7 +192,7 @@ export class JSONDecoder { return false; } let key = this.state.lastKey; - //@ts-ignore can be null + // @ts-ignore can be null this.state.lastKey = ""; if (this.handler.pushArray(key)) { this.readChar(); @@ -206,12 +219,15 @@ export class JSONDecoder { } this.handler.setString(this.state.lastKey, this.readString()); return true; - } + } private readString(): string { - assert(this.readChar() == '"'.charCodeAt(0), "Expected double-quoted string"); + assert( + this.readChar() == '"'.charCodeAt(0), + "Expected double-quoted string" + ); let savedIndex = this.state.readIndex; - //@ts-ignore can be null + // @ts-ignore can be null let stringParts: Array = new Array(); for (;;) { let byte = this.readChar(); @@ -280,7 +296,6 @@ export class JSONDecoder { digit = byte - CHAR_A_LOWER + 10; } } - let arr: Array = [byte, digit]; assert(digit >= 0 && digit < 16, "Unexpected \\u digit"); return digit; } @@ -291,13 +306,13 @@ export class JSONDecoder { let sign: i64 = 1; if (this.peekChar() == "-".charCodeAt(0)) { sign = -1; - this.readChar(); - } - let digits = 0; - while (CHAR_0 <= this.peekChar() && this.peekChar() <= CHAR_9 ) { - let byte = this.readChar(); - number *= 10; - number += byte - CHAR_0; + this.readChar(); + } + let digits = 0; + while (CHAR_0 <= this.peekChar() && this.peekChar() <= CHAR_9) { + let byte = this.readChar(); + number *= 10; + number += byte - CHAR_0; digits++; } if (digits > 0) { @@ -341,9 +356,11 @@ export class JSONDecoder { while (this.isWhitespace(this.peekChar())) { this.readChar(); } - } + } - private isWhitespace(charCode: i32): bool { - return charCode == 0x9 || charCode == 0xa || charCode == 0xd || charCode == 0x20; - } + private isWhitespace(charCode: i32): bool { + return ( + charCode == 0x9 || charCode == 0xa || charCode == 0xd || charCode == 0x20 + ); + } } diff --git a/assembly/encoder.ts b/assembly/encoder.ts index f35306e..78eccc1 100644 --- a/assembly/encoder.ts +++ b/assembly/encoder.ts @@ -1,128 +1,129 @@ -import { Buffer } from './util/index'; -/// - +import { Buffer } from "./util/index"; export class JSONEncoder { - private _isFirstKey: i32[]; - private result: string[]; - - constructor() { - this._isFirstKey = new Array(10); - this.result = new Array(); - this._isFirstKey.push(1); - } - - get isFirstKey(): bool { - return this._isFirstKey[this._isFirstKey.length - 1]; - } - - serialize(): Uint8Array { - // TODO: Write directly to UTF8 bytes - return Buffer.fromString(this.toString()); - } - - toString(): string { - return this.result.join(""); - } - - setString(name: string | null, value: string): void { - this.writeKey(name); - this.writeString(value); - } - - setBoolean(name: string | null, value: bool): void { - this.writeKey(name); - this.writeBoolean(value); - } - - setNull(name: string | null): void { - this.writeKey(name); - this.write("null"); - } - - setInteger(name: string | null, value: i64): void { - this.writeKey(name); - this.writeInteger(value); - } - - pushArray(name: string | null): bool { - this.writeKey(name); - this.write("["); - this._isFirstKey.push(1); - return true; - } - - popArray(): void { - this.write("]"); - this._isFirstKey.pop(); - } - - pushObject(name: string | null): bool { - this.writeKey(name); - this.write("{"); - this._isFirstKey.push(1); - return true; - } - - popObject(): void { - this.write("}"); - this._isFirstKey.pop(); - } - - private writeKey(str: string | null): void { - if (!this.isFirstKey) { - this.write(","); + private _isFirstKey: i32[]; + private result: string[]; + + constructor() { + this._isFirstKey = new Array(10); + this.result = new Array(); + this._isFirstKey.push(1); + } + + get isFirstKey(): bool { + return this._isFirstKey[this._isFirstKey.length - 1]; + } + + serialize(): Uint8Array { + // TODO: Write directly to UTF8 bytes + return Buffer.fromString(this.toString()); + } + + toString(): string { + return this.result.join(""); + } + + setString(name: string | null, value: string): void { + this.writeKey(name); + this.writeString(value); + } + + setBoolean(name: string | null, value: bool): void { + this.writeKey(name); + this.writeBoolean(value); + } + + setNull(name: string | null): void { + this.writeKey(name); + this.write("null"); + } + + setInteger(name: string | null, value: i64): void { + this.writeKey(name); + this.writeInteger(value); + } + + pushArray(name: string | null): bool { + this.writeKey(name); + this.write("["); + this._isFirstKey.push(1); + return true; + } + + popArray(): void { + this.write("]"); + this._isFirstKey.pop(); + } + + pushObject(name: string | null): bool { + this.writeKey(name); + this.write("{"); + this._isFirstKey.push(1); + return true; + } + + popObject(): void { + this.write("}"); + this._isFirstKey.pop(); + } + + private writeKey(str: string | null): void { + if (!this.isFirstKey) { + this.write(","); + } else { + this._isFirstKey[this._isFirstKey.length - 1] = 0; + } + if (str != null && (str).length > 0) { + this.writeString(str!); + this.write(":"); + } + } + + private writeString(str: string): void { + this.write('"'); + let savedIndex = 0; + for (let i = 0; i < str.length; i++) { + let char = str.charCodeAt(i); + let needsEscaping = + char < 0x20 || char == '"'.charCodeAt(0) || char == "\\".charCodeAt(0); + if (needsEscaping) { + this.write(str.substring(savedIndex, i)); + savedIndex = i + 1; + if (char == '"'.charCodeAt(0)) { + this.write('\\"'); + } else if (char == "\\".charCodeAt(0)) { + this.write("\\\\"); + } else if (char == "\b".charCodeAt(0)) { + this.write("\\b"); + } else if (char == "\n".charCodeAt(0)) { + this.write("\\n"); + } else if (char == "\r".charCodeAt(0)) { + this.write("\\r"); + } else if (char == "\t".charCodeAt(0)) { + this.write("\\t"); } else { - this._isFirstKey[this._isFirstKey.length - 1] = 0; - } - if (str != null && (str).length > 0) { - this.writeString(str!); - this.write(":"); - } - } - - private writeString(str: string): void { - this.write('"'); - let savedIndex = 0; - for (let i = 0; i < str.length; i++) { - let char = str.charCodeAt(i); - let needsEscaping = char < 0x20 || char == '"'.charCodeAt(0) || char == '\\'.charCodeAt(0); - if (needsEscaping) { - this.write(str.substring(savedIndex, i)); - savedIndex = i + 1; - if (char == '"'.charCodeAt(0)) { - this.write('\\"'); - } else if (char == "\\".charCodeAt(0)) { - this.write("\\\\"); - } else if (char == "\b".charCodeAt(0)) { - this.write("\\b"); - } else if (char == "\n".charCodeAt(0)) { - this.write("\\n"); - } else if (char == "\r".charCodeAt(0)) { - this.write("\\r"); - } else if (char == "\t".charCodeAt(0)) { - this.write("\\t"); - } else { - // TODO: Implement encoding for other contol characters - //@ts-ignore integer does have toString - assert(false, "Unsupported control character code: " + char.toString()); - } - } + // TODO: Implement encoding for other contol characters + // @ts-ignore integer does have toString + assert( + false, + "Unsupported control character code: " + char.toString() + ); } - this.write(str.substring(savedIndex, str.length)); - this.write('"'); + } } + this.write(str.substring(savedIndex, str.length)); + this.write('"'); + } - private writeBoolean(value: bool): void { - this.write(value ? "true" : "false"); - } + private writeBoolean(value: bool): void { + this.write(value ? "true" : "false"); + } - private writeInteger(value: i64): void { - //@ts-ignore integer does have toString - this.write(value.toString()); - } + private writeInteger(value: i64): void { + this.write(value.toString()); + } - private write(str: string): void { - this.result.push(str); - } + private write(str: string): void { + this.result.push(str); + } } diff --git a/assembly/index.ts b/assembly/index.ts index c07ccec..ef3f570 100644 --- a/assembly/index.ts +++ b/assembly/index.ts @@ -1,3 +1,3 @@ export * from "./decoder"; export * from "./encoder"; -export * from "./JSON"; \ No newline at end of file +export * from "./JSON"; diff --git a/assembly/tsconfig.json b/assembly/tsconfig.json index 891cc23..798b474 100644 --- a/assembly/tsconfig.json +++ b/assembly/tsconfig.json @@ -1,6 +1,4 @@ { "extends": "assemblyscript/std/assembly.json", - "include": [ - "./**/*.ts" - ] + "include": ["./**/*.ts"] } diff --git a/assembly/util/index.ts b/assembly/util/index.ts index 3687264..989f33f 100644 --- a/assembly/util/index.ts +++ b/assembly/util/index.ts @@ -1,27 +1,31 @@ export namespace Buffer { - export function fromString(str: string): Uint8Array { - const buffer = String.UTF8.encode(str, false); + export function fromString(str: string): Uint8Array { + const buffer = String.UTF8.encode(str, false); - // Workaround for https://github.com/AssemblyScript/assemblyscript/issues/1066 - if (buffer.byteLength === 0) return new Uint8Array(0); + // Workaround for https://github.com/AssemblyScript/assemblyscript/issues/1066 + if (buffer.byteLength === 0) return new Uint8Array(0); - return Uint8Array.wrap(buffer); - } + return Uint8Array.wrap(buffer); + } - export function toString(arr: Uint8Array): string { - return String.UTF8.decode(arr.buffer, false); - } + export function toString(arr: Uint8Array): string { + return String.UTF8.decode(arr.buffer, false); + } - /** - * Returns a pointer to the start of the raw data (i.e. after the header) - * - * @see https://docs.assemblyscript.org/details/memory#internals - */ - export function getDataPtr(arr: Uint8Array): usize { - return changetype(arr.buffer) + arr.byteOffset; - } + /** + * Returns a pointer to the start of the raw data (i.e. after the header) + * + * @see https://docs.assemblyscript.org/details/memory#internals + */ + export function getDataPtr(arr: Uint8Array): usize { + return changetype(arr.buffer) + arr.byteOffset; + } - export function readString(arr: Uint8Array, start: usize, end: usize): string { - return String.UTF8.decodeUnsafe(getDataPtr(arr) + start, end - start); - } + export function readString( + arr: Uint8Array, + start: usize, + end: usize + ): string { + return String.UTF8.decodeUnsafe(getDataPtr(arr) + start, end - start); + } } diff --git a/index.js b/index.js index 298993c..a3a6e85 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,10 @@ const fs = require("fs"); -const compiled = new WebAssembly.Module(fs.readFileSync(__dirname + "/build/optimized.wasm")); +const compiled = new WebAssembly.Module( + fs.readFileSync(__dirname + "/build/optimized.wasm") +); const imports = { - //log: + //log: }; Object.defineProperty(module, "exports", { - get: () => new WebAssembly.Instance(compiled, imports).exports + get: () => new WebAssembly.Instance(compiled, imports).exports, }); diff --git a/package.json b/package.json index 9df0928..d8242d5 100644 --- a/package.json +++ b/package.json @@ -6,10 +6,22 @@ "asbuild:untouched": "asc assembly/index.ts -b build/untouched.wasm -t build/untouched.wat --sourceMap --validate --debug", "asbuild:optimized": "asc assembly/index.ts -b build/optimized.wasm -t build/optimized.wat --sourceMap --validate --optimize", "asbuild": "yarn asbuild:untouched && yarn asbuild:optimized", + "lint": "eslint --max-warnings 0 --ext ts \"assembly/**/*.ts\"", + "lint:fix": "yarn lint --fix", "test": "asp" }, + "husky": { + "hooks": { + "pre-commit": "yarn lint || (yarn lint --fix && exit 1)" + } + }, "devDependencies": { "@as-pect/cli": "^4.0.0", - "assemblyscript": "^0.15.0" + "@typescript-eslint/eslint-plugin": "^4.13.0", + "@typescript-eslint/parser": "^4.13.0", + "assemblyscript": "^0.15.0", + "eslint": "^7.17.0", + "husky": "^4.3.7", + "typescript": "^4.1.3" } } diff --git a/yarn.lock b/yarn.lock index 6a34b54..55aad6a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -52,36 +52,233 @@ diff "^4.0.2" nearley "^2.19.3" -"@types/color-name@^1.1.1": - version "1.1.1" - resolved "https://registry.yarnpkg.com/@types/color-name/-/color-name-1.1.1.tgz#1c1261bbeaa10a8055bbc5d8ab84b7b2afc846a0" - integrity sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ== +"@babel/code-frame@^7.0.0": + version "7.12.11" + resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.12.11.tgz#f4ad435aa263db935b8f10f2c552d23fb716a63f" + integrity sha512-Zt1yodBx1UcyiePMSkWnU4hPqhwq7hGi2nFL1LeA3EUl+q2LQx16MISgJ0+z7dnmgvP9QtIleuETGOiOH1RcIw== + dependencies: + "@babel/highlight" "^7.10.4" + +"@babel/helper-validator-identifier@^7.10.4": + version "7.12.11" + resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.12.11.tgz#c9a1f021917dcb5ccf0d4e453e399022981fc9ed" + integrity sha512-np/lG3uARFybkoHokJUmf1QfEvRVCPbmQeUQpKow5cQ3xWrV9i3rUHodKDJPQfTVX61qKi+UdYk8kik84n7XOw== + +"@babel/highlight@^7.10.4": + version "7.10.4" + resolved "https://registry.yarnpkg.com/@babel/highlight/-/highlight-7.10.4.tgz#7d1bdfd65753538fabe6c38596cdb76d9ac60143" + integrity sha512-i6rgnR/YgPEQzZZnbTHHuZdlE8qyoBNalD6F+q4vAFlcMEcqmkoG+mPqJYJCo63qPf74+Y1UZsl3l6f7/RIkmA== + dependencies: + "@babel/helper-validator-identifier" "^7.10.4" + chalk "^2.0.0" + js-tokens "^4.0.0" + +"@eslint/eslintrc@^0.2.2": + version "0.2.2" + resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-0.2.2.tgz#d01fc791e2fc33e88a29d6f3dc7e93d0cd784b76" + integrity sha512-EfB5OHNYp1F4px/LI/FEnGylop7nOqkQ1LRzCM0KccA2U8tvV8w01KBv37LbO7nW4H+YhKyo2LcJhRwjjV17QQ== + dependencies: + ajv "^6.12.4" + debug "^4.1.1" + espree "^7.3.0" + globals "^12.1.0" + ignore "^4.0.6" + import-fresh "^3.2.1" + js-yaml "^3.13.1" + lodash "^4.17.19" + minimatch "^3.0.4" + strip-json-comments "^3.1.1" + +"@nodelib/fs.scandir@2.1.4": + version "2.1.4" + resolved "https://registry.yarnpkg.com/@nodelib/fs.scandir/-/fs.scandir-2.1.4.tgz#d4b3549a5db5de2683e0c1071ab4f140904bbf69" + integrity sha512-33g3pMJk3bg5nXbL/+CY6I2eJDzZAni49PfJnL5fghPTggPvBd/pFNSgJsdAgWptuFu7qq/ERvOYFlhvsLTCKA== + dependencies: + "@nodelib/fs.stat" "2.0.4" + run-parallel "^1.1.9" + +"@nodelib/fs.stat@2.0.4", "@nodelib/fs.stat@^2.0.2": + version "2.0.4" + resolved "https://registry.yarnpkg.com/@nodelib/fs.stat/-/fs.stat-2.0.4.tgz#a3f2dd61bab43b8db8fa108a121cfffe4c676655" + integrity sha512-IYlHJA0clt2+Vg7bccq+TzRdJvv19c2INqBSsoOLp1je7xjtr7J26+WXR72MCdvU9q1qTzIWDfhMf+DRvQJK4Q== + +"@nodelib/fs.walk@^1.2.3": + version "1.2.6" + resolved "https://registry.yarnpkg.com/@nodelib/fs.walk/-/fs.walk-1.2.6.tgz#cce9396b30aa5afe9e3756608f5831adcb53d063" + integrity sha512-8Broas6vTtW4GIXTAHDoE32hnN2M5ykgCpWGbuXHQ15vEMqr23pB76e/GZcYsZCHALv50ktd24qhEyKr6wBtow== + dependencies: + "@nodelib/fs.scandir" "2.1.4" + fastq "^1.6.0" + +"@types/json-schema@^7.0.3": + version "7.0.6" + resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.6.tgz#f4c7ec43e81b319a9815115031709f26987891f0" + integrity sha512-3c+yGKvVP5Y9TYBEibGNR+kLtijnj7mYrXRg+WpFb2X9xm04g/DXYkfg4hmzJQosc9snFNUPkbYIhu+KAm6jJw== + +"@types/parse-json@^4.0.0": + version "4.0.0" + resolved "https://registry.yarnpkg.com/@types/parse-json/-/parse-json-4.0.0.tgz#2f8bb441434d163b35fb8ffdccd7138927ffb8c0" + integrity sha512-//oorEZjL6sbPcKUaCdIGlIUeH26mgzimjBB77G6XRgnDl/L5wOnpyBGRe/Mmf5CVW3PwEBE1NjiMZ/ssFh4wA== + +"@typescript-eslint/eslint-plugin@^4.13.0": + version "4.13.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-4.13.0.tgz#5f580ea520fa46442deb82c038460c3dd3524bb6" + integrity sha512-ygqDUm+BUPvrr0jrXqoteMqmIaZ/bixYOc3A4BRwzEPTZPi6E+n44rzNZWaB0YvtukgP+aoj0i/fyx7FkM2p1w== + dependencies: + "@typescript-eslint/experimental-utils" "4.13.0" + "@typescript-eslint/scope-manager" "4.13.0" + debug "^4.1.1" + functional-red-black-tree "^1.0.1" + lodash "^4.17.15" + regexpp "^3.0.0" + semver "^7.3.2" + tsutils "^3.17.1" + +"@typescript-eslint/experimental-utils@4.13.0": + version "4.13.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-4.13.0.tgz#9dc9ab375d65603b43d938a0786190a0c72be44e" + integrity sha512-/ZsuWmqagOzNkx30VWYV3MNB/Re/CGv/7EzlqZo5RegBN8tMuPaBgNK6vPBCQA8tcYrbsrTdbx3ixMRRKEEGVw== + dependencies: + "@types/json-schema" "^7.0.3" + "@typescript-eslint/scope-manager" "4.13.0" + "@typescript-eslint/types" "4.13.0" + "@typescript-eslint/typescript-estree" "4.13.0" + eslint-scope "^5.0.0" + eslint-utils "^2.0.0" + +"@typescript-eslint/parser@^4.13.0": + version "4.13.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-4.13.0.tgz#c413d640ea66120cfcc37f891e8cb3fd1c9d247d" + integrity sha512-KO0J5SRF08pMXzq9+abyHnaGQgUJZ3Z3ax+pmqz9vl81JxmTTOUfQmq7/4awVfq09b6C4owNlOgOwp61pYRBSg== + dependencies: + "@typescript-eslint/scope-manager" "4.13.0" + "@typescript-eslint/types" "4.13.0" + "@typescript-eslint/typescript-estree" "4.13.0" + debug "^4.1.1" -ansi-styles@^4.1.0: - version "4.2.1" - resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-4.2.1.tgz#90ae75c424d008d2624c5bf29ead3177ebfcf359" - integrity sha512-9VGjrMsG1vePxcSweQsN20KY/c4zN0h9fLjqAbwbPfahM3t+NL+M9HC8xeXG2I8pX5NoamTGNuomEUFI7fcUjA== +"@typescript-eslint/scope-manager@4.13.0": + version "4.13.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-4.13.0.tgz#5b45912a9aa26b29603d8fa28f5e09088b947141" + integrity sha512-UpK7YLG2JlTp/9G4CHe7GxOwd93RBf3aHO5L+pfjIrhtBvZjHKbMhBXTIQNkbz7HZ9XOe++yKrXutYm5KmjWgQ== + dependencies: + "@typescript-eslint/types" "4.13.0" + "@typescript-eslint/visitor-keys" "4.13.0" + +"@typescript-eslint/types@4.13.0": + version "4.13.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-4.13.0.tgz#6a7c6015a59a08fbd70daa8c83dfff86250502f8" + integrity sha512-/+aPaq163oX+ObOG00M0t9tKkOgdv9lq0IQv/y4SqGkAXmhFmCfgsELV7kOCTb2vVU5VOmVwXBXJTDr353C1rQ== + +"@typescript-eslint/typescript-estree@4.13.0": + version "4.13.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-4.13.0.tgz#cf6e2207c7d760f5dfd8d18051428fadfc37b45e" + integrity sha512-9A0/DFZZLlGXn5XA349dWQFwPZxcyYyCFX5X88nWs2uachRDwGeyPz46oTsm9ZJE66EALvEns1lvBwa4d9QxMg== + dependencies: + "@typescript-eslint/types" "4.13.0" + "@typescript-eslint/visitor-keys" "4.13.0" + debug "^4.1.1" + globby "^11.0.1" + is-glob "^4.0.1" + lodash "^4.17.15" + semver "^7.3.2" + tsutils "^3.17.1" + +"@typescript-eslint/visitor-keys@4.13.0": + version "4.13.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-4.13.0.tgz#9acb1772d3b3183182b6540d3734143dce9476fe" + integrity sha512-6RoxWK05PAibukE7jElqAtNMq+RWZyqJ6Q/GdIxaiUj2Ept8jh8+FUVlbq9WxMYxkmEOPvCE5cRSyupMpwW31g== + dependencies: + "@typescript-eslint/types" "4.13.0" + eslint-visitor-keys "^2.0.0" + +acorn-jsx@^5.3.1: + version "5.3.1" + resolved "https://registry.yarnpkg.com/acorn-jsx/-/acorn-jsx-5.3.1.tgz#fc8661e11b7ac1539c47dbfea2e72b3af34d267b" + integrity sha512-K0Ptm/47OKfQRpNQ2J/oIN/3QYiK6FwW+eJbILhsdxh2WTLdl+30o8aGdTbm5JbffpFFAg/g+zi1E+jvJha5ng== + +acorn@^7.4.0: + version "7.4.1" + resolved "https://registry.yarnpkg.com/acorn/-/acorn-7.4.1.tgz#feaed255973d2e77555b83dbc08851a6c63520fa" + integrity sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A== + +ajv@^6.10.0, ajv@^6.12.4: + version "6.12.6" + resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.12.6.tgz#baf5a62e802b07d977034586f8c3baf5adf26df4" + integrity sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g== + dependencies: + fast-deep-equal "^3.1.1" + fast-json-stable-stringify "^2.0.0" + json-schema-traverse "^0.4.1" + uri-js "^4.2.2" + +ajv@^7.0.2: + version "7.0.3" + resolved "https://registry.yarnpkg.com/ajv/-/ajv-7.0.3.tgz#13ae747eff125cafb230ac504b2406cf371eece2" + integrity sha512-R50QRlXSxqXcQP5SvKUrw8VZeypvo12i2IX0EeR5PiZ7bEKeHWgzgo264LDadUsCU42lTJVhFikTqJwNeH34gQ== + dependencies: + fast-deep-equal "^3.1.1" + json-schema-traverse "^1.0.0" + require-from-string "^2.0.2" + uri-js "^4.2.2" + +ansi-colors@^4.1.1: + version "4.1.1" + resolved "https://registry.yarnpkg.com/ansi-colors/-/ansi-colors-4.1.1.tgz#cbb9ae256bf750af1eab344f229aa27fe94ba348" + integrity sha512-JoX0apGbHaUJBNl6yF+p6JAFYZ666/hhCGKN5t9QFjbJQKUU/g8MNbFDbvfrgKXvI1QpZplPOnwIo99lX/AAmA== + +ansi-regex@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.0.tgz#388539f55179bf39339c81af30a654d69f87cb75" + integrity sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg== + +ansi-styles@^3.2.1: + version "3.2.1" + resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.2.1.tgz#41fbb20243e50b12be0f04b8dedbf07520ce841d" + integrity sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA== + dependencies: + color-convert "^1.9.0" + +ansi-styles@^4.0.0, ansi-styles@^4.1.0: + version "4.3.0" + resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-4.3.0.tgz#edd803628ae71c04c85ae7a0906edad34b648937" + integrity sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg== dependencies: - "@types/color-name" "^1.1.1" color-convert "^2.0.1" +argparse@^1.0.7: + version "1.0.10" + resolved "https://registry.yarnpkg.com/argparse/-/argparse-1.0.10.tgz#bcd6791ea5ae09725e17e5ad988134cd40b3d911" + integrity sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg== + dependencies: + sprintf-js "~1.0.2" + +array-union@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/array-union/-/array-union-2.1.0.tgz#b798420adbeb1de828d84acd8a2e23d3efe85e8d" + integrity sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw== + assemblyscript@^0.15.0: - version "0.15.0" - resolved "https://registry.yarnpkg.com/assemblyscript/-/assemblyscript-0.15.0.tgz#cc349f6255c841f6e8b8026646a502839c0238d2" - integrity sha512-pP10bt+Vum8r5pybvMYVl+xaddhwPaUZiibztxD7l60rcqtoOWF5o5XSAMzDx/WykT7FNnAkKflp0JFywarFOw== + version "0.15.2" + resolved "https://registry.yarnpkg.com/assemblyscript/-/assemblyscript-0.15.2.tgz#601ee527d8baeeb76b21a36511e6a07505b7ecee" + integrity sha512-o4tjNWzE1i1d38Ga8uXQLJoO6wuz+WKL45Vg8uWZcfrbAO+K9pfjBGg+XveBU9lqjxQ/ScaX7V9k2LXnuokpmw== dependencies: - binaryen "97.0.0-nightly.20201006" + binaryen "97.0.0-nightly.20201008" long "^4.0.0" +astral-regex@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/astral-regex/-/astral-regex-2.0.0.tgz#483143c567aeed4785759c0865786dc77d7d2e31" + integrity sha512-Z7tMw1ytTXt5jqMcOP+OQteU1VuNK9Y02uuJtKQ1Sv69jXQKKg5cibLwGJow8yzZP+eAc18EmLGPal0bp36rvQ== + balanced-match@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767" integrity sha1-ibTRmasr7kneFk6gK4nORi1xt2c= -binaryen@97.0.0-nightly.20201006: - version "97.0.0-nightly.20201006" - resolved "https://registry.yarnpkg.com/binaryen/-/binaryen-97.0.0-nightly.20201006.tgz#725d39c7445d10a04674c9f2978099c6fc882b48" - integrity sha512-/xZwg4pDUQYg8BIn1F6OypJGwADNTIEDm48O5KuSE250bPj1tGCvAinYmm2JAoiio7DovTkwb5I3w0G+CvG8Jg== +binaryen@97.0.0-nightly.20201008: + version "97.0.0-nightly.20201008" + resolved "https://registry.yarnpkg.com/binaryen/-/binaryen-97.0.0-nightly.20201008.tgz#b9dc6fa3b92b764b66956d079190b48d2e22065f" + integrity sha512-GWV30FOQqz+vBIZRbc7GSasLNhh8BNLKH+2u2j5BjqM0WOEqqaP5iSj0mq72We2aVYqpBajJPI/CORY6o2RBxA== brace-expansion@^1.1.7: version "1.1.11" @@ -91,7 +288,28 @@ brace-expansion@^1.1.7: balanced-match "^1.0.0" concat-map "0.0.1" -chalk@^4.1.0: +braces@^3.0.1: + version "3.0.2" + resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.2.tgz#3454e1a462ee8d599e236df336cd9ea4f8afe107" + integrity sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A== + dependencies: + fill-range "^7.0.1" + +callsites@^3.0.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/callsites/-/callsites-3.1.0.tgz#b3630abd8943432f54b3f0519238e33cd7df2f73" + integrity sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ== + +chalk@^2.0.0: + version "2.4.2" + resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424" + integrity sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ== + dependencies: + ansi-styles "^3.2.1" + escape-string-regexp "^1.0.5" + supports-color "^5.3.0" + +chalk@^4.0.0, chalk@^4.1.0: version "4.1.0" resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.0.tgz#4e14870a618d9e2edd97dd8345fd9d9dc315646a" integrity sha512-qwx12AxXe2Q5xQ43Ac//I6v5aXTipYrSESdOgzrN+9XjgEpyjpKuvSGaN4qE93f7TQTlerQQ8S+EQ0EyDoVL1A== @@ -99,6 +317,18 @@ chalk@^4.1.0: ansi-styles "^4.1.0" supports-color "^7.1.0" +ci-info@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-2.0.0.tgz#67a9e964be31a51e15e5010d58e6f12834002f46" + integrity sha512-5tK7EtrZ0N+OLFMthtqOj4fI2Jeb88C4CAZPu25LDVUgXJ0A3Js4PMGqrn0JU1W0Mh1/Z8wZzYPxqUrXeBboCQ== + +color-convert@^1.9.0: + version "1.9.3" + resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-1.9.3.tgz#bb71850690e1f136567de629d2d5471deda4c1e8" + integrity sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg== + dependencies: + color-name "1.1.3" + color-convert@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-2.0.1.tgz#72d3a68d598c9bdb3af2ad1e84f21d896abd4de3" @@ -106,6 +336,11 @@ color-convert@^2.0.1: dependencies: color-name "~1.1.4" +color-name@1.1.3: + version "1.1.3" + resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.3.tgz#a7d0558bd89c42f795dd42328f740831ca53bc25" + integrity sha1-p9BVi9icQveV3UIyj3QIMcpTvCU= + color-name@~1.1.4: version "1.1.4" resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2" @@ -116,27 +351,301 @@ commander@^2.19.0: resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33" integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ== +compare-versions@^3.6.0: + version "3.6.0" + resolved "https://registry.yarnpkg.com/compare-versions/-/compare-versions-3.6.0.tgz#1a5689913685e5a87637b8d3ffca75514ec41d62" + integrity sha512-W6Af2Iw1z4CB7q4uU4hv646dW9GQuBM+YpC0UvUCWSD8w90SJjp+ujJuXaEMtAXBtSqGfMPuFOVn4/+FlaqfBA== + concat-map@0.0.1: version "0.0.1" resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" integrity sha1-2Klr13/Wjfd5OnMDajug1UBdR3s= +cosmiconfig@^7.0.0: + version "7.0.0" + resolved "https://registry.yarnpkg.com/cosmiconfig/-/cosmiconfig-7.0.0.tgz#ef9b44d773959cae63ddecd122de23853b60f8d3" + integrity sha512-pondGvTuVYDk++upghXJabWzL6Kxu6f26ljFw64Swq9v6sQPUL3EUlVDV56diOjpCayKihL6hVe8exIACU4XcA== + dependencies: + "@types/parse-json" "^4.0.0" + import-fresh "^3.2.1" + parse-json "^5.0.0" + path-type "^4.0.0" + yaml "^1.10.0" + +cross-spawn@^7.0.2: + version "7.0.3" + resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6" + integrity sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w== + dependencies: + path-key "^3.1.0" + shebang-command "^2.0.0" + which "^2.0.1" + +debug@^4.0.1, debug@^4.1.1: + version "4.3.1" + resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.1.tgz#f0d229c505e0c6d8c49ac553d1b13dc183f6b2ee" + integrity sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ== + dependencies: + ms "2.1.2" + +deep-is@^0.1.3: + version "0.1.3" + resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.3.tgz#b369d6fb5dbc13eecf524f91b070feedc357cf34" + integrity sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ= + diff@^4.0.2: version "4.0.2" resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d" integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A== +dir-glob@^3.0.1: + version "3.0.1" + resolved "https://registry.yarnpkg.com/dir-glob/-/dir-glob-3.0.1.tgz#56dbf73d992a4a93ba1584f4534063fd2e41717f" + integrity sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA== + dependencies: + path-type "^4.0.0" + discontinuous-range@1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/discontinuous-range/-/discontinuous-range-1.0.0.tgz#e38331f0844bba49b9a9cb71c771585aab1bc65a" integrity sha1-44Mx8IRLukm5qctxx3FYWqsbxlo= +doctrine@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/doctrine/-/doctrine-3.0.0.tgz#addebead72a6574db783639dc87a121773973961" + integrity sha512-yS+Q5i3hBf7GBkd4KG8a7eBNNWNGLTaEwwYWUijIYM7zrlYDM0BFXHjjPWlWZ1Rg7UaddZeIDmi9jF3HmqiQ2w== + dependencies: + esutils "^2.0.2" + +emoji-regex@^8.0.0: + version "8.0.0" + resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-8.0.0.tgz#e818fd69ce5ccfcb404594f842963bf53164cc37" + integrity sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A== + +enquirer@^2.3.5: + version "2.3.6" + resolved "https://registry.yarnpkg.com/enquirer/-/enquirer-2.3.6.tgz#2a7fe5dd634a1e4125a975ec994ff5456dc3734d" + integrity sha512-yjNnPr315/FjS4zIsUxYguYUPP2e1NK4d7E7ZOLiyYCcbFBiTMyID+2wvm2w6+pZ/odMA7cRkjhsPbltwBOrLg== + dependencies: + ansi-colors "^4.1.1" + +error-ex@^1.3.1: + version "1.3.2" + resolved "https://registry.yarnpkg.com/error-ex/-/error-ex-1.3.2.tgz#b4ac40648107fdcdcfae242f428bea8a14d4f1bf" + integrity sha512-7dFHNmqeFSEt2ZBsCriorKnn3Z2pj+fd9kmI6QoWw4//DL+icEBfc0U7qJCisqrTsKTjw4fNFy2pW9OqStD84g== + dependencies: + is-arrayish "^0.2.1" + +escape-string-regexp@^1.0.5: + version "1.0.5" + resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" + integrity sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ= + +eslint-scope@^5.0.0, eslint-scope@^5.1.1: + version "5.1.1" + resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-5.1.1.tgz#e786e59a66cb92b3f6c1fb0d508aab174848f48c" + integrity sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw== + dependencies: + esrecurse "^4.3.0" + estraverse "^4.1.1" + +eslint-utils@^2.0.0, eslint-utils@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/eslint-utils/-/eslint-utils-2.1.0.tgz#d2de5e03424e707dc10c74068ddedae708741b27" + integrity sha512-w94dQYoauyvlDc43XnGB8lU3Zt713vNChgt4EWwhXAP2XkBvndfxF0AgIqKOOasjPIPzj9JqgwkwbCYD0/V3Zg== + dependencies: + eslint-visitor-keys "^1.1.0" + +eslint-visitor-keys@^1.1.0, eslint-visitor-keys@^1.3.0: + version "1.3.0" + resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.3.0.tgz#30ebd1ef7c2fdff01c3a4f151044af25fab0523e" + integrity sha512-6J72N8UNa462wa/KFODt/PJ3IU60SDpC3QXC1Hjc1BXXpfL2C9R5+AU7jhe0F6GREqVMh4Juu+NY7xn+6dipUQ== + +eslint-visitor-keys@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-2.0.0.tgz#21fdc8fbcd9c795cc0321f0563702095751511a8" + integrity sha512-QudtT6av5WXels9WjIM7qz1XD1cWGvX4gGXvp/zBn9nXG02D0utdU3Em2m/QjTnrsk6bBjmCygl3rmj118msQQ== + +eslint@^7.17.0: + version "7.17.0" + resolved "https://registry.yarnpkg.com/eslint/-/eslint-7.17.0.tgz#4ccda5bf12572ad3bf760e6f195886f50569adb0" + integrity sha512-zJk08MiBgwuGoxes5sSQhOtibZ75pz0J35XTRlZOk9xMffhpA9BTbQZxoXZzOl5zMbleShbGwtw+1kGferfFwQ== + dependencies: + "@babel/code-frame" "^7.0.0" + "@eslint/eslintrc" "^0.2.2" + ajv "^6.10.0" + chalk "^4.0.0" + cross-spawn "^7.0.2" + debug "^4.0.1" + doctrine "^3.0.0" + enquirer "^2.3.5" + eslint-scope "^5.1.1" + eslint-utils "^2.1.0" + eslint-visitor-keys "^2.0.0" + espree "^7.3.1" + esquery "^1.2.0" + esutils "^2.0.2" + file-entry-cache "^6.0.0" + functional-red-black-tree "^1.0.1" + glob-parent "^5.0.0" + globals "^12.1.0" + ignore "^4.0.6" + import-fresh "^3.0.0" + imurmurhash "^0.1.4" + is-glob "^4.0.0" + js-yaml "^3.13.1" + json-stable-stringify-without-jsonify "^1.0.1" + levn "^0.4.1" + lodash "^4.17.19" + minimatch "^3.0.4" + natural-compare "^1.4.0" + optionator "^0.9.1" + progress "^2.0.0" + regexpp "^3.1.0" + semver "^7.2.1" + strip-ansi "^6.0.0" + strip-json-comments "^3.1.0" + table "^6.0.4" + text-table "^0.2.0" + v8-compile-cache "^2.0.3" + +espree@^7.3.0, espree@^7.3.1: + version "7.3.1" + resolved "https://registry.yarnpkg.com/espree/-/espree-7.3.1.tgz#f2df330b752c6f55019f8bd89b7660039c1bbbb6" + integrity sha512-v3JCNCE64umkFpmkFGqzVKsOT0tN1Zr+ueqLZfpV1Ob8e+CEgPWa+OxCoGH3tnhimMKIaBm4m/vaRpJ/krRz2g== + dependencies: + acorn "^7.4.0" + acorn-jsx "^5.3.1" + eslint-visitor-keys "^1.3.0" + +esprima@^4.0.0: + version "4.0.1" + resolved "https://registry.yarnpkg.com/esprima/-/esprima-4.0.1.tgz#13b04cdb3e6c5d19df91ab6987a8695619b0aa71" + integrity sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A== + +esquery@^1.2.0: + version "1.3.1" + resolved "https://registry.yarnpkg.com/esquery/-/esquery-1.3.1.tgz#b78b5828aa8e214e29fb74c4d5b752e1c033da57" + integrity sha512-olpvt9QG0vniUBZspVRN6lwB7hOZoTRtT+jzR+tS4ffYx2mzbw+z0XCOk44aaLYKApNX5nMm+E+P6o25ip/DHQ== + dependencies: + estraverse "^5.1.0" + +esrecurse@^4.3.0: + version "4.3.0" + resolved "https://registry.yarnpkg.com/esrecurse/-/esrecurse-4.3.0.tgz#7ad7964d679abb28bee72cec63758b1c5d2c9921" + integrity sha512-KmfKL3b6G+RXvP8N1vr3Tq1kL/oCFgn2NYXEtqP8/L3pKapUA4G8cFVaoF3SU323CD4XypR/ffioHmkti6/Tag== + dependencies: + estraverse "^5.2.0" + +estraverse@^4.1.1: + version "4.3.0" + resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-4.3.0.tgz#398ad3f3c5a24948be7725e83d11a7de28cdbd1d" + integrity sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw== + +estraverse@^5.1.0, estraverse@^5.2.0: + version "5.2.0" + resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-5.2.0.tgz#307df42547e6cc7324d3cf03c155d5cdb8c53880" + integrity sha512-BxbNGGNm0RyRYvUdHpIwv9IWzeM9XClbOxwoATuFdOE7ZE6wHL+HQ5T8hoPM+zHvmKzzsEqhgy0GrQ5X13afiQ== + +esutils@^2.0.2: + version "2.0.3" + resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.3.tgz#74d2eb4de0b8da1293711910d50775b9b710ef64" + integrity sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g== + +fast-deep-equal@^3.1.1: + version "3.1.3" + resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz#3a7d56b559d6cbc3eb512325244e619a65c6c525" + integrity sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q== + +fast-glob@^3.1.1: + version "3.2.4" + resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.2.4.tgz#d20aefbf99579383e7f3cc66529158c9b98554d3" + integrity sha512-kr/Oo6PX51265qeuCYsyGypiO5uJFgBS0jksyG7FUeCyQzNwYnzrNIMR1NXfkZXsMYXYLRAHgISHBz8gQcxKHQ== + dependencies: + "@nodelib/fs.stat" "^2.0.2" + "@nodelib/fs.walk" "^1.2.3" + glob-parent "^5.1.0" + merge2 "^1.3.0" + micromatch "^4.0.2" + picomatch "^2.2.1" + +fast-json-stable-stringify@^2.0.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz#874bf69c6f404c2b5d99c481341399fd55892633" + integrity sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw== + +fast-levenshtein@^2.0.6: + version "2.0.6" + resolved "https://registry.yarnpkg.com/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz#3d8a5c66883a16a30ca8643e851f19baa7797917" + integrity sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc= + +fastq@^1.6.0: + version "1.10.0" + resolved "https://registry.yarnpkg.com/fastq/-/fastq-1.10.0.tgz#74dbefccade964932cdf500473ef302719c652bb" + integrity sha512-NL2Qc5L3iQEsyYzweq7qfgy5OtXCmGzGvhElGEd/SoFWEMOEczNh5s5ocaF01HDetxz+p8ecjNPA6cZxxIHmzA== + dependencies: + reusify "^1.0.4" + +file-entry-cache@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/file-entry-cache/-/file-entry-cache-6.0.0.tgz#7921a89c391c6d93efec2169ac6bf300c527ea0a" + integrity sha512-fqoO76jZ3ZnYrXLDRxBR1YvOvc0k844kcOg40bgsPrE25LAb/PDqTY+ho64Xh2c8ZXgIKldchCFHczG2UVRcWA== + dependencies: + flat-cache "^3.0.4" + +fill-range@^7.0.1: + version "7.0.1" + resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-7.0.1.tgz#1919a6a7c75fe38b2c7c77e5198535da9acdda40" + integrity sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ== + dependencies: + to-regex-range "^5.0.1" + +find-up@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/find-up/-/find-up-5.0.0.tgz#4c92819ecb7083561e4f4a240a86be5198f536fc" + integrity sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng== + dependencies: + locate-path "^6.0.0" + path-exists "^4.0.0" + +find-versions@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/find-versions/-/find-versions-4.0.0.tgz#3c57e573bf97769b8cb8df16934b627915da4965" + integrity sha512-wgpWy002tA+wgmO27buH/9KzyEOQnKsG/R0yrcjPT9BOFm0zRBVQbZ95nRGXWMywS8YR5knRbpohio0bcJABxQ== + dependencies: + semver-regex "^3.1.2" + +flat-cache@^3.0.4: + version "3.0.4" + resolved "https://registry.yarnpkg.com/flat-cache/-/flat-cache-3.0.4.tgz#61b0338302b2fe9f957dcc32fc2a87f1c3048b11" + integrity sha512-dm9s5Pw7Jc0GvMYbshN6zchCA9RgQlzzEZX3vylR9IqFfS8XciblUXOKfW6SiuJ0e13eDYZoZV5wdrev7P3Nwg== + dependencies: + flatted "^3.1.0" + rimraf "^3.0.2" + +flatted@^3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.1.0.tgz#a5d06b4a8b01e3a63771daa5cb7a1903e2e57067" + integrity sha512-tW+UkmtNg/jv9CSofAKvgVcO7c2URjhTdW1ZTkcAritblu8tajiYy7YisnIflEwtKssCtOxpnBRoCB7iap0/TA== + fs.realpath@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" integrity sha1-FQStJSMVjKpA20onh8sBQRmU6k8= -glob@^7.1.6: +functional-red-black-tree@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz#1b0ab3bd553b2a0d6399d29c0e3ea0b252078327" + integrity sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc= + +glob-parent@^5.0.0, glob-parent@^5.1.0: + version "5.1.1" + resolved "https://registry.yarnpkg.com/glob-parent/-/glob-parent-5.1.1.tgz#b6c1ef417c4e5663ea498f1c45afac6916bbc229" + integrity sha512-FnI+VGOpnlGHWZxthPGR+QhR78fuiK0sNLkHQv+bL9fQi57lNNdquIbna/WrfROrolq8GK5Ek6BiMwqL/voRYQ== + dependencies: + is-glob "^4.0.1" + +glob@^7.1.3, glob@^7.1.6: version "7.1.6" resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.6.tgz#141f33b81a7c2492e125594307480c46679278a6" integrity sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA== @@ -148,11 +657,74 @@ glob@^7.1.6: once "^1.3.0" path-is-absolute "^1.0.0" +globals@^12.1.0: + version "12.4.0" + resolved "https://registry.yarnpkg.com/globals/-/globals-12.4.0.tgz#a18813576a41b00a24a97e7f815918c2e19925f8" + integrity sha512-BWICuzzDvDoH54NHKCseDanAhE3CeDorgDL5MT6LMXXj2WCnd9UC2szdk4AWLfjdgNBCXLUanXYcpBBKOSWGwg== + dependencies: + type-fest "^0.8.1" + +globby@^11.0.1: + version "11.0.2" + resolved "https://registry.yarnpkg.com/globby/-/globby-11.0.2.tgz#1af538b766a3b540ebfb58a32b2e2d5897321d83" + integrity sha512-2ZThXDvvV8fYFRVIxnrMQBipZQDr7MxKAmQK1vujaj9/7eF0efG7BPUKJ7jP7G5SLF37xKDXvO4S/KKLj/Z0og== + dependencies: + array-union "^2.1.0" + dir-glob "^3.0.1" + fast-glob "^3.1.1" + ignore "^5.1.4" + merge2 "^1.3.0" + slash "^3.0.0" + +has-flag@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-3.0.0.tgz#b5d454dc2199ae225699f3467e5a07f3b955bafd" + integrity sha1-tdRU3CGZriJWmfNGfloH87lVuv0= + has-flag@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-4.0.0.tgz#944771fd9c81c81265c4d6941860da06bb59479b" integrity sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ== +husky@^4.3.7: + version "4.3.7" + resolved "https://registry.yarnpkg.com/husky/-/husky-4.3.7.tgz#ca47bbe6213c1aa8b16bbd504530d9600de91e88" + integrity sha512-0fQlcCDq/xypoyYSJvEuzbDPHFf8ZF9IXKJxlrnvxABTSzK1VPT2RKYQKrcgJ+YD39swgoB6sbzywUqFxUiqjw== + dependencies: + chalk "^4.0.0" + ci-info "^2.0.0" + compare-versions "^3.6.0" + cosmiconfig "^7.0.0" + find-versions "^4.0.0" + opencollective-postinstall "^2.0.2" + pkg-dir "^5.0.0" + please-upgrade-node "^3.2.0" + slash "^3.0.0" + which-pm-runs "^1.0.0" + +ignore@^4.0.6: + version "4.0.6" + resolved "https://registry.yarnpkg.com/ignore/-/ignore-4.0.6.tgz#750e3db5862087b4737ebac8207ffd1ef27b25fc" + integrity sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg== + +ignore@^5.1.4: + version "5.1.8" + resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.1.8.tgz#f150a8b50a34289b33e22f5889abd4d8016f0e57" + integrity sha512-BMpfD7PpiETpBl/A6S498BaIJ6Y/ABT93ETbby2fP00v4EbvPBXWEoaR1UBPKs3iR53pJY7EtZk5KACI57i1Uw== + +import-fresh@^3.0.0, import-fresh@^3.2.1: + version "3.3.0" + resolved "https://registry.yarnpkg.com/import-fresh/-/import-fresh-3.3.0.tgz#37162c25fcb9ebaa2e6e53d5b4d88ce17d9e0c2b" + integrity sha512-veYYhQa+D1QBKznvhUHxb8faxlrwUnxseDAbAp457E0wLNio2bOSKnjYDhMj+YiAq61xrMGhQk9iXVk5FzgQMw== + dependencies: + parent-module "^1.0.0" + resolve-from "^4.0.0" + +imurmurhash@^0.1.4: + version "0.1.4" + resolved "https://registry.yarnpkg.com/imurmurhash/-/imurmurhash-0.1.4.tgz#9218b9b2b928a238b13dc4fb6b6d576f231453ea" + integrity sha1-khi5srkoojixPcT7a21XbyMUU+o= + inflight@^1.0.4: version "1.0.6" resolved "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9" @@ -166,11 +738,121 @@ inherits@2: resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c" integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== +is-arrayish@^0.2.1: + version "0.2.1" + resolved "https://registry.yarnpkg.com/is-arrayish/-/is-arrayish-0.2.1.tgz#77c99840527aa8ecb1a8ba697b80645a7a926a9d" + integrity sha1-d8mYQFJ6qOyxqLppe4BkWnqSap0= + +is-extglob@^2.1.1: + version "2.1.1" + resolved "https://registry.yarnpkg.com/is-extglob/-/is-extglob-2.1.1.tgz#a88c02535791f02ed37c76a1b9ea9773c833f8c2" + integrity sha1-qIwCU1eR8C7TfHahueqXc8gz+MI= + +is-fullwidth-code-point@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz#f116f8064fe90b3f7844a38997c0b75051269f1d" + integrity sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg== + +is-glob@^4.0.0, is-glob@^4.0.1: + version "4.0.1" + resolved "https://registry.yarnpkg.com/is-glob/-/is-glob-4.0.1.tgz#7567dbe9f2f5e2467bc77ab83c4a29482407a5dc" + integrity sha512-5G0tKtBTFImOqDnLB2hG6Bp2qcKEFduo4tZu9MT/H6NQv/ghhy30o55ufafxJ/LdH79LLs2Kfrn85TLKyA7BUg== + dependencies: + is-extglob "^2.1.1" + +is-number@^7.0.0: + version "7.0.0" + resolved "https://registry.yarnpkg.com/is-number/-/is-number-7.0.0.tgz#7535345b896734d5f80c4d06c50955527a14f12b" + integrity sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng== + +isexe@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10" + integrity sha1-6PvzdNxVb/iUehDcsFctYz8s+hA= + +js-tokens@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499" + integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ== + +js-yaml@^3.13.1: + version "3.14.1" + resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.14.1.tgz#dae812fdb3825fa306609a8717383c50c36a0537" + integrity sha512-okMH7OXXJ7YrN9Ok3/SXrnu4iX9yOk+25nqX4imS2npuvTYDmo/QEZoqwZkYaIDk3jVvBOTOIEgEhaLOynBS9g== + dependencies: + argparse "^1.0.7" + esprima "^4.0.0" + +json-parse-even-better-errors@^2.3.0: + version "2.3.1" + resolved "https://registry.yarnpkg.com/json-parse-even-better-errors/-/json-parse-even-better-errors-2.3.1.tgz#7c47805a94319928e05777405dc12e1f7a4ee02d" + integrity sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w== + +json-schema-traverse@^0.4.1: + version "0.4.1" + resolved "https://registry.yarnpkg.com/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz#69f6a87d9513ab8bb8fe63bdb0979c448e684660" + integrity sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg== + +json-schema-traverse@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz#ae7bcb3656ab77a73ba5c49bf654f38e6b6860e2" + integrity sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug== + +json-stable-stringify-without-jsonify@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz#9db7b59496ad3f3cfef30a75142d2d930ad72651" + integrity sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE= + +levn@^0.4.1: + version "0.4.1" + resolved "https://registry.yarnpkg.com/levn/-/levn-0.4.1.tgz#ae4562c007473b932a6200d403268dd2fffc6ade" + integrity sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ== + dependencies: + prelude-ls "^1.2.1" + type-check "~0.4.0" + +lines-and-columns@^1.1.6: + version "1.1.6" + resolved "https://registry.yarnpkg.com/lines-and-columns/-/lines-and-columns-1.1.6.tgz#1c00c743b433cd0a4e80758f7b64a57440d9ff00" + integrity sha1-HADHQ7QzzQpOgHWPe2SldEDZ/wA= + +locate-path@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-6.0.0.tgz#55321eb309febbc59c4801d931a72452a681d286" + integrity sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw== + dependencies: + p-locate "^5.0.0" + +lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.20: + version "4.17.20" + resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.20.tgz#b44a9b6297bcb698f1c51a3545a2b3b368d59c52" + integrity sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA== + long@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/long/-/long-4.0.0.tgz#9a7b71cfb7d361a194ea555241c92f7468d5bf28" integrity sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA== +lru-cache@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-6.0.0.tgz#6d6fe6570ebd96aaf90fcad1dafa3b2566db3a94" + integrity sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA== + dependencies: + yallist "^4.0.0" + +merge2@^1.3.0: + version "1.4.1" + resolved "https://registry.yarnpkg.com/merge2/-/merge2-1.4.1.tgz#4368892f885e907455a6fd7dc55c0c9d404990ae" + integrity sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg== + +micromatch@^4.0.2: + version "4.0.2" + resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-4.0.2.tgz#4fcb0999bf9fbc2fcbdd212f6d629b9a56c39259" + integrity sha512-y7FpHSbMUMoyPbYUSzO6PaZ6FyRnQOpHuKwbo1G+Knck95XVU4QAiKdGEnj5wwoS7PlOgthX/09u5iFJ+aYf5Q== + dependencies: + braces "^3.0.1" + picomatch "^2.0.5" + minimatch@^3.0.4: version "3.0.4" resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083" @@ -183,16 +865,25 @@ moo@^0.5.0: resolved "https://registry.yarnpkg.com/moo/-/moo-0.5.1.tgz#7aae7f384b9b09f620b6abf6f74ebbcd1b65dbc4" integrity sha512-I1mnb5xn4fO80BH9BLcF0yLypy2UKl+Cb01Fu0hJRkJjlCRtxZMWkTdAtDd5ZqCOxtCkhmRwyI57vWT+1iZ67w== +ms@2.1.2: + version "2.1.2" + resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009" + integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w== + +natural-compare@^1.4.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7" + integrity sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc= + nearley@^2.19.3: - version "2.19.4" - resolved "https://registry.yarnpkg.com/nearley/-/nearley-2.19.4.tgz#7518cbdd7d0e8e08b5f82841b9edb0126239c8b1" - integrity sha512-oqj3m4oqwKsN77pETa9IPvxHHHLW68KrDc2KYoWMUOhDlrNUo7finubwffQMBRnwNCOXc4kRxCZO0Rvx4L6Zrw== + version "2.20.1" + resolved "https://registry.yarnpkg.com/nearley/-/nearley-2.20.1.tgz#246cd33eff0d012faf197ff6774d7ac78acdd474" + integrity sha512-+Mc8UaAebFzgV+KpI5n7DasuuQCHA89dmwm7JXw3TV43ukfNQ9DnBH3Mdb2g/I4Fdxc26pwimBWvjIw0UAILSQ== dependencies: commander "^2.19.0" moo "^0.5.0" railroad-diagrams "^1.0.0" randexp "0.4.6" - semver "^5.4.1" once@^1.3.0: version "1.4.0" @@ -201,11 +892,108 @@ once@^1.3.0: dependencies: wrappy "1" +opencollective-postinstall@^2.0.2: + version "2.0.3" + resolved "https://registry.yarnpkg.com/opencollective-postinstall/-/opencollective-postinstall-2.0.3.tgz#7a0fff978f6dbfa4d006238fbac98ed4198c3259" + integrity sha512-8AV/sCtuzUeTo8gQK5qDZzARrulB3egtLzFgteqB2tcT4Mw7B8Kt7JcDHmltjz6FOAHsvTevk70gZEbhM4ZS9Q== + +optionator@^0.9.1: + version "0.9.1" + resolved "https://registry.yarnpkg.com/optionator/-/optionator-0.9.1.tgz#4f236a6373dae0566a6d43e1326674f50c291499" + integrity sha512-74RlY5FCnhq4jRxVUPKDaRwrVNXMqsGsiW6AJw4XK8hmtm10wC0ypZBLw5IIp85NZMr91+qd1RvvENwg7jjRFw== + dependencies: + deep-is "^0.1.3" + fast-levenshtein "^2.0.6" + levn "^0.4.1" + prelude-ls "^1.2.1" + type-check "^0.4.0" + word-wrap "^1.2.3" + +p-limit@^3.0.2: + version "3.1.0" + resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-3.1.0.tgz#e1daccbe78d0d1388ca18c64fea38e3e57e3706b" + integrity sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ== + dependencies: + yocto-queue "^0.1.0" + +p-locate@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/p-locate/-/p-locate-5.0.0.tgz#83c8315c6785005e3bd021839411c9e110e6d834" + integrity sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw== + dependencies: + p-limit "^3.0.2" + +parent-module@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/parent-module/-/parent-module-1.0.1.tgz#691d2709e78c79fae3a156622452d00762caaaa2" + integrity sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g== + dependencies: + callsites "^3.0.0" + +parse-json@^5.0.0: + version "5.1.0" + resolved "https://registry.yarnpkg.com/parse-json/-/parse-json-5.1.0.tgz#f96088cdf24a8faa9aea9a009f2d9d942c999646" + integrity sha512-+mi/lmVVNKFNVyLXV31ERiy2CY5E1/F6QtJFEzoChPRwwngMNXRDQ9GJ5WdE2Z2P4AujsOi0/+2qHID68KwfIQ== + dependencies: + "@babel/code-frame" "^7.0.0" + error-ex "^1.3.1" + json-parse-even-better-errors "^2.3.0" + lines-and-columns "^1.1.6" + +path-exists@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/path-exists/-/path-exists-4.0.0.tgz#513bdbe2d3b95d7762e8c1137efa195c6c61b5b3" + integrity sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w== + path-is-absolute@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f" integrity sha1-F0uSaHNVNP+8es5r9TpanhtcX18= +path-key@^3.1.0: + version "3.1.1" + resolved "https://registry.yarnpkg.com/path-key/-/path-key-3.1.1.tgz#581f6ade658cbba65a0d3380de7753295054f375" + integrity sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q== + +path-type@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/path-type/-/path-type-4.0.0.tgz#84ed01c0a7ba380afe09d90a8c180dcd9d03043b" + integrity sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw== + +picomatch@^2.0.5, picomatch@^2.2.1: + version "2.2.2" + resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.2.2.tgz#21f333e9b6b8eaff02468f5146ea406d345f4dad" + integrity sha512-q0M/9eZHzmr0AulXyPwNfZjtwZ/RBZlbN3K3CErVrk50T2ASYI7Bye0EvekFY3IP1Nt2DHu0re+V2ZHIpMkuWg== + +pkg-dir@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/pkg-dir/-/pkg-dir-5.0.0.tgz#a02d6aebe6ba133a928f74aec20bafdfe6b8e760" + integrity sha512-NPE8TDbzl/3YQYY7CSS228s3g2ollTFnc+Qi3tqmqJp9Vg2ovUpixcJEo2HJScN2Ez+kEaal6y70c0ehqJBJeA== + dependencies: + find-up "^5.0.0" + +please-upgrade-node@^3.2.0: + version "3.2.0" + resolved "https://registry.yarnpkg.com/please-upgrade-node/-/please-upgrade-node-3.2.0.tgz#aeddd3f994c933e4ad98b99d9a556efa0e2fe942" + integrity sha512-gQR3WpIgNIKwBMVLkpMUeR3e1/E1y42bqDQZfql+kDeXd8COYfM8PQA4X6y7a8u9Ua9FHmsrrmirW2vHs45hWg== + dependencies: + semver-compare "^1.0.0" + +prelude-ls@^1.2.1: + version "1.2.1" + resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.2.1.tgz#debc6489d7a6e6b0e7611888cec880337d316396" + integrity sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g== + +progress@^2.0.0: + version "2.0.3" + resolved "https://registry.yarnpkg.com/progress/-/progress-2.0.3.tgz#7e8cf8d8f5b8f239c1bc68beb4eb78567d572ef8" + integrity sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA== + +punycode@^2.1.0: + version "2.1.1" + resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.1.tgz#b58b010ac40c22c5657616c8d2c2c02c7bf479ec" + integrity sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A== + railroad-diagrams@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/railroad-diagrams/-/railroad-diagrams-1.0.0.tgz#eb7e6267548ddedfb899c1b90e57374559cddb7e" @@ -219,24 +1007,222 @@ randexp@0.4.6: discontinuous-range "1.0.0" ret "~0.1.10" +regexpp@^3.0.0, regexpp@^3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/regexpp/-/regexpp-3.1.0.tgz#206d0ad0a5648cffbdb8ae46438f3dc51c9f78e2" + integrity sha512-ZOIzd8yVsQQA7j8GCSlPGXwg5PfmA1mrq0JP4nGhh54LaKN3xdai/vHUDu74pKwV8OxseMS65u2NImosQcSD0Q== + +require-from-string@^2.0.2: + version "2.0.2" + resolved "https://registry.yarnpkg.com/require-from-string/-/require-from-string-2.0.2.tgz#89a7fdd938261267318eafe14f9c32e598c36909" + integrity sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw== + +resolve-from@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-4.0.0.tgz#4abcd852ad32dd7baabfe9b40e00a36db5f392e6" + integrity sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g== + ret@~0.1.10: version "0.1.15" resolved "https://registry.yarnpkg.com/ret/-/ret-0.1.15.tgz#b8a4825d5bdb1fc3f6f53c2bc33f81388681c7bc" integrity sha512-TTlYpa+OL+vMMNG24xSlQGEJ3B/RzEfUlLct7b5G/ytav+wPrplCpVMFuwzXbkecJrb6IYo1iFb0S9v37754mg== -semver@^5.4.1: - version "5.7.1" - resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7" - integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ== +reusify@^1.0.4: + version "1.0.4" + resolved "https://registry.yarnpkg.com/reusify/-/reusify-1.0.4.tgz#90da382b1e126efc02146e90845a88db12925d76" + integrity sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw== + +rimraf@^3.0.2: + version "3.0.2" + resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-3.0.2.tgz#f1a5402ba6220ad52cc1282bac1ae3aa49fd061a" + integrity sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA== + dependencies: + glob "^7.1.3" + +run-parallel@^1.1.9: + version "1.1.10" + resolved "https://registry.yarnpkg.com/run-parallel/-/run-parallel-1.1.10.tgz#60a51b2ae836636c81377df16cb107351bcd13ef" + integrity sha512-zb/1OuZ6flOlH6tQyMPUrE3x3Ulxjlo9WIVXR4yVYi4H9UXQaeIsPbLn2R3O3vQCnDKkAl2qHiuocKKX4Tz/Sw== + +semver-compare@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/semver-compare/-/semver-compare-1.0.0.tgz#0dee216a1c941ab37e9efb1788f6afc5ff5537fc" + integrity sha1-De4hahyUGrN+nvsXiPavxf9VN/w= + +semver-regex@^3.1.2: + version "3.1.2" + resolved "https://registry.yarnpkg.com/semver-regex/-/semver-regex-3.1.2.tgz#34b4c0d361eef262e07199dbef316d0f2ab11807" + integrity sha512-bXWyL6EAKOJa81XG1OZ/Yyuq+oT0b2YLlxx7c+mrdYPaPbnj6WgVULXhinMIeZGufuUBu/eVRqXEhiv4imfwxA== + +semver@^7.2.1, semver@^7.3.2: + version "7.3.4" + resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.4.tgz#27aaa7d2e4ca76452f98d3add093a72c943edc97" + integrity sha512-tCfb2WLjqFAtXn4KEdxIhalnRtoKFN7nAwj0B3ZXCbQloV2tq5eDbcTmT68JJD3nRJq24/XgxtQKFIpQdtvmVw== + dependencies: + lru-cache "^6.0.0" + +shebang-command@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/shebang-command/-/shebang-command-2.0.0.tgz#ccd0af4f8835fbdc265b82461aaf0c36663f34ea" + integrity sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA== + dependencies: + shebang-regex "^3.0.0" + +shebang-regex@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-3.0.0.tgz#ae16f1644d873ecad843b0307b143362d4c42172" + integrity sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A== + +slash@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/slash/-/slash-3.0.0.tgz#6539be870c165adbd5240220dbe361f1bc4d4634" + integrity sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q== + +slice-ansi@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/slice-ansi/-/slice-ansi-4.0.0.tgz#500e8dd0fd55b05815086255b3195adf2a45fe6b" + integrity sha512-qMCMfhY040cVHT43K9BFygqYbUPFZKHOg7K73mtTWJRb8pyP3fzf4Ixd5SzdEJQ6MRUg/WBnOLxghZtKKurENQ== + dependencies: + ansi-styles "^4.0.0" + astral-regex "^2.0.0" + is-fullwidth-code-point "^3.0.0" + +sprintf-js@~1.0.2: + version "1.0.3" + resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c" + integrity sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw= + +string-width@^4.2.0: + version "4.2.0" + resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.0.tgz#952182c46cc7b2c313d1596e623992bd163b72b5" + integrity sha512-zUz5JD+tgqtuDjMhwIg5uFVV3dtqZ9yQJlZVfq4I01/K5Paj5UHj7VyrQOJvzawSVlKpObApbfD0Ed6yJc+1eg== + dependencies: + emoji-regex "^8.0.0" + is-fullwidth-code-point "^3.0.0" + strip-ansi "^6.0.0" + +strip-ansi@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.0.tgz#0b1571dd7669ccd4f3e06e14ef1eed26225ae532" + integrity sha512-AuvKTrTfQNYNIctbR1K/YGTR1756GycPsg7b9bdV9Duqur4gv6aKqHXah67Z8ImS7WEz5QVcOtlfW2rZEugt6w== + dependencies: + ansi-regex "^5.0.0" + +strip-json-comments@^3.1.0, strip-json-comments@^3.1.1: + version "3.1.1" + resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-3.1.1.tgz#31f1281b3832630434831c310c01cccda8cbe006" + integrity sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig== + +supports-color@^5.3.0: + version "5.5.0" + resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-5.5.0.tgz#e2e69a44ac8772f78a1ec0b35b689df6530efc8f" + integrity sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow== + dependencies: + has-flag "^3.0.0" supports-color@^7.1.0: - version "7.1.0" - resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-7.1.0.tgz#68e32591df73e25ad1c4b49108a2ec507962bfd1" - integrity sha512-oRSIpR8pxT1Wr2FquTNnGet79b3BWljqOuoW/h4oBhxJ/HUbX5nX6JSruTkvXDCFMwDPvsaTTbvMLKZWSy0R5g== + version "7.2.0" + resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-7.2.0.tgz#1b7dcdcb32b8138801b3e478ba6a51caa89648da" + integrity sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw== dependencies: has-flag "^4.0.0" +table@^6.0.4: + version "6.0.7" + resolved "https://registry.yarnpkg.com/table/-/table-6.0.7.tgz#e45897ffbcc1bcf9e8a87bf420f2c9e5a7a52a34" + integrity sha512-rxZevLGTUzWna/qBLObOe16kB2RTnnbhciwgPbMMlazz1yZGVEgnZK762xyVdVznhqxrfCeBMmMkgOOaPwjH7g== + dependencies: + ajv "^7.0.2" + lodash "^4.17.20" + slice-ansi "^4.0.0" + string-width "^4.2.0" + +text-table@^0.2.0: + version "0.2.0" + resolved "https://registry.yarnpkg.com/text-table/-/text-table-0.2.0.tgz#7f5ee823ae805207c00af2df4a84ec3fcfa570b4" + integrity sha1-f17oI66AUgfACvLfSoTsP8+lcLQ= + +to-regex-range@^5.0.1: + version "5.0.1" + resolved "https://registry.yarnpkg.com/to-regex-range/-/to-regex-range-5.0.1.tgz#1648c44aae7c8d988a326018ed72f5b4dd0392e4" + integrity sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ== + dependencies: + is-number "^7.0.0" + +tslib@^1.8.1: + version "1.14.1" + resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00" + integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg== + +tsutils@^3.17.1: + version "3.19.1" + resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-3.19.1.tgz#d8566e0c51c82f32f9c25a4d367cd62409a547a9" + integrity sha512-GEdoBf5XI324lu7ycad7s6laADfnAqCw6wLGI+knxvw9vsIYBaJfYdmeCEG3FMMUiSm3OGgNb+m6utsWf5h9Vw== + dependencies: + tslib "^1.8.1" + +type-check@^0.4.0, type-check@~0.4.0: + version "0.4.0" + resolved "https://registry.yarnpkg.com/type-check/-/type-check-0.4.0.tgz#07b8203bfa7056c0657050e3ccd2c37730bab8f1" + integrity sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew== + dependencies: + prelude-ls "^1.2.1" + +type-fest@^0.8.1: + version "0.8.1" + resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.8.1.tgz#09e249ebde851d3b1e48d27c105444667f17b83d" + integrity sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA== + +typescript@^4.1.3: + version "4.1.3" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.1.3.tgz#519d582bd94cba0cf8934c7d8e8467e473f53bb7" + integrity sha512-B3ZIOf1IKeH2ixgHhj6la6xdwR9QrLC5d1VKeCSY4tvkqhF2eqd9O7txNlS0PO3GrBAFIdr3L1ndNwteUbZLYg== + +uri-js@^4.2.2: + version "4.4.1" + resolved "https://registry.yarnpkg.com/uri-js/-/uri-js-4.4.1.tgz#9b1a52595225859e55f669d928f88c6c57f2a77e" + integrity sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg== + dependencies: + punycode "^2.1.0" + +v8-compile-cache@^2.0.3: + version "2.2.0" + resolved "https://registry.yarnpkg.com/v8-compile-cache/-/v8-compile-cache-2.2.0.tgz#9471efa3ef9128d2f7c6a7ca39c4dd6b5055b132" + integrity sha512-gTpR5XQNKFwOd4clxfnhaqvfqMpqEwr4tOtCyz4MtYZX2JYhfr1JvBFKdS+7K/9rfpZR3VLX+YWBbKoxCgS43Q== + +which-pm-runs@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/which-pm-runs/-/which-pm-runs-1.0.0.tgz#670b3afbc552e0b55df6b7780ca74615f23ad1cb" + integrity sha1-Zws6+8VS4LVd9rd4DKdGFfI60cs= + +which@^2.0.1: + version "2.0.2" + resolved "https://registry.yarnpkg.com/which/-/which-2.0.2.tgz#7c6a8dd0a636a0327e10b59c9286eee93f3f51b1" + integrity sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA== + dependencies: + isexe "^2.0.0" + +word-wrap@^1.2.3: + version "1.2.3" + resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.3.tgz#610636f6b1f703891bd34771ccb17fb93b47079c" + integrity sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ== + wrappy@1: version "1.0.2" resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f" integrity sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8= + +yallist@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/yallist/-/yallist-4.0.0.tgz#9bb92790d9c0effec63be73519e11a35019a3a72" + integrity sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A== + +yaml@^1.10.0: + version "1.10.0" + resolved "https://registry.yarnpkg.com/yaml/-/yaml-1.10.0.tgz#3b593add944876077d4d683fee01081bd9fff31e" + integrity sha512-yr2icI4glYaNG+KWONODapy2/jDdMSDnrONSjblABjD9B4Z5LgiircSt8m8sRZFNi08kG9Sm0uSHtEmP3zaEGg== + +yocto-queue@^0.1.0: + version "0.1.0" + resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b" + integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q== From f93259b3f0f501532cf9ea9ed2eefa33d1295c08 Mon Sep 17 00:00:00 2001 From: Aaron Turner Date: Wed, 3 Feb 2021 09:10:32 -0800 Subject: [PATCH 02/10] Added support for floats (#111) * Implemented Float support * Used parseFloat to handle float precisions * Added support for minus e * Made requested changes for special floats * Removed NaN and Infinity --- assembly/JSON.ts | 33 ++++++++++-- assembly/__tests__/roundtrip.spec.ts | 75 +++++++++++++++++++++++++++- assembly/decoder.ts | 67 +++++++++++++++++++++---- assembly/encoder.ts | 9 ++++ 4 files changed, 168 insertions(+), 16 deletions(-) diff --git a/assembly/JSON.ts b/assembly/JSON.ts index 5bab23e..6e4aac1 100644 --- a/assembly/JSON.ts +++ b/assembly/JSON.ts @@ -30,7 +30,12 @@ class Handler { } setInteger(name: string, value: i64): void { - const obj = JSON.Value.Number(value); + const obj = JSON.Value.Integer(value); + this.addValue(name, obj); + } + + setFloat(name: string, value: f64): void { + const obj = JSON.Value.Float(value); this.addValue(name, obj); } @@ -109,9 +114,15 @@ export namespace JSON { static String(str: string): Str { return new Str(str); } - static Number(num: i64): Num { + static Number(num: f64): Num { return new Num(num); } + static Float(num: f64): Float { + return new Float(num); + } + static Integer(num: i64): Integer { + return new Integer(num); + } static Bool(b: bool): Bool { return new Bool(b); } @@ -159,6 +170,19 @@ export namespace JSON { } export class Num extends Value { + constructor(public _num: f64) { + super(); + } + + toString(): string { + return this._num.toString(); + } + } + + export class Float extends Num { + } + + export class Integer extends Value { constructor(public _num: i64) { super(); } @@ -265,7 +289,10 @@ export namespace JSON { return Value.Bool(val); } if (isInteger(val)) { - return Value.Number(val); + return Value.Integer(val); + } + if (isFloat(val)) { + return Value.Float(val); } if (isString(val)) { return Value.String(val); diff --git a/assembly/__tests__/roundtrip.spec.ts b/assembly/__tests__/roundtrip.spec.ts index 4cec3a9..4eb3247 100644 --- a/assembly/__tests__/roundtrip.spec.ts +++ b/assembly/__tests__/roundtrip.spec.ts @@ -32,10 +32,41 @@ describe("Round trip", () => { roundtripTest('{"int":4660}'); }); + it("should handle float32", () => { + // expectFn(():void => { + roundtripTest('{"float":24.24}'); + }); + it("should handle int32Sign", () => { roundtripTest('{"int":-4660}'); }); + it("should handle float32Sign", () => { + roundtripTest('{"float":-24.24}'); + }); + + it("should handle scientific notation float", () => { + // Lower and Upper E + roundtripTest( + '{"floatLowerE":1.23456e5,"floatUpperE":1.23456E5}', + '{"floatLowerE":123456.0,"floatUpperE":123456.0}' + ); + + // Complex Scientific Notation + roundtripTest( + '{"floatEMinus":123456e-5,"floatEPlus":1.23456E+5}', + '{"floatEMinus":1.23456,"floatEPlus":123456.0}' + ); + }); + + it("should handle special floats", () => { + roundtripTest( + '{"negativeZero":-0}', + '{"negativeZero":0.0}', + ); + }); + + it("should handle true", () => { roundtripTest('{"val":true}'); }); @@ -117,8 +148,48 @@ describe("JSON.parse", () => { describe("Primitive Values", () => { it("should handle numbers", () => { - expect((JSON.parse("123456789"))._num).toStrictEqual( - (JSON.from(123456789))._num + expect((JSON.parse("123456789.0"))._num).toStrictEqual( + (JSON.from(123456789.0))._num + ); + }); + + it("should handle floats", () => { + expect((JSON.parse("123456789.0"))._num).toStrictEqual( + (JSON.from(123456789.0))._num + ); + }); + + it("should handle scientific notation floats", () => { + // Supports lower e + expect((JSON.parse("1.23456e5"))._num).toStrictEqual( + (JSON.from(123456.0))._num + ); + + // Supports Upper e + expect((JSON.parse("1.23456E5"))._num).toStrictEqual( + (JSON.from(123456.0))._num + ); + + // Supports Complex + + expect((JSON.parse("1.23456e+5"))._num).toStrictEqual( + (JSON.from(123456.0))._num + ); + + // Supports Complex - + expect((JSON.parse("123456E-5"))._num).toStrictEqual( + (JSON.from(1.23456))._num + ); + }); + + it("should handle special floats", () => { + expect((JSON.parse("-0"))._num).toStrictEqual( + (JSON.from(-0.0))._num + ); + }); + + it("should handle integers", () => { + expect((JSON.parse("123456789"))._num).toStrictEqual( + (JSON.from(123456789))._num ); }); diff --git a/assembly/decoder.ts b/assembly/decoder.ts index 5926596..98a634a 100644 --- a/assembly/decoder.ts +++ b/assembly/decoder.ts @@ -13,6 +13,8 @@ export abstract class JSONHandler { setInteger(name: string, value: i64): void {} + setFloat(name: string, value: f64): void {} + pushArray(name: string): bool { return true; } @@ -55,6 +57,14 @@ export class ThrowingJSONHandler extends JSONHandler { ); } + setFloat(name: string, value: f64): void { + // @ts-ignore integer does have toString + assert( + false, + "Unexpected float field " + name + " : " + value.toString() + ); + } + pushArray(name: string): bool { assert(false, "Unexpected array field " + name); return true; @@ -80,6 +90,16 @@ export class ThrowingJSONHandler extends JSONHandler { @lazy const CHAR_A: i32 = 65; // "A".charCodeAt(0); // @ts-ignore: decorator @lazy const CHAR_A_LOWER: i32 = 97; // "a".charCodeAt(0); +// @ts-ignore: decorator +@lazy const CHAR_PERIOD: i32 = 46; // ".".charCodeAt(0); +// @ts-ignore: decorator +@lazy const CHAR_MINUS: i32 = 45; // "-".charCodeAt(0); +// @ts-ignore: decorator +@lazy const CHAR_PLUS: i32 = 43; // "+".charCodeAt(0); +// @ts-ignore: decorator +@lazy const CHAR_E: i32 = 69; // "E".charCodeAt(0); +// @ts-ignore: decorator +@lazy const CHAR_E_LOWER: i32 = 101; // "e".charCodeAt(0); export class DecoderState { lastKey: string = ""; @@ -301,22 +321,47 @@ export class JSONDecoder { } private parseNumber(): bool { - // TODO: Parse floats - let number: i64 = 0; - let sign: i64 = 1; - if (this.peekChar() == "-".charCodeAt(0)) { + let number: f64 = 0; + let sign: f64 = 1; + let isFloat: boolean = false; + // Also keeping the number as a string, because we will want to use the + // AS parseFloat as it handles precision best. + let numberAsString: string = ""; + + if (this.peekChar() == CHAR_MINUS) { sign = -1; - this.readChar(); + numberAsString += String.fromCharCode(this.readChar()); } let digits = 0; - while (CHAR_0 <= this.peekChar() && this.peekChar() <= CHAR_9) { - let byte = this.readChar(); - number *= 10; - number += byte - CHAR_0; - digits++; + while ( + (CHAR_0 <= this.peekChar() && this.peekChar() <= CHAR_9) || + CHAR_PERIOD == this.peekChar() || + CHAR_MINUS == this.peekChar() || + CHAR_PLUS == this.peekChar() || + CHAR_E == this.peekChar() || + CHAR_E_LOWER == this.peekChar() + ) { + + let charCode = this.readChar(); + numberAsString += String.fromCharCode(charCode); + + if (charCode == CHAR_E || charCode == CHAR_E_LOWER || charCode == CHAR_PERIOD || charCode == CHAR_PLUS || charCode == CHAR_MINUS) { + isFloat = true; + } else { + if (!isFloat) { + let value: f64 = charCode - CHAR_0; + number *= 10; + number += value; + } + digits++; + } } if (digits > 0) { - this.handler.setInteger(this.state.lastKey, number * sign); + if (isFloat || numberAsString == "-0") { + this.handler.setFloat(this.state.lastKey, parseFloat(numberAsString)); + } else { + this.handler.setInteger(this.state.lastKey, (number * sign)); + } return true; } return false; diff --git a/assembly/encoder.ts b/assembly/encoder.ts index 78eccc1..c1e5d67 100644 --- a/assembly/encoder.ts +++ b/assembly/encoder.ts @@ -43,6 +43,11 @@ export class JSONEncoder { this.writeInteger(value); } + setFloat(name: string | null, value: f64): void { + this.writeKey(name); + this.writeFloat(value); + } + pushArray(name: string | null): bool { this.writeKey(name); this.write("["); @@ -123,6 +128,10 @@ export class JSONEncoder { this.write(value.toString()); } + private writeFloat(value: f64): void { + this.write(value.toString()); + } + private write(str: string): void { this.result.push(str); } From ec60316a178f7b17ed5c99a077318a9d711b36a3 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Fri, 5 Feb 2021 14:52:55 -0500 Subject: [PATCH 03/10] v0.4.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d8242d5..62d8e49 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "assemblyscript-json", - "version": "0.3.3", + "version": "0.4.0", "types": "assembly/index.ts", "scripts": { "asbuild:untouched": "asc assembly/index.ts -b build/untouched.wasm -t build/untouched.wat --sourceMap --validate --debug", From c6508f5f0eea7bcc7bf804fda9909113c3df2848 Mon Sep 17 00:00:00 2001 From: Aaron Turner Date: Wed, 10 Feb 2021 07:09:02 -0800 Subject: [PATCH 04/10] API Fixes, README cleanup, and generated Reference Documentation (#121) * Got most of the JSON API cleaned up * Added support for generating docs * Finished deploying docs * Added the docs to the README * Removed the quotes on Str.toString() * One last comment on getX functions * Added a test for toString all the values --- .gitignore | 1 + .travis.yml | 1 + README.md | 175 +++++---- assembly/JSON.ts | 422 +++++++++++++++------- assembly/__tests__/json-parse.spec.ts | 139 +++++++ assembly/__tests__/roundtrip.spec.ts | 136 +------ assembly/__tests__/to-string.spec.ts | 66 ++++ assembly/__tests__/usage.spec.ts | 119 ++++++ assembly/index.ts | 3 +- docs/README.md | 17 + docs/classes/decoderstate.md | 92 +++++ docs/classes/json.arr.md | 310 ++++++++++++++++ docs/classes/json.bool.md | 297 +++++++++++++++ docs/classes/json.float.md | 301 ++++++++++++++++ docs/classes/json.integer.md | 297 +++++++++++++++ docs/classes/json.null.md | 281 +++++++++++++++ docs/classes/json.num.md | 299 ++++++++++++++++ docs/classes/json.obj.md | 497 ++++++++++++++++++++++++++ docs/classes/json.str.md | 297 +++++++++++++++ docs/classes/json.value.md | 260 ++++++++++++++ docs/classes/jsondecoder.md | 297 +++++++++++++++ docs/classes/jsonencoder.md | 330 +++++++++++++++++ docs/classes/jsonhandler.md | 174 +++++++++ docs/classes/throwingjsonhandler.md | 195 ++++++++++ docs/modules/json.md | 66 ++++ package.json | 4 + yarn.lock | 230 +++++++++++- 27 files changed, 4962 insertions(+), 344 deletions(-) create mode 100644 assembly/__tests__/json-parse.spec.ts create mode 100644 assembly/__tests__/to-string.spec.ts create mode 100644 assembly/__tests__/usage.spec.ts create mode 100644 docs/README.md create mode 100644 docs/classes/decoderstate.md create mode 100644 docs/classes/json.arr.md create mode 100644 docs/classes/json.bool.md create mode 100644 docs/classes/json.float.md create mode 100644 docs/classes/json.integer.md create mode 100644 docs/classes/json.null.md create mode 100644 docs/classes/json.num.md create mode 100644 docs/classes/json.obj.md create mode 100644 docs/classes/json.str.md create mode 100644 docs/classes/json.value.md create mode 100644 docs/classes/jsondecoder.md create mode 100644 docs/classes/jsonencoder.md create mode 100644 docs/classes/jsonhandler.md create mode 100644 docs/classes/throwingjsonhandler.md create mode 100644 docs/modules/json.md diff --git a/.gitignore b/.gitignore index f6ff34d..65cbaee 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ node_modules/ build/ +temp-docs/ tests/build .DS_Store diff --git a/.travis.yml b/.travis.yml index 5e530bf..6abf2ad 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,3 +5,4 @@ node_js: script: - yarn test + - yarn docs diff --git a/README.md b/README.md index cb9526b..4df16d0 100644 --- a/README.md +++ b/README.md @@ -1,28 +1,61 @@ # assemblyscript-json +![npm version](https://img.shields.io/npm/v/assemblyscript-json) ![npm downloads per month](https://img.shields.io/npm/dm/assemblyscript-json) + JSON encoder / decoder for AssemblyScript. Special thanks to https://github.com/MaxGraey/bignum.wasm for basic unit testing infra for AssemblyScript. -# Limitations +## Installation + +`assemblyscript-json` is available as a [npm package](https://www.npmjs.com/package/assemblyscript-json). You can install `assemblyscript-json` in your AssemblyScript project by running: -This is developed for use in smart contracts written in AssemblyScript for https://github.com/nearprotocol/nearcore. -This imposes such limitations: +`npm install --save assemblyscript-json` -- Float numbers not supported -- We assume that memory never needs to be deallocated (cause these contracts are short-lived). +## Usage -Note that this mostly just defines the way it's currently implemented. Contributors are welcome to fix limitations. +### Parsing JSON -# Usage +```typescript +import { JSON } from "assemblyscript-json"; -## Encoding JSON +// Parse an object using the JSON object +let jsonObj: JSON.Obj = (JSON.parse('{"hello": "world", "value": 24}')); -```ts -// Make sure memory allocator is available -import "allocator/arena"; -// Import encoder -import { JSONEncoder } from "path/to/module"; +// We can then use the .getX functions to read from the object if you know it's type +// This will return the appropriate JSON.X value if the key exists, or null if the key does not exist +let worldOrNull: JSON.Str | null = jsonObj.getString("hello"); // This will return a JSON.Str or null +if (worldOrNull != null) { + // use .valueOf() to turn the high level JSON.Str type into a string + let world: string = worldOrNull.valueOf(); +} + +let numOrNull: JSON.Num | null = jsonObj.getNum("value"); +if (numOrNull != null) { + // use .valueOf() to turn the high level JSON.Num type into a f64 + let value: f64 = numOrNull.valueOf(); +} + +// If you don't know the value type, get the parent JSON.Value +let valueOrNull: JSON.Value | null = jsonObj.getValue("hello"); + if (valueOrNull != null) { + let value: JSON.Value = changetype(valueOrNull); + + // Next we could figure out what type we are + if(value.isString) { + // value.isString would be true, so we can cast to a string + let stringValue: string = changetype(value).toString(); + + // Do something with string value + } +} +``` + +### Encoding JSON + + +```typescript +import { JSONEncoder } from "assemblyscript-json"; // Create encoder let encoder = new JSONEncoder(); @@ -37,83 +70,79 @@ encoder.popObject(); let json: Uint8Array = encoder.serialize(); // Or get serialized data as string -let jsonString: String = encoder.toString(); +let jsonString: string = encoder.toString(); + +assert(jsonString, '"obj": {"int": 10, "str": ""}'); // True! ``` -## Parsing JSON +### Custom JSON Deserializers -```ts -// Make sure memory allocator is available -import "allocator/arena"; -// Import decoder -import { JSONDecoder, JSONHandler } from "path/to/module"; +```typescript +import { JSONDecoder, JSONHandler } from "assemblyscript-json"; // Events need to be received by custom object extending JSONHandler. // NOTE: All methods are optional to implement. class MyJSONEventsHandler extends JSONHandler { - setString(name: string, value: string): void { - // Handle field - } - - setBoolean(name: string, value: bool): void { - // Handle field - } - - setNull(name: string): void { - // Handle field - } - - setInteger(name: string, value: i32): void { - // Handle field - } - - pushArray(name: string): bool { - // Handle array start - // true means that nested object needs to be traversed, false otherwise - // Note that returning false means JSONDecoder.startIndex need to be updated by handler - return true; - } - - popArray(): void { - // Handle array end - } - - pushObject(name: string): bool { - // Handle object start - // true means that nested object needs to be traversed, false otherwise - // Note that returning false means JSONDecoder.startIndex need to be updated by handler - return true; - } - - popObject(): void { - // Handle object end - } + setString(name: string, value: string): void { + // Handle field + } + + setBoolean(name: string, value: bool): void { + // Handle field + } + + setNull(name: string): void { + // Handle field + } + + setInteger(name: string, value: i64): void { + // Handle field + } + + setFloat(name: string, value: f64): void { + // Handle field + } + + pushArray(name: string): bool { + // Handle array start + // true means that nested object needs to be traversed, false otherwise + // Note that returning false means JSONDecoder.startIndex need to be updated by handler + return true; + } + + popArray(): void { + // Handle array end + } + + pushObject(name: string): bool { + // Handle object start + // true means that nested object needs to be traversed, false otherwise + // Note that returning false means JSONDecoder.startIndex need to be updated by handler + return true; + } + + popObject(): void { + // Handle object end + } } // Create decoder let decoder = new JSONDecoder(new MyJSONEventsHandler()); -// Let's assume JSON data is available in this variable -let json: Uint8Array = ...; +// Create a byte buffer of our JSON. NOTE: Deserializers work on UTF8 string buffers. +let jsonString = '{"hello": "world"}'; +let jsonBuffer = Uint8Array.wrap(String.UTF8.encode(jsonString)); // Parse JSON -decoder.deserialize(json); // This will send events to MyJSONEventsHandler - +decoder.deserialize(jsonBuffer); // This will send events to MyJSONEventsHandler ``` -## JSON namespace +Feel free to look through the [tests](https://github.com/nearprotocol/assemblyscript-json/tree/master/assembly/__tests__) for more usage examples. -```ts -import { JSON } from "path/to/module"; +## Reference Documentation -// Can use JS parse api -let jsonObj: JSON.Object = JSON.parse(`{"hello": "world"}`); +Reference API Documentation can be found in the [docs directory](./docs). -// Can then use a key to read from the object if you know it's type -let world = jsonObj.getString("hello"); +## License -// If you don't know what the type of the value -let unknown = jsonObj.getValue("hello"); - -unknown.isString; // true; -``` +[MIT](./LICENSE) diff --git a/assembly/JSON.ts b/assembly/JSON.ts index 6e4aac1..af7ef1d 100644 --- a/assembly/JSON.ts +++ b/assembly/JSON.ts @@ -2,7 +2,7 @@ import { Buffer } from "./util"; import { JSONDecoder } from "./decoder"; class Handler { - stack: JSON.Value[] = new Array(); + stack: Value[] = new Array(); reset(): void { while (this.stack.length > 0) { @@ -10,37 +10,37 @@ class Handler { } } - get peek(): JSON.Value { + get peek(): Value { return this.stack[this.stack.length - 1]; } setString(name: string, value: string): void { - const obj: JSON.Value = JSON.Value.String(value); + const obj: Value = Value.String(value); this.addValue(name, obj); } setBoolean(name: string, value: bool): void { - const obj = JSON.Value.Bool(value); + const obj = Value.Bool(value); this.addValue(name, obj); } setNull(name: string): void { - const obj = JSON.Value.Null(); + const obj = Value.Null(); this.addValue(name, obj); } setInteger(name: string, value: i64): void { - const obj = JSON.Value.Integer(value); + const obj = Value.Integer(value); this.addValue(name, obj); } setFloat(name: string, value: f64): void { - const obj = JSON.Value.Float(value); + const obj = Value.Float(value); this.addValue(name, obj); } pushArray(name: string): bool { - const obj: JSON.Value = JSON.Value.Array(); + const obj: Value = Value.Array(); if (this.stack.length == 0) { this.stack.push(obj); } else { @@ -57,7 +57,7 @@ class Handler { } pushObject(name: string): bool { - const obj: JSON.Value = JSON.Value.Object(); + const obj: Value = Value.Object(); this.addValue(name, obj); this.stack.push(obj); return true; @@ -69,15 +69,15 @@ class Handler { } } - addValue(name: string, obj: JSON.Value): void { + addValue(name: string, obj: Value): void { if (name.length == 0 && this.stack.length == 0) { this.stack.push(obj); return; } - if (this.peek instanceof JSON.Obj) { - (this.peek as JSON.Obj).set(name, obj); - } else if (this.peek instanceof JSON.Arr) { - (this.peek).push(obj); + if (this.peek instanceof Obj) { + (this.peek as Obj).set(name, obj); + } else if (this.peek instanceof Arr) { + (this.peek).push(obj); } } } @@ -93,7 +93,7 @@ namespace _JSON { ); /** Parses a string or Uint8Array and returns a Json Value. */ - export function parse(str: T): JSON.Value { + export function parse(str: T): Value { var arr: Uint8Array; if (isString(str)) { arr = Buffer.fromString(str); @@ -107,112 +107,168 @@ namespace _JSON { } } -// @ts-ignore -@global -export namespace JSON { - export abstract class Value { - static String(str: string): Str { - return new Str(str); - } - static Number(num: f64): Num { - return new Num(num); - } - static Float(num: f64): Float { - return new Float(num); - } - static Integer(num: i64): Integer { - return new Integer(num); - } - static Bool(b: bool): Bool { - return new Bool(b); - } - static Null(): Null { - return new Null(); +export abstract class Value { + static String(str: string): Str { + return new Str(str); + } + static Number(num: f64): Num { + return new Num(num); + } + static Float(num: f64): Float { + return new Float(num); + } + static Integer(num: i64): Integer { + return new Integer(num); + } + static Bool(b: bool): Bool { + return new Bool(b); + } + static Null(): Null { + return new Null(); + } + static Array(): Arr { + return new Arr(); + } + static Object(): Obj { + return new Obj(); + } + + get isString(): boolean { + if (this instanceof Str) { + return true; } - static Array(): Arr { - return new Arr(); + return false; + } + + get isNum(): boolean { + if (this instanceof Num) { + return true; } - static Object(): Obj { - return new Obj(); + return false; + } + + get isFloat(): boolean { + if (this instanceof Float) { + return true; } + return false; + } - toString(): string { - if (this instanceof Str) { - return (this).toString(); - } - if (this instanceof Num) { - return (this).toString(); - } - if (this instanceof Bool) { - return (this).toString(); - } - if (this instanceof Null) { - return (this).toString(); - } - if (this instanceof Arr) { - return (this).toString(); - } - if (this instanceof Obj) { - return (this).toString(); - } - throw new Error("Not a value."); + get isInteger(): boolean { + if (this instanceof Integer) { + return true; } + return false; } - export class Str extends Value { - constructor(public _str: string) { - super(); + get isBool(): boolean { + if (this instanceof Bool) { + return true; } + return false; + } - toString(): string { - return '"' + this._str + '"'; + get isNull(): boolean { + if (this instanceof Null) { + return true; } + return false; } - export class Num extends Value { - constructor(public _num: f64) { - super(); + get isArr(): boolean { + if (this instanceof Arr) { + return true; } + return false; + } - toString(): string { - return this._num.toString(); + get isObj(): boolean { + if (this instanceof Obj) { + return true; } + return false; } - export class Float extends Num { + toString(): string { + throw new Error("Values must be casted to their JSON type for .toString()"); + return ""; } +} - export class Integer extends Value { - constructor(public _num: i64) { - super(); - } +export class Str extends Value { + constructor(public _str: string) { + super(); + } - toString(): string { - return this._num.toString(); - } + toString(): string { + return this._str; } - export class Null extends Value { - constructor() { - super(); - } + valueOf(): string { + return this._str; + } +} - toString(): string { - return "null"; - } +export class Num extends Value { + constructor(public _num: f64) { + super(); } - export class Bool extends Value { - constructor(public _bool: bool) { - super(); - } + toString(): string { + return this._num.toString(); + } - toString(): string { - return this._bool.toString(); - } + valueOf(): f64 { + return this._num; + } +} + +export class Float extends Num { +} + +export class Integer extends Value { + constructor(public _num: i64) { + super(); + } + + toString(): string { + return this._num.toString(); + } + + valueOf(): i64 { + return this._num; + } +} + +export class Null extends Value { + constructor() { + super(); + } + + toString(): string { + return "null"; } - export class Arr extends Value { + valueOf(): null { + return null; + } +} + +export class Bool extends Value { + constructor(public _bool: bool) { + super(); + } + + toString(): string { + return this._bool.toString(); + } + + valueOf(): bool { + return this._bool; + } +} + +export class Arr extends Value { _arr: Array; constructor() { super(); @@ -234,9 +290,13 @@ export namespace JSON { "]" ); } - } - export class Obj extends Value { + valueOf(): Array { + return this._arr; + } +} + +export class Obj extends Value { _obj: Map; keys: Array; @@ -246,6 +306,55 @@ export namespace JSON { this.keys = new Array(); } + toString(): string { + const objs: string[] = []; + for (let i: i32 = 0; i < this.keys.length; i++) { + let keyValueString = '"' + this.keys[i] + '": '; + + // Cast our value into it's appropriate type + let value: Value | null = this._obj.get(this.keys[i]); + + // Check for null values + if (value == null || value.isNull) { + objs.push(keyValueString += "null"); + continue; + } + + // Cast to our proper type + if (value.isString) { + let castedValue = changetype(value); + keyValueString += '"' + castedValue.toString() + '"'; + } else if (value.isNum) { + let castedValue = changetype(value); + keyValueString += castedValue.toString(); + } else if (value.isFloat) { + let castedValue = changetype(value); + keyValueString += castedValue.toString(); + } else if (value.isInteger) { + let castedValue = changetype(value); + keyValueString += castedValue.toString(); + } else if (value.isBool) { + let castedValue = changetype(value); + keyValueString += castedValue.toString(); + } else if (value.isArr) { + let castedValue = changetype(value); + keyValueString += castedValue.toString(); + } else if (value.isObj) { + let castedValue = changetype(value); + keyValueString += castedValue.toString(); + } + + // Push the keyValueString + objs.push(keyValueString); + } + return "{" + objs.join(",") + "}"; + } + + valueOf(): Map { + return this._obj; + } + + set(key: string, value: T): void { if (isReference(value)) { if (value instanceof Value) { @@ -262,6 +371,10 @@ export namespace JSON { this._obj.set(key, value); } + has(key: string): bool { + return this._obj.has(key); + } + get(key: string): Value | null { if (!this._obj.has(key)) { return null; @@ -269,55 +382,100 @@ export namespace JSON { return this._obj.get(key); } - toString(): string { - const objs: string[] = []; - for (let i: i32 = 0; i < this.keys.length; i++) { - objs.push( - '"' + this.keys[i] + '":' + this._obj.get(this.keys[i]).toString() - ); - } - return "{" + objs.join(",") + "}"; + getValue(key: string): Value | null { + return this.get(key); } - has(key: string): bool { - return this._obj.has(key); + getString(key: string): Str | null { + let jsonValue = this.get(key); + if (jsonValue != null && jsonValue.isString) { + return changetype(jsonValue); + } + return null; } - } - export function from(val: T): Value { - if (isBoolean(val)) { - return Value.Bool(val); + getNum(key: string): Num | null { + let jsonValue = this.get(key); + if (jsonValue != null && jsonValue.isNum) { + return changetype(jsonValue); + } + return null; } - if (isInteger(val)) { - return Value.Integer(val); + + getFloat(key: string): Float | null { + let jsonValue = this.get(key); + if (jsonValue != null && jsonValue.isFloat) { + return changetype(jsonValue); + } + return null; } - if (isFloat(val)) { - return Value.Float(val); + + getInteger(key: string): Integer | null { + let jsonValue = this.get(key); + if (jsonValue != null && jsonValue.isInteger) { + return changetype(jsonValue); + } + return null; } - if (isString(val)) { - return Value.String(val); + + getBool(key: string): Bool | null { + let jsonValue = this.get(key); + if (jsonValue != null && jsonValue.isBool) { + return changetype(jsonValue); + } + return null; } - if (val == null) { - return Value.Null(); + + getArr(key: string): Arr | null { + let jsonValue = this.get(key); + if (jsonValue != null && jsonValue.isArr) { + return changetype(jsonValue); + } + return null; } - if (isArrayLike(val)) { - const arr = Value.Array(); - for (let i: i32 = 0; i < val.length; i++) { - // @ts-ignore - arr.push(from>(val[i])); + + getObj(key: string): Obj | null { + let jsonValue = this.get(key); + if (jsonValue != null && jsonValue.isObj) { + return changetype(jsonValue); } - return arr; + return null; + } +} + +export function from(val: T): Value { + if (isBoolean(val)) { + return Value.Bool(val); + } + if (isInteger(val)) { + return Value.Integer(val); + } + if (isFloat(val)) { + return Value.Float(val); + } + if (isString(val)) { + return Value.String(val); + } + if (val == null) { + return Value.Null(); + } + if (isArrayLike(val)) { + const arr = Value.Array(); + for (let i: i32 = 0; i < val.length; i++) { + // @ts-ignore + arr.push(from>(val[i])); } - /** + return arr; + } + /** * TODO: add object support. */ - return Value.Object(); - } + return Value.Object(); +} - // @ts-ignore - @inline - /** Parses a string or Uint8Array and returns a Json Value. */ - export function parse(str: T): Value { - return _JSON.parse(str); - } +// @ts-ignore +@inline +/** Parses a string or Uint8Array and returns a Json Value. */ +export function parse(str: T): Value { + return _JSON.parse(str); } diff --git a/assembly/__tests__/json-parse.spec.ts b/assembly/__tests__/json-parse.spec.ts new file mode 100644 index 0000000..b5e577e --- /dev/null +++ b/assembly/__tests__/json-parse.spec.ts @@ -0,0 +1,139 @@ +import { JSONDecoder } from "../decoder"; +import { JSONEncoder } from "../encoder"; +import { Buffer } from "../util"; +import * as JSON from "../JSON"; + +let primObj: JSON.Obj; +let primArr: JSON.Arr; + +function parseToString(input: string): string { + return JSON.parse(input).toString(); +} + +describe("JSON.parse", () => { + beforeAll(() => { + primObj = JSON.Value.Object(); + primArr = JSON.from([42]); + primObj.set("number", JSON.from(42)); + primObj.set("boolean", JSON.from(true)); + primObj.set("string", JSON.from("Hello")); + }); + + describe("Primitive Values", () => { + it("should handle numbers", () => { + expect((JSON.parse("123456789.0"))._num).toStrictEqual( + (JSON.from(123456789.0))._num + ); + }); + + it("should handle floats", () => { + expect((JSON.parse("123456789.0"))._num).toStrictEqual( + (JSON.from(123456789.0))._num + ); + }); + + it("should handle scientific notation floats", () => { + // Supports lower e + expect((JSON.parse("1.23456e5"))._num).toStrictEqual( + (JSON.from(123456.0))._num + ); + + // Supports Upper e + expect((JSON.parse("1.23456E5"))._num).toStrictEqual( + (JSON.from(123456.0))._num + ); + + // Supports Complex + + expect((JSON.parse("1.23456e+5"))._num).toStrictEqual( + (JSON.from(123456.0))._num + ); + + // Supports Complex - + expect((JSON.parse("123456E-5"))._num).toStrictEqual( + (JSON.from(1.23456))._num + ); + }); + + it("should handle special floats", () => { + expect((JSON.parse("-0"))._num).toStrictEqual( + (JSON.from(-0.0))._num + ); + }); + + it("should handle integers", () => { + expect((JSON.parse("123456789"))._num).toStrictEqual( + (JSON.from(123456789))._num + ); + }); + + it("should handle strings", () => { + expect(parseToString('"hello"')).toStrictEqual( + JSON.from("hello").toString() + ); + }); + + it("should handle booleans", () => { + expect(parseToString("true")).toStrictEqual(JSON.from(true).toString()); + expect(parseToString("false")).toStrictEqual(JSON.from(false).toString()); + }); + + // TODO: JSON.from(null) should equal JSON.NUll(); + it("should handle null", () => { + expect(parseToString("null")).toStrictEqual("null"); + }); + }); + + describe("Arrays", () => { + it("should handle empty ones", () => { + expect(parseToString("[]")).toStrictEqual( + JSON.from([]).toString() + ); + }); + + it("should handle non-empty ones", () => { + expect(parseToString("[42]")).toStrictEqual(primArr.toString()); + }); + + it("should handle nested ones", () => { + const outterArr = JSON.Value.Array(); + outterArr.push(primArr); + expect(parseToString("[[42]]")).toStrictEqual(outterArr.toString()); + }); + }); + + describe("Objects", () => { + it("should handle empty objects", () => { + expect(parseToString("{}")).toStrictEqual(JSON.Value.Object().toString()); + }); + + it("should handle primitive values", () => { + expect( + parseToString(`{ + "number": 42, + "boolean": true, + "string": "Hello" + }`) + ).toStrictEqual(primObj.toString()); + }); + + it("should handle nested objects", () => { + const outerObj = JSON.Value.Object(); + outerObj.set("innerObject", primObj); + expect( + JSON.parse(`{ + "innerObject": { + "number": 42, + "boolean": true, + "string": "Hello" + } + }`) + ).toStrictEqual(outerObj); + }); + + it("should handle arrays", () => { + const obj = JSON.Value.Object(); + obj.set("arr", primArr); + expect(parseToString('{"arr": [42]}')).toStrictEqual(obj.toString()); + }); + }); +}); diff --git a/assembly/__tests__/roundtrip.spec.ts b/assembly/__tests__/roundtrip.spec.ts index 4eb3247..2a88403 100644 --- a/assembly/__tests__/roundtrip.spec.ts +++ b/assembly/__tests__/roundtrip.spec.ts @@ -1,7 +1,7 @@ import { JSONDecoder } from "../decoder"; import { JSONEncoder } from "../encoder"; import { Buffer } from "../util"; -import { JSON } from "../JSON"; +import * as JSON from "../JSON"; function roundtripTest(jsonString: string, _expectedString: string = ""): void { const expectedString = _expectedString == "" ? jsonString : _expectedString; @@ -130,137 +130,3 @@ describe("Round trip", () => { }); }); -var primObj: JSON.Obj; -var primArr: JSON.Arr; - -function parseToString(input: string): string { - return JSON.parse(input).toString(); -} - -describe("JSON.parse", () => { - beforeAll(() => { - primObj = JSON.Value.Object(); - primArr = JSON.from([42]); - primObj.set("number", JSON.from(42)); - primObj.set("boolean", JSON.from(true)); - primObj.set("string", JSON.from("Hello")); - }); - - describe("Primitive Values", () => { - it("should handle numbers", () => { - expect((JSON.parse("123456789.0"))._num).toStrictEqual( - (JSON.from(123456789.0))._num - ); - }); - - it("should handle floats", () => { - expect((JSON.parse("123456789.0"))._num).toStrictEqual( - (JSON.from(123456789.0))._num - ); - }); - - it("should handle scientific notation floats", () => { - // Supports lower e - expect((JSON.parse("1.23456e5"))._num).toStrictEqual( - (JSON.from(123456.0))._num - ); - - // Supports Upper e - expect((JSON.parse("1.23456E5"))._num).toStrictEqual( - (JSON.from(123456.0))._num - ); - - // Supports Complex + - expect((JSON.parse("1.23456e+5"))._num).toStrictEqual( - (JSON.from(123456.0))._num - ); - - // Supports Complex - - expect((JSON.parse("123456E-5"))._num).toStrictEqual( - (JSON.from(1.23456))._num - ); - }); - - it("should handle special floats", () => { - expect((JSON.parse("-0"))._num).toStrictEqual( - (JSON.from(-0.0))._num - ); - }); - - it("should handle integers", () => { - expect((JSON.parse("123456789"))._num).toStrictEqual( - (JSON.from(123456789))._num - ); - }); - - it("should handle strings", () => { - expect(parseToString('"hello"')).toStrictEqual( - JSON.from("hello").toString() - ); - }); - - it("should handle booleans", () => { - expect(parseToString("true")).toStrictEqual(JSON.from(true).toString()); - expect(parseToString("false")).toStrictEqual(JSON.from(false).toString()); - }); - - // TODO: JSON.from(null) should equal JSON.NUll(); - it("should handle null", () => { - expect(parseToString("null")).toStrictEqual("null"); - }); - }); - - describe("Arrays", () => { - it("should handle empty ones", () => { - expect(parseToString("[]")).toStrictEqual( - JSON.from([]).toString() - ); - }); - - it("should handle non-empty ones", () => { - expect(parseToString("[42]")).toStrictEqual(primArr.toString()); - }); - - it("should handle nested ones", () => { - const outterArr = JSON.Value.Array(); - outterArr.push(primArr); - expect(parseToString("[[42]]")).toStrictEqual(outterArr.toString()); - }); - }); - - describe("Objects", () => { - it("should handle empty objects", () => { - expect(parseToString("{}")).toStrictEqual(JSON.Value.Object().toString()); - }); - - it("should handle primitive values", () => { - expect( - parseToString(`{ - "number": 42, - "boolean": true, - "string": "Hello" - }`) - ).toStrictEqual(primObj.toString()); - }); - - it("should handle nested objects", () => { - const outerObj = JSON.Value.Object(); - outerObj.set("innerObject", primObj); - expect( - JSON.parse(`{ - "innerObject": { - "number": 42, - "boolean": true, - "string": "Hello" - } - }`) - ).toStrictEqual(outerObj); - }); - - it("should handle arrays", () => { - const obj = JSON.Value.Object(); - obj.set("arr", primArr); - expect(parseToString('{"arr": [42]}')).toStrictEqual(obj.toString()); - }); - }); -}); diff --git a/assembly/__tests__/to-string.spec.ts b/assembly/__tests__/to-string.spec.ts new file mode 100644 index 0000000..4a66fb7 --- /dev/null +++ b/assembly/__tests__/to-string.spec.ts @@ -0,0 +1,66 @@ +import { JSONDecoder } from "../decoder"; +import { JSONEncoder } from "../encoder"; +import { Buffer } from "../util"; +import * as JSON from "../JSON"; + +let primObj: JSON.Obj; +let testFloat = 42.24; +let testInteger = 42; +let testBool = true; +let testArray = [1, 2, 3]; + +describe("JSON.Value.toString()", () => { + beforeAll(() => { + primObj = JSON.Value.Object(); + primObj.set("Str", JSON.from("Hello")); + primObj.set("Num", JSON.from(testFloat)); + primObj.set("Float", JSON.from(testFloat)); + primObj.set("Integer", JSON.from(testInteger)); + primObj.set("Bool", JSON.from(testBool)); + primObj.set("Arr", JSON.from(testArray)); + let childObj = JSON.Value.Object(); + childObj.set("isChild", JSON.from(true)); + primObj.set("Obj", childObj); + }); + + it("Str", () => { + let value = primObj.getString("Str"); + expect(value!.toString()).toBe("Hello"); + }); + + it("Num", () => { + let value = primObj.getNum("Num"); + expect(value!.toString()).toBe(testFloat.toString()); + }); + + it("Float", () => { + let value = primObj.getFloat("Float"); + expect(value!.toString()).toBe(testFloat.toString()); + + }); + + it("Integer", () => { + let value = primObj.getInteger("Integer"); + expect(value!.toString()).toBe(testInteger.toString()); + }); + + it("Bool", () => { + let value = primObj.getBool("Bool"); + expect(value!.toString()).toBe(testBool.toString()); + }); + + it("Arr", () => { + let value = primObj.getArr("Arr"); + expect(value!.toString()).toBe("[" + testArray.toString() + "]"); + }); + + it("Obj", () => { + let value = primObj.getObj("Obj"); + expect(value!.toString()).toBe('{"isChild": true}'); + }); + + it("Entire Object", () => { + expect(primObj.toString()).toBe("{\"Str\": \"Hello\",\"Num\": 42.24,\"Float\": 42.24,\"Integer\": 42,\"Bool\": true,\"Arr\": [1,2,3],\"Obj\": {\"isChild\": true}}"); + }); +}); + diff --git a/assembly/__tests__/usage.spec.ts b/assembly/__tests__/usage.spec.ts new file mode 100644 index 0000000..f60869d --- /dev/null +++ b/assembly/__tests__/usage.spec.ts @@ -0,0 +1,119 @@ +import * as JSON from "../JSON"; +import { JSONEncoder } from "../encoder"; +import { JSONDecoder, JSONHandler } from "../decoder"; + +// Events need to be received by custom object extending JSONHandler. +// NOTE: All methods are optional to implement. +class MyJSONEventsHandler extends JSONHandler { + setString(name: string, value: string): void { + // Handle field + } + + setBoolean(name: string, value: bool): void { + // Handle field + } + + setNull(name: string): void { + // Handle field + } + + setInteger(name: string, value: i64): void { + // Handle field + } + + setFloat(name: string, value: f64): void { + // Handle field + } + + pushArray(name: string): bool { + // Handle array start + // true means that nested object needs to be traversed, false otherwise + // Note that returning false means JSONDecoder.startIndex need to be updated by handler + return true; + } + + popArray(): void { + // Handle array end + } + + pushObject(name: string): bool { + // Handle object start + // true means that nested object needs to be traversed, false otherwise + // Note that returning false means JSONDecoder.startIndex need to be updated by handler + return true; + } + + popObject(): void { + // Handle object end + } +} + +describe("README Usage Examples", () => { + it("Parsing JSON", () => { + // Parse an object using the JSON object + let jsonObj: JSON.Obj = (JSON.parse('{"hello": "world", "value": 24}')); + + // We can then use the .getX functions to read from the object if you know it's type + // This will return the appropriate JSON.X value if the key exists, or null if the key does not exist + let worldOrNull: JSON.Str | null = jsonObj.getString("hello"); // This will return a JSON.Str or null + if (worldOrNull != null) { + // use .valueOf() to turn the high level JSON.Str type into a string + let world: string = worldOrNull.valueOf(); + } + + let numOrNull: JSON.Num | null = jsonObj.getNum("value"); + if (numOrNull != null) { + // use .valueOf() to turn the high level JSON.Num type into a f64 + let value: f64 = numOrNull.valueOf(); + } + + // If you don't know the value type, get the parent JSON.Value + let valueOrNull: JSON.Value | null = jsonObj.getValue("hello"); + if (valueOrNull != null) { + let value: JSON.Value = changetype(valueOrNull); + + // Next we could figure out what type we are + if(value.isString) { + // value.isString would be true, so we can cast to a string + let stringValue: string = changetype(value).toString(); + + // Do something with string value + } + } + }); + + it("Encoding JSON", () => { + // Create encoder + let encoder = new JSONEncoder(); + + // Construct necessary object + encoder.pushObject("obj"); + encoder.setInteger("int", 10); + encoder.setString("str", ""); + encoder.popObject(); + + // Get serialized data + let json: Uint8Array = encoder.serialize(); + + // Or get serialized data as string + let jsonString: string = encoder.toString(); + + assert(jsonString, '"obj": {"int": 10, "str": ""}'); // True! + }); + + it("Decoding JSON", () => { + + // NOTE: Include the JSON Handler Class here + + // Create decoder + let decoder = new JSONDecoder(new MyJSONEventsHandler()); + + // Create a byte buffer of our JSON. NOTE: Deserializers work on UTF8 string buffers. + let jsonString = '{"hello": "world"}'; + let jsonBuffer = Uint8Array.wrap(String.UTF8.encode(jsonString)); + + // Parse JSON + decoder.deserialize(jsonBuffer); // This will send events to MyJSONEventsHandler + }); +}); + diff --git a/assembly/index.ts b/assembly/index.ts index ef3f570..400081f 100644 --- a/assembly/index.ts +++ b/assembly/index.ts @@ -1,3 +1,4 @@ export * from "./decoder"; export * from "./encoder"; -export * from "./JSON"; +import * as JSON from "./JSON"; +export { JSON }; diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000..1e9c76c --- /dev/null +++ b/docs/README.md @@ -0,0 +1,17 @@ +assemblyscript-json + +# assemblyscript-json + +## Table of contents + +### Namespaces + +- [JSON](modules/json.md) + +### Classes + +- [DecoderState](classes/decoderstate.md) +- [JSONDecoder](classes/jsondecoder.md) +- [JSONEncoder](classes/jsonencoder.md) +- [JSONHandler](classes/jsonhandler.md) +- [ThrowingJSONHandler](classes/throwingjsonhandler.md) diff --git a/docs/classes/decoderstate.md b/docs/classes/decoderstate.md new file mode 100644 index 0000000..3fc4010 --- /dev/null +++ b/docs/classes/decoderstate.md @@ -0,0 +1,92 @@ +[assemblyscript-json](../README.md) / DecoderState + +# Class: DecoderState + +## Hierarchy + +* **DecoderState** + +## Table of contents + +### Constructors + +- [constructor](decoderstate.md#constructor) + +### Properties + +- [buffer](decoderstate.md#buffer) +- [lastKey](decoderstate.md#lastkey) +- [readIndex](decoderstate.md#readindex) + +### Accessors + +- [ptr](decoderstate.md#ptr) + +### Methods + +- [readString](decoderstate.md#readstring) + +## Constructors + +### constructor + +\+ **new DecoderState**(`buffer`: *Uint8Array*): [*DecoderState*](decoderstate.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`buffer` | *Uint8Array* | + +**Returns:** [*DecoderState*](decoderstate.md) + +Defined in: [decoder.ts:106](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/decoder.ts#L106) + +## Properties + +### buffer + +• **buffer**: *Uint8Array* + +___ + +### lastKey + +• **lastKey**: *string*= "" + +Defined in: [decoder.ts:105](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/decoder.ts#L105) + +___ + +### readIndex + +• **readIndex**: *number*= 0 + +Defined in: [decoder.ts:106](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/decoder.ts#L106) + +## Accessors + +### ptr + +• **ptr**(): *number* + +**Returns:** *number* + +Defined in: [decoder.ts:109](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/decoder.ts#L109) + +## Methods + +### readString + +▸ **readString**(`start`: *number*, `end?`: *number*): *string* + +#### Parameters: + +Name | Type | Default value | +------ | ------ | ------ | +`start` | *number* | - | +`end` | *number* | ... | + +**Returns:** *string* + +Defined in: [decoder.ts:113](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/decoder.ts#L113) diff --git a/docs/classes/json.arr.md b/docs/classes/json.arr.md new file mode 100644 index 0000000..905fae1 --- /dev/null +++ b/docs/classes/json.arr.md @@ -0,0 +1,310 @@ +[assemblyscript-json](../README.md) / [JSON](../modules/json.md) / Arr + +# Class: Arr + +[JSON](../modules/json.md).Arr + +## Hierarchy + +* [*Value*](json.value.md) + + ↳ **Arr** + +## Table of contents + +### Constructors + +- [constructor](json.arr.md#constructor) + +### Properties + +- [\_arr](json.arr.md#_arr) + +### Accessors + +- [isArr](json.arr.md#isarr) +- [isBool](json.arr.md#isbool) +- [isFloat](json.arr.md#isfloat) +- [isInteger](json.arr.md#isinteger) +- [isNull](json.arr.md#isnull) +- [isNum](json.arr.md#isnum) +- [isObj](json.arr.md#isobj) +- [isString](json.arr.md#isstring) + +### Methods + +- [push](json.arr.md#push) +- [toString](json.arr.md#tostring) +- [valueOf](json.arr.md#valueof) +- [Array](json.arr.md#array) +- [Bool](json.arr.md#bool) +- [Float](json.arr.md#float) +- [Integer](json.arr.md#integer) +- [Null](json.arr.md#null) +- [Number](json.arr.md#number) +- [Object](json.arr.md#object) +- [String](json.arr.md#string) + +## Constructors + +### constructor + +\+ **new Arr**(): [*Arr*](json.arr.md) + +**Returns:** [*Arr*](json.arr.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:272](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L272) + +## Properties + +### \_arr + +• **\_arr**: [*Value*](json.value.md)[] + +Defined in: [JSON.ts:272](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L272) + +## Accessors + +### isArr + +• **isArr**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:178](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L178) + +___ + +### isBool + +• **isBool**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:164](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L164) + +___ + +### isFloat + +• **isFloat**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:150](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L150) + +___ + +### isInteger + +• **isInteger**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:157](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L157) + +___ + +### isNull + +• **isNull**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:171](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L171) + +___ + +### isNum + +• **isNum**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:143](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L143) + +___ + +### isObj + +• **isObj**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:185](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L185) + +___ + +### isString + +• **isString**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:136](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L136) + +## Methods + +### push + +▸ **push**(`obj`: [*Value*](json.value.md)): *void* + +#### Parameters: + +Name | Type | +------ | ------ | +`obj` | [*Value*](json.value.md) | + +**Returns:** *void* + +Defined in: [JSON.ts:278](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L278) + +___ + +### toString + +▸ **toString**(): *string* + +**Returns:** *string* + +Overrides: [Value](json.value.md) + +Defined in: [JSON.ts:282](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L282) + +___ + +### valueOf + +▸ **valueOf**(): [*Value*](json.value.md)[] + +**Returns:** [*Value*](json.value.md)[] + +Defined in: [JSON.ts:294](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L294) + +___ + +### Array + +▸ `Static`**Array**(): [*Arr*](json.arr.md) + +**Returns:** [*Arr*](json.arr.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:129](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L129) + +___ + +### Bool + +▸ `Static`**Bool**(`b`: bool): [*Bool*](json.bool.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`b` | bool | + +**Returns:** [*Bool*](json.bool.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:123](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L123) + +___ + +### Float + +▸ `Static`**Float**(`num`: *number*): [*Float*](json.float.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`num` | *number* | + +**Returns:** [*Float*](json.float.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:117](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L117) + +___ + +### Integer + +▸ `Static`**Integer**(`num`: *number*): [*Integer*](json.integer.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`num` | *number* | + +**Returns:** [*Integer*](json.integer.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:120](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L120) + +___ + +### Null + +▸ `Static`**Null**(): [*Null*](json.null.md) + +**Returns:** [*Null*](json.null.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:126](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L126) + +___ + +### Number + +▸ `Static`**Number**(`num`: *number*): [*Num*](json.num.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`num` | *number* | + +**Returns:** [*Num*](json.num.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:114](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L114) + +___ + +### Object + +▸ `Static`**Object**(): [*Obj*](json.obj.md) + +**Returns:** [*Obj*](json.obj.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:132](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L132) + +___ + +### String + +▸ `Static`**String**(`str`: *string*): [*Str*](json.str.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`str` | *string* | + +**Returns:** [*Str*](json.str.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:111](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L111) diff --git a/docs/classes/json.bool.md b/docs/classes/json.bool.md new file mode 100644 index 0000000..584928c --- /dev/null +++ b/docs/classes/json.bool.md @@ -0,0 +1,297 @@ +[assemblyscript-json](../README.md) / [JSON](../modules/json.md) / Bool + +# Class: Bool + +[JSON](../modules/json.md).Bool + +## Hierarchy + +* [*Value*](json.value.md) + + ↳ **Bool** + +## Table of contents + +### Constructors + +- [constructor](json.bool.md#constructor) + +### Properties + +- [\_bool](json.bool.md#_bool) + +### Accessors + +- [isArr](json.bool.md#isarr) +- [isBool](json.bool.md#isbool) +- [isFloat](json.bool.md#isfloat) +- [isInteger](json.bool.md#isinteger) +- [isNull](json.bool.md#isnull) +- [isNum](json.bool.md#isnum) +- [isObj](json.bool.md#isobj) +- [isString](json.bool.md#isstring) + +### Methods + +- [toString](json.bool.md#tostring) +- [valueOf](json.bool.md#valueof) +- [Array](json.bool.md#array) +- [Bool](json.bool.md#bool) +- [Float](json.bool.md#float) +- [Integer](json.bool.md#integer) +- [Null](json.bool.md#null) +- [Number](json.bool.md#number) +- [Object](json.bool.md#object) +- [String](json.bool.md#string) + +## Constructors + +### constructor + +\+ **new Bool**(`_bool`: bool): [*Bool*](json.bool.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`_bool` | bool | + +**Returns:** [*Bool*](json.bool.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:257](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L257) + +## Properties + +### \_bool + +• **\_bool**: bool + +## Accessors + +### isArr + +• **isArr**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:178](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L178) + +___ + +### isBool + +• **isBool**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:164](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L164) + +___ + +### isFloat + +• **isFloat**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:150](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L150) + +___ + +### isInteger + +• **isInteger**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:157](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L157) + +___ + +### isNull + +• **isNull**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:171](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L171) + +___ + +### isNum + +• **isNum**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:143](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L143) + +___ + +### isObj + +• **isObj**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:185](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L185) + +___ + +### isString + +• **isString**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:136](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L136) + +## Methods + +### toString + +▸ **toString**(): *string* + +**Returns:** *string* + +Overrides: [Value](json.value.md) + +Defined in: [JSON.ts:262](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L262) + +___ + +### valueOf + +▸ **valueOf**(): bool + +**Returns:** bool + +Defined in: [JSON.ts:266](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L266) + +___ + +### Array + +▸ `Static`**Array**(): [*Arr*](json.arr.md) + +**Returns:** [*Arr*](json.arr.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:129](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L129) + +___ + +### Bool + +▸ `Static`**Bool**(`b`: bool): [*Bool*](json.bool.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`b` | bool | + +**Returns:** [*Bool*](json.bool.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:123](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L123) + +___ + +### Float + +▸ `Static`**Float**(`num`: *number*): [*Float*](json.float.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`num` | *number* | + +**Returns:** [*Float*](json.float.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:117](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L117) + +___ + +### Integer + +▸ `Static`**Integer**(`num`: *number*): [*Integer*](json.integer.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`num` | *number* | + +**Returns:** [*Integer*](json.integer.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:120](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L120) + +___ + +### Null + +▸ `Static`**Null**(): [*Null*](json.null.md) + +**Returns:** [*Null*](json.null.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:126](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L126) + +___ + +### Number + +▸ `Static`**Number**(`num`: *number*): [*Num*](json.num.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`num` | *number* | + +**Returns:** [*Num*](json.num.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:114](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L114) + +___ + +### Object + +▸ `Static`**Object**(): [*Obj*](json.obj.md) + +**Returns:** [*Obj*](json.obj.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:132](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L132) + +___ + +### String + +▸ `Static`**String**(`str`: *string*): [*Str*](json.str.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`str` | *string* | + +**Returns:** [*Str*](json.str.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:111](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L111) diff --git a/docs/classes/json.float.md b/docs/classes/json.float.md new file mode 100644 index 0000000..8f78c75 --- /dev/null +++ b/docs/classes/json.float.md @@ -0,0 +1,301 @@ +[assemblyscript-json](../README.md) / [JSON](../modules/json.md) / Float + +# Class: Float + +[JSON](../modules/json.md).Float + +## Hierarchy + +* [*Num*](json.num.md) + + ↳ **Float** + +## Table of contents + +### Constructors + +- [constructor](json.float.md#constructor) + +### Properties + +- [\_num](json.float.md#_num) + +### Accessors + +- [isArr](json.float.md#isarr) +- [isBool](json.float.md#isbool) +- [isFloat](json.float.md#isfloat) +- [isInteger](json.float.md#isinteger) +- [isNull](json.float.md#isnull) +- [isNum](json.float.md#isnum) +- [isObj](json.float.md#isobj) +- [isString](json.float.md#isstring) + +### Methods + +- [toString](json.float.md#tostring) +- [valueOf](json.float.md#valueof) +- [Array](json.float.md#array) +- [Bool](json.float.md#bool) +- [Float](json.float.md#float) +- [Integer](json.float.md#integer) +- [Null](json.float.md#null) +- [Number](json.float.md#number) +- [Object](json.float.md#object) +- [String](json.float.md#string) + +## Constructors + +### constructor + +\+ **new Float**(`_num`: *number*): [*Float*](json.float.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`_num` | *number* | + +**Returns:** [*Float*](json.float.md) + +Inherited from: [Num](json.num.md) + +Defined in: [JSON.ts:212](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L212) + +## Properties + +### \_num + +• **\_num**: *number* + +Inherited from: [Num](json.num.md).[_num](json.num.md#_num) + +## Accessors + +### isArr + +• **isArr**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:178](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L178) + +___ + +### isBool + +• **isBool**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:164](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L164) + +___ + +### isFloat + +• **isFloat**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:150](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L150) + +___ + +### isInteger + +• **isInteger**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:157](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L157) + +___ + +### isNull + +• **isNull**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:171](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L171) + +___ + +### isNum + +• **isNum**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:143](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L143) + +___ + +### isObj + +• **isObj**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:185](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L185) + +___ + +### isString + +• **isString**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:136](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L136) + +## Methods + +### toString + +▸ **toString**(): *string* + +**Returns:** *string* + +Inherited from: [Num](json.num.md) + +Defined in: [JSON.ts:217](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L217) + +___ + +### valueOf + +▸ **valueOf**(): *number* + +**Returns:** *number* + +Inherited from: [Num](json.num.md) + +Defined in: [JSON.ts:221](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L221) + +___ + +### Array + +▸ `Static`**Array**(): [*Arr*](json.arr.md) + +**Returns:** [*Arr*](json.arr.md) + +Inherited from: [Num](json.num.md) + +Defined in: [JSON.ts:129](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L129) + +___ + +### Bool + +▸ `Static`**Bool**(`b`: bool): [*Bool*](json.bool.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`b` | bool | + +**Returns:** [*Bool*](json.bool.md) + +Inherited from: [Num](json.num.md) + +Defined in: [JSON.ts:123](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L123) + +___ + +### Float + +▸ `Static`**Float**(`num`: *number*): [*Float*](json.float.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`num` | *number* | + +**Returns:** [*Float*](json.float.md) + +Inherited from: [Num](json.num.md) + +Defined in: [JSON.ts:117](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L117) + +___ + +### Integer + +▸ `Static`**Integer**(`num`: *number*): [*Integer*](json.integer.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`num` | *number* | + +**Returns:** [*Integer*](json.integer.md) + +Inherited from: [Num](json.num.md) + +Defined in: [JSON.ts:120](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L120) + +___ + +### Null + +▸ `Static`**Null**(): [*Null*](json.null.md) + +**Returns:** [*Null*](json.null.md) + +Inherited from: [Num](json.num.md) + +Defined in: [JSON.ts:126](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L126) + +___ + +### Number + +▸ `Static`**Number**(`num`: *number*): [*Num*](json.num.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`num` | *number* | + +**Returns:** [*Num*](json.num.md) + +Inherited from: [Num](json.num.md) + +Defined in: [JSON.ts:114](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L114) + +___ + +### Object + +▸ `Static`**Object**(): [*Obj*](json.obj.md) + +**Returns:** [*Obj*](json.obj.md) + +Inherited from: [Num](json.num.md) + +Defined in: [JSON.ts:132](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L132) + +___ + +### String + +▸ `Static`**String**(`str`: *string*): [*Str*](json.str.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`str` | *string* | + +**Returns:** [*Str*](json.str.md) + +Inherited from: [Num](json.num.md) + +Defined in: [JSON.ts:111](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L111) diff --git a/docs/classes/json.integer.md b/docs/classes/json.integer.md new file mode 100644 index 0000000..9ceb838 --- /dev/null +++ b/docs/classes/json.integer.md @@ -0,0 +1,297 @@ +[assemblyscript-json](../README.md) / [JSON](../modules/json.md) / Integer + +# Class: Integer + +[JSON](../modules/json.md).Integer + +## Hierarchy + +* [*Value*](json.value.md) + + ↳ **Integer** + +## Table of contents + +### Constructors + +- [constructor](json.integer.md#constructor) + +### Properties + +- [\_num](json.integer.md#_num) + +### Accessors + +- [isArr](json.integer.md#isarr) +- [isBool](json.integer.md#isbool) +- [isFloat](json.integer.md#isfloat) +- [isInteger](json.integer.md#isinteger) +- [isNull](json.integer.md#isnull) +- [isNum](json.integer.md#isnum) +- [isObj](json.integer.md#isobj) +- [isString](json.integer.md#isstring) + +### Methods + +- [toString](json.integer.md#tostring) +- [valueOf](json.integer.md#valueof) +- [Array](json.integer.md#array) +- [Bool](json.integer.md#bool) +- [Float](json.integer.md#float) +- [Integer](json.integer.md#integer) +- [Null](json.integer.md#null) +- [Number](json.integer.md#number) +- [Object](json.integer.md#object) +- [String](json.integer.md#string) + +## Constructors + +### constructor + +\+ **new Integer**(`_num`: *number*): [*Integer*](json.integer.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`_num` | *number* | + +**Returns:** [*Integer*](json.integer.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:229](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L229) + +## Properties + +### \_num + +• **\_num**: *number* + +## Accessors + +### isArr + +• **isArr**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:178](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L178) + +___ + +### isBool + +• **isBool**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:164](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L164) + +___ + +### isFloat + +• **isFloat**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:150](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L150) + +___ + +### isInteger + +• **isInteger**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:157](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L157) + +___ + +### isNull + +• **isNull**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:171](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L171) + +___ + +### isNum + +• **isNum**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:143](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L143) + +___ + +### isObj + +• **isObj**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:185](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L185) + +___ + +### isString + +• **isString**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:136](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L136) + +## Methods + +### toString + +▸ **toString**(): *string* + +**Returns:** *string* + +Overrides: [Value](json.value.md) + +Defined in: [JSON.ts:234](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L234) + +___ + +### valueOf + +▸ **valueOf**(): *number* + +**Returns:** *number* + +Defined in: [JSON.ts:238](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L238) + +___ + +### Array + +▸ `Static`**Array**(): [*Arr*](json.arr.md) + +**Returns:** [*Arr*](json.arr.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:129](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L129) + +___ + +### Bool + +▸ `Static`**Bool**(`b`: bool): [*Bool*](json.bool.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`b` | bool | + +**Returns:** [*Bool*](json.bool.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:123](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L123) + +___ + +### Float + +▸ `Static`**Float**(`num`: *number*): [*Float*](json.float.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`num` | *number* | + +**Returns:** [*Float*](json.float.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:117](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L117) + +___ + +### Integer + +▸ `Static`**Integer**(`num`: *number*): [*Integer*](json.integer.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`num` | *number* | + +**Returns:** [*Integer*](json.integer.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:120](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L120) + +___ + +### Null + +▸ `Static`**Null**(): [*Null*](json.null.md) + +**Returns:** [*Null*](json.null.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:126](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L126) + +___ + +### Number + +▸ `Static`**Number**(`num`: *number*): [*Num*](json.num.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`num` | *number* | + +**Returns:** [*Num*](json.num.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:114](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L114) + +___ + +### Object + +▸ `Static`**Object**(): [*Obj*](json.obj.md) + +**Returns:** [*Obj*](json.obj.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:132](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L132) + +___ + +### String + +▸ `Static`**String**(`str`: *string*): [*Str*](json.str.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`str` | *string* | + +**Returns:** [*Str*](json.str.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:111](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L111) diff --git a/docs/classes/json.null.md b/docs/classes/json.null.md new file mode 100644 index 0000000..6653cc8 --- /dev/null +++ b/docs/classes/json.null.md @@ -0,0 +1,281 @@ +[assemblyscript-json](../README.md) / [JSON](../modules/json.md) / Null + +# Class: Null + +[JSON](../modules/json.md).Null + +## Hierarchy + +* [*Value*](json.value.md) + + ↳ **Null** + +## Table of contents + +### Constructors + +- [constructor](json.null.md#constructor) + +### Accessors + +- [isArr](json.null.md#isarr) +- [isBool](json.null.md#isbool) +- [isFloat](json.null.md#isfloat) +- [isInteger](json.null.md#isinteger) +- [isNull](json.null.md#isnull) +- [isNum](json.null.md#isnum) +- [isObj](json.null.md#isobj) +- [isString](json.null.md#isstring) + +### Methods + +- [toString](json.null.md#tostring) +- [valueOf](json.null.md#valueof) +- [Array](json.null.md#array) +- [Bool](json.null.md#bool) +- [Float](json.null.md#float) +- [Integer](json.null.md#integer) +- [Null](json.null.md#null) +- [Number](json.null.md#number) +- [Object](json.null.md#object) +- [String](json.null.md#string) + +## Constructors + +### constructor + +\+ **new Null**(): [*Null*](json.null.md) + +**Returns:** [*Null*](json.null.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:243](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L243) + +## Accessors + +### isArr + +• **isArr**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:178](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L178) + +___ + +### isBool + +• **isBool**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:164](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L164) + +___ + +### isFloat + +• **isFloat**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:150](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L150) + +___ + +### isInteger + +• **isInteger**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:157](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L157) + +___ + +### isNull + +• **isNull**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:171](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L171) + +___ + +### isNum + +• **isNum**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:143](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L143) + +___ + +### isObj + +• **isObj**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:185](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L185) + +___ + +### isString + +• **isString**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:136](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L136) + +## Methods + +### toString + +▸ **toString**(): *string* + +**Returns:** *string* + +Overrides: [Value](json.value.md) + +Defined in: [JSON.ts:248](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L248) + +___ + +### valueOf + +▸ **valueOf**(): *null* + +**Returns:** *null* + +Defined in: [JSON.ts:252](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L252) + +___ + +### Array + +▸ `Static`**Array**(): [*Arr*](json.arr.md) + +**Returns:** [*Arr*](json.arr.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:129](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L129) + +___ + +### Bool + +▸ `Static`**Bool**(`b`: bool): [*Bool*](json.bool.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`b` | bool | + +**Returns:** [*Bool*](json.bool.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:123](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L123) + +___ + +### Float + +▸ `Static`**Float**(`num`: *number*): [*Float*](json.float.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`num` | *number* | + +**Returns:** [*Float*](json.float.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:117](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L117) + +___ + +### Integer + +▸ `Static`**Integer**(`num`: *number*): [*Integer*](json.integer.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`num` | *number* | + +**Returns:** [*Integer*](json.integer.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:120](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L120) + +___ + +### Null + +▸ `Static`**Null**(): [*Null*](json.null.md) + +**Returns:** [*Null*](json.null.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:126](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L126) + +___ + +### Number + +▸ `Static`**Number**(`num`: *number*): [*Num*](json.num.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`num` | *number* | + +**Returns:** [*Num*](json.num.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:114](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L114) + +___ + +### Object + +▸ `Static`**Object**(): [*Obj*](json.obj.md) + +**Returns:** [*Obj*](json.obj.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:132](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L132) + +___ + +### String + +▸ `Static`**String**(`str`: *string*): [*Str*](json.str.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`str` | *string* | + +**Returns:** [*Str*](json.str.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:111](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L111) diff --git a/docs/classes/json.num.md b/docs/classes/json.num.md new file mode 100644 index 0000000..dad05d0 --- /dev/null +++ b/docs/classes/json.num.md @@ -0,0 +1,299 @@ +[assemblyscript-json](../README.md) / [JSON](../modules/json.md) / Num + +# Class: Num + +[JSON](../modules/json.md).Num + +## Hierarchy + +* [*Value*](json.value.md) + + ↳ **Num** + + ↳↳ [*Float*](json.float.md) + +## Table of contents + +### Constructors + +- [constructor](json.num.md#constructor) + +### Properties + +- [\_num](json.num.md#_num) + +### Accessors + +- [isArr](json.num.md#isarr) +- [isBool](json.num.md#isbool) +- [isFloat](json.num.md#isfloat) +- [isInteger](json.num.md#isinteger) +- [isNull](json.num.md#isnull) +- [isNum](json.num.md#isnum) +- [isObj](json.num.md#isobj) +- [isString](json.num.md#isstring) + +### Methods + +- [toString](json.num.md#tostring) +- [valueOf](json.num.md#valueof) +- [Array](json.num.md#array) +- [Bool](json.num.md#bool) +- [Float](json.num.md#float) +- [Integer](json.num.md#integer) +- [Null](json.num.md#null) +- [Number](json.num.md#number) +- [Object](json.num.md#object) +- [String](json.num.md#string) + +## Constructors + +### constructor + +\+ **new Num**(`_num`: *number*): [*Num*](json.num.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`_num` | *number* | + +**Returns:** [*Num*](json.num.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:212](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L212) + +## Properties + +### \_num + +• **\_num**: *number* + +## Accessors + +### isArr + +• **isArr**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:178](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L178) + +___ + +### isBool + +• **isBool**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:164](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L164) + +___ + +### isFloat + +• **isFloat**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:150](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L150) + +___ + +### isInteger + +• **isInteger**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:157](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L157) + +___ + +### isNull + +• **isNull**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:171](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L171) + +___ + +### isNum + +• **isNum**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:143](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L143) + +___ + +### isObj + +• **isObj**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:185](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L185) + +___ + +### isString + +• **isString**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:136](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L136) + +## Methods + +### toString + +▸ **toString**(): *string* + +**Returns:** *string* + +Overrides: [Value](json.value.md) + +Defined in: [JSON.ts:217](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L217) + +___ + +### valueOf + +▸ **valueOf**(): *number* + +**Returns:** *number* + +Defined in: [JSON.ts:221](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L221) + +___ + +### Array + +▸ `Static`**Array**(): [*Arr*](json.arr.md) + +**Returns:** [*Arr*](json.arr.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:129](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L129) + +___ + +### Bool + +▸ `Static`**Bool**(`b`: bool): [*Bool*](json.bool.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`b` | bool | + +**Returns:** [*Bool*](json.bool.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:123](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L123) + +___ + +### Float + +▸ `Static`**Float**(`num`: *number*): [*Float*](json.float.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`num` | *number* | + +**Returns:** [*Float*](json.float.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:117](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L117) + +___ + +### Integer + +▸ `Static`**Integer**(`num`: *number*): [*Integer*](json.integer.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`num` | *number* | + +**Returns:** [*Integer*](json.integer.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:120](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L120) + +___ + +### Null + +▸ `Static`**Null**(): [*Null*](json.null.md) + +**Returns:** [*Null*](json.null.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:126](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L126) + +___ + +### Number + +▸ `Static`**Number**(`num`: *number*): [*Num*](json.num.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`num` | *number* | + +**Returns:** [*Num*](json.num.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:114](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L114) + +___ + +### Object + +▸ `Static`**Object**(): [*Obj*](json.obj.md) + +**Returns:** [*Obj*](json.obj.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:132](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L132) + +___ + +### String + +▸ `Static`**String**(`str`: *string*): [*Str*](json.str.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`str` | *string* | + +**Returns:** [*Str*](json.str.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:111](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L111) diff --git a/docs/classes/json.obj.md b/docs/classes/json.obj.md new file mode 100644 index 0000000..7a718a9 --- /dev/null +++ b/docs/classes/json.obj.md @@ -0,0 +1,497 @@ +[assemblyscript-json](../README.md) / [JSON](../modules/json.md) / Obj + +# Class: Obj + +[JSON](../modules/json.md).Obj + +## Hierarchy + +* [*Value*](json.value.md) + + ↳ **Obj** + +## Table of contents + +### Constructors + +- [constructor](json.obj.md#constructor) + +### Properties + +- [\_obj](json.obj.md#_obj) +- [keys](json.obj.md#keys) + +### Accessors + +- [isArr](json.obj.md#isarr) +- [isBool](json.obj.md#isbool) +- [isFloat](json.obj.md#isfloat) +- [isInteger](json.obj.md#isinteger) +- [isNull](json.obj.md#isnull) +- [isNum](json.obj.md#isnum) +- [isObj](json.obj.md#isobj) +- [isString](json.obj.md#isstring) + +### Methods + +- [\_set](json.obj.md#_set) +- [get](json.obj.md#get) +- [getArr](json.obj.md#getarr) +- [getBool](json.obj.md#getbool) +- [getFloat](json.obj.md#getfloat) +- [getInteger](json.obj.md#getinteger) +- [getNum](json.obj.md#getnum) +- [getString](json.obj.md#getstring) +- [getValue](json.obj.md#getvalue) +- [has](json.obj.md#has) +- [set](json.obj.md#set) +- [toString](json.obj.md#tostring) +- [valueOf](json.obj.md#valueof) +- [Array](json.obj.md#array) +- [Bool](json.obj.md#bool) +- [Float](json.obj.md#float) +- [Integer](json.obj.md#integer) +- [Null](json.obj.md#null) +- [Number](json.obj.md#number) +- [Object](json.obj.md#object) +- [String](json.obj.md#string) + +## Constructors + +### constructor + +\+ **new Obj**(): [*Obj*](json.obj.md) + +**Returns:** [*Obj*](json.obj.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:301](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L301) + +## Properties + +### \_obj + +• **\_obj**: *Map*<*string*, [*Value*](json.value.md)\> + +Defined in: [JSON.ts:300](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L300) + +___ + +### keys + +• **keys**: *string*[] + +Defined in: [JSON.ts:301](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L301) + +## Accessors + +### isArr + +• **isArr**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:178](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L178) + +___ + +### isBool + +• **isBool**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:164](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L164) + +___ + +### isFloat + +• **isFloat**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:150](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L150) + +___ + +### isInteger + +• **isInteger**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:157](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L157) + +___ + +### isNull + +• **isNull**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:171](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L171) + +___ + +### isNum + +• **isNum**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:143](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L143) + +___ + +### isObj + +• **isObj**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:185](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L185) + +___ + +### isString + +• **isString**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:136](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L136) + +## Methods + +### \_set + +▸ `Private`**_set**(`key`: *string*, `value`: [*Value*](json.value.md)): *void* + +#### Parameters: + +Name | Type | +------ | ------ | +`key` | *string* | +`value` | [*Value*](json.value.md) | + +**Returns:** *void* + +Defined in: [JSON.ts:333](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L333) + +___ + +### get + +▸ **get**(`key`: *string*): *null* \| [*Value*](json.value.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`key` | *string* | + +**Returns:** *null* \| [*Value*](json.value.md) + +Defined in: [JSON.ts:344](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L344) + +___ + +### getArr + +▸ **getArr**(`key`: *string*): *null* \| [*Arr*](json.arr.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`key` | *string* | + +**Returns:** *null* \| [*Arr*](json.arr.md) + +Defined in: [JSON.ts:395](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L395) + +___ + +### getBool + +▸ **getBool**(`key`: *string*): *null* \| [*Bool*](json.bool.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`key` | *string* | + +**Returns:** *null* \| [*Bool*](json.bool.md) + +Defined in: [JSON.ts:387](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L387) + +___ + +### getFloat + +▸ **getFloat**(`key`: *string*): *null* \| [*Float*](json.float.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`key` | *string* | + +**Returns:** *null* \| [*Float*](json.float.md) + +Defined in: [JSON.ts:371](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L371) + +___ + +### getInteger + +▸ **getInteger**(`key`: *string*): *null* \| [*Integer*](json.integer.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`key` | *string* | + +**Returns:** *null* \| [*Integer*](json.integer.md) + +Defined in: [JSON.ts:379](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L379) + +___ + +### getNum + +▸ **getNum**(`key`: *string*): *null* \| [*Num*](json.num.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`key` | *string* | + +**Returns:** *null* \| [*Num*](json.num.md) + +Defined in: [JSON.ts:363](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L363) + +___ + +### getString + +▸ **getString**(`key`: *string*): *null* \| [*Str*](json.str.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`key` | *string* | + +**Returns:** *null* \| [*Str*](json.str.md) + +Defined in: [JSON.ts:355](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L355) + +___ + +### getValue + +▸ **getValue**(`key`: *string*): *null* \| [*Value*](json.value.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`key` | *string* | + +**Returns:** *null* \| [*Value*](json.value.md) + +Defined in: [JSON.ts:351](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L351) + +___ + +### has + +▸ **has**(`key`: *string*): bool + +#### Parameters: + +Name | Type | +------ | ------ | +`key` | *string* | + +**Returns:** bool + +Defined in: [JSON.ts:340](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L340) + +___ + +### set + +▸ **set**(`key`: *string*, `value`: T): *void* + +#### Type parameters: + +Name | +------ | +`T` | + +#### Parameters: + +Name | Type | +------ | ------ | +`key` | *string* | +`value` | T | + +**Returns:** *void* + +Defined in: [JSON.ts:324](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L324) + +___ + +### toString + +▸ **toString**(): *string* + +**Returns:** *string* + +Overrides: [Value](json.value.md) + +Defined in: [JSON.ts:309](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L309) + +___ + +### valueOf + +▸ **valueOf**(): *Map*<*string*, [*Value*](json.value.md)\> + +**Returns:** *Map*<*string*, [*Value*](json.value.md)\> + +Defined in: [JSON.ts:319](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L319) + +___ + +### Array + +▸ `Static`**Array**(): [*Arr*](json.arr.md) + +**Returns:** [*Arr*](json.arr.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:129](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L129) + +___ + +### Bool + +▸ `Static`**Bool**(`b`: bool): [*Bool*](json.bool.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`b` | bool | + +**Returns:** [*Bool*](json.bool.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:123](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L123) + +___ + +### Float + +▸ `Static`**Float**(`num`: *number*): [*Float*](json.float.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`num` | *number* | + +**Returns:** [*Float*](json.float.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:117](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L117) + +___ + +### Integer + +▸ `Static`**Integer**(`num`: *number*): [*Integer*](json.integer.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`num` | *number* | + +**Returns:** [*Integer*](json.integer.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:120](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L120) + +___ + +### Null + +▸ `Static`**Null**(): [*Null*](json.null.md) + +**Returns:** [*Null*](json.null.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:126](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L126) + +___ + +### Number + +▸ `Static`**Number**(`num`: *number*): [*Num*](json.num.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`num` | *number* | + +**Returns:** [*Num*](json.num.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:114](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L114) + +___ + +### Object + +▸ `Static`**Object**(): [*Obj*](json.obj.md) + +**Returns:** [*Obj*](json.obj.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:132](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L132) + +___ + +### String + +▸ `Static`**String**(`str`: *string*): [*Str*](json.str.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`str` | *string* | + +**Returns:** [*Str*](json.str.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:111](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L111) diff --git a/docs/classes/json.str.md b/docs/classes/json.str.md new file mode 100644 index 0000000..e6c4832 --- /dev/null +++ b/docs/classes/json.str.md @@ -0,0 +1,297 @@ +[assemblyscript-json](../README.md) / [JSON](../modules/json.md) / Str + +# Class: Str + +[JSON](../modules/json.md).Str + +## Hierarchy + +* [*Value*](json.value.md) + + ↳ **Str** + +## Table of contents + +### Constructors + +- [constructor](json.str.md#constructor) + +### Properties + +- [\_str](json.str.md#_str) + +### Accessors + +- [isArr](json.str.md#isarr) +- [isBool](json.str.md#isbool) +- [isFloat](json.str.md#isfloat) +- [isInteger](json.str.md#isinteger) +- [isNull](json.str.md#isnull) +- [isNum](json.str.md#isnum) +- [isObj](json.str.md#isobj) +- [isString](json.str.md#isstring) + +### Methods + +- [toString](json.str.md#tostring) +- [valueOf](json.str.md#valueof) +- [Array](json.str.md#array) +- [Bool](json.str.md#bool) +- [Float](json.str.md#float) +- [Integer](json.str.md#integer) +- [Null](json.str.md#null) +- [Number](json.str.md#number) +- [Object](json.str.md#object) +- [String](json.str.md#string) + +## Constructors + +### constructor + +\+ **new Str**(`_str`: *string*): [*Str*](json.str.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`_str` | *string* | + +**Returns:** [*Str*](json.str.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:198](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L198) + +## Properties + +### \_str + +• **\_str**: *string* + +## Accessors + +### isArr + +• **isArr**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:178](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L178) + +___ + +### isBool + +• **isBool**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:164](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L164) + +___ + +### isFloat + +• **isFloat**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:150](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L150) + +___ + +### isInteger + +• **isInteger**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:157](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L157) + +___ + +### isNull + +• **isNull**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:171](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L171) + +___ + +### isNum + +• **isNum**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:143](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L143) + +___ + +### isObj + +• **isObj**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:185](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L185) + +___ + +### isString + +• **isString**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:136](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L136) + +## Methods + +### toString + +▸ **toString**(): *string* + +**Returns:** *string* + +Overrides: [Value](json.value.md) + +Defined in: [JSON.ts:203](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L203) + +___ + +### valueOf + +▸ **valueOf**(): *string* + +**Returns:** *string* + +Defined in: [JSON.ts:207](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L207) + +___ + +### Array + +▸ `Static`**Array**(): [*Arr*](json.arr.md) + +**Returns:** [*Arr*](json.arr.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:129](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L129) + +___ + +### Bool + +▸ `Static`**Bool**(`b`: bool): [*Bool*](json.bool.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`b` | bool | + +**Returns:** [*Bool*](json.bool.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:123](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L123) + +___ + +### Float + +▸ `Static`**Float**(`num`: *number*): [*Float*](json.float.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`num` | *number* | + +**Returns:** [*Float*](json.float.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:117](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L117) + +___ + +### Integer + +▸ `Static`**Integer**(`num`: *number*): [*Integer*](json.integer.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`num` | *number* | + +**Returns:** [*Integer*](json.integer.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:120](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L120) + +___ + +### Null + +▸ `Static`**Null**(): [*Null*](json.null.md) + +**Returns:** [*Null*](json.null.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:126](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L126) + +___ + +### Number + +▸ `Static`**Number**(`num`: *number*): [*Num*](json.num.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`num` | *number* | + +**Returns:** [*Num*](json.num.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:114](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L114) + +___ + +### Object + +▸ `Static`**Object**(): [*Obj*](json.obj.md) + +**Returns:** [*Obj*](json.obj.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:132](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L132) + +___ + +### String + +▸ `Static`**String**(`str`: *string*): [*Str*](json.str.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`str` | *string* | + +**Returns:** [*Str*](json.str.md) + +Inherited from: [Value](json.value.md) + +Defined in: [JSON.ts:111](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L111) diff --git a/docs/classes/json.value.md b/docs/classes/json.value.md new file mode 100644 index 0000000..411cbd9 --- /dev/null +++ b/docs/classes/json.value.md @@ -0,0 +1,260 @@ +[assemblyscript-json](../README.md) / [JSON](../modules/json.md) / Value + +# Class: Value + +[JSON](../modules/json.md).Value + +## Hierarchy + +* **Value** + + ↳ [*Str*](json.str.md) + + ↳ [*Num*](json.num.md) + + ↳ [*Integer*](json.integer.md) + + ↳ [*Null*](json.null.md) + + ↳ [*Bool*](json.bool.md) + + ↳ [*Arr*](json.arr.md) + + ↳ [*Obj*](json.obj.md) + +## Table of contents + +### Constructors + +- [constructor](json.value.md#constructor) + +### Accessors + +- [isArr](json.value.md#isarr) +- [isBool](json.value.md#isbool) +- [isFloat](json.value.md#isfloat) +- [isInteger](json.value.md#isinteger) +- [isNull](json.value.md#isnull) +- [isNum](json.value.md#isnum) +- [isObj](json.value.md#isobj) +- [isString](json.value.md#isstring) + +### Methods + +- [toString](json.value.md#tostring) +- [Array](json.value.md#array) +- [Bool](json.value.md#bool) +- [Float](json.value.md#float) +- [Integer](json.value.md#integer) +- [Null](json.value.md#null) +- [Number](json.value.md#number) +- [Object](json.value.md#object) +- [String](json.value.md#string) + +## Constructors + +### constructor + +\+ **new Value**(): [*Value*](json.value.md) + +**Returns:** [*Value*](json.value.md) + +## Accessors + +### isArr + +• **isArr**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:178](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L178) + +___ + +### isBool + +• **isBool**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:164](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L164) + +___ + +### isFloat + +• **isFloat**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:150](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L150) + +___ + +### isInteger + +• **isInteger**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:157](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L157) + +___ + +### isNull + +• **isNull**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:171](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L171) + +___ + +### isNum + +• **isNum**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:143](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L143) + +___ + +### isObj + +• **isObj**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:185](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L185) + +___ + +### isString + +• **isString**(): *boolean* + +**Returns:** *boolean* + +Defined in: [JSON.ts:136](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L136) + +## Methods + +### toString + +▸ **toString**(): *string* + +**Returns:** *string* + +Defined in: [JSON.ts:192](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L192) + +___ + +### Array + +▸ `Static`**Array**(): [*Arr*](json.arr.md) + +**Returns:** [*Arr*](json.arr.md) + +Defined in: [JSON.ts:129](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L129) + +___ + +### Bool + +▸ `Static`**Bool**(`b`: bool): [*Bool*](json.bool.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`b` | bool | + +**Returns:** [*Bool*](json.bool.md) + +Defined in: [JSON.ts:123](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L123) + +___ + +### Float + +▸ `Static`**Float**(`num`: *number*): [*Float*](json.float.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`num` | *number* | + +**Returns:** [*Float*](json.float.md) + +Defined in: [JSON.ts:117](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L117) + +___ + +### Integer + +▸ `Static`**Integer**(`num`: *number*): [*Integer*](json.integer.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`num` | *number* | + +**Returns:** [*Integer*](json.integer.md) + +Defined in: [JSON.ts:120](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L120) + +___ + +### Null + +▸ `Static`**Null**(): [*Null*](json.null.md) + +**Returns:** [*Null*](json.null.md) + +Defined in: [JSON.ts:126](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L126) + +___ + +### Number + +▸ `Static`**Number**(`num`: *number*): [*Num*](json.num.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`num` | *number* | + +**Returns:** [*Num*](json.num.md) + +Defined in: [JSON.ts:114](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L114) + +___ + +### Object + +▸ `Static`**Object**(): [*Obj*](json.obj.md) + +**Returns:** [*Obj*](json.obj.md) + +Defined in: [JSON.ts:132](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L132) + +___ + +### String + +▸ `Static`**String**(`str`: *string*): [*Str*](json.str.md) + +#### Parameters: + +Name | Type | +------ | ------ | +`str` | *string* | + +**Returns:** [*Str*](json.str.md) + +Defined in: [JSON.ts:111](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L111) diff --git a/docs/classes/jsondecoder.md b/docs/classes/jsondecoder.md new file mode 100644 index 0000000..c52f6d6 --- /dev/null +++ b/docs/classes/jsondecoder.md @@ -0,0 +1,297 @@ +[assemblyscript-json](../README.md) / JSONDecoder + +# Class: JSONDecoder + +## Type parameters + +Name | Type | +------ | ------ | +`JSONHandlerT` | [*JSONHandler*](jsonhandler.md) | + +## Hierarchy + +* **JSONDecoder** + +## Table of contents + +### Constructors + +- [constructor](jsondecoder.md#constructor) + +### Properties + +- [\_state](jsondecoder.md#_state) +- [handler](jsondecoder.md#handler) + +### Accessors + +- [state](jsondecoder.md#state) + +### Methods + +- [deserialize](jsondecoder.md#deserialize) +- [isWhitespace](jsondecoder.md#iswhitespace) +- [parseArray](jsondecoder.md#parsearray) +- [parseBoolean](jsondecoder.md#parseboolean) +- [parseKey](jsondecoder.md#parsekey) +- [parseNull](jsondecoder.md#parsenull) +- [parseNumber](jsondecoder.md#parsenumber) +- [parseObject](jsondecoder.md#parseobject) +- [parseString](jsondecoder.md#parsestring) +- [parseValue](jsondecoder.md#parsevalue) +- [peekChar](jsondecoder.md#peekchar) +- [readAndAssert](jsondecoder.md#readandassert) +- [readChar](jsondecoder.md#readchar) +- [readEscapedChar](jsondecoder.md#readescapedchar) +- [readHexDigit](jsondecoder.md#readhexdigit) +- [readString](jsondecoder.md#readstring) +- [skipWhitespace](jsondecoder.md#skipwhitespace) + +## Constructors + +### constructor + +\+ **new JSONDecoder**(`handler`: JSONHandlerT): [*JSONDecoder*](jsondecoder.md) + +#### Type parameters: + +Name | Type | +------ | ------ | +`JSONHandlerT` | [*JSONHandler*](jsonhandler.md) | + +#### Parameters: + +Name | Type | +------ | ------ | +`handler` | JSONHandlerT | + +**Returns:** [*JSONDecoder*](jsondecoder.md) + +Defined in: [decoder.ts:120](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/decoder.ts#L120) + +## Properties + +### \_state + +• **\_state**: *null* \| [*DecoderState*](decoderstate.md)= null + +Defined in: [decoder.ts:120](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/decoder.ts#L120) + +___ + +### handler + +• **handler**: JSONHandlerT + +Defined in: [decoder.ts:119](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/decoder.ts#L119) + +## Accessors + +### state + +• **state**(): [*DecoderState*](decoderstate.md) + +**Returns:** [*DecoderState*](decoderstate.md) + +Defined in: [decoder.ts:126](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/decoder.ts#L126) + +• **state**(`state`: [*DecoderState*](decoderstate.md)): *void* + +#### Parameters: + +Name | Type | +------ | ------ | +`state` | [*DecoderState*](decoderstate.md) | + +**Returns:** *void* + +Defined in: [decoder.ts:130](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/decoder.ts#L130) + +## Methods + +### deserialize + +▸ **deserialize**(`buffer`: *Uint8Array*, `decoderState?`: *null* \| [*DecoderState*](decoderstate.md)): *void* + +#### Parameters: + +Name | Type | Default value | +------ | ------ | ------ | +`buffer` | *Uint8Array* | - | +`decoderState` | *null* \| [*DecoderState*](decoderstate.md) | null | + +**Returns:** *void* + +Defined in: [decoder.ts:134](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/decoder.ts#L134) + +___ + +### isWhitespace + +▸ `Private`**isWhitespace**(`charCode`: *number*): bool + +#### Parameters: + +Name | Type | +------ | ------ | +`charCode` | *number* | + +**Returns:** bool + +Defined in: [decoder.ts:406](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/decoder.ts#L406) + +___ + +### parseArray + +▸ `Private`**parseArray**(): bool + +**Returns:** bool + +Defined in: [decoder.ts:210](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/decoder.ts#L210) + +___ + +### parseBoolean + +▸ `Private`**parseBoolean**(): bool + +**Returns:** bool + +Defined in: [decoder.ts:370](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/decoder.ts#L370) + +___ + +### parseKey + +▸ `Private`**parseKey**(): *void* + +**Returns:** *void* + +Defined in: [decoder.ts:203](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/decoder.ts#L203) + +___ + +### parseNull + +▸ `Private`**parseNull**(): bool + +**Returns:** bool + +Defined in: [decoder.ts:385](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/decoder.ts#L385) + +___ + +### parseNumber + +▸ `Private`**parseNumber**(): bool + +**Returns:** bool + +Defined in: [decoder.ts:323](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/decoder.ts#L323) + +___ + +### parseObject + +▸ `Private`**parseObject**(): bool + +**Returns:** bool + +Defined in: [decoder.ts:176](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/decoder.ts#L176) + +___ + +### parseString + +▸ `Private`**parseString**(): bool + +**Returns:** bool + +Defined in: [decoder.ts:236](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/decoder.ts#L236) + +___ + +### parseValue + +▸ `Private`**parseValue**(): bool + +**Returns:** bool + +Defined in: [decoder.ts:163](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/decoder.ts#L163) + +___ + +### peekChar + +▸ `Private`**peekChar**(): *number* + +**Returns:** *number* + +Defined in: [decoder.ts:148](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/decoder.ts#L148) + +___ + +### readAndAssert + +▸ `Private`**readAndAssert**(`str`: *string*): *void* + +#### Parameters: + +Name | Type | +------ | ------ | +`str` | *string* | + +**Returns:** *void* + +Defined in: [decoder.ts:394](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/decoder.ts#L394) + +___ + +### readChar + +▸ `Private`**readChar**(): *number* + +**Returns:** *number* + +Defined in: [decoder.ts:155](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/decoder.ts#L155) + +___ + +### readEscapedChar + +▸ `Private`**readEscapedChar**(): *string* + +**Returns:** *string* + +Defined in: [decoder.ts:274](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/decoder.ts#L274) + +___ + +### readHexDigit + +▸ `Private`**readHexDigit**(): *number* + +**Returns:** *number* + +Defined in: [decoder.ts:310](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/decoder.ts#L310) + +___ + +### readString + +▸ `Private`**readString**(): *string* + +**Returns:** *string* + +Defined in: [decoder.ts:244](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/decoder.ts#L244) + +___ + +### skipWhitespace + +▸ `Private`**skipWhitespace**(): *void* + +**Returns:** *void* + +Defined in: [decoder.ts:400](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/decoder.ts#L400) diff --git a/docs/classes/jsonencoder.md b/docs/classes/jsonencoder.md new file mode 100644 index 0000000..1e7b17e --- /dev/null +++ b/docs/classes/jsonencoder.md @@ -0,0 +1,330 @@ +[assemblyscript-json](../README.md) / JSONEncoder + +# Class: JSONEncoder + +## Hierarchy + +* **JSONEncoder** + +## Table of contents + +### Constructors + +- [constructor](jsonencoder.md#constructor) + +### Properties + +- [\_isFirstKey](jsonencoder.md#_isfirstkey) +- [result](jsonencoder.md#result) + +### Accessors + +- [isFirstKey](jsonencoder.md#isfirstkey) + +### Methods + +- [popArray](jsonencoder.md#poparray) +- [popObject](jsonencoder.md#popobject) +- [pushArray](jsonencoder.md#pusharray) +- [pushObject](jsonencoder.md#pushobject) +- [serialize](jsonencoder.md#serialize) +- [setBoolean](jsonencoder.md#setboolean) +- [setFloat](jsonencoder.md#setfloat) +- [setInteger](jsonencoder.md#setinteger) +- [setNull](jsonencoder.md#setnull) +- [setString](jsonencoder.md#setstring) +- [toString](jsonencoder.md#tostring) +- [write](jsonencoder.md#write) +- [writeBoolean](jsonencoder.md#writeboolean) +- [writeFloat](jsonencoder.md#writefloat) +- [writeInteger](jsonencoder.md#writeinteger) +- [writeKey](jsonencoder.md#writekey) +- [writeString](jsonencoder.md#writestring) + +## Constructors + +### constructor + +\+ **new JSONEncoder**(): [*JSONEncoder*](jsonencoder.md) + +**Returns:** [*JSONEncoder*](jsonencoder.md) + +Defined in: [encoder.ts:5](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/encoder.ts#L5) + +## Properties + +### \_isFirstKey + +• `Private` **\_isFirstKey**: *number*[] + +Defined in: [encoder.ts:4](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/encoder.ts#L4) + +___ + +### result + +• `Private` **result**: *string*[] + +Defined in: [encoder.ts:5](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/encoder.ts#L5) + +## Accessors + +### isFirstKey + +• **isFirstKey**(): bool + +**Returns:** bool + +Defined in: [encoder.ts:13](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/encoder.ts#L13) + +## Methods + +### popArray + +▸ **popArray**(): *void* + +**Returns:** *void* + +Defined in: [encoder.ts:58](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/encoder.ts#L58) + +___ + +### popObject + +▸ **popObject**(): *void* + +**Returns:** *void* + +Defined in: [encoder.ts:70](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/encoder.ts#L70) + +___ + +### pushArray + +▸ **pushArray**(`name`: *null* \| *string*): bool + +#### Parameters: + +Name | Type | +------ | ------ | +`name` | *null* \| *string* | + +**Returns:** bool + +Defined in: [encoder.ts:51](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/encoder.ts#L51) + +___ + +### pushObject + +▸ **pushObject**(`name`: *null* \| *string*): bool + +#### Parameters: + +Name | Type | +------ | ------ | +`name` | *null* \| *string* | + +**Returns:** bool + +Defined in: [encoder.ts:63](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/encoder.ts#L63) + +___ + +### serialize + +▸ **serialize**(): *Uint8Array* + +**Returns:** *Uint8Array* + +Defined in: [encoder.ts:17](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/encoder.ts#L17) + +___ + +### setBoolean + +▸ **setBoolean**(`name`: *null* \| *string*, `value`: bool): *void* + +#### Parameters: + +Name | Type | +------ | ------ | +`name` | *null* \| *string* | +`value` | bool | + +**Returns:** *void* + +Defined in: [encoder.ts:31](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/encoder.ts#L31) + +___ + +### setFloat + +▸ **setFloat**(`name`: *null* \| *string*, `value`: *number*): *void* + +#### Parameters: + +Name | Type | +------ | ------ | +`name` | *null* \| *string* | +`value` | *number* | + +**Returns:** *void* + +Defined in: [encoder.ts:46](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/encoder.ts#L46) + +___ + +### setInteger + +▸ **setInteger**(`name`: *null* \| *string*, `value`: *number*): *void* + +#### Parameters: + +Name | Type | +------ | ------ | +`name` | *null* \| *string* | +`value` | *number* | + +**Returns:** *void* + +Defined in: [encoder.ts:41](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/encoder.ts#L41) + +___ + +### setNull + +▸ **setNull**(`name`: *null* \| *string*): *void* + +#### Parameters: + +Name | Type | +------ | ------ | +`name` | *null* \| *string* | + +**Returns:** *void* + +Defined in: [encoder.ts:36](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/encoder.ts#L36) + +___ + +### setString + +▸ **setString**(`name`: *null* \| *string*, `value`: *string*): *void* + +#### Parameters: + +Name | Type | +------ | ------ | +`name` | *null* \| *string* | +`value` | *string* | + +**Returns:** *void* + +Defined in: [encoder.ts:26](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/encoder.ts#L26) + +___ + +### toString + +▸ **toString**(): *string* + +**Returns:** *string* + +Defined in: [encoder.ts:22](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/encoder.ts#L22) + +___ + +### write + +▸ `Private`**write**(`str`: *string*): *void* + +#### Parameters: + +Name | Type | +------ | ------ | +`str` | *string* | + +**Returns:** *void* + +Defined in: [encoder.ts:135](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/encoder.ts#L135) + +___ + +### writeBoolean + +▸ `Private`**writeBoolean**(`value`: bool): *void* + +#### Parameters: + +Name | Type | +------ | ------ | +`value` | bool | + +**Returns:** *void* + +Defined in: [encoder.ts:123](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/encoder.ts#L123) + +___ + +### writeFloat + +▸ `Private`**writeFloat**(`value`: *number*): *void* + +#### Parameters: + +Name | Type | +------ | ------ | +`value` | *number* | + +**Returns:** *void* + +Defined in: [encoder.ts:131](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/encoder.ts#L131) + +___ + +### writeInteger + +▸ `Private`**writeInteger**(`value`: *number*): *void* + +#### Parameters: + +Name | Type | +------ | ------ | +`value` | *number* | + +**Returns:** *void* + +Defined in: [encoder.ts:127](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/encoder.ts#L127) + +___ + +### writeKey + +▸ `Private`**writeKey**(`str`: *null* \| *string*): *void* + +#### Parameters: + +Name | Type | +------ | ------ | +`str` | *null* \| *string* | + +**Returns:** *void* + +Defined in: [encoder.ts:75](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/encoder.ts#L75) + +___ + +### writeString + +▸ `Private`**writeString**(`str`: *string*): *void* + +#### Parameters: + +Name | Type | +------ | ------ | +`str` | *string* | + +**Returns:** *void* + +Defined in: [encoder.ts:87](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/encoder.ts#L87) diff --git a/docs/classes/jsonhandler.md b/docs/classes/jsonhandler.md new file mode 100644 index 0000000..fed62c2 --- /dev/null +++ b/docs/classes/jsonhandler.md @@ -0,0 +1,174 @@ +[assemblyscript-json](../README.md) / JSONHandler + +# Class: JSONHandler + +Extend from this class to handle events from parser. +Default implementation traverses whole object tree and does nothing. + +## Hierarchy + +* **JSONHandler** + + ↳ [*ThrowingJSONHandler*](throwingjsonhandler.md) + +## Table of contents + +### Constructors + +- [constructor](jsonhandler.md#constructor) + +### Methods + +- [popArray](jsonhandler.md#poparray) +- [popObject](jsonhandler.md#popobject) +- [pushArray](jsonhandler.md#pusharray) +- [pushObject](jsonhandler.md#pushobject) +- [setBoolean](jsonhandler.md#setboolean) +- [setFloat](jsonhandler.md#setfloat) +- [setInteger](jsonhandler.md#setinteger) +- [setNull](jsonhandler.md#setnull) +- [setString](jsonhandler.md#setstring) + +## Constructors + +### constructor + +\+ **new JSONHandler**(): [*JSONHandler*](jsonhandler.md) + +**Returns:** [*JSONHandler*](jsonhandler.md) + +## Methods + +### popArray + +▸ **popArray**(): *void* + +**Returns:** *void* + +Defined in: [decoder.ts:22](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/decoder.ts#L22) + +___ + +### popObject + +▸ **popObject**(): *void* + +**Returns:** *void* + +Defined in: [decoder.ts:28](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/decoder.ts#L28) + +___ + +### pushArray + +▸ **pushArray**(`name`: *string*): bool + +#### Parameters: + +Name | Type | +------ | ------ | +`name` | *string* | + +**Returns:** bool + +Defined in: [decoder.ts:18](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/decoder.ts#L18) + +___ + +### pushObject + +▸ **pushObject**(`name`: *string*): bool + +#### Parameters: + +Name | Type | +------ | ------ | +`name` | *string* | + +**Returns:** bool + +Defined in: [decoder.ts:24](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/decoder.ts#L24) + +___ + +### setBoolean + +▸ **setBoolean**(`name`: *string*, `value`: bool): *void* + +#### Parameters: + +Name | Type | +------ | ------ | +`name` | *string* | +`value` | bool | + +**Returns:** *void* + +Defined in: [decoder.ts:10](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/decoder.ts#L10) + +___ + +### setFloat + +▸ **setFloat**(`name`: *string*, `value`: *number*): *void* + +#### Parameters: + +Name | Type | +------ | ------ | +`name` | *string* | +`value` | *number* | + +**Returns:** *void* + +Defined in: [decoder.ts:16](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/decoder.ts#L16) + +___ + +### setInteger + +▸ **setInteger**(`name`: *string*, `value`: *number*): *void* + +#### Parameters: + +Name | Type | +------ | ------ | +`name` | *string* | +`value` | *number* | + +**Returns:** *void* + +Defined in: [decoder.ts:14](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/decoder.ts#L14) + +___ + +### setNull + +▸ **setNull**(`name`: *string*): *void* + +#### Parameters: + +Name | Type | +------ | ------ | +`name` | *string* | + +**Returns:** *void* + +Defined in: [decoder.ts:12](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/decoder.ts#L12) + +___ + +### setString + +▸ **setString**(`name`: *string*, `value`: *string*): *void* + +#### Parameters: + +Name | Type | +------ | ------ | +`name` | *string* | +`value` | *string* | + +**Returns:** *void* + +Defined in: [decoder.ts:8](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/decoder.ts#L8) diff --git a/docs/classes/throwingjsonhandler.md b/docs/classes/throwingjsonhandler.md new file mode 100644 index 0000000..1a8ca29 --- /dev/null +++ b/docs/classes/throwingjsonhandler.md @@ -0,0 +1,195 @@ +[assemblyscript-json](../README.md) / ThrowingJSONHandler + +# Class: ThrowingJSONHandler + +Extend from this class to handle events from parser. +This implementation crashes on every unimplemented set/push method +to allow easier validation of input. + +## Hierarchy + +* [*JSONHandler*](jsonhandler.md) + + ↳ **ThrowingJSONHandler** + +## Table of contents + +### Constructors + +- [constructor](throwingjsonhandler.md#constructor) + +### Methods + +- [popArray](throwingjsonhandler.md#poparray) +- [popObject](throwingjsonhandler.md#popobject) +- [pushArray](throwingjsonhandler.md#pusharray) +- [pushObject](throwingjsonhandler.md#pushobject) +- [setBoolean](throwingjsonhandler.md#setboolean) +- [setFloat](throwingjsonhandler.md#setfloat) +- [setInteger](throwingjsonhandler.md#setinteger) +- [setNull](throwingjsonhandler.md#setnull) +- [setString](throwingjsonhandler.md#setstring) + +## Constructors + +### constructor + +\+ **new ThrowingJSONHandler**(): [*ThrowingJSONHandler*](throwingjsonhandler.md) + +**Returns:** [*ThrowingJSONHandler*](throwingjsonhandler.md) + +Inherited from: [JSONHandler](jsonhandler.md) + +## Methods + +### popArray + +▸ **popArray**(): *void* + +**Returns:** *void* + +Inherited from: [JSONHandler](jsonhandler.md) + +Defined in: [decoder.ts:22](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/decoder.ts#L22) + +___ + +### popObject + +▸ **popObject**(): *void* + +**Returns:** *void* + +Inherited from: [JSONHandler](jsonhandler.md) + +Defined in: [decoder.ts:28](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/decoder.ts#L28) + +___ + +### pushArray + +▸ **pushArray**(`name`: *string*): bool + +#### Parameters: + +Name | Type | +------ | ------ | +`name` | *string* | + +**Returns:** bool + +Overrides: [JSONHandler](jsonhandler.md) + +Defined in: [decoder.ts:68](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/decoder.ts#L68) + +___ + +### pushObject + +▸ **pushObject**(`name`: *string*): bool + +#### Parameters: + +Name | Type | +------ | ------ | +`name` | *string* | + +**Returns:** bool + +Overrides: [JSONHandler](jsonhandler.md) + +Defined in: [decoder.ts:73](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/decoder.ts#L73) + +___ + +### setBoolean + +▸ **setBoolean**(`name`: *string*, `value`: bool): *void* + +#### Parameters: + +Name | Type | +------ | ------ | +`name` | *string* | +`value` | bool | + +**Returns:** *void* + +Overrides: [JSONHandler](jsonhandler.md) + +Defined in: [decoder.ts:41](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/decoder.ts#L41) + +___ + +### setFloat + +▸ **setFloat**(`name`: *string*, `value`: *number*): *void* + +#### Parameters: + +Name | Type | +------ | ------ | +`name` | *string* | +`value` | *number* | + +**Returns:** *void* + +Overrides: [JSONHandler](jsonhandler.md) + +Defined in: [decoder.ts:60](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/decoder.ts#L60) + +___ + +### setInteger + +▸ **setInteger**(`name`: *string*, `value`: *number*): *void* + +#### Parameters: + +Name | Type | +------ | ------ | +`name` | *string* | +`value` | *number* | + +**Returns:** *void* + +Overrides: [JSONHandler](jsonhandler.md) + +Defined in: [decoder.ts:52](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/decoder.ts#L52) + +___ + +### setNull + +▸ **setNull**(`name`: *string*): *void* + +#### Parameters: + +Name | Type | +------ | ------ | +`name` | *string* | + +**Returns:** *void* + +Overrides: [JSONHandler](jsonhandler.md) + +Defined in: [decoder.ts:48](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/decoder.ts#L48) + +___ + +### setString + +▸ **setString**(`name`: *string*, `value`: *string*): *void* + +#### Parameters: + +Name | Type | +------ | ------ | +`name` | *string* | +`value` | *string* | + +**Returns:** *void* + +Overrides: [JSONHandler](jsonhandler.md) + +Defined in: [decoder.ts:37](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/decoder.ts#L37) diff --git a/docs/modules/json.md b/docs/modules/json.md new file mode 100644 index 0000000..0a0d975 --- /dev/null +++ b/docs/modules/json.md @@ -0,0 +1,66 @@ +[assemblyscript-json](../README.md) / JSON + +# Namespace: JSON + +## Table of contents + +### Classes + +- [Arr](../classes/json.arr.md) +- [Bool](../classes/json.bool.md) +- [Float](../classes/json.float.md) +- [Integer](../classes/json.integer.md) +- [Null](../classes/json.null.md) +- [Num](../classes/json.num.md) +- [Obj](../classes/json.obj.md) +- [Str](../classes/json.str.md) +- [Value](../classes/json.value.md) + +### Functions + +- [from](json.md#from) +- [parse](json.md#parse) + +## Functions + +### from + +▸ **from**(`val`: T): [*Value*](../classes/json.value.md) + +#### Type parameters: + +Name | +------ | +`T` | + +#### Parameters: + +Name | Type | +------ | ------ | +`val` | T | + +**Returns:** [*Value*](../classes/json.value.md) + +Defined in: [JSON.ts:404](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L404) + +___ + +### parse + +▸ **parse**(`str`: T): [*Value*](../classes/json.value.md) + +#### Type parameters: + +Name | Default | +------ | ------ | +`T` | *Uint8Array* | + +#### Parameters: + +Name | Type | +------ | ------ | +`str` | T | + +**Returns:** [*Value*](../classes/json.value.md) + +Defined in: [JSON.ts:437](https://github.com/torch2424/assemblyscript-json/blob/d5af3b8/assembly/JSON.ts#L437) diff --git a/package.json b/package.json index 62d8e49..4c05baf 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,8 @@ "asbuild": "yarn asbuild:untouched && yarn asbuild:optimized", "lint": "eslint --max-warnings 0 --ext ts \"assembly/**/*.ts\"", "lint:fix": "yarn lint --fix", + "docs": "typedoc --plugin typedoc-plugin-markdown --out temp-docs --tsconfig assembly/tsconfig.json --exclude \"node_modules/**/*\" --readme none assembly/index.ts", + "docs:deploy": "cp -r temp-docs/* docs", "test": "asp" }, "husky": { @@ -22,6 +24,8 @@ "assemblyscript": "^0.15.0", "eslint": "^7.17.0", "husky": "^4.3.7", + "typedoc": "^0.20.21", + "typedoc-plugin-markdown": "^3.4.5", "typescript": "^4.1.3" } } diff --git a/yarn.lock b/yarn.lock index 55aad6a..fb18e30 100644 --- a/yarn.lock +++ b/yarn.lock @@ -270,6 +270,11 @@ astral-regex@^2.0.0: resolved "https://registry.yarnpkg.com/astral-regex/-/astral-regex-2.0.0.tgz#483143c567aeed4785759c0865786dc77d7d2e31" integrity sha512-Z7tMw1ytTXt5jqMcOP+OQteU1VuNK9Y02uuJtKQ1Sv69jXQKKg5cibLwGJow8yzZP+eAc18EmLGPal0bp36rvQ== +at-least-node@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/at-least-node/-/at-least-node-1.0.0.tgz#602cd4b46e844ad4effc92a8011a3c46e0238dc2" + integrity sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg== + balanced-match@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767" @@ -346,6 +351,11 @@ color-name@~1.1.4: resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2" integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA== +colors@^1.4.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/colors/-/colors-1.4.0.tgz#c50491479d4c1bdaed2c9ced32cf7c7dc2360f78" + integrity sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA== + commander@^2.19.0: version "2.20.3" resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33" @@ -628,11 +638,26 @@ flatted@^3.1.0: resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.1.0.tgz#a5d06b4a8b01e3a63771daa5cb7a1903e2e57067" integrity sha512-tW+UkmtNg/jv9CSofAKvgVcO7c2URjhTdW1ZTkcAritblu8tajiYy7YisnIflEwtKssCtOxpnBRoCB7iap0/TA== +fs-extra@^9.1.0: + version "9.1.0" + resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-9.1.0.tgz#5954460c764a8da2094ba3554bf839e6b9a7c86d" + integrity sha512-hcg3ZmepS30/7BSFqRvoo3DOMQu7IjqxO5nCDt+zM9XWjb33Wg7ziNT+Qvqbuc3+gWpzO02JubVyk2G4Zvo1OQ== + dependencies: + at-least-node "^1.0.0" + graceful-fs "^4.2.0" + jsonfile "^6.0.1" + universalify "^2.0.0" + fs.realpath@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" integrity sha1-FQStJSMVjKpA20onh8sBQRmU6k8= +function-bind@^1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.1.tgz#a56899d3ea3c9bab874bb9773b7c5ede92f4895d" + integrity sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A== + functional-red-black-tree@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz#1b0ab3bd553b2a0d6399d29c0e3ea0b252078327" @@ -645,7 +670,7 @@ glob-parent@^5.0.0, glob-parent@^5.1.0: dependencies: is-glob "^4.0.1" -glob@^7.1.3, glob@^7.1.6: +glob@^7.0.0, glob@^7.1.3, glob@^7.1.6: version "7.1.6" resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.6.tgz#141f33b81a7c2492e125594307480c46679278a6" integrity sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA== @@ -676,6 +701,23 @@ globby@^11.0.1: merge2 "^1.3.0" slash "^3.0.0" +graceful-fs@^4.1.6, graceful-fs@^4.2.0: + version "4.2.5" + resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.5.tgz#bc18864a6c9fc7b303f2e2abdb9155ad178fbe29" + integrity sha512-kBBSQbz2K0Nyn+31j/w36fUfxkBW9/gfwRWdUY1ULReH3iokVJgddZAFcD1D0xlgTmFxJCbUkUclAlc6/IDJkw== + +handlebars@^4.7.6: + version "4.7.6" + resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.7.6.tgz#d4c05c1baf90e9945f77aa68a7a219aa4a7df74e" + integrity sha512-1f2BACcBfiwAfStCKZNrUCgqNZkGsAT7UM3kkYtXuLo0KnaVfjKOyf7PRzB6++aK9STyT1Pd2ZCPe3EGOXleXA== + dependencies: + minimist "^1.2.5" + neo-async "^2.6.0" + source-map "^0.6.1" + wordwrap "^1.0.0" + optionalDependencies: + uglify-js "^3.1.4" + has-flag@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-3.0.0.tgz#b5d454dc2199ae225699f3467e5a07f3b955bafd" @@ -686,6 +728,13 @@ has-flag@^4.0.0: resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-4.0.0.tgz#944771fd9c81c81265c4d6941860da06bb59479b" integrity sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ== +has@^1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/has/-/has-1.0.3.tgz#722d7cbfc1f6aa8241f16dd814e011e1f41e8796" + integrity sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw== + dependencies: + function-bind "^1.1.1" + husky@^4.3.7: version "4.3.7" resolved "https://registry.yarnpkg.com/husky/-/husky-4.3.7.tgz#ca47bbe6213c1aa8b16bbd504530d9600de91e88" @@ -738,11 +787,23 @@ inherits@2: resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c" integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== +interpret@^1.0.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/interpret/-/interpret-1.4.0.tgz#665ab8bc4da27a774a40584e812e3e0fa45b1a1e" + integrity sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA== + is-arrayish@^0.2.1: version "0.2.1" resolved "https://registry.yarnpkg.com/is-arrayish/-/is-arrayish-0.2.1.tgz#77c99840527aa8ecb1a8ba697b80645a7a926a9d" integrity sha1-d8mYQFJ6qOyxqLppe4BkWnqSap0= +is-core-module@^2.1.0: + version "2.2.0" + resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.2.0.tgz#97037ef3d52224d85163f5597b2b63d9afed981a" + integrity sha512-XRAfAdyyY5F5cOXn7hYQDqh2Xmii+DEfIcQGxK/uNwMHhIkPWO0g8msXcbzLe+MpGoR951MlqM/2iIlU4vKDdQ== + dependencies: + has "^1.0.3" + is-extglob@^2.1.1: version "2.1.1" resolved "https://registry.yarnpkg.com/is-extglob/-/is-extglob-2.1.1.tgz#a88c02535791f02ed37c76a1b9ea9773c833f8c2" @@ -803,6 +864,22 @@ json-stable-stringify-without-jsonify@^1.0.1: resolved "https://registry.yarnpkg.com/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz#9db7b59496ad3f3cfef30a75142d2d930ad72651" integrity sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE= +json5@^2.1.0: + version "2.2.0" + resolved "https://registry.yarnpkg.com/json5/-/json5-2.2.0.tgz#2dfefe720c6ba525d9ebd909950f0515316c89a3" + integrity sha512-f+8cldu7X/y7RAJurMEJmdoKXGB/X550w2Nr3tTbezL6RwEE/iMcm+tZnXeoZtKuOq6ft8+CqzEkrIgx1fPoQA== + dependencies: + minimist "^1.2.5" + +jsonfile@^6.0.1: + version "6.1.0" + resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-6.1.0.tgz#bc55b2634793c679ec6403094eb13698a6ec0aae" + integrity sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ== + dependencies: + universalify "^2.0.0" + optionalDependencies: + graceful-fs "^4.1.6" + levn@^0.4.1: version "0.4.1" resolved "https://registry.yarnpkg.com/levn/-/levn-0.4.1.tgz#ae4562c007473b932a6200d403268dd2fffc6ade" @@ -833,6 +910,13 @@ long@^4.0.0: resolved "https://registry.yarnpkg.com/long/-/long-4.0.0.tgz#9a7b71cfb7d361a194ea555241c92f7468d5bf28" integrity sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA== +lru-cache@^5.1.1: + version "5.1.1" + resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-5.1.1.tgz#1da27e6710271947695daf6848e847f01d84b920" + integrity sha512-KpNARQA3Iwv+jTA0utUVVbrh+Jlrr1Fv0e56GGzAFOXN7dk/FviaDW8LHmK52DlcH4WP2n6gI8vN1aesBFgo9w== + dependencies: + yallist "^3.0.2" + lru-cache@^6.0.0: version "6.0.0" resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-6.0.0.tgz#6d6fe6570ebd96aaf90fcad1dafa3b2566db3a94" @@ -840,6 +924,16 @@ lru-cache@^6.0.0: dependencies: yallist "^4.0.0" +lunr@^2.3.9: + version "2.3.9" + resolved "https://registry.yarnpkg.com/lunr/-/lunr-2.3.9.tgz#18b123142832337dd6e964df1a5a7707b25d35e1" + integrity sha512-zTU3DaZaF3Rt9rhN3uBMGQD3dD2/vFQqnvZCDv4dl5iOzq2IZQqTxu90r4E5J+nP70J3ilqVCrbho2eWaeW8Ow== + +marked@^1.2.8: + version "1.2.9" + resolved "https://registry.yarnpkg.com/marked/-/marked-1.2.9.tgz#53786f8b05d4c01a2a5a76b7d1ec9943d29d72dc" + integrity sha512-H8lIX2SvyitGX+TRdtS06m1jHMijKN/XjfH6Ooii9fvxMlh8QdqBfBDkGUpMWH2kQNrtixjzYUa3SH8ROTgRRw== + merge2@^1.3.0: version "1.4.1" resolved "https://registry.yarnpkg.com/merge2/-/merge2-1.4.1.tgz#4368892f885e907455a6fd7dc55c0c9d404990ae" @@ -853,13 +947,18 @@ micromatch@^4.0.2: braces "^3.0.1" picomatch "^2.0.5" -minimatch@^3.0.4: +minimatch@^3.0.0, minimatch@^3.0.4: version "3.0.4" resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083" integrity sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA== dependencies: brace-expansion "^1.1.7" +minimist@^1.2.5: + version "1.2.5" + resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.5.tgz#67d66014b66a6a8aaa0c083c5fd58df4e4e97602" + integrity sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw== + moo@^0.5.0: version "0.5.1" resolved "https://registry.yarnpkg.com/moo/-/moo-0.5.1.tgz#7aae7f384b9b09f620b6abf6f74ebbcd1b65dbc4" @@ -885,6 +984,11 @@ nearley@^2.19.3: railroad-diagrams "^1.0.0" randexp "0.4.6" +neo-async@^2.6.0: + version "2.6.2" + resolved "https://registry.yarnpkg.com/neo-async/-/neo-async-2.6.2.tgz#b4aafb93e3aeb2d8174ca53cf163ab7d7308305f" + integrity sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw== + once@^1.3.0: version "1.4.0" resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1" @@ -892,6 +996,13 @@ once@^1.3.0: dependencies: wrappy "1" +onigasm@^2.2.5: + version "2.2.5" + resolved "https://registry.yarnpkg.com/onigasm/-/onigasm-2.2.5.tgz#cc4d2a79a0fa0b64caec1f4c7ea367585a676892" + integrity sha512-F+th54mPc0l1lp1ZcFMyL/jTs2Tlq4SqIHKIXGZOR/VkHkF9A7Fr5rRr5+ZG/lWeRsyrClLYRq7s/yFQ/XhWCA== + dependencies: + lru-cache "^5.1.1" + opencollective-postinstall@^2.0.2: version "2.0.3" resolved "https://registry.yarnpkg.com/opencollective-postinstall/-/opencollective-postinstall-2.0.3.tgz#7a0fff978f6dbfa4d006238fbac98ed4198c3259" @@ -955,6 +1066,11 @@ path-key@^3.1.0: resolved "https://registry.yarnpkg.com/path-key/-/path-key-3.1.1.tgz#581f6ade658cbba65a0d3380de7753295054f375" integrity sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q== +path-parse@^1.0.6: + version "1.0.6" + resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.6.tgz#d62dbb5679405d72c4737ec58600e9ddcf06d24c" + integrity sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw== + path-type@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/path-type/-/path-type-4.0.0.tgz#84ed01c0a7ba380afe09d90a8c180dcd9d03043b" @@ -984,7 +1100,7 @@ prelude-ls@^1.2.1: resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.2.1.tgz#debc6489d7a6e6b0e7611888cec880337d316396" integrity sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g== -progress@^2.0.0: +progress@^2.0.0, progress@^2.0.3: version "2.0.3" resolved "https://registry.yarnpkg.com/progress/-/progress-2.0.3.tgz#7e8cf8d8f5b8f239c1bc68beb4eb78567d572ef8" integrity sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA== @@ -1007,6 +1123,13 @@ randexp@0.4.6: discontinuous-range "1.0.0" ret "~0.1.10" +rechoir@^0.6.2: + version "0.6.2" + resolved "https://registry.yarnpkg.com/rechoir/-/rechoir-0.6.2.tgz#85204b54dba82d5742e28c96756ef43af50e3384" + integrity sha1-hSBLVNuoLVdC4oyWdW70OvUOM4Q= + dependencies: + resolve "^1.1.6" + regexpp@^3.0.0, regexpp@^3.1.0: version "3.1.0" resolved "https://registry.yarnpkg.com/regexpp/-/regexpp-3.1.0.tgz#206d0ad0a5648cffbdb8ae46438f3dc51c9f78e2" @@ -1022,6 +1145,14 @@ resolve-from@^4.0.0: resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-4.0.0.tgz#4abcd852ad32dd7baabfe9b40e00a36db5f392e6" integrity sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g== +resolve@^1.1.6: + version "1.19.0" + resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.19.0.tgz#1af5bf630409734a067cae29318aac7fa29a267c" + integrity sha512-rArEXAgsBG4UgRGcynxWIWKFvh/XZCcS8UJdHhwy91zwAvCZIbcs+vAbflgBnNjYMs/i/i+/Ux6IZhML1yPvxg== + dependencies: + is-core-module "^2.1.0" + path-parse "^1.0.6" + ret@~0.1.10: version "0.1.15" resolved "https://registry.yarnpkg.com/ret/-/ret-0.1.15.tgz#b8a4825d5bdb1fc3f6f53c2bc33f81388681c7bc" @@ -1073,6 +1204,40 @@ shebang-regex@^3.0.0: resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-3.0.0.tgz#ae16f1644d873ecad843b0307b143362d4c42172" integrity sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A== +shelljs@^0.8.4: + version "0.8.4" + resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.8.4.tgz#de7684feeb767f8716b326078a8a00875890e3c2" + integrity sha512-7gk3UZ9kOfPLIAbslLzyWeGiEqx9e3rxwZM0KE6EL8GlGwjym9Mrlx5/p33bWTu9YG6vcS4MBxYZDHYr5lr8BQ== + dependencies: + glob "^7.0.0" + interpret "^1.0.0" + rechoir "^0.6.2" + +shiki-languages@^0.2.7: + version "0.2.7" + resolved "https://registry.yarnpkg.com/shiki-languages/-/shiki-languages-0.2.7.tgz#7230b675b96d37a36ac1bf995525375ce69f3924" + integrity sha512-REmakh7pn2jCn9GDMRSK36oDgqhh+rSvJPo77sdWTOmk44C5b0XlYPwJZcFOMJWUZJE0c7FCbKclw4FLwUKLRw== + dependencies: + vscode-textmate "^5.2.0" + +shiki-themes@^0.2.7: + version "0.2.7" + resolved "https://registry.yarnpkg.com/shiki-themes/-/shiki-themes-0.2.7.tgz#6e04451d832152e0fc969876a7bd926b3963c1f2" + integrity sha512-ZMmboDYw5+SEpugM8KGUq3tkZ0vXg+k60XX6NngDK7gc1Sv6YLUlanpvG3evm57uKJvfXsky/S5MzSOTtYKLjA== + dependencies: + json5 "^2.1.0" + vscode-textmate "^5.2.0" + +shiki@^0.2.7: + version "0.2.7" + resolved "https://registry.yarnpkg.com/shiki/-/shiki-0.2.7.tgz#d2547548ed8742673730e1e4bbe792a77c445540" + integrity sha512-bwVc7cdtYYHEO9O+XJ8aNOskKRfaQd5Y4ovLRfbQkmiLSUaR+bdlssbZUUhbQ0JAFMYcTcJ5tjG5KtnufttDHQ== + dependencies: + onigasm "^2.2.5" + shiki-languages "^0.2.7" + shiki-themes "^0.2.7" + vscode-textmate "^5.2.0" + slash@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/slash/-/slash-3.0.0.tgz#6539be870c165adbd5240220dbe361f1bc4d4634" @@ -1087,6 +1252,11 @@ slice-ansi@^4.0.0: astral-regex "^2.0.0" is-fullwidth-code-point "^3.0.0" +source-map@^0.6.1: + version "0.6.1" + resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263" + integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g== + sprintf-js@~1.0.2: version "1.0.3" resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c" @@ -1173,11 +1343,50 @@ type-fest@^0.8.1: resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.8.1.tgz#09e249ebde851d3b1e48d27c105444667f17b83d" integrity sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA== +typedoc-default-themes@^0.12.7: + version "0.12.7" + resolved "https://registry.yarnpkg.com/typedoc-default-themes/-/typedoc-default-themes-0.12.7.tgz#d44f68d40a3e90a19b5ea7be4cc6ed949afe768d" + integrity sha512-0XAuGEqID+gon1+fhi4LycOEFM+5Mvm2PjwaiVZNAzU7pn3G2DEpsoXnFOPlLDnHY6ZW0BY0nO7ur9fHOFkBLQ== + +typedoc-plugin-markdown@^3.4.5: + version "3.4.5" + resolved "https://registry.yarnpkg.com/typedoc-plugin-markdown/-/typedoc-plugin-markdown-3.4.5.tgz#d32aad06a9b93946a31ea68438cd02620c12e857" + integrity sha512-m24mSCGcEk6tQDCHIG4TM3AS2a7e9NtC/YdO0mefyF+z1/bKYnZ/oQswLZmm2zBngiLIoKX6eNdufdBpQNPtrA== + dependencies: + handlebars "^4.7.6" + +typedoc@^0.20.21: + version "0.20.21" + resolved "https://registry.yarnpkg.com/typedoc/-/typedoc-0.20.21.tgz#e83a5d599173ae4bbc6402c9a510e1f0a85c1972" + integrity sha512-KAXRnKyyhdA5Wgd96QMdld7gvlL/izUaJi2FAf6KoGuRNgYIUVHQy4KExl9enMt24l/y4LgTFqR6aw3P8NGiZg== + dependencies: + colors "^1.4.0" + fs-extra "^9.1.0" + handlebars "^4.7.6" + lodash "^4.17.20" + lunr "^2.3.9" + marked "^1.2.8" + minimatch "^3.0.0" + progress "^2.0.3" + shelljs "^0.8.4" + shiki "^0.2.7" + typedoc-default-themes "^0.12.7" + typescript@^4.1.3: version "4.1.3" resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.1.3.tgz#519d582bd94cba0cf8934c7d8e8467e473f53bb7" integrity sha512-B3ZIOf1IKeH2ixgHhj6la6xdwR9QrLC5d1VKeCSY4tvkqhF2eqd9O7txNlS0PO3GrBAFIdr3L1ndNwteUbZLYg== +uglify-js@^3.1.4: + version "3.12.6" + resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.12.6.tgz#f884584fcc42e10bca70db5cb32e8625c2c42535" + integrity sha512-aqWHe3DfQmZUDGWBbabZ2eQnJlQd1fKlMUu7gV+MiTuDzdgDw31bI3wA2jLLsV/hNcDP26IfyEgSVoft5+0SVw== + +universalify@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/universalify/-/universalify-2.0.0.tgz#75a4984efedc4b08975c5aeb73f530d02df25717" + integrity sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ== + uri-js@^4.2.2: version "4.4.1" resolved "https://registry.yarnpkg.com/uri-js/-/uri-js-4.4.1.tgz#9b1a52595225859e55f669d928f88c6c57f2a77e" @@ -1190,6 +1399,11 @@ v8-compile-cache@^2.0.3: resolved "https://registry.yarnpkg.com/v8-compile-cache/-/v8-compile-cache-2.2.0.tgz#9471efa3ef9128d2f7c6a7ca39c4dd6b5055b132" integrity sha512-gTpR5XQNKFwOd4clxfnhaqvfqMpqEwr4tOtCyz4MtYZX2JYhfr1JvBFKdS+7K/9rfpZR3VLX+YWBbKoxCgS43Q== +vscode-textmate@^5.2.0: + version "5.2.0" + resolved "https://registry.yarnpkg.com/vscode-textmate/-/vscode-textmate-5.2.0.tgz#01f01760a391e8222fe4f33fbccbd1ad71aed74e" + integrity sha512-Uw5ooOQxRASHgu6C7GVvUxisKXfSgW4oFlO+aa+PAkgmH89O3CXxEEzNRNtHSqtXFTl0nAC1uYj0GMSH27uwtQ== + which-pm-runs@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/which-pm-runs/-/which-pm-runs-1.0.0.tgz#670b3afbc552e0b55df6b7780ca74615f23ad1cb" @@ -1207,11 +1421,21 @@ word-wrap@^1.2.3: resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.3.tgz#610636f6b1f703891bd34771ccb17fb93b47079c" integrity sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ== +wordwrap@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb" + integrity sha1-J1hIEIkUVqQXHI0CJkQa3pDLyus= + wrappy@1: version "1.0.2" resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f" integrity sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8= +yallist@^3.0.2: + version "3.1.1" + resolved "https://registry.yarnpkg.com/yallist/-/yallist-3.1.1.tgz#dbb7daf9bfd8bac9ab45ebf602b8cbad0d5d08fd" + integrity sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g== + yallist@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/yallist/-/yallist-4.0.0.tgz#9bb92790d9c0effec63be73519e11a35019a3a72" From 88cf93b91becf3fba74ed53b36e3f73586483aec Mon Sep 17 00:00:00 2001 From: chefsale Date: Thu, 11 Feb 2021 16:15:53 +0000 Subject: [PATCH 05/10] feat(fossa): add fossa integration --- .travis.yml | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6abf2ad..2813d4d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,17 @@ node_js: - "node" - "lts/*" -script: - - yarn test - - yarn docs +jobs: + include: + - name: yarn + script: + - yarn test + - yarn docs + + - name: fossa + before_script: + - "curl -H 'Cache-Control: no-cache' https://raw.githubusercontent.com/fossas/fossa-cli/fc60c6631a5d372d5a45fea35e31665b338f260d/install.sh | sudo bash" + script: + - fossa init + - fossa analyze --server-scan + - fossa test From ee138a5557a6ca63a7e3143c462f542029857ecc Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Wed, 17 Feb 2021 10:50:47 -0500 Subject: [PATCH 06/10] v1.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4c05baf..f6a1bfe 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "assemblyscript-json", - "version": "0.4.0", + "version": "1.0.0", "types": "assembly/index.ts", "scripts": { "asbuild:untouched": "asc assembly/index.ts -b build/untouched.wasm -t build/untouched.wat --sourceMap --validate --debug", From 10b4c50a6aba8b86d18188f1e354b1b83031064e Mon Sep 17 00:00:00 2001 From: yjh Date: Fri, 14 May 2021 01:13:20 +0800 Subject: [PATCH 07/10] chore: let Handler extends JSONHandler (#170) --- assembly/JSON.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/assembly/JSON.ts b/assembly/JSON.ts index af7ef1d..35022b7 100644 --- a/assembly/JSON.ts +++ b/assembly/JSON.ts @@ -1,7 +1,7 @@ import { Buffer } from "./util"; -import { JSONDecoder } from "./decoder"; +import { JSONDecoder, JSONHandler } from './decoder'; -class Handler { +class Handler extends JSONHandler { stack: Value[] = new Array(); reset(): void { From e68b42eec4eb7ebea69c1cf6d416bd3e47ec08b2 Mon Sep 17 00:00:00 2001 From: Ashutosh Varma Date: Thu, 13 May 2021 23:06:40 +0530 Subject: [PATCH 08/10] Add CI Job to run "JSON Spec Test Suite" against as-json (#168) * add helper wasm module for testing suite * add new CI job to run JSONTestSuite * rename test runner bash script * add readme for test helper cli wasm --- .gitignore | 1 + .travis.yml | 6 ++++++ utils/run_testsuite.sh | 19 +++++++++++++++++ utils/testsuite_helper/README.md | 25 ++++++++++++++++++++++ utils/testsuite_helper/index.ts | 32 ++++++++++++++++++++++++++++ utils/testsuite_helper/package.json | 18 ++++++++++++++++ utils/testsuite_helper/tsconfig.json | 4 ++++ utils/testsuite_helper/yarn.lock | 26 ++++++++++++++++++++++ 8 files changed, 131 insertions(+) create mode 100644 utils/run_testsuite.sh create mode 100644 utils/testsuite_helper/README.md create mode 100644 utils/testsuite_helper/index.ts create mode 100644 utils/testsuite_helper/package.json create mode 100644 utils/testsuite_helper/tsconfig.json create mode 100644 utils/testsuite_helper/yarn.lock diff --git a/.gitignore b/.gitignore index 65cbaee..52476ed 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ node_modules/ build/ temp-docs/ tests/build +utils/testsuite_helper/build .DS_Store *.wat diff --git a/.travis.yml b/.travis.yml index 2813d4d..82bd45e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,3 +17,9 @@ jobs: - fossa init - fossa analyze --server-scan - fossa test + + - name: JSON Test Suite + before_script: + - "curl https://wasmtime.dev/install.sh -sSf | bash" + script: + - bash utils/run_testsuite.sh \ No newline at end of file diff --git a/utils/run_testsuite.sh b/utils/run_testsuite.sh new file mode 100644 index 0000000..23f7016 --- /dev/null +++ b/utils/run_testsuite.sh @@ -0,0 +1,19 @@ +#!/usr/bin/bash +# Helper scipt to run JSONTestSuite in CI + + +set -e +set -x + +cd utils/testsuite_helper +yarn && yarn build + +git clone https://github.com/ashutoshvarma/JSONTestSuite.git testsuite + +# replace with newly build wasm +rm testsuite/parsers/test_as_json/index.wasm +cp build/index.wasm testsuite/parsers/test_as_json/index.wasm + +# run tests +echo '["Assemblyscript-JSON"]' > filter.json +python3 testsuite/run_tests.py --filter=filter.json \ No newline at end of file diff --git a/utils/testsuite_helper/README.md b/utils/testsuite_helper/README.md new file mode 100644 index 0000000..1fdd99f --- /dev/null +++ b/utils/testsuite_helper/README.md @@ -0,0 +1,25 @@ +# testsuite_helper + +This module is primarily used to expose `JSON.parse` through a CLI environment for testing purpose. + +### Return codes :- +- 0 - If successfully parsed the input +- 2 - Can't read the file properly + +(It needs `wasmtime` to execute) + +## Build +``` +yarn +yarn build +``` + +## Run +``` +yarn start --dir FOLDER JSON_FILE_NAME +``` +or +``` +wasmtime build/index.wasm --dir FOLDER JSON_FILE_NAME +``` + diff --git a/utils/testsuite_helper/index.ts b/utils/testsuite_helper/index.ts new file mode 100644 index 0000000..536b4aa --- /dev/null +++ b/utils/testsuite_helper/index.ts @@ -0,0 +1,32 @@ +import "wasi"; + +import { Console, CommandLine, Process, FileSystem, Descriptor } from "as-wasi"; +import { JSON } from "../../assembly"; + +function parse(file: string): u32 { + const fd = FileSystem.open(file); + if (fd == null) { + Console.error("Cannot open file - " + file); + return 2; + } + let content: string = fd.readString()!; + if (content == null) { + Console.error("Cannot read file - " + file); + return 2; + } + + // parse the file + let res = JSON.parse(content); + // Console.log(res.toString()); + Console.log(file + " - Success!"); + return 0; +} + +let cmd = new CommandLine(); +let f: string | null = cmd.get(1); +if (f) { + Process.exit(parse(f)); +} else { + Console.log("No File"); + Process.exit(2); +} diff --git a/utils/testsuite_helper/package.json b/utils/testsuite_helper/package.json new file mode 100644 index 0000000..d68c9fc --- /dev/null +++ b/utils/testsuite_helper/package.json @@ -0,0 +1,18 @@ +{ + "name": "testsuite_helper", + "version": "1.0.0", + "description": "", + "scripts": { + "build": "asc index.ts -b build/index.wasm --debug", + "start": "wasmtime build/index.wasm --dir ." + }, + "keywords": [], + "author": "", + "license": "MIT", + "devDependencies": { + "assemblyscript": "^0.18.15" + }, + "dependencies": { + "as-wasi": "^0.4.4" + } +} diff --git a/utils/testsuite_helper/tsconfig.json b/utils/testsuite_helper/tsconfig.json new file mode 100644 index 0000000..798b474 --- /dev/null +++ b/utils/testsuite_helper/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "assemblyscript/std/assembly.json", + "include": ["./**/*.ts"] +} diff --git a/utils/testsuite_helper/yarn.lock b/utils/testsuite_helper/yarn.lock new file mode 100644 index 0000000..df0ebea --- /dev/null +++ b/utils/testsuite_helper/yarn.lock @@ -0,0 +1,26 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +as-wasi@^0.4.4: + version "0.4.4" + resolved "https://registry.yarnpkg.com/as-wasi/-/as-wasi-0.4.4.tgz#3b439c25e975d8cc04f6deec898b57138862aa15" + integrity sha512-CNeZ3AjKSjrFXRNDRzX1VzxsWz3Fwksn4g0J7tZv5RKz4agKhVlcl0QeMIOOkJms7DujCBCpbelGxNDtvlFKmw== + +assemblyscript@^0.18.15: + version "0.18.15" + resolved "https://registry.yarnpkg.com/assemblyscript/-/assemblyscript-0.18.15.tgz#b66a4d96c7de14e311303fb7c8ccf14b9d689e8f" + integrity sha512-s1N1qwdBhen2SLQApYCtRIPWm1Am3oAbW58GCEKbeN6ZbQRh7nq0pv4RDqKw6CgK7dySn/F2S1D6p0scyRbQRw== + dependencies: + binaryen "100.0.0" + long "^4.0.0" + +binaryen@100.0.0: + version "100.0.0" + resolved "https://registry.yarnpkg.com/binaryen/-/binaryen-100.0.0.tgz#8ed91955eff14eb4758d68d593869cbc1a9a0dff" + integrity sha512-nxOt8d8/VXAuSVEtAWUdKrqpqCy365QqD223EzzB1GzS5himiZAfM/R5lXx+M/5q8TB8cYp3tYxv5rTjNTJveQ== + +long@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/long/-/long-4.0.0.tgz#9a7b71cfb7d361a194ea555241c92f7468d5bf28" + integrity sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA== From 3f0ffd6c31035ff03ccf9e8dba23b586c30b0d75 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Thu, 1 Jul 2021 10:56:47 -0400 Subject: [PATCH 09/10] fix: add `"` to string's `toString` and make toString an abstract method --- assembly/JSON.ts | 57 ++++++++++-------------------------------------- 1 file changed, 12 insertions(+), 45 deletions(-) diff --git a/assembly/JSON.ts b/assembly/JSON.ts index 35022b7..89a7a34 100644 --- a/assembly/JSON.ts +++ b/assembly/JSON.ts @@ -107,6 +107,9 @@ namespace _JSON { } } +// @ts-ignore +@lazy const NULL: Null = new Null(); + export abstract class Value { static String(str: string): Str { return new Str(str); @@ -124,7 +127,7 @@ export abstract class Value { return new Bool(b); } static Null(): Null { - return new Null(); + return NULL; } static Array(): Arr { return new Arr(); @@ -189,10 +192,7 @@ export abstract class Value { return false; } - toString(): string { - throw new Error("Values must be casted to their JSON type for .toString()"); - return ""; - } + abstract toString(): string; } export class Str extends Value { @@ -201,7 +201,7 @@ export class Str extends Value { } toString(): string { - return this._str; + return `"${this._str}"`; } valueOf(): string { @@ -307,47 +307,14 @@ export class Obj extends Value { } toString(): string { - const objs: string[] = []; + const objs: string[] = new Array(this.keys.length); for (let i: i32 = 0; i < this.keys.length; i++) { - let keyValueString = '"' + this.keys[i] + '": '; - - // Cast our value into it's appropriate type - let value: Value | null = this._obj.get(this.keys[i]); - - // Check for null values - if (value == null || value.isNull) { - objs.push(keyValueString += "null"); - continue; - } - - // Cast to our proper type - if (value.isString) { - let castedValue = changetype(value); - keyValueString += '"' + castedValue.toString() + '"'; - } else if (value.isNum) { - let castedValue = changetype(value); - keyValueString += castedValue.toString(); - } else if (value.isFloat) { - let castedValue = changetype(value); - keyValueString += castedValue.toString(); - } else if (value.isInteger) { - let castedValue = changetype(value); - keyValueString += castedValue.toString(); - } else if (value.isBool) { - let castedValue = changetype(value); - keyValueString += castedValue.toString(); - } else if (value.isArr) { - let castedValue = changetype(value); - keyValueString += castedValue.toString(); - } else if (value.isObj) { - let castedValue = changetype(value); - keyValueString += castedValue.toString(); - } - - // Push the keyValueString - objs.push(keyValueString); + const key = this.keys[i]; + const value = this._obj.get(key) || Value.Null(); + objs[i] = `"${key}":${value}`; } - return "{" + objs.join(",") + "}"; + + return `{${objs.join(",")}}`; } valueOf(): Map { From 8de62fdaef2871ed3f34dcb6c53edeef679f4ba2 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Thu, 1 Jul 2021 14:09:19 -0400 Subject: [PATCH 10/10] fix: Obj.toString interpolation issue and simplify Obj implementation --- assembly/JSON.ts | 27 +++++++++++---------------- assembly/__tests__/to-string.spec.ts | 9 +++------ 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/assembly/JSON.ts b/assembly/JSON.ts index 89a7a34..84e3634 100644 --- a/assembly/JSON.ts +++ b/assembly/JSON.ts @@ -298,20 +298,22 @@ export class Arr extends Value { export class Obj extends Value { _obj: Map; - keys: Array; constructor() { super(); this._obj = new Map(); - this.keys = new Array(); } toString(): string { - const objs: string[] = new Array(this.keys.length); - for (let i: i32 = 0; i < this.keys.length; i++) { - const key = this.keys[i]; - const value = this._obj.get(key) || Value.Null(); - objs[i] = `"${key}":${value}`; + const keys = this._obj.keys(); + const objs: string[] = new Array(keys.length); + for (let i: i32 = 0; i < keys.length; i++) { + const key = keys[i]; + const value = this._obj.get(key); + // Currently must get the string value before interpolation + // see: https://github.com/AssemblyScript/assemblyscript/issues/1944 + const valStr = value.toString(); + objs[i] = `"${key}":${valStr}`; } return `{${objs.join(",")}}`; @@ -321,21 +323,14 @@ export class Obj extends Value { return this._obj; } - set(key: string, value: T): void { if (isReference(value)) { if (value instanceof Value) { - this._set(key, value); + this._obj.set(key, value); return; } } - this._set(key, from(value)); - } - private _set(key: string, value: Value): void { - if (!this._obj.has(key)) { - this.keys.push(key); - } - this._obj.set(key, value); + this._obj.set(key, from(value)); } has(key: string): bool { diff --git a/assembly/__tests__/to-string.spec.ts b/assembly/__tests__/to-string.spec.ts index 4a66fb7..a8d411e 100644 --- a/assembly/__tests__/to-string.spec.ts +++ b/assembly/__tests__/to-string.spec.ts @@ -1,6 +1,3 @@ -import { JSONDecoder } from "../decoder"; -import { JSONEncoder } from "../encoder"; -import { Buffer } from "../util"; import * as JSON from "../JSON"; let primObj: JSON.Obj; @@ -25,7 +22,7 @@ describe("JSON.Value.toString()", () => { it("Str", () => { let value = primObj.getString("Str"); - expect(value!.toString()).toBe("Hello"); + expect(value!.toString()).toBe(`"Hello"`); }); it("Num", () => { @@ -56,11 +53,11 @@ describe("JSON.Value.toString()", () => { it("Obj", () => { let value = primObj.getObj("Obj"); - expect(value!.toString()).toBe('{"isChild": true}'); + expect(value!.toString()).toBe('{"isChild":true}'); }); it("Entire Object", () => { - expect(primObj.toString()).toBe("{\"Str\": \"Hello\",\"Num\": 42.24,\"Float\": 42.24,\"Integer\": 42,\"Bool\": true,\"Arr\": [1,2,3],\"Obj\": {\"isChild\": true}}"); + expect(primObj.toString()).toBe(`{"Str":"Hello","Num":42.24,"Float":42.24,"Integer":42,"Bool":true,"Arr":[1,2,3],"Obj":{"isChild":true}}`); }); });