ts-data-forge 14.7.0 → 14.8.0
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.
- package/README.md +21 -34
- package/dist/array/impl/array-utils-creation.d.mts +3 -3
- package/dist/array/impl/array-utils-creation.d.mts.map +1 -1
- package/dist/array/impl/array-utils-creation.mjs.map +1 -1
- package/dist/array/impl/array-utils-element-access.d.mts +2 -2
- package/dist/array/impl/array-utils-element-access.d.mts.map +1 -1
- package/dist/array/impl/array-utils-element-access.mjs +1 -1
- package/dist/array/impl/array-utils-element-access.mjs.map +1 -1
- package/dist/array/impl/array-utils-iterators.d.mts +1 -1
- package/dist/array/impl/array-utils-iterators.d.mts.map +1 -1
- package/dist/array/impl/array-utils-length-bounded-array-cast.d.mts +37 -7
- package/dist/array/impl/array-utils-length-bounded-array-cast.d.mts.map +1 -1
- package/dist/array/impl/array-utils-length-bounded-array-cast.mjs +4 -0
- package/dist/array/impl/array-utils-length-bounded-array-cast.mjs.map +1 -1
- package/dist/array/impl/array-utils-length-bounded-array-guard.d.mts +9 -9
- package/dist/array/impl/array-utils-length-bounded-array-guard.d.mts.map +1 -1
- package/dist/array/impl/array-utils-length-bounded-array-guard.mjs +1 -1
- package/dist/array/impl/array-utils-length-bounded-array-guard.mjs.map +1 -1
- package/dist/array/impl/array-utils-length-bounded-tuple-cast.d.mts +28 -8
- package/dist/array/impl/array-utils-length-bounded-tuple-cast.d.mts.map +1 -1
- package/dist/array/impl/array-utils-length-bounded-tuple-cast.mjs +4 -0
- package/dist/array/impl/array-utils-length-bounded-tuple-cast.mjs.map +1 -1
- package/dist/array/impl/array-utils-length-bounded-tuple-guard.d.mts +3 -3
- package/dist/array/impl/array-utils-length-bounded-tuple-guard.d.mts.map +1 -1
- package/dist/array/impl/array-utils-length-bounded-tuple-guard.mjs +1 -1
- package/dist/array/impl/array-utils-length-bounded-tuple-guard.mjs.map +1 -1
- package/dist/array/impl/array-utils-modification.d.mts +2 -2
- package/dist/array/impl/array-utils-modification.d.mts.map +1 -1
- package/dist/array/impl/array-utils-reducing-value.d.mts +2 -2
- package/dist/array/impl/array-utils-reducing-value.d.mts.map +1 -1
- package/dist/array/impl/array-utils-reducing-value.mjs +3 -4
- package/dist/array/impl/array-utils-reducing-value.mjs.map +1 -1
- package/dist/array/impl/array-utils-search.d.mts +1 -1
- package/dist/array/impl/array-utils-search.d.mts.map +1 -1
- package/dist/array/impl/array-utils-set-op.d.mts +1 -1
- package/dist/array/impl/array-utils-set-op.d.mts.map +1 -1
- package/dist/array/impl/array-utils-size.d.mts +2 -2
- package/dist/array/impl/array-utils-size.d.mts.map +1 -1
- package/dist/array/impl/array-utils-slice-clamped.d.mts +1 -1
- package/dist/array/impl/array-utils-slice-clamped.d.mts.map +1 -1
- package/dist/array/impl/array-utils-slicing.d.mts +2 -2
- package/dist/array/impl/array-utils-slicing.d.mts.map +1 -1
- package/dist/array/impl/array-utils-transformation.d.mts +2 -2
- package/dist/array/impl/array-utils-transformation.d.mts.map +1 -1
- package/dist/array/impl/array-utils-transformation.mjs +6 -3
- package/dist/array/impl/array-utils-transformation.mjs.map +1 -1
- package/dist/array/impl/array-utils-validation.d.mts +2 -2
- package/dist/array/impl/array-utils-validation.d.mts.map +1 -1
- package/dist/collections/imap-mapped.d.mts +2 -2
- package/dist/collections/imap-mapped.d.mts.map +1 -1
- package/dist/collections/imap-mapped.mjs +10 -7
- package/dist/collections/imap-mapped.mjs.map +1 -1
- package/dist/collections/imap.d.mts +2 -2
- package/dist/collections/imap.d.mts.map +1 -1
- package/dist/collections/imap.mjs +10 -7
- package/dist/collections/imap.mjs.map +1 -1
- package/dist/collections/iset-mapped.d.mts +2 -2
- package/dist/collections/iset-mapped.d.mts.map +1 -1
- package/dist/collections/iset-mapped.mjs +6 -3
- package/dist/collections/iset-mapped.mjs.map +1 -1
- package/dist/collections/iset.d.mts +2 -2
- package/dist/collections/iset.d.mts.map +1 -1
- package/dist/collections/iset.mjs +5 -5
- package/dist/collections/iset.mjs.map +1 -1
- package/dist/collections/queue.d.mts +1 -1
- package/dist/collections/queue.d.mts.map +1 -1
- package/dist/collections/stack.d.mts +1 -1
- package/dist/collections/stack.d.mts.map +1 -1
- package/dist/guard/is-non-empty-string.d.mts +1 -1
- package/dist/guard/is-non-empty-string.d.mts.map +1 -1
- package/dist/guard/is-primitive.d.mts +1 -1
- package/dist/guard/is-primitive.d.mts.map +1 -1
- package/dist/guard/is-type.d.mts +1 -1
- package/dist/guard/is-type.d.mts.map +1 -1
- package/dist/index.d.mts +2 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -1
- package/dist/iterator/range.d.mts +5 -4
- package/dist/iterator/range.d.mts.map +1 -1
- package/dist/iterator/range.mjs.map +1 -1
- package/dist/json/json.d.mts +29 -32
- package/dist/json/json.d.mts.map +1 -1
- package/dist/json/json.mjs +1 -4
- package/dist/json/json.mjs.map +1 -1
- package/dist/number/branded-types/finite-number.d.mts +1 -1
- package/dist/number/branded-types/finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/int.d.mts +2 -2
- package/dist/number/branded-types/int.d.mts.map +1 -1
- package/dist/number/branded-types/int16.d.mts +1 -1
- package/dist/number/branded-types/int16.d.mts.map +1 -1
- package/dist/number/branded-types/int32.d.mts +1 -1
- package/dist/number/branded-types/int32.d.mts.map +1 -1
- package/dist/number/branded-types/negative-finite-number.d.mts +1 -1
- package/dist/number/branded-types/negative-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/negative-int.d.mts +1 -1
- package/dist/number/branded-types/negative-int.d.mts.map +1 -1
- package/dist/number/branded-types/negative-safe-int.d.mts +1 -1
- package/dist/number/branded-types/negative-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-negative-finite-number.d.mts +1 -1
- package/dist/number/branded-types/non-negative-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/non-negative-int16.d.mts +1 -1
- package/dist/number/branded-types/non-negative-int16.d.mts.map +1 -1
- package/dist/number/branded-types/non-negative-int32.d.mts +1 -1
- package/dist/number/branded-types/non-negative-int32.d.mts.map +1 -1
- package/dist/number/branded-types/non-positive-finite-number.d.mts +1 -1
- package/dist/number/branded-types/non-positive-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/non-positive-int.d.mts +1 -1
- package/dist/number/branded-types/non-positive-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-positive-safe-int.d.mts +1 -1
- package/dist/number/branded-types/non-positive-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-finite-number.d.mts +1 -1
- package/dist/number/branded-types/non-zero-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-int.d.mts +1 -1
- package/dist/number/branded-types/non-zero-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-int16.d.mts +1 -1
- package/dist/number/branded-types/non-zero-int16.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-int32.d.mts +1 -1
- package/dist/number/branded-types/non-zero-int32.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-safe-int.d.mts +1 -1
- package/dist/number/branded-types/non-zero-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-uint16.d.mts +1 -1
- package/dist/number/branded-types/non-zero-uint16.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-uint32.d.mts +1 -1
- package/dist/number/branded-types/non-zero-uint32.d.mts.map +1 -1
- package/dist/number/branded-types/positive-finite-number.d.mts +1 -1
- package/dist/number/branded-types/positive-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/positive-int.d.mts +2 -2
- package/dist/number/branded-types/positive-int.d.mts.map +1 -1
- package/dist/number/branded-types/positive-int16.d.mts +1 -1
- package/dist/number/branded-types/positive-int16.d.mts.map +1 -1
- package/dist/number/branded-types/positive-int32.d.mts +1 -1
- package/dist/number/branded-types/positive-int32.d.mts.map +1 -1
- package/dist/number/branded-types/positive-safe-int.d.mts +2 -2
- package/dist/number/branded-types/positive-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/positive-uint16.d.mts +1 -1
- package/dist/number/branded-types/positive-uint16.d.mts.map +1 -1
- package/dist/number/branded-types/positive-uint32.d.mts +1 -1
- package/dist/number/branded-types/positive-uint32.d.mts.map +1 -1
- package/dist/number/branded-types/safe-int.d.mts +2 -2
- package/dist/number/branded-types/safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/safe-int.mjs.map +1 -1
- package/dist/number/branded-types/safe-uint.d.mts +1 -1
- package/dist/number/branded-types/safe-uint.d.mts.map +1 -1
- package/dist/number/branded-types/uint.d.mts +2 -2
- package/dist/number/branded-types/uint.d.mts.map +1 -1
- package/dist/number/branded-types/uint16.d.mts +1 -1
- package/dist/number/branded-types/uint16.d.mts.map +1 -1
- package/dist/number/branded-types/uint32.d.mts +1 -1
- package/dist/number/branded-types/uint32.d.mts.map +1 -1
- package/dist/number/enum/int8.d.mts +1 -1
- package/dist/number/enum/int8.d.mts.map +1 -1
- package/dist/number/enum/uint8.d.mts +1 -1
- package/dist/number/enum/uint8.d.mts.map +1 -1
- package/dist/number/num-arithmetic-types.d.mts +1 -1
- package/dist/number/num-arithmetic-types.d.mts.map +1 -1
- package/dist/number/num.d.mts +3 -3
- package/dist/number/num.d.mts.map +1 -1
- package/dist/number/refined-number-utils.d.mts +2 -2
- package/dist/number/refined-number-utils.d.mts.map +1 -1
- package/dist/number/refined-number-utils.mjs +6 -4
- package/dist/number/refined-number-utils.mjs.map +1 -1
- package/dist/object/object.d.mts +5 -8
- package/dist/object/object.d.mts.map +1 -1
- package/dist/object/object.mjs +16 -13
- package/dist/object/object.mjs.map +1 -1
- package/dist/others/cast-mutable.d.mts +1 -1
- package/dist/others/cast-mutable.d.mts.map +1 -1
- package/dist/others/cast-readonly.d.mts +1 -1
- package/dist/others/cast-readonly.d.mts.map +1 -1
- package/dist/others/debounce-function.d.mts.map +1 -1
- package/dist/others/debounce-function.mjs +1 -5
- package/dist/others/debounce-function.mjs.map +1 -1
- package/dist/others/memoize-function.d.mts +1 -1
- package/dist/others/memoize-function.d.mts.map +1 -1
- package/dist/string/str.d.mts +26 -18
- package/dist/string/str.d.mts.map +1 -1
- package/dist/string/str.mjs +9 -1
- package/dist/string/str.mjs.map +1 -1
- package/dist/types.d.mts +1 -1
- package/dist/types.d.mts.map +1 -1
- package/package.json +33 -32
- package/src/array/impl/array-utils-creation.mts +24 -22
- package/src/array/impl/array-utils-creation.test.mts +25 -22
- package/src/array/impl/array-utils-element-access.mts +7 -7
- package/src/array/impl/array-utils-element-access.test.mts +2 -2
- package/src/array/impl/array-utils-iterators.mts +1 -1
- package/src/array/impl/array-utils-iterators.test.mts +1 -1
- package/src/array/impl/array-utils-length-bounded-array-cast.mts +43 -13
- package/src/array/impl/array-utils-length-bounded-array-cast.test.mts +6 -6
- package/src/array/impl/array-utils-length-bounded-array-guard.mts +15 -15
- package/src/array/impl/array-utils-length-bounded-array-guard.test.mts +66 -54
- package/src/array/impl/array-utils-length-bounded-tuple-cast.mts +32 -12
- package/src/array/impl/array-utils-length-bounded-tuple-cast.test.mts +10 -10
- package/src/array/impl/array-utils-length-bounded-tuple-guard.mts +8 -8
- package/src/array/impl/array-utils-length-bounded-tuple-guard.test.mts +38 -28
- package/src/array/impl/array-utils-length-constraint-preservation.test.mts +14 -14
- package/src/array/impl/array-utils-modification.mts +12 -12
- package/src/array/impl/array-utils-modification.test.mts +7 -7
- package/src/array/impl/array-utils-overload-type-error.test.mts +1 -1
- package/src/array/impl/array-utils-reducing-value.mts +9 -11
- package/src/array/impl/array-utils-reducing-value.test.mts +2 -2
- package/src/array/impl/array-utils-search.mts +4 -4
- package/src/array/impl/array-utils-search.test.mts +25 -17
- package/src/array/impl/array-utils-set-op.mts +1 -1
- package/src/array/impl/array-utils-shape-invariants.test.mts +8 -8
- package/src/array/impl/array-utils-size.mts +5 -5
- package/src/array/impl/array-utils-slice-clamped.mts +2 -2
- package/src/array/impl/array-utils-slicing.mts +8 -8
- package/src/array/impl/array-utils-slicing.test.mts +1 -1
- package/src/array/impl/array-utils-transformation.mts +26 -24
- package/src/array/impl/array-utils-transformation.test.mts +12 -10
- package/src/array/impl/array-utils-validation.mts +7 -7
- package/src/array/impl/array-utils-validation.test.mts +39 -39
- package/src/array/impl/array.test.mts +1 -1
- package/src/collections/imap-mapped.mts +15 -9
- package/src/collections/imap-mapped.test.mts +1 -1
- package/src/collections/imap.mts +15 -9
- package/src/collections/imap.test.mts +7 -5
- package/src/collections/iset-mapped.mts +14 -8
- package/src/collections/iset.mts +12 -10
- package/src/collections/iset.test.mts +14 -12
- package/src/collections/queue.mts +1 -1
- package/src/collections/stack.mts +1 -1
- package/src/collections/stack.test.mts +8 -6
- package/src/guard/is-error.test.mts +6 -4
- package/src/guard/is-non-empty-string.mts +1 -1
- package/src/guard/is-non-empty-string.test.mts +15 -11
- package/src/guard/is-primitive.mts +1 -1
- package/src/guard/is-type.mts +1 -1
- package/src/guard/is-type.test.mts +87 -59
- package/src/index.mts +2 -0
- package/src/iterator/range.mts +5 -9
- package/src/iterator/range.test.mts +29 -0
- package/src/json/json.mts +32 -35
- package/src/json/json.test.mts +106 -89
- package/src/number/branded-types/finite-number.mts +4 -4
- package/src/number/branded-types/int.mts +2 -2
- package/src/number/branded-types/int16.mts +1 -1
- package/src/number/branded-types/int32.mts +1 -1
- package/src/number/branded-types/negative-finite-number.mts +1 -1
- package/src/number/branded-types/negative-finite-number.test.mts +4 -4
- package/src/number/branded-types/negative-int.mts +3 -3
- package/src/number/branded-types/negative-int.test.mts +1 -1
- package/src/number/branded-types/negative-safe-int.mts +3 -3
- package/src/number/branded-types/negative-safe-int.test.mts +1 -1
- package/src/number/branded-types/non-negative-finite-number.mts +3 -3
- package/src/number/branded-types/non-negative-int16.mts +1 -1
- package/src/number/branded-types/non-negative-int32.mts +1 -1
- package/src/number/branded-types/non-positive-finite-number.mts +1 -1
- package/src/number/branded-types/non-positive-int.mts +1 -1
- package/src/number/branded-types/non-positive-safe-int.mts +1 -1
- package/src/number/branded-types/non-zero-finite-number.mts +5 -5
- package/src/number/branded-types/non-zero-int.mts +1 -1
- package/src/number/branded-types/non-zero-int16.mts +1 -1
- package/src/number/branded-types/non-zero-int32.mts +1 -1
- package/src/number/branded-types/non-zero-safe-int.mts +4 -4
- package/src/number/branded-types/non-zero-uint16.mts +1 -1
- package/src/number/branded-types/non-zero-uint32.mts +1 -1
- package/src/number/branded-types/positive-finite-number.mts +4 -4
- package/src/number/branded-types/positive-int.mts +2 -2
- package/src/number/branded-types/positive-int16.mts +1 -1
- package/src/number/branded-types/positive-int32.mts +1 -1
- package/src/number/branded-types/positive-safe-int.mts +4 -4
- package/src/number/branded-types/positive-uint16.mts +1 -1
- package/src/number/branded-types/positive-uint32.mts +1 -1
- package/src/number/branded-types/safe-int.mts +2 -5
- package/src/number/branded-types/safe-uint.mts +1 -1
- package/src/number/branded-types/uint.mts +2 -2
- package/src/number/branded-types/uint16.mts +1 -1
- package/src/number/branded-types/uint32.mts +1 -1
- package/src/number/enum/int8.mts +5 -5
- package/src/number/enum/uint8.mts +4 -4
- package/src/number/num-arithmetic-types.mts +27 -27
- package/src/number/num-arithmetic-types.test.mts +21 -21
- package/src/number/num-arithmetic.test.mts +6 -6
- package/src/number/num.mts +24 -24
- package/src/number/num.test.mts +1 -1
- package/src/number/refined-number-utils.mts +25 -21
- package/src/object/object.mts +46 -34
- package/src/object/object.test.mts +5 -5
- package/src/others/cast-mutable.mts +1 -1
- package/src/others/cast-readonly.mts +1 -1
- package/src/others/debounce-function.mts +1 -5
- package/src/others/fast-deep-equal.test.mts +1 -1
- package/src/others/map-nullable.test.mts +1 -1
- package/src/others/memoize-function.mts +1 -1
- package/src/string/str.mts +33 -25
- package/src/string/str.test.mts +48 -38
- package/src/types.mts +14 -14
package/src/json/json.test.mts
CHANGED
|
@@ -127,13 +127,10 @@ describe('parse', () => {
|
|
|
127
127
|
});
|
|
128
128
|
|
|
129
129
|
test('should use reviver function to transform values', () => {
|
|
130
|
-
const dateReviver = (_key: string, value: unknown): unknown =>
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
return value;
|
|
136
|
-
};
|
|
130
|
+
const dateReviver = (_key: string, value: unknown): unknown =>
|
|
131
|
+
typeof value === 'string' && /^\d{4}-\d{2}-\d{2}T/u.test(value)
|
|
132
|
+
? new Date(value)
|
|
133
|
+
: value;
|
|
137
134
|
|
|
138
135
|
const jsonString = '{"name":"test","created":"2023-12-01T10:00:00.000Z"}';
|
|
139
136
|
|
|
@@ -141,25 +138,24 @@ describe('parse', () => {
|
|
|
141
138
|
|
|
142
139
|
assert.isTrue(Result.isOk(result));
|
|
143
140
|
|
|
144
|
-
if (
|
|
141
|
+
if (!(
|
|
145
142
|
isRecord(result.value) &&
|
|
146
143
|
hasKey(result.value, 'name') &&
|
|
147
144
|
hasKey(result.value, 'created')
|
|
148
|
-
) {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
expect(result.value.created).toBeInstanceOf(Date);
|
|
145
|
+
)) {
|
|
146
|
+
return;
|
|
152
147
|
}
|
|
148
|
+
|
|
149
|
+
expect(result.value.name).toBe('test');
|
|
150
|
+
|
|
151
|
+
expect(result.value.created).toBeInstanceOf(Date);
|
|
153
152
|
});
|
|
154
153
|
|
|
155
154
|
test('should handle reviver returning different types', () => {
|
|
156
|
-
const transformReviver = (key: string, value: unknown): unknown =>
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
return value;
|
|
162
|
-
};
|
|
155
|
+
const transformReviver = (key: string, value: unknown): unknown =>
|
|
156
|
+
key === 'number' && typeof value === 'string'
|
|
157
|
+
? Result.unwrapOkOr(Num.safeParseInt(value), Number.NaN)
|
|
158
|
+
: value;
|
|
163
159
|
|
|
164
160
|
const result = Json.parse(
|
|
165
161
|
'{"number":"42","text":"hello"}',
|
|
@@ -172,15 +168,17 @@ describe('parse', () => {
|
|
|
172
168
|
|
|
173
169
|
expect(result.value).toHaveProperty('text');
|
|
174
170
|
|
|
175
|
-
if (
|
|
171
|
+
if (!(
|
|
176
172
|
isRecord(result.value) &&
|
|
177
173
|
hasKey(result.value, 'number') &&
|
|
178
174
|
hasKey(result.value, 'text')
|
|
179
|
-
) {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
expect(result.value.text).toBe('hello');
|
|
175
|
+
)) {
|
|
176
|
+
return;
|
|
183
177
|
}
|
|
178
|
+
|
|
179
|
+
expect(result.value.number).toBe(42);
|
|
180
|
+
|
|
181
|
+
expect(result.value.text).toBe('hello');
|
|
184
182
|
});
|
|
185
183
|
});
|
|
186
184
|
|
|
@@ -336,11 +334,8 @@ describe('stringify', () => {
|
|
|
336
334
|
email: 'john@example.com',
|
|
337
335
|
} as const;
|
|
338
336
|
|
|
339
|
-
const secureReplacer = (key: string, value: unknown): unknown =>
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
return value;
|
|
343
|
-
};
|
|
337
|
+
const secureReplacer = (key: string, value: unknown): unknown =>
|
|
338
|
+
key === 'password' ? '[REDACTED]' : value;
|
|
344
339
|
|
|
345
340
|
const result = Json.stringify(data, secureReplacer);
|
|
346
341
|
|
|
@@ -428,25 +423,29 @@ describe('stringifySelected', () => {
|
|
|
428
423
|
|
|
429
424
|
const parsed: unknown = JSON.parse(result.value);
|
|
430
425
|
|
|
431
|
-
if (isRecord(parsed) && hasKey(parsed, 'users')) {
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
expect(parsed.users).toHaveLength(2);
|
|
426
|
+
if (!(isRecord(parsed) && hasKey(parsed, 'users'))) {
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
435
429
|
|
|
436
|
-
|
|
437
|
-
assert.deepStrictEqual(parsed.users[0], { id: 1, name: 'Alice' });
|
|
430
|
+
assert.isTrue(Arr.isArray(parsed.users));
|
|
438
431
|
|
|
439
|
-
|
|
440
|
-
}
|
|
432
|
+
expect(parsed.users).toHaveLength(2);
|
|
441
433
|
|
|
442
|
-
|
|
443
|
-
|
|
434
|
+
if (Arr.isArray(parsed.users)) {
|
|
435
|
+
assert.deepStrictEqual(parsed.users[0], { id: 1, name: 'Alice' });
|
|
444
436
|
|
|
445
|
-
|
|
437
|
+
expect(parsed.users[0]).not.toHaveProperty('secret');
|
|
438
|
+
}
|
|
446
439
|
|
|
447
|
-
|
|
448
|
-
|
|
440
|
+
if (!(isRecord(parsed) && hasKey(parsed, 'metadata'))) {
|
|
441
|
+
return;
|
|
449
442
|
}
|
|
443
|
+
|
|
444
|
+
assert.deepStrictEqual(parsed.metadata, { total: 2 });
|
|
445
|
+
|
|
446
|
+
expect(parsed.metadata).not.toHaveProperty('page');
|
|
447
|
+
|
|
448
|
+
expect(parsed.metadata).not.toHaveProperty('internal');
|
|
450
449
|
});
|
|
451
450
|
|
|
452
451
|
test('should work with array indices', () => {
|
|
@@ -569,23 +568,29 @@ describe('stringifySortedKey', () => {
|
|
|
569
568
|
|
|
570
569
|
const parsed: unknown = JSON.parse(result.value);
|
|
571
570
|
|
|
572
|
-
if (isRecord(parsed)) {
|
|
573
|
-
|
|
571
|
+
if (!isRecord(parsed)) {
|
|
572
|
+
return;
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
const keys = Object.keys(parsed);
|
|
574
576
|
|
|
575
|
-
|
|
577
|
+
assert.deepStrictEqual(keys, ['settings', 'user']); // sorted top-level keys
|
|
576
578
|
|
|
577
|
-
|
|
578
|
-
|
|
579
|
+
if (!hasKey(parsed, 'user') || !isRecord(parsed.user)) {
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
579
582
|
|
|
580
|
-
|
|
583
|
+
const userKeys = Object.keys(parsed.user);
|
|
581
584
|
|
|
582
|
-
|
|
583
|
-
const addressKeys = Object.keys(parsed.user.address);
|
|
585
|
+
assert.deepStrictEqual(userKeys, ['address', 'age', 'name']); // sorted nested keys
|
|
584
586
|
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
}
|
|
587
|
+
if (!hasKey(parsed.user, 'address') || !isRecord(parsed.user.address)) {
|
|
588
|
+
return;
|
|
588
589
|
}
|
|
590
|
+
|
|
591
|
+
const addressKeys = Object.keys(parsed.user.address);
|
|
592
|
+
|
|
593
|
+
assert.deepStrictEqual(addressKeys, ['city', 'country', 'zip']); // sorted deeper nested keys
|
|
589
594
|
});
|
|
590
595
|
|
|
591
596
|
test('should handle arrays with objects', () => {
|
|
@@ -609,34 +614,40 @@ describe('stringifySortedKey', () => {
|
|
|
609
614
|
|
|
610
615
|
const parsed: unknown = JSON.parse(result.value);
|
|
611
616
|
|
|
612
|
-
if (isRecord(parsed)) {
|
|
613
|
-
|
|
614
|
-
|
|
617
|
+
if (!isRecord(parsed)) {
|
|
618
|
+
return;
|
|
619
|
+
}
|
|
615
620
|
|
|
616
|
-
|
|
621
|
+
// Check top-level keys are sorted
|
|
622
|
+
const topKeys = Object.keys(parsed);
|
|
617
623
|
|
|
618
|
-
|
|
619
|
-
if (hasKey(parsed, 'metadata') && isRecord(parsed.metadata)) {
|
|
620
|
-
const metadataKeys = Object.keys(parsed.metadata);
|
|
624
|
+
assert.deepStrictEqual(topKeys, ['metadata', 'users']);
|
|
621
625
|
|
|
622
|
-
|
|
623
|
-
|
|
626
|
+
// Check metadata keys are sorted
|
|
627
|
+
if (hasKey(parsed, 'metadata') && isRecord(parsed.metadata)) {
|
|
628
|
+
const metadataKeys = Object.keys(parsed.metadata);
|
|
624
629
|
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
hasKey(parsed, 'users') &&
|
|
628
|
-
Arr.isArray(parsed.users) &&
|
|
629
|
-
Arr.isNonEmpty(parsed.users)
|
|
630
|
-
) {
|
|
631
|
-
const firstUser = parsed.users[0];
|
|
630
|
+
assert.deepStrictEqual(metadataKeys, ['author', 'created', 'version']);
|
|
631
|
+
}
|
|
632
632
|
|
|
633
|
-
|
|
634
|
-
|
|
633
|
+
// Check user object keys are sorted
|
|
634
|
+
if (
|
|
635
|
+
!hasKey(parsed, 'users') ||
|
|
636
|
+
!Arr.isArray(parsed.users) ||
|
|
637
|
+
!Arr.isNonEmpty(parsed.users)
|
|
638
|
+
) {
|
|
639
|
+
return;
|
|
640
|
+
}
|
|
635
641
|
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
642
|
+
const firstUser = parsed.users[0];
|
|
643
|
+
|
|
644
|
+
if (!isRecord(firstUser)) {
|
|
645
|
+
return;
|
|
639
646
|
}
|
|
647
|
+
|
|
648
|
+
const userKeys = Object.keys(firstUser);
|
|
649
|
+
|
|
650
|
+
assert.deepStrictEqual(userKeys, ['active', 'id', 'name']);
|
|
640
651
|
});
|
|
641
652
|
|
|
642
653
|
test('should handle formatting with space parameter', () => {
|
|
@@ -727,24 +738,30 @@ describe('stringifySortedKey', () => {
|
|
|
727
738
|
|
|
728
739
|
const parsed: unknown = JSON.parse(result.value);
|
|
729
740
|
|
|
730
|
-
if (isRecord(parsed)
|
|
731
|
-
|
|
741
|
+
if (!isRecord(parsed) || !hasKey(parsed, 'level1')) {
|
|
742
|
+
return;
|
|
743
|
+
}
|
|
732
744
|
|
|
733
|
-
|
|
734
|
-
assert.deepStrictEqual(Object.keys(level1), ['a', 'z']);
|
|
745
|
+
const level1 = parsed.level1;
|
|
735
746
|
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
hasKey(level1.a, 'nested')
|
|
740
|
-
) {
|
|
741
|
-
const nested = level1.a.nested;
|
|
747
|
+
if (!isRecord(level1)) {
|
|
748
|
+
return;
|
|
749
|
+
}
|
|
742
750
|
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
751
|
+
assert.deepStrictEqual(Object.keys(level1), ['a', 'z']);
|
|
752
|
+
|
|
753
|
+
if (
|
|
754
|
+
!hasKey(level1, 'a') ||
|
|
755
|
+
!isRecord(level1.a) ||
|
|
756
|
+
!hasKey(level1.a, 'nested')
|
|
757
|
+
) {
|
|
758
|
+
return;
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
const nested = level1.a.nested;
|
|
762
|
+
|
|
763
|
+
if (isRecord(nested)) {
|
|
764
|
+
assert.deepStrictEqual(Object.keys(nested), ['x', 'y']);
|
|
748
765
|
}
|
|
749
766
|
});
|
|
750
767
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import type {
|
|
2
|
+
Int,
|
|
3
|
+
NonNegativeFiniteNumber,
|
|
4
|
+
FiniteNumber as TtfImported_FiniteNumber,
|
|
5
5
|
} from 'ts-type-forge';
|
|
6
6
|
import { expectType } from '../../expect-type.mjs';
|
|
7
7
|
import { TsDataForgeInternals } from '../refined-number-utils.mjs';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Int as TtfImported_Int } from 'ts-type-forge';
|
|
2
2
|
import { expectType } from '../../expect-type.mjs';
|
|
3
3
|
import { TsDataForgeInternals } from '../refined-number-utils.mjs';
|
|
4
4
|
|
|
@@ -175,7 +175,7 @@ export const Int = {
|
|
|
175
175
|
*
|
|
176
176
|
* assert.isTrue(Int.is(randomValue));
|
|
177
177
|
*
|
|
178
|
-
* assert.isTrue(
|
|
178
|
+
* assert.isTrue(1 <= randomValue && randomValue <= 6);
|
|
179
179
|
* ```
|
|
180
180
|
*
|
|
181
181
|
* @param min - The minimum value (inclusive)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { NegativeFiniteNumber as TtfImported_NegativeFiniteNumber } from 'ts-type-forge';
|
|
2
2
|
import { TsDataForgeInternals } from '../refined-number-utils.mjs';
|
|
3
3
|
import { PositiveFiniteNumber } from './positive-finite-number.mjs';
|
|
4
4
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import type {
|
|
2
|
+
NegativeInt,
|
|
3
|
+
NonPositiveInt,
|
|
4
|
+
PositiveFiniteNumber,
|
|
5
5
|
} from 'ts-type-forge';
|
|
6
6
|
import { expectType } from '../../expect-type.mjs';
|
|
7
7
|
import { range } from '../../iterator/index.mjs';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import type {
|
|
2
|
+
NegativeInt as TtfImported_NegativeInt,
|
|
3
|
+
WithSmallInt,
|
|
4
4
|
} from 'ts-type-forge';
|
|
5
5
|
import { TsDataForgeInternals } from '../refined-number-utils.mjs';
|
|
6
6
|
import { PositiveInt } from './positive-int.mjs';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { PositiveInt } from 'ts-type-forge';
|
|
2
2
|
import { expectType } from '../../expect-type.mjs';
|
|
3
3
|
import { range } from '../../iterator/index.mjs';
|
|
4
4
|
import { asNegativeInt, isNegativeInt, NegativeInt } from './negative-int.mjs';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import type {
|
|
2
|
+
NegativeSafeInt as TtfImported_NegativeSafeInt,
|
|
3
|
+
WithSmallInt,
|
|
4
4
|
} from 'ts-type-forge';
|
|
5
5
|
import { TsDataForgeInternals } from '../refined-number-utils.mjs';
|
|
6
6
|
import { PositiveSafeInt } from './positive-safe-int.mjs';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import type {
|
|
2
|
+
NonNegativeFiniteNumber as TtfImported_NonNegativeFiniteNumber,
|
|
3
|
+
Uint,
|
|
4
4
|
} from 'ts-type-forge';
|
|
5
5
|
import { expectType } from '../../expect-type.mjs';
|
|
6
6
|
import { TsDataForgeInternals } from '../refined-number-utils.mjs';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { NonNegativeInt16 as TtfImported_NonNegativeInt16 } from 'ts-type-forge';
|
|
2
2
|
import { expectType } from '../../expect-type.mjs';
|
|
3
3
|
import { TsDataForgeInternals } from '../refined-number-utils.mjs';
|
|
4
4
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { NonNegativeInt32 as TtfImported_NonNegativeInt32 } from 'ts-type-forge';
|
|
2
2
|
import { expectType } from '../../expect-type.mjs';
|
|
3
3
|
import { TsDataForgeInternals } from '../refined-number-utils.mjs';
|
|
4
4
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { NonPositiveFiniteNumber as TtfImported_NonPositiveFiniteNumber } from 'ts-type-forge';
|
|
2
2
|
import { TsDataForgeInternals } from '../refined-number-utils.mjs';
|
|
3
3
|
|
|
4
4
|
export type NonPositiveFiniteNumber = TtfImported_NonPositiveFiniteNumber;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { NonPositiveInt as TtfImported_NonPositiveInt } from 'ts-type-forge';
|
|
2
2
|
import { TsDataForgeInternals } from '../refined-number-utils.mjs';
|
|
3
3
|
|
|
4
4
|
export type NonPositiveInt = TtfImported_NonPositiveInt;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { NonPositiveSafeInt as TtfImported_NonPositiveSafeInt } from 'ts-type-forge';
|
|
2
2
|
import { TsDataForgeInternals } from '../refined-number-utils.mjs';
|
|
3
3
|
|
|
4
4
|
export type NonPositiveSafeInt = TtfImported_NonPositiveSafeInt;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import type {
|
|
2
|
+
Int,
|
|
3
|
+
NonZeroInt,
|
|
4
|
+
PositiveFiniteNumber,
|
|
5
|
+
NonZeroFiniteNumber as TtfImported_NonZeroFiniteNumber,
|
|
6
6
|
} from 'ts-type-forge';
|
|
7
7
|
import { expectType } from '../../expect-type.mjs';
|
|
8
8
|
import { TsDataForgeInternals } from '../refined-number-utils.mjs';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { NonZeroInt as TtfImported_NonZeroInt } from 'ts-type-forge';
|
|
2
2
|
import { expectType } from '../../expect-type.mjs';
|
|
3
3
|
import { TsDataForgeInternals } from '../refined-number-utils.mjs';
|
|
4
4
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { NonZeroInt16 as TtfImported_NonZeroInt16 } from 'ts-type-forge';
|
|
2
2
|
import { expectType } from '../../expect-type.mjs';
|
|
3
3
|
import { TsDataForgeInternals } from '../refined-number-utils.mjs';
|
|
4
4
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { NonZeroInt32 as TtfImported_NonZeroInt32 } from 'ts-type-forge';
|
|
2
2
|
import { expectType } from '../../expect-type.mjs';
|
|
3
3
|
import { TsDataForgeInternals } from '../refined-number-utils.mjs';
|
|
4
4
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import type {
|
|
2
|
+
SafeInt,
|
|
3
|
+
SafeUint,
|
|
4
|
+
NonZeroSafeInt as TtfImported_NonZeroSafeInt,
|
|
5
5
|
} from 'ts-type-forge';
|
|
6
6
|
import { expectType } from '../../expect-type.mjs';
|
|
7
7
|
import { TsDataForgeInternals } from '../refined-number-utils.mjs';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { NonZeroUint16 as TtfImported_NonZeroUint16 } from 'ts-type-forge';
|
|
2
2
|
import { expectType } from '../../expect-type.mjs';
|
|
3
3
|
import { TsDataForgeInternals } from '../refined-number-utils.mjs';
|
|
4
4
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { NonZeroUint32 as TtfImported_NonZeroUint32 } from 'ts-type-forge';
|
|
2
2
|
import { expectType } from '../../expect-type.mjs';
|
|
3
3
|
import { TsDataForgeInternals } from '../refined-number-utils.mjs';
|
|
4
4
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import type {
|
|
2
|
+
PositiveInt,
|
|
3
|
+
PositiveFiniteNumber as TtfImported_PositiveFiniteNumber,
|
|
4
|
+
Uint,
|
|
5
5
|
} from 'ts-type-forge';
|
|
6
6
|
import { expectType } from '../../expect-type.mjs';
|
|
7
7
|
import { TsDataForgeInternals } from '../refined-number-utils.mjs';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { PositiveInt as TtfImported_PositiveInt } from 'ts-type-forge';
|
|
2
2
|
import { expectType } from '../../expect-type.mjs';
|
|
3
3
|
import { TsDataForgeInternals } from '../refined-number-utils.mjs';
|
|
4
4
|
|
|
@@ -192,7 +192,7 @@ export const PositiveInt = {
|
|
|
192
192
|
*
|
|
193
193
|
* assert.isTrue(PositiveInt.is(randomValue));
|
|
194
194
|
*
|
|
195
|
-
* assert.isTrue(
|
|
195
|
+
* assert.isTrue(3 <= randomValue && randomValue <= 6);
|
|
196
196
|
* ```
|
|
197
197
|
*
|
|
198
198
|
* @param min - The minimum value (inclusive)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { PositiveInt16 as TtfImported_PositiveInt16 } from 'ts-type-forge';
|
|
2
2
|
import { expectType } from '../../expect-type.mjs';
|
|
3
3
|
import { TsDataForgeInternals } from '../refined-number-utils.mjs';
|
|
4
4
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { PositiveInt32 as TtfImported_PositiveInt32 } from 'ts-type-forge';
|
|
2
2
|
import { expectType } from '../../expect-type.mjs';
|
|
3
3
|
import { TsDataForgeInternals } from '../refined-number-utils.mjs';
|
|
4
4
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import type {
|
|
2
|
+
SafeUint,
|
|
3
|
+
PositiveSafeInt as TtfImported_PositiveSafeInt,
|
|
4
4
|
} from 'ts-type-forge';
|
|
5
5
|
import { expectType } from '../../expect-type.mjs';
|
|
6
6
|
import { TsDataForgeInternals } from '../refined-number-utils.mjs';
|
|
@@ -206,7 +206,7 @@ export const PositiveSafeInt = {
|
|
|
206
206
|
*
|
|
207
207
|
* assert.isTrue(PositiveSafeInt.is(randomValue));
|
|
208
208
|
*
|
|
209
|
-
* assert.isTrue(
|
|
209
|
+
* assert.isTrue(1 <= randomValue && randomValue <= 6);
|
|
210
210
|
* ```
|
|
211
211
|
*
|
|
212
212
|
* @param min - The minimum value (inclusive)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { PositiveUint16 as TtfImported_PositiveUint16 } from 'ts-type-forge';
|
|
2
2
|
import { expectType } from '../../expect-type.mjs';
|
|
3
3
|
import { TsDataForgeInternals } from '../refined-number-utils.mjs';
|
|
4
4
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { PositiveUint32 as TtfImported_PositiveUint32 } from 'ts-type-forge';
|
|
2
2
|
import { expectType } from '../../expect-type.mjs';
|
|
3
3
|
import { TsDataForgeInternals } from '../refined-number-utils.mjs';
|
|
4
4
|
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type SafeUint,
|
|
3
|
-
type SafeInt as TtfImported_SafeInt,
|
|
4
|
-
} from 'ts-type-forge';
|
|
1
|
+
import type { SafeUint, SafeInt as TtfImported_SafeInt } from 'ts-type-forge';
|
|
5
2
|
import { expectType } from '../../expect-type.mjs';
|
|
6
3
|
import { TsDataForgeInternals } from '../refined-number-utils.mjs';
|
|
7
4
|
|
|
@@ -217,7 +214,7 @@ export const SafeInt = {
|
|
|
217
214
|
*
|
|
218
215
|
* assert.isTrue(SafeInt.is(randomValue));
|
|
219
216
|
*
|
|
220
|
-
* assert.isTrue(
|
|
217
|
+
* assert.isTrue(-10 <= randomValue && randomValue <= 10);
|
|
221
218
|
* ```
|
|
222
219
|
*
|
|
223
220
|
* @param min - The minimum value (inclusive)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Uint as TtfImported_Uint } from 'ts-type-forge';
|
|
2
2
|
import { expectType } from '../../expect-type.mjs';
|
|
3
3
|
import { TsDataForgeInternals } from '../refined-number-utils.mjs';
|
|
4
4
|
|
|
@@ -184,7 +184,7 @@ export const Uint = {
|
|
|
184
184
|
*
|
|
185
185
|
* assert.isTrue(Uint.is(randomValue));
|
|
186
186
|
*
|
|
187
|
-
* assert.isTrue(
|
|
187
|
+
* assert.isTrue(0 <= randomValue && randomValue <= 3);
|
|
188
188
|
* ```
|
|
189
189
|
*
|
|
190
190
|
* @param min - The minimum value (inclusive)
|
package/src/number/enum/int8.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import type {
|
|
2
|
+
AbsoluteValue,
|
|
3
|
+
Int16,
|
|
4
|
+
StrictExclude,
|
|
5
|
+
Int8 as TtfImported_Int8,
|
|
6
6
|
} from 'ts-type-forge';
|
|
7
7
|
import { expectType } from '../../expect-type.mjs';
|
|
8
8
|
import { TsDataForgeInternals } from '../refined-number-utils.mjs';
|