@open-kappa/myjson
Version:
A simple JSON management library.
111 lines (110 loc) • 3.79 kB
TypeScript
import { MyJson } from "./myjsonImpl";
/**
* @brief A JSON array of homogeneous objects.
* @typeparam Element The type of the array elements.
*/
declare class MyJsonArray<Element extends MyJson> extends MyJson {
/**
* @brief Constructor.
* @param {Element} element The validator for array elements. If it is
* mandatory, then the array cannot be empty.
* @param {boolean} isMandatory True if the object must appear in the
* hierarchy.
* @param {string} name The name of the object.
*/
constructor(element: Element, isMandatory: boolean, name: string);
/**
* @brief Return the internal validator element of the array.
* It uses a symbol to hide the properties to "usual" javascript methods.
* @private
* @return {Element} The validator.
*/
private _getValidatorElement;
/**
* @brief Return the internal array of objects.
* It uses a symbol to hide the properties to "usual" javascript methods.
* @private
* @return {Element} The validator.
*/
private _getValidatorValues;
/**
* @brief Parse a JSON object.
* @param {any} json The JSON to parse.
* @throws {Error} If a validation error occurrs.
*/
protected parseJsonImpl(json: any): void;
/**
* @brief Clone this object.
* @return {MyJsonArray<Element>} The copy.
*/
clone(): MyJsonArray<Element>;
/**
* @brief Check if two JSON objects are equals.
* @param {MyJson} other The other object of comparison.
* @return {boolean} True if they are equals.
*/
isEqual(other: MyJson): boolean;
/**
* @brief Check whether the array is empty.
* @return {boolean} True if empty.
*/
isEmpty(): boolean;
/**
* @brief Get the number of stored elements.
* @return {number} The array size.
*/
getSize(): number;
/**
* @brief Get the element at given position.
* @param {number} pos The position.
* @return {Element} The internal element.
*/
get(pos: number): Element;
/**
* @brief Set the element at given position.
* @param {number} pos The position.
* @param {Element} value The element.
*/
set(pos: number, value: Element): void;
/**
* @brief Push back a new element into the array.
* @param {Element} value The new element.
*/
push(value: Element): void;
/**
* @brief Clear the object content.
*/
protected clearImpl(): void;
/**
* @brief Execute the given callback on each array element.
* The callback takes the element, its index, and the whole array.
* It returns true to break the loop before having rolled on all elements.
* @param {(value:Element,index:number,array:Array<Element>)=>boolean} func
* The callback.
* @param {any | null | undefined} [funcThis=null] The optional "this" for
* the callback.
*/
forEach(func: (value: Element, index: number, array: Array<Element>) => boolean, funcThis?: any | null | undefined): boolean;
/**
* @brief Convert the object to a JSON object.
* @return {Array<Element>} The converted object.
*/
toJSON(): Array<Element>;
/**
* @brief Merge the two objects.
* Array elements are concatenated.
* @param {MyJson} other The other object to merge.
* @throws {Error} If the two objects cannot be merged.
*/
merge(other: MyJson): void;
/**
* @brief Add a new child element.
* This is a build-time support method.
* @param {MyJson} _element The child element.
* @return {MyJson} This.
* @throws {Error} If element cannot be added.
*/
add(_element: MyJson): MyJson;
}
export { MyJsonArray };
export default MyJsonArray;