ts-data-forge 14.6.2 → 14.6.3

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.
Files changed (182) hide show
  1. package/dist/array/impl/array-utils-creation.mjs +103 -103
  2. package/dist/array/impl/array-utils-element-access.mjs +46 -46
  3. package/dist/array/impl/array-utils-iterators.mjs +54 -54
  4. package/dist/array/impl/array-utils-length-bounded-array-cast.mjs +49 -49
  5. package/dist/array/impl/array-utils-length-bounded-array-guard.mjs +40 -40
  6. package/dist/array/impl/array-utils-length-bounded-tuple-cast.mjs +42 -42
  7. package/dist/array/impl/array-utils-length-bounded-tuple-guard.mjs +46 -46
  8. package/dist/array/impl/array-utils-modification.mjs +4 -4
  9. package/dist/array/impl/array-utils-reducing-value.mjs +11 -11
  10. package/dist/array/impl/array-utils-search.mjs +6 -6
  11. package/dist/array/impl/array-utils-set-op.mjs +116 -116
  12. package/dist/array/impl/array-utils-size.mjs +6 -6
  13. package/dist/array/impl/array-utils-slice-clamped.mjs +1 -1
  14. package/dist/array/impl/array-utils-slicing.mjs +56 -56
  15. package/dist/array/impl/array-utils-transformation.mjs +156 -156
  16. package/dist/array/impl/array-utils-validation.mjs +36 -36
  17. package/dist/collections/imap-mapped.mjs +195 -195
  18. package/dist/collections/imap.mjs +143 -143
  19. package/dist/collections/iset-mapped.mjs +320 -320
  20. package/dist/collections/iset.mjs +207 -207
  21. package/dist/collections/queue.mjs +130 -130
  22. package/dist/collections/stack.mjs +125 -125
  23. package/dist/expect-type.mjs +68 -68
  24. package/dist/functional/async-result/impl/async-result-flat-map.mjs +3 -3
  25. package/dist/functional/async-result/impl/async-result-map-err.mjs +2 -2
  26. package/dist/functional/async-result/impl/async-result-map.mjs +2 -2
  27. package/dist/functional/async-result/impl/async-result-unwrap-or.mjs +31 -31
  28. package/dist/functional/optional/impl/optional-expect-to-be.mjs +1 -1
  29. package/dist/functional/optional/impl/optional-filter.mjs +1 -1
  30. package/dist/functional/optional/impl/optional-flat-map.mjs +1 -1
  31. package/dist/functional/optional/impl/optional-from-nullable.mjs +24 -24
  32. package/dist/functional/optional/impl/optional-is-none.mjs +19 -19
  33. package/dist/functional/optional/impl/optional-is-optional.mjs +18 -18
  34. package/dist/functional/optional/impl/optional-is-some.mjs +20 -20
  35. package/dist/functional/optional/impl/optional-map.mjs +2 -2
  36. package/dist/functional/optional/impl/optional-match.mjs +2 -2
  37. package/dist/functional/optional/impl/optional-none.mjs +16 -16
  38. package/dist/functional/optional/impl/optional-or-else.mjs +1 -1
  39. package/dist/functional/optional/impl/optional-some.mjs +19 -19
  40. package/dist/functional/optional/impl/optional-to-nullable.mjs +26 -26
  41. package/dist/functional/optional/impl/optional-unwrap-or.mjs +1 -1
  42. package/dist/functional/optional/impl/optional-unwrap-throw.mjs +28 -28
  43. package/dist/functional/optional/impl/optional-unwrap.mjs +1 -1
  44. package/dist/functional/optional/impl/optional-zip.mjs +32 -32
  45. package/dist/functional/optional/impl/tag.mjs +1 -1
  46. package/dist/functional/pipe.mjs +19 -19
  47. package/dist/functional/result/impl/result-err.mjs +25 -25
  48. package/dist/functional/result/impl/result-expect-to-be.mjs +2 -2
  49. package/dist/functional/result/impl/result-flat-map.mjs +4 -4
  50. package/dist/functional/result/impl/result-fold.mjs +4 -4
  51. package/dist/functional/result/impl/result-from-optional.mjs +2 -2
  52. package/dist/functional/result/impl/result-from-promise.mjs +34 -34
  53. package/dist/functional/result/impl/result-from-throwable.mjs +29 -29
  54. package/dist/functional/result/impl/result-is-err.mjs +19 -19
  55. package/dist/functional/result/impl/result-is-ok.mjs +19 -19
  56. package/dist/functional/result/impl/result-is-result.mjs +19 -19
  57. package/dist/functional/result/impl/result-map-err.mjs +4 -4
  58. package/dist/functional/result/impl/result-map.mjs +4 -4
  59. package/dist/functional/result/impl/result-match.mjs +3 -3
  60. package/dist/functional/result/impl/result-ok.mjs +25 -25
  61. package/dist/functional/result/impl/result-or-else.mjs +2 -2
  62. package/dist/functional/result/impl/result-safe-try.mjs +15 -15
  63. package/dist/functional/result/impl/result-safe-unwrap.mjs +33 -33
  64. package/dist/functional/result/impl/result-swap.mjs +20 -20
  65. package/dist/functional/result/impl/result-to-optional.mjs +27 -27
  66. package/dist/functional/result/impl/result-unwrap-err-or.mjs +2 -2
  67. package/dist/functional/result/impl/result-unwrap-err-throw.mjs +31 -31
  68. package/dist/functional/result/impl/result-unwrap-err.mjs +30 -30
  69. package/dist/functional/result/impl/result-unwrap-ok-or.mjs +2 -2
  70. package/dist/functional/result/impl/result-unwrap-ok.mjs +1 -1
  71. package/dist/functional/result/impl/result-unwrap-throw.mjs +31 -31
  72. package/dist/functional/result/impl/result-zip.mjs +29 -29
  73. package/dist/functional/result/impl/tag.mjs +1 -1
  74. package/dist/functional/ternary-result/impl/tag.mjs +2 -2
  75. package/dist/functional/ternary-result/impl/ternary-result-err.mjs +13 -13
  76. package/dist/functional/ternary-result/impl/ternary-result-flat-map.mjs +4 -4
  77. package/dist/functional/ternary-result/impl/ternary-result-fold.mjs +4 -4
  78. package/dist/functional/ternary-result/impl/ternary-result-from-promise.mjs +18 -18
  79. package/dist/functional/ternary-result/impl/ternary-result-from-throwable.mjs +17 -17
  80. package/dist/functional/ternary-result/impl/ternary-result-is-err.mjs +17 -17
  81. package/dist/functional/ternary-result/impl/ternary-result-is-ok.mjs +19 -19
  82. package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.mjs +19 -19
  83. package/dist/functional/ternary-result/impl/ternary-result-is-warn.mjs +18 -18
  84. package/dist/functional/ternary-result/impl/ternary-result-map-err.mjs +2 -2
  85. package/dist/functional/ternary-result/impl/ternary-result-map-warn.mjs +3 -3
  86. package/dist/functional/ternary-result/impl/ternary-result-map.mjs +4 -4
  87. package/dist/functional/ternary-result/impl/ternary-result-ok.mjs +14 -14
  88. package/dist/functional/ternary-result/impl/ternary-result-to-optional.mjs +19 -19
  89. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mjs +19 -19
  90. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.mjs +17 -17
  91. package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.mjs +1 -1
  92. package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.mjs +20 -20
  93. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mjs +18 -18
  94. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.mjs +17 -17
  95. package/dist/functional/ternary-result/impl/ternary-result-warn.mjs +16 -16
  96. package/dist/functional/ternary-result/impl/ternary-result-zip.mjs +31 -31
  97. package/dist/functional/ternary-result/impl/variant-name.mjs +1 -1
  98. package/dist/guard/has-key.mjs +41 -41
  99. package/dist/guard/is-non-empty-string.mjs +37 -37
  100. package/dist/guard/is-non-null-object.mjs +34 -34
  101. package/dist/guard/is-primitive.mjs +31 -31
  102. package/dist/guard/is-record.mjs +86 -86
  103. package/dist/guard/is-type.mjs +387 -387
  104. package/dist/guard/key-is-in.mjs +40 -40
  105. package/dist/iterator/range.mjs +1 -1
  106. package/dist/json/json.mjs +289 -289
  107. package/dist/number/branded-types/finite-number.mjs +116 -116
  108. package/dist/number/branded-types/int.mjs +223 -223
  109. package/dist/number/branded-types/int16.mjs +116 -116
  110. package/dist/number/branded-types/int32.mjs +116 -116
  111. package/dist/number/branded-types/negative-finite-number.mjs +126 -126
  112. package/dist/number/branded-types/negative-int.mjs +104 -104
  113. package/dist/number/branded-types/negative-safe-int.mjs +104 -104
  114. package/dist/number/branded-types/non-negative-finite-number.mjs +132 -132
  115. package/dist/number/branded-types/non-negative-int16.mjs +113 -113
  116. package/dist/number/branded-types/non-negative-int32.mjs +113 -113
  117. package/dist/number/branded-types/non-positive-finite-number.mjs +116 -116
  118. package/dist/number/branded-types/non-positive-int.mjs +97 -97
  119. package/dist/number/branded-types/non-positive-safe-int.mjs +98 -98
  120. package/dist/number/branded-types/non-zero-finite-number.mjs +112 -112
  121. package/dist/number/branded-types/non-zero-int.mjs +82 -82
  122. package/dist/number/branded-types/non-zero-int16.mjs +95 -95
  123. package/dist/number/branded-types/non-zero-int32.mjs +95 -95
  124. package/dist/number/branded-types/non-zero-safe-int.mjs +99 -99
  125. package/dist/number/branded-types/non-zero-uint16.mjs +95 -95
  126. package/dist/number/branded-types/non-zero-uint32.mjs +95 -95
  127. package/dist/number/branded-types/positive-finite-number.mjs +134 -134
  128. package/dist/number/branded-types/positive-int.mjs +237 -237
  129. package/dist/number/branded-types/positive-int16.mjs +110 -110
  130. package/dist/number/branded-types/positive-int32.mjs +110 -110
  131. package/dist/number/branded-types/positive-safe-int.mjs +268 -268
  132. package/dist/number/branded-types/positive-uint16.mjs +110 -110
  133. package/dist/number/branded-types/positive-uint32.mjs +110 -110
  134. package/dist/number/branded-types/safe-int.mjs +259 -259
  135. package/dist/number/branded-types/safe-uint.mjs +111 -111
  136. package/dist/number/branded-types/uint.mjs +225 -225
  137. package/dist/number/branded-types/uint16.mjs +108 -108
  138. package/dist/number/branded-types/uint32.mjs +108 -108
  139. package/dist/number/enum/int8.mjs +118 -118
  140. package/dist/number/enum/uint8.mjs +109 -109
  141. package/dist/number/num-arithmetic-types.mjs +1 -1
  142. package/dist/number/num.mjs +478 -478
  143. package/dist/number/refined-number-utils.mjs +170 -170
  144. package/dist/object/object.mjs +234 -234
  145. package/dist/others/cast-mutable.mjs +33 -33
  146. package/dist/others/cast-readonly.mjs +32 -32
  147. package/dist/others/debounce-function.mjs +13 -13
  148. package/dist/others/fast-deep-equal.mjs +14 -14
  149. package/dist/others/if-then.mjs +29 -29
  150. package/dist/others/tuple.mjs +50 -50
  151. package/dist/others/unknown-to-string.mjs +38 -38
  152. package/dist/promise/promise.mjs +47 -47
  153. package/dist/string/str.mjs +177 -177
  154. package/dist/types.mjs +1 -1
  155. package/package.json +6 -6
  156. package/src/guard/is-type.test.mts +2 -2
  157. package/src/number/branded-types/finite-number.test.mts +1 -1
  158. package/src/number/branded-types/int.test.mts +1 -1
  159. package/src/number/branded-types/int16.test.mts +1 -1
  160. package/src/number/branded-types/int32.test.mts +1 -1
  161. package/src/number/branded-types/non-negative-finite-number.test.mts +1 -1
  162. package/src/number/branded-types/non-negative-int16.test.mts +1 -1
  163. package/src/number/branded-types/non-negative-int32.test.mts +1 -1
  164. package/src/number/branded-types/non-zero-finite-number.test.mts +1 -1
  165. package/src/number/branded-types/non-zero-int.test.mts +1 -1
  166. package/src/number/branded-types/non-zero-int16.test.mts +1 -1
  167. package/src/number/branded-types/non-zero-int32.test.mts +1 -1
  168. package/src/number/branded-types/non-zero-safe-int.test.mts +1 -1
  169. package/src/number/branded-types/non-zero-uint16.test.mts +1 -1
  170. package/src/number/branded-types/non-zero-uint32.test.mts +1 -1
  171. package/src/number/branded-types/positive-finite-number.test.mts +1 -1
  172. package/src/number/branded-types/positive-int.test.mts +1 -1
  173. package/src/number/branded-types/positive-int16.test.mts +1 -1
  174. package/src/number/branded-types/positive-int32.test.mts +1 -1
  175. package/src/number/branded-types/positive-safe-int.test.mts +1 -1
  176. package/src/number/branded-types/positive-uint16.test.mts +1 -1
  177. package/src/number/branded-types/positive-uint32.test.mts +1 -1
  178. package/src/number/branded-types/safe-int.test.mts +1 -1
  179. package/src/number/branded-types/safe-uint.test.mts +1 -1
  180. package/src/number/branded-types/uint.test.mts +1 -1
  181. package/src/number/branded-types/uint16.test.mts +1 -1
  182. package/src/number/branded-types/uint32.test.mts +1 -1
@@ -2,70 +2,70 @@ import { Arr } from '../array/index.mjs';
2
2
  import { pipe, Result } from '../functional/index.mjs';
3
3
  import { isRecord } from '../guard/index.mjs';
4
4
  import { unknownToString } from '../others/index.mjs';
5
- /**
6
- * A collection of type-safe JSON utility functions that provide safe parsing,
7
- * stringification, and manipulation of JSON data. All functions return `Result`
8
- * types to handle errors without throwing exceptions.
9
- */
5
+
6
+
7
+
8
+
9
+
10
10
  export var Json;
11
11
  (function (Json) {
12
- /**
13
- * Safely converts a JSON string into a JavaScript value without throwing
14
- * exceptions.
15
- *
16
- * This function provides type-safe JSON parsing by wrapping the native
17
- * `JSON.parse` in a `Result` type, allowing you to handle parsing errors
18
- * gracefully without try-catch blocks.
19
- *
20
- * @example
21
- *
22
- * ```ts
23
- * const validJson = '{"name": "Alice", "age": 30}';
24
- *
25
- * const invalidJson = '{invalid json}';
26
- *
27
- * const parsed = Json.parse(validJson);
28
- *
29
- * const failed = Json.parse(invalidJson);
30
- *
31
- * assert.isTrue(Result.isOk(parsed));
32
- *
33
- * if (Result.isOk(parsed)) {
34
- * assert.deepStrictEqual(parsed.value, { name: 'Alice', age: 30 });
35
- * }
36
- *
37
- * assert.isTrue(Result.isErr(failed));
38
- *
39
- * // With reviver
40
- * const jsonWithDate = '{"created": "2024-01-01T00:00:00.000Z"}';
41
- *
42
- * const withReviver = Json.parse(jsonWithDate, (key, value) => {
43
- * if (key === 'created' && typeof value === 'string') {
44
- * return new Date(value);
45
- * }
46
- *
47
- * return value;
48
- * });
49
- *
50
- * assert.isTrue(Result.isOk(withReviver));
51
- * ```
52
- *
53
- * @param text - A valid JSON string to parse. Can contain any valid JSON data
54
- * type: primitives (string, number, boolean, null), arrays, or objects.
55
- * @param reviver - Optional function that transforms parsed values. Called
56
- * for each key-value pair in the JSON. The function receives the key name
57
- * and parsed value, and should return the transformed value. For nested
58
- * objects, inner objects are processed before outer objects.
59
- * @returns A `Result<JsonValue, string>` containing:
60
- *
61
- * - On success: `Result.ok(parsedValue)` where `parsedValue` is the parsed JSON
62
- * - On failure: `Result.err(errorMessage)` where `errorMessage` describes the
63
- * parsing error
64
- */
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+
55
+
56
+
57
+
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
65
  Json.parse = (text, reviver) => {
66
66
  try {
67
67
  return Result.ok(JSON.parse(text,
68
- // eslint-disable-next-line total-functions/no-unsafe-type-assertion
68
+
69
69
  reviver));
70
70
  }
71
71
  catch (error) {
@@ -73,70 +73,70 @@ export var Json;
73
73
  return Result.err(errStr);
74
74
  }
75
75
  };
76
- /**
77
- * Safely converts a JavaScript value to a JSON string without throwing
78
- * exceptions.
79
- *
80
- * This function provides type-safe JSON stringification by wrapping the
81
- * native `JSON.stringify` in a `Result` type, allowing you to handle
82
- * serialization errors gracefully (such as circular references or BigInt
83
- * values).
84
- *
85
- * @example
86
- *
87
- * ```ts
88
- * const data = { name: 'Bob', age: 25, active: true } as const;
89
- *
90
- * // Basic stringify
91
- * const basic = Json.stringify(data);
92
- *
93
- * assert.isTrue(Result.isOk(basic));
94
- *
95
- * if (Result.isOk(basic)) {
96
- * assert.isTrue(basic.value === '{"name":"Bob","age":25,"active":true}');
97
- * }
98
- *
99
- * // With formatting
100
- * const formatted = Json.stringify(data, undefined, 2);
101
- *
102
- * assert.isTrue(Result.isOk(formatted));
103
- *
104
- * // With replacer
105
- * const filtered = Json.stringify(data, (key, value) => {
106
- * if (key === 'age') return undefined; // omit age field
107
- *
108
- * return value;
109
- * });
110
- *
111
- * assert.isTrue(Result.isOk(filtered));
112
- *
113
- * if (Result.isOk(filtered)) {
114
- * assert.isTrue(isString(filtered.value));
115
- *
116
- * assert.isFalse(filtered.value.includes('age'));
117
- * }
118
- * ```
119
- *
120
- * @param value - The JavaScript value to serialize. Can be any value that
121
- * JSON.stringify accepts: primitives, objects, arrays. Non-serializable
122
- * values (functions, undefined, symbols) will be omitted or converted to
123
- * null according to JSON.stringify behavior.
124
- * @param replacer - Optional function that transforms values during
125
- * serialization. Called for each key-value pair. Should return the value to
126
- * be serialized, or undefined to omit the property from the result.
127
- * @param space - Optional parameter for formatting the output JSON:
128
- *
129
- * - Number (1-10): Number of spaces to indent each level
130
- * - String: String to use for indentation (first 10 characters)
131
- * - Undefined/null: No formatting (compact output)
132
- *
133
- * @returns A `Result<string, string>` containing:
134
- *
135
- * - On success: `Result.ok(jsonString)` where `jsonString` is the serialized
136
- * JSON
137
- * - On failure: `Result.err(errorMessage)` where `errorMessage` describes the
138
- * error
139
- */
76
+
77
+
78
+
79
+
80
+
81
+
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+
90
+
91
+
92
+
93
+
94
+
95
+
96
+
97
+
98
+
99
+
100
+
101
+
102
+
103
+
104
+
105
+
106
+
107
+
108
+
109
+
110
+
111
+
112
+
113
+
114
+
115
+
116
+
117
+
118
+
119
+
120
+
121
+
122
+
123
+
124
+
125
+
126
+
127
+
128
+
129
+
130
+
131
+
132
+
133
+
134
+
135
+
136
+
137
+
138
+
139
+
140
140
  Json.stringify = (value, replacer, space) => {
141
141
  try {
142
142
  return Result.ok(JSON.stringify(value, replacer, space));
@@ -146,71 +146,71 @@ export var Json;
146
146
  return Result.err(errStr);
147
147
  }
148
148
  };
149
- /**
150
- * Safely converts a JavaScript value to a JSON string, including only the
151
- * specified properties.
152
- *
153
- * This function provides selective serialization by allowing you to specify
154
- * exactly which object properties should be included in the resulting JSON.
155
- * It's useful for creating filtered or minimal representations of objects,
156
- * such as for API responses or logging.
157
- *
158
- * @example
159
- *
160
- * ```ts
161
- * const user = {
162
- * id: 1,
163
- * name: 'Charlie',
164
- * email: 'charlie@example.com',
165
- * password: 'secret123',
166
- * role: 'admin',
167
- * } as const;
168
- *
169
- * // Select only safe properties to serialize
170
- * const safeJson = Json.stringifySelected(user, ['id', 'name', 'role']);
171
- *
172
- * assert.isTrue(Result.isOk(safeJson));
173
- *
174
- * if (Result.isOk(safeJson)) {
175
- * assert.isTrue(isString(safeJson.value));
176
- *
177
- * const parsed: unknown = JSON.parse(safeJson.value);
178
- *
179
- * assert.deepStrictEqual(parsed, {
180
- * id: 1,
181
- * name: 'Charlie',
182
- * role: 'admin',
183
- * });
184
- *
185
- * assert.isFalse(safeJson.value.includes('password'));
186
- *
187
- * assert.isFalse(safeJson.value.includes('email'));
188
- * }
189
- *
190
- * // With formatting
191
- * const formatted = Json.stringifySelected(user, ['id', 'name'], 2);
192
- *
193
- * assert.isTrue(Result.isOk(formatted));
194
- * ```
195
- *
196
- * @param value - The JavaScript value to serialize. While any value is
197
- * accepted, the property filtering only applies to objects and nested
198
- * objects.
199
- * @param propertiesToBeSelected - Optional array of property names (strings)
200
- * and array indices (numbers) to include in the serialization. If provided,
201
- * only these properties will appear in the output JSON. If undefined, all
202
- * properties are included.
203
- * @param space - Optional formatting parameter:
204
- *
205
- * - Number (1-10): Number of spaces to indent each level
206
- * - String: String to use for indentation (first 10 characters)
207
- * - Undefined/null: No formatting (compact output)
208
- *
209
- * @returns A `Result<string, string>` containing:
210
- *
211
- * - On success: `Result.ok(jsonString)` with only selected properties
212
- * - On failure: `Result.err(errorMessage)` describing the serialization error
213
- */
149
+
150
+
151
+
152
+
153
+
154
+
155
+
156
+
157
+
158
+
159
+
160
+
161
+
162
+
163
+
164
+
165
+
166
+
167
+
168
+
169
+
170
+
171
+
172
+
173
+
174
+
175
+
176
+
177
+
178
+
179
+
180
+
181
+
182
+
183
+
184
+
185
+
186
+
187
+
188
+
189
+
190
+
191
+
192
+
193
+
194
+
195
+
196
+
197
+
198
+
199
+
200
+
201
+
202
+
203
+
204
+
205
+
206
+
207
+
208
+
209
+
210
+
211
+
212
+
213
+
214
214
  Json.stringifySelected = (value, propertiesToBeSelected, space) => {
215
215
  try {
216
216
  return Result.ok(JSON.stringify(value, propertiesToBeSelected, space));
@@ -220,83 +220,83 @@ export var Json;
220
220
  return Result.err(errStr);
221
221
  }
222
222
  };
223
- /**
224
- * Safely converts a JavaScript record to a JSON string with keys sorted
225
- * alphabetically at all levels.
226
- *
227
- * This function creates deterministic JSON output by ensuring that object
228
- * keys appear in alphabetical order at every level of nesting. This is
229
- * particularly useful for creating consistent output for comparison, hashing,
230
- * caching, or when you need reproducible JSON representations across
231
- * different JavaScript engines or runs.
232
- *
233
- * @example
234
- *
235
- * ```ts
236
- * const unorderedData = {
237
- * zebra: 1,
238
- * apple: 2,
239
- * mango: 3,
240
- * nested: {
241
- * zulu: 'z',
242
- * alpha: 'a',
243
- * beta: 'b',
244
- * },
245
- * } as const;
246
- *
247
- * // Keys will be sorted alphabetically at all levels
248
- * const sorted = Json.stringifySortedKey(unorderedData);
249
- *
250
- * assert.isTrue(Result.isOk(sorted));
251
- *
252
- * if (Result.isOk(sorted)) {
253
- * // Keys should appear in alphabetical order
254
- * const expected =
255
- * '{"apple":2,"mango":3,"nested":{"alpha":"a","beta":"b","zulu":"z"},"zebra":1}';
256
- *
257
- * assert.isTrue(sorted.value === expected);
258
- * }
259
- *
260
- * // With formatting
261
- * const formatted = Json.stringifySortedKey(unorderedData, 2);
262
- *
263
- * assert.isTrue(Result.isOk(formatted));
264
- *
265
- * if (Result.isOk(formatted)) {
266
- * assert.isTrue(isString(formatted.value));
267
- *
268
- * // Check that keys are in order (first key should be "apple")
269
- * assert.isTrue(
270
- * formatted.value.indexOf('"apple"') < formatted.value.indexOf('"mango"'),
271
- * );
272
- *
273
- * assert.isTrue(
274
- * formatted.value.indexOf('"mango"') <
275
- * formatted.value.indexOf('"nested"'),
276
- * );
277
- *
278
- * assert.isTrue(
279
- * formatted.value.indexOf('"nested"') <
280
- * formatted.value.indexOf('"zebra"'),
281
- * );
282
- * }
283
- * ```
284
- *
285
- * @param value - An object (`UnknownRecord`) to serialize. Must be a plain
286
- * object (not an array, primitive, or null). Nested objects and arrays
287
- * within the object will also have their keys sorted alphabetically.
288
- * @param space - Optional formatting parameter:
289
- *
290
- * - Number (1-10): Number of spaces to indent each level
291
- * - String: String to use for indentation (first 10 characters)
292
- * - Undefined/null: No formatting (compact output)
293
- *
294
- * @returns A `Result<string, string>` containing:
295
- *
296
- * - On success: `Result.ok(jsonString)` with all object keys sorted
297
- * alphabetically
298
- * - On failure: `Result.err(errorMessage)` describing the serialization error
299
- */
223
+
224
+
225
+
226
+
227
+
228
+
229
+
230
+
231
+
232
+
233
+
234
+
235
+
236
+
237
+
238
+
239
+
240
+
241
+
242
+
243
+
244
+
245
+
246
+
247
+
248
+
249
+
250
+
251
+
252
+
253
+
254
+
255
+
256
+
257
+
258
+
259
+
260
+
261
+
262
+
263
+
264
+
265
+
266
+
267
+
268
+
269
+
270
+
271
+
272
+
273
+
274
+
275
+
276
+
277
+
278
+
279
+
280
+
281
+
282
+
283
+
284
+
285
+
286
+
287
+
288
+
289
+
290
+
291
+
292
+
293
+
294
+
295
+
296
+
297
+
298
+
299
+
300
300
  Json.stringifySortedKey = (value, space) => {
301
301
  const allKeys = pipe(keysDeep(value))
302
302
  .map(Arr.uniq)
@@ -304,19 +304,19 @@ export var Json;
304
304
  return Json.stringifySelected(value, allKeys, space);
305
305
  };
306
306
  })(Json || (Json = {}));
307
- /**
308
- * @param obj - The record to extract keys from. Must be a plain object.
309
- * @param mut_keys - A mutable array to accumulate the collected keys. This
310
- * array will be modified in-place by the function for performance reasons.
311
- * @internal
312
- * Recursively collects all property keys from a nested object structure.
313
- *
314
- * This helper function traverses an object and its nested objects and arrays,
315
- * collecting all string keys found at any level of nesting. The function mutates
316
- * the provided keys array for performance reasons.
317
- */
307
+
308
+
309
+
310
+
311
+
312
+
313
+
314
+
315
+
316
+
317
+
318
318
  const keysDeepImpl = (obj,
319
- // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
319
+
320
320
  mut_keys) => {
321
321
  for (const [k, v] of Object.entries(obj)) {
322
322
  mut_keys.push(k);
@@ -332,18 +332,18 @@ mut_keys) => {
332
332
  }
333
333
  }
334
334
  };
335
- /**
336
- * @param obj - The record to extract keys from. Must be a plain object.
337
- * @returns A readonly array of all string keys found in the object and its
338
- * nested objects/arrays. May contain duplicates if the same key appears at
339
- * multiple levels.
340
- * @internal
341
- * Extracts all property keys from a nested object structure into a flat array.
342
- *
343
- * This function serves as a safe wrapper around `keysDeepImpl`, creating a new
344
- * mutable array and passing it to the recursive implementation. The result
345
- * contains all keys found at any level of nesting within the input object.
346
- */
335
+
336
+
337
+
338
+
339
+
340
+
341
+
342
+
343
+
344
+
345
+
346
+
347
347
  const keysDeep = (obj) => {
348
348
  const mut_keys = [];
349
349
  keysDeepImpl(obj, mut_keys);