@rcompat/is 0.4.3 → 0.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,7 +3,7 @@ import newable from "#newable";
3
3
  import numeric from "#numeric";
4
4
  import object from "#object";
5
5
  import primitive from "#primitive";
6
- import type { Dict, Nullish, UnknownFunction } from "@rcompat/type";
6
+ import type { Dict, JSONValue, Nullish, UnknownFunction } from "@rcompat/type";
7
7
  declare function isArray(x: unknown): x is unknown[];
8
8
  declare function isArrayBuffer(x: unknown): x is ArrayBuffer;
9
9
  declare function isBigint(x: unknown): x is bigint;
@@ -18,6 +18,7 @@ declare function isFalsy(x: unknown): boolean;
18
18
  declare function isFile(x: unknown): x is File;
19
19
  declare function isFunction(x: unknown): x is UnknownFunction;
20
20
  declare function isIterable(x: unknown): x is Iterable<unknown>;
21
+ declare function isJSON(x: unknown): x is JSONValue;
21
22
  declare function isMap(x: unknown): x is Map<unknown, unknown>;
22
23
  declare function isNull(x: unknown): x is null;
23
24
  declare function isNullish(x: unknown): x is Nullish;
@@ -53,6 +54,7 @@ declare const _default: {
53
54
  function: typeof isFunction;
54
55
  int: (x: unknown) => x is bigint | number;
55
56
  iterable: typeof isIterable;
57
+ json: typeof isJSON;
56
58
  map: typeof isMap;
57
59
  nan: (x: unknown) => x is number;
58
60
  nonempty: <T>(x: T | Nullish) => x is T;
@@ -50,6 +50,20 @@ function isFunction(x) {
50
50
  function isIterable(x) {
51
51
  return typeof x?.[Symbol.iterator] === "function";
52
52
  }
53
+ function isJSON(x) {
54
+ if (x === null)
55
+ return true;
56
+ if (typeof x === "string" || typeof x === "number" || typeof x === "boolean")
57
+ return true;
58
+ if (Array.isArray(x))
59
+ return x.every(isJSON);
60
+ if (typeof x === "object") {
61
+ if (x instanceof Date || x instanceof URL)
62
+ return false;
63
+ return Object.values(x).every(isJSON);
64
+ }
65
+ return false;
66
+ }
53
67
  function isMap(x) {
54
68
  return x instanceof Map;
55
69
  }
@@ -115,6 +129,7 @@ export default {
115
129
  function: isFunction,
116
130
  int: numbers.isInt,
117
131
  iterable: isIterable,
132
+ json: isJSON,
118
133
  map: isMap,
119
134
  nan: numbers.isNaN,
120
135
  nonempty: (x) => !empty(x),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rcompat/is",
3
- "version": "0.4.3",
3
+ "version": "0.4.4",
4
4
  "description": "Standard library identity checks",
5
5
  "bugs": "https://github.com/rcompat/rcompat/issues",
6
6
  "license": "MIT",