@open-kappa/myjson
Version:
A simple JSON management library.
128 lines (127 loc) • 4.47 kB
TypeScript
import { MyJson, MyJsonArray, MyJsonFixed, MyJsonFlex, MyJsonMap, MyJsonValue } from "./myjsonImpl";
/**
* @brief Base class for classes mapping JSON objects.
*/
declare abstract class MyJsonBaseObject extends MyJson {
/**
* @brief Constructor.
* @param {boolean} isMandatory True if the object must appear in the
* hierarchy.
* @param {string} name The name of the object.
*/
constructor(isMandatory: boolean, name: string);
/**
* @brief Common implementation of clone().
* @param {MyJsonBaseObject} other The copy.
*/
protected _cloneImpl(other: MyJsonBaseObject): void;
/**
* @brief Common implementation of isEqual().
* @param {MyJson} other The other object of comparison.
* @return {boolean} True if they are equals.
*/
protected _isEqualImpl(other: MyJsonBaseObject): boolean;
/**
* @brief Check whether the object 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 with the given key.
* @param {string} key The key.
* @return {MyJson} The internal element.
*/
get(key: string): MyJson;
/**
* @brief Set the element with given key.
* @param {key} key The key.
* @param {MyJson} value The element.
*/
set(key: string, value: MyJson): void;
/**
* @brief Check if the element exists.
* @param {string} key The key.
* @return {boolean} True if it exists.
*/
has(key: string): boolean;
/**
* @brief Common implementation of forEach()..
* The callback takes the key, the element, and the whole object.
* It returns true to break the loop before having rolled on all elements.
* @param {(key:string,value:MyJson,obj:MyJsonBaseObject)=>boolean} func
* The callback.
* @param {any | null | undefined} [funcThis=null] The optional "this" for
* the callback.
*/
protected _forEachImpl(func: (key: string, value: MyJson, obj: MyJsonBaseObject) => boolean, funcThis?: any | null | undefined): boolean;
/**
* @brief Common implementation of merge().
* Already existent keys are merged recursively.
* @param {MyJsonBaseObject} other The other object to merge.
* @throws {Error} If the two objects cannot be merged.
*/
protected _mergeImpl(other: MyJsonBaseObject): 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): MyJsonBaseObject;
/**
* @brief Get element as array.
* @param {string} key The key.
* @throws {Error} If element is not an array.
*/
getAsArray<Element extends MyJson>(key: string): MyJsonArray<Element>;
/**
* @brief Get element as fixed.
* @param {string} key The key.
* @throws {Error} If element is not a fixed.
*/
getAsFixed<Element extends MyJson>(key: string): MyJsonFixed;
/**
* @brief Get element as flex.
* @param {string} key The key.
* @throws {Error} If element is not a flex.
*/
getAsFlex<Element extends MyJson>(key: string): MyJsonFlex<Element>;
/**
* @brief Get element as map.
* @param {string} key The key.
* @throws {Error} If element is not a map.
*/
getAsMap<Element extends MyJson>(key: string): MyJsonMap<Element>;
/**
* @brief Get element as value.
* @param {string} key The key.
* @throws {Error} If element is not a value.
*/
getAsValue<Element>(key: string): MyJsonValue<Element>;
/**
* @brief Get element as value.
* @param {string} key The key.
* @throws {Error} If element is not a value.
*/
getAsStringValue(key: string): MyJsonValue<string>;
/**
* @brief Get element as value.
* @param {string} key The key.
* @throws {Error} If element is not a value.
*/
getAsNumberValue(key: string): MyJsonValue<number>;
/**
* @brief Get element as value.
* @param {string} key The key.
* @throws {Error} If element is not a value.
*/
getAsBooleanValue(key: string): MyJsonValue<boolean>;
}
export { MyJsonBaseObject };
export default MyJsonBaseObject;