@baseplate-dev/utils 0.2.2 → 0.2.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.
@@ -1,3 +1,4 @@
1
+ export * from './json-deep-clone.js';
1
2
  export * from './stringify-pretty-compact.js';
2
3
  export * from './stringify-pretty-stable.js';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/json/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,8BAA8B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/json/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,8BAA8B,CAAC"}
@@ -1,3 +1,4 @@
1
+ export * from './json-deep-clone.js';
1
2
  export * from './stringify-pretty-compact.js';
2
3
  export * from './stringify-pretty-stable.js';
3
4
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/json/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,8BAA8B,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/json/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,8BAA8B,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Recursively deep clones JSON-compatible values.
3
+ * Throws if the value is not JSON-serializable.
4
+ *
5
+ * @param value - The value to clone
6
+ * @returns A deep-cloned copy of the value
7
+ * @throws Error if a non-JSON value is encountered
8
+ */
9
+ export declare function jsonDeepClone<T>(value: T): T;
10
+ //# sourceMappingURL=json-deep-clone.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-deep-clone.d.ts","sourceRoot":"","sources":["../../src/json/json-deep-clone.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CA2C5C"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Recursively deep clones JSON-compatible values.
3
+ * Throws if the value is not JSON-serializable.
4
+ *
5
+ * @param value - The value to clone
6
+ * @returns A deep-cloned copy of the value
7
+ * @throws Error if a non-JSON value is encountered
8
+ */
9
+ export function jsonDeepClone(value) {
10
+ if (value === undefined ||
11
+ value === null ||
12
+ typeof value === 'boolean' ||
13
+ typeof value === 'string') {
14
+ return value;
15
+ }
16
+ if (typeof value === 'number') {
17
+ return value;
18
+ }
19
+ if (typeof value === 'object') {
20
+ if (value instanceof Date || value instanceof RegExp) {
21
+ throw new TypeError(`Cannot clone value of unsupported type: ${value.constructor.name}`);
22
+ }
23
+ if (Array.isArray(value)) {
24
+ // Clone array elements
25
+ const copy = [];
26
+ for (const [i, element] of value.entries()) {
27
+ copy[i] = jsonDeepClone(element);
28
+ }
29
+ return copy;
30
+ }
31
+ // Clone plain object properties
32
+ const copy = {};
33
+ for (const key in value) {
34
+ if (Object.prototype.hasOwnProperty.call(value, key)) {
35
+ const prop = value[key];
36
+ copy[key] = jsonDeepClone(prop);
37
+ }
38
+ }
39
+ return copy;
40
+ }
41
+ // Reject functions, symbols, BigInt, etc.
42
+ throw new Error(`Cannot clone value of unsupported type: ${typeof value}`);
43
+ }
44
+ //# sourceMappingURL=json-deep-clone.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-deep-clone.js","sourceRoot":"","sources":["../../src/json/json-deep-clone.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAAI,KAAQ;IACvC,IACE,KAAK,KAAK,SAAS;QACnB,KAAK,KAAK,IAAI;QACd,OAAO,KAAK,KAAK,SAAS;QAC1B,OAAO,KAAK,KAAK,QAAQ,EACzB,CAAC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  "description": "Shared utility functions for Baseplate",
5
5
  "keywords": [
6
6
  "utilities",
@@ -51,7 +51,7 @@
51
51
  "prettier": "3.5.3",
52
52
  "typescript": "5.7.3",
53
53
  "vitest": "3.0.7",
54
- "@baseplate-dev/tools": "0.2.2"
54
+ "@baseplate-dev/tools": "0.2.4"
55
55
  },
56
56
  "engines": {
57
57
  "node": "^22.0.0"