UNPKG

ts-json-simple

Version:

TypeScript package inspired by Java's JSONObject, providing a chainable API for JSON manipulation.

46 lines (45 loc) 1.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); class JSONArray { constructor(elements = []) { this.elements = elements; } element(key, value) { this.elements[key] = value; return this; } add(element) { this.elements.push(element); return this; } get(index) { return this.elements[index]; } get size() { return this.elements.length; } toJSON() { return this.elements; } [Symbol.iterator]() { let index = 0; const elements = this.elements; return { next() { if (index < elements.length) { return { value: elements[index++], done: false }; } else { return { value: undefined, done: true }; } } }; } } exports.default = JSONArray;