source: node_modules/es-toolkit/dist/predicate/isJSONValue.d.mts

Last change on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 2.0 KB
Line 
1/**
2 * Checks if a given value is a valid JSON value.
3 *
4 * A valid JSON value can be:
5 * - null
6 * - a JSON object (an object with string keys and valid JSON values)
7 * - a JSON array (an array of valid JSON values)
8 * - a string
9 * - a number
10 * - a boolean
11 *
12 * @param {unknown} value - The value to check.
13 * @returns {boolean} - True if the value is a valid JSON value, otherwise false.
14 *
15 * @example
16 * console.log(isJSONValue(null)); // true
17 * console.log(isJSONValue({ key: "value" })); // true
18 * console.log(isJSONValue([1, 2, 3])); // true
19 * console.log(isJSONValue("Hello")); // true
20 * console.log(isJSONValue(42)); // true
21 * console.log(isJSONValue(true)); // true
22 * console.log(isJSONValue(undefined)); // false
23 * console.log(isJSONValue(() => {})); // false
24 */
25declare function isJSONValue(value: unknown): value is Record<string, any> | any[] | string | number | boolean | null;
26/**
27 * Checks if a given value is a valid JSON array.
28 *
29 * A valid JSON array is defined as an array where all items are valid JSON values.
30 *
31 * @param {unknown} value - The value to check.
32 * @returns {value is any[]} - True if the value is a valid JSON array, otherwise false.
33 *
34 * @example
35 * console.log(isJSONArray([1, 2, 3])); // true
36 * console.log(isJSONArray(["string", null, true])); // true
37 * console.log(isJSONArray([1, 2, () => {}])); // false
38 * console.log(isJSONArray("not an array")); // false
39 */
40declare function isJSONArray(value: unknown): value is any[];
41/**
42 * Checks if a value is a JSON object.
43 *
44 * A valid JSON object is defined as an object with string keys and valid JSON values.
45 *
46 * @param {unknown} obj The value to check.
47 * @returns {obj is Record<string, any>} True if `obj` is a JSON object, false otherwise.
48 *
49 * @example
50 * isJSONObject({ nested: { boolean: true, array: [1, 2, 3], string: 'test', null: null } }); // true
51 * isJSONObject({ regexp: /test/ }); // false
52 * isJSONObject(123); // false
53 */
54declare function isJSONObject(obj: unknown): obj is Record<string, any>;
55
56export { isJSONArray, isJSONObject, isJSONValue };
Note: See TracBrowser for help on using the repository browser.