@lumino/coreutils
Version:
Lumino Core Utilities
138 lines (137 loc) • 4.42 kB
TypeScript
/**
* A type alias for a JSON primitive.
*/
export type JSONPrimitive = boolean | number | string | null;
/**
* A type alias for a JSON value.
*/
export type JSONValue = JSONPrimitive | JSONObject | JSONArray;
/**
* A type definition for a JSON object.
*/
export interface JSONObject {
[key: string]: JSONValue;
}
/**
* A type definition for a JSON array.
*/
export interface JSONArray extends Array<JSONValue> {
}
/**
* A type definition for a readonly JSON object.
*/
export interface ReadonlyJSONObject {
readonly [key: string]: ReadonlyJSONValue;
}
/**
* A type definition for a readonly JSON array.
*/
export interface ReadonlyJSONArray extends ReadonlyArray<ReadonlyJSONValue> {
}
/**
* A type alias for a readonly JSON value.
*/
export type ReadonlyJSONValue = JSONPrimitive | ReadonlyJSONObject | ReadonlyJSONArray;
/**
* A type alias for a partial JSON value.
*
* Note: Partial here means that JSON object attributes can be `undefined`.
*/
export type PartialJSONValue = JSONPrimitive | PartialJSONObject | PartialJSONArray;
/**
* A type definition for a partial JSON object.
*
* Note: Partial here means that the JSON object attributes can be `undefined`.
*/
export interface PartialJSONObject {
[key: string]: PartialJSONValue | undefined;
}
/**
* A type definition for a partial JSON array.
*
* Note: Partial here means that JSON object attributes can be `undefined`.
*/
export interface PartialJSONArray extends Array<PartialJSONValue> {
}
/**
* A type definition for a readonly partial JSON object.
*
* Note: Partial here means that JSON object attributes can be `undefined`.
*/
export interface ReadonlyPartialJSONObject {
readonly [key: string]: ReadonlyPartialJSONValue | undefined;
}
/**
* A type definition for a readonly partial JSON array.
*
* Note: Partial here means that JSON object attributes can be `undefined`.
*/
export interface ReadonlyPartialJSONArray extends ReadonlyArray<ReadonlyPartialJSONValue> {
}
/**
* A type alias for a readonly partial JSON value.
*
* Note: Partial here means that JSON object attributes can be `undefined`.
*/
export type ReadonlyPartialJSONValue = JSONPrimitive | ReadonlyPartialJSONObject | ReadonlyPartialJSONArray;
/**
* The namespace for JSON-specific functions.
*/
export declare namespace JSONExt {
/**
* A shared frozen empty JSONObject
*/
const emptyObject: ReadonlyJSONObject;
/**
* A shared frozen empty JSONArray
*/
const emptyArray: ReadonlyJSONArray;
/**
* Test whether a JSON value is a primitive.
*
* @param value - The JSON value of interest.
*
* @returns `true` if the value is a primitive,`false` otherwise.
*/
function isPrimitive(value: ReadonlyPartialJSONValue): value is JSONPrimitive;
/**
* Test whether a JSON value is an array.
*
* @param value - The JSON value of interest.
*
* @returns `true` if the value is a an array, `false` otherwise.
*/
function isArray(value: JSONValue): value is JSONArray;
function isArray(value: ReadonlyJSONValue): value is ReadonlyJSONArray;
function isArray(value: PartialJSONValue): value is PartialJSONArray;
function isArray(value: ReadonlyPartialJSONValue): value is ReadonlyPartialJSONArray;
/**
* Test whether a JSON value is an object.
*
* @param value - The JSON value of interest.
*
* @returns `true` if the value is a an object, `false` otherwise.
*/
function isObject(value: JSONValue): value is JSONObject;
function isObject(value: ReadonlyJSONValue): value is ReadonlyJSONObject;
function isObject(value: PartialJSONValue): value is PartialJSONObject;
function isObject(value: ReadonlyPartialJSONValue): value is ReadonlyPartialJSONObject;
/**
* Compare two JSON values for deep equality.
*
* @param first - The first JSON value of interest.
*
* @param second - The second JSON value of interest.
*
* @returns `true` if the values are equivalent, `false` otherwise.
*/
function deepEqual(first: ReadonlyPartialJSONValue, second: ReadonlyPartialJSONValue): boolean;
/**
* Create a deep copy of a JSON value.
*
* @param value - The JSON value to copy.
*
* @returns A deep copy of the given JSON value.
*/
function deepCopy<T extends ReadonlyPartialJSONValue>(value: T): T;
}