UNPKG

4.49 kBTypeScriptView Raw
1/**
2 * A type alias for a JSON primitive.
3 */
4export declare type JSONPrimitive = boolean | number | string | null;
5/**
6 * A type alias for a JSON value.
7 */
8export declare type JSONValue = JSONPrimitive | JSONObject | JSONArray;
9/**
10 * A type definition for a JSON object.
11 */
12export interface JSONObject {
13 [key: string]: JSONValue;
14}
15/**
16 * A type definition for a JSON array.
17 */
18export interface JSONArray extends Array<JSONValue> {
19}
20/**
21 * A type definition for a readonly JSON object.
22 */
23export interface ReadonlyJSONObject {
24 readonly [key: string]: ReadonlyJSONValue;
25}
26/**
27 * A type definition for a readonly JSON array.
28 */
29export interface ReadonlyJSONArray extends ReadonlyArray<ReadonlyJSONValue> {
30}
31/**
32 * A type alias for a readonly JSON value.
33 */
34export declare type ReadonlyJSONValue = JSONPrimitive | ReadonlyJSONObject | ReadonlyJSONArray;
35/**
36 * A type alias for a partial JSON value.
37 *
38 * Note: Partial here means that JSON object attributes can be `undefined`.
39 */
40export declare type PartialJSONValue = JSONPrimitive | PartialJSONObject | PartialJSONArray;
41/**
42 * A type definition for a partial JSON object.
43 *
44 * Note: Partial here means that the JSON object attributes can be `undefined`.
45 */
46export interface PartialJSONObject {
47 [key: string]: PartialJSONValue | undefined;
48}
49/**
50 * A type definition for a partial JSON array.
51 *
52 * Note: Partial here means that JSON object attributes can be `undefined`.
53 */
54export interface PartialJSONArray extends Array<PartialJSONValue> {
55}
56/**
57 * A type definition for a readonly partial JSON object.
58 *
59 * Note: Partial here means that JSON object attributes can be `undefined`.
60 */
61export interface ReadonlyPartialJSONObject {
62 readonly [key: string]: ReadonlyPartialJSONValue | undefined;
63}
64/**
65 * A type definition for a readonly partial JSON array.
66 *
67 * Note: Partial here means that JSON object attributes can be `undefined`.
68 */
69export interface ReadonlyPartialJSONArray extends ReadonlyArray<ReadonlyPartialJSONValue> {
70}
71/**
72 * A type alias for a readonly partial JSON value.
73 *
74 * Note: Partial here means that JSON object attributes can be `undefined`.
75 */
76export declare type ReadonlyPartialJSONValue = JSONPrimitive | ReadonlyPartialJSONObject | ReadonlyPartialJSONArray;
77/**
78 * The namespace for JSON-specific functions.
79 */
80export declare namespace JSONExt {
81 /**
82 * A shared frozen empty JSONObject
83 */
84 const emptyObject: ReadonlyJSONObject;
85 /**
86 * A shared frozen empty JSONArray
87 */
88 const emptyArray: ReadonlyJSONArray;
89 /**
90 * Test whether a JSON value is a primitive.
91 *
92 * @param value - The JSON value of interest.
93 *
94 * @returns `true` if the value is a primitive,`false` otherwise.
95 */
96 function isPrimitive(value: ReadonlyPartialJSONValue): value is JSONPrimitive;
97 /**
98 * Test whether a JSON value is an array.
99 *
100 * @param value - The JSON value of interest.
101 *
102 * @returns `true` if the value is a an array, `false` otherwise.
103 */
104 function isArray(value: JSONValue): value is JSONArray;
105 function isArray(value: ReadonlyJSONValue): value is ReadonlyJSONArray;
106 function isArray(value: PartialJSONValue): value is PartialJSONArray;
107 function isArray(value: ReadonlyPartialJSONValue): value is ReadonlyPartialJSONArray;
108 /**
109 * Test whether a JSON value is an object.
110 *
111 * @param value - The JSON value of interest.
112 *
113 * @returns `true` if the value is a an object, `false` otherwise.
114 */
115 function isObject(value: JSONValue): value is JSONObject;
116 function isObject(value: ReadonlyJSONValue): value is ReadonlyJSONObject;
117 function isObject(value: PartialJSONValue): value is PartialJSONObject;
118 function isObject(value: ReadonlyPartialJSONValue): value is ReadonlyPartialJSONObject;
119 /**
120 * Compare two JSON values for deep equality.
121 *
122 * @param first - The first JSON value of interest.
123 *
124 * @param second - The second JSON value of interest.
125 *
126 * @returns `true` if the values are equivalent, `false` otherwise.
127 */
128 function deepEqual(first: ReadonlyPartialJSONValue, second: ReadonlyPartialJSONValue): boolean;
129 /**
130 * Create a deep copy of a JSON value.
131 *
132 * @param value - The JSON value to copy.
133 *
134 * @returns A deep copy of the given JSON value.
135 */
136 function deepCopy<T extends ReadonlyPartialJSONValue>(value: T): T;
137}
138//# sourceMappingURL=json.d.ts.map
\No newline at end of file