ts-fortress 1.0.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/LICENSE +201 -0
- package/README.md +324 -0
- package/dist/array/array-of-length.d.mts +6 -0
- package/dist/array/array-of-length.d.mts.map +1 -0
- package/dist/array/array-of-length.mjs +50 -0
- package/dist/array/array-of-length.mjs.map +1 -0
- package/dist/array/array.d.mts +6 -0
- package/dist/array/array.d.mts.map +1 -0
- package/dist/array/array.mjs +39 -0
- package/dist/array/array.mjs.map +1 -0
- package/dist/array/index.d.mts +5 -0
- package/dist/array/index.d.mts.map +1 -0
- package/dist/array/index.mjs +5 -0
- package/dist/array/index.mjs.map +1 -0
- package/dist/array/non-empty-array.d.mts +6 -0
- package/dist/array/non-empty-array.d.mts.map +1 -0
- package/dist/array/non-empty-array.mjs +46 -0
- package/dist/array/non-empty-array.mjs.map +1 -0
- package/dist/array/tuple.d.mts +9 -0
- package/dist/array/tuple.d.mts.map +1 -0
- package/dist/array/tuple.mjs +47 -0
- package/dist/array/tuple.mjs.map +1 -0
- package/dist/branded/brand.d.mts +11 -0
- package/dist/branded/brand.d.mts.map +1 -0
- package/dist/branded/brand.mjs +29 -0
- package/dist/branded/brand.mjs.map +1 -0
- package/dist/branded/index.d.mts +5 -0
- package/dist/branded/index.d.mts.map +1 -0
- package/dist/branded/index.mjs +20 -0
- package/dist/branded/index.mjs.map +1 -0
- package/dist/branded/number/finite-number.d.mts +3 -0
- package/dist/branded/number/finite-number.d.mts.map +1 -0
- package/dist/branded/number/finite-number.mjs +14 -0
- package/dist/branded/number/finite-number.mjs.map +1 -0
- package/dist/branded/number/index.d.mts +17 -0
- package/dist/branded/number/index.d.mts.map +1 -0
- package/dist/branded/number/index.mjs +17 -0
- package/dist/branded/number/index.mjs.map +1 -0
- package/dist/branded/number/int.d.mts +3 -0
- package/dist/branded/number/int.d.mts.map +1 -0
- package/dist/branded/number/int.mjs +14 -0
- package/dist/branded/number/int.mjs.map +1 -0
- package/dist/branded/number/int16.d.mts +3 -0
- package/dist/branded/number/int16.d.mts.map +1 -0
- package/dist/branded/number/int16.mjs +26 -0
- package/dist/branded/number/int16.mjs.map +1 -0
- package/dist/branded/number/int32.d.mts +3 -0
- package/dist/branded/number/int32.d.mts.map +1 -0
- package/dist/branded/number/int32.mjs +22 -0
- package/dist/branded/number/int32.mjs.map +1 -0
- package/dist/branded/number/non-negative-finite-number.d.mts +3 -0
- package/dist/branded/number/non-negative-finite-number.d.mts.map +1 -0
- package/dist/branded/number/non-negative-finite-number.mjs +14 -0
- package/dist/branded/number/non-negative-finite-number.mjs.map +1 -0
- package/dist/branded/number/non-zero-finite-number.d.mts +3 -0
- package/dist/branded/number/non-zero-finite-number.d.mts.map +1 -0
- package/dist/branded/number/non-zero-finite-number.mjs +14 -0
- package/dist/branded/number/non-zero-finite-number.mjs.map +1 -0
- package/dist/branded/number/non-zero-int.d.mts +3 -0
- package/dist/branded/number/non-zero-int.d.mts.map +1 -0
- package/dist/branded/number/non-zero-int.mjs +14 -0
- package/dist/branded/number/non-zero-int.mjs.map +1 -0
- package/dist/branded/number/non-zero-safe-int.d.mts +3 -0
- package/dist/branded/number/non-zero-safe-int.d.mts.map +1 -0
- package/dist/branded/number/non-zero-safe-int.mjs +14 -0
- package/dist/branded/number/non-zero-safe-int.mjs.map +1 -0
- package/dist/branded/number/positive-finite-number.d.mts +3 -0
- package/dist/branded/number/positive-finite-number.d.mts.map +1 -0
- package/dist/branded/number/positive-finite-number.mjs +22 -0
- package/dist/branded/number/positive-finite-number.mjs.map +1 -0
- package/dist/branded/number/positive-int.d.mts +3 -0
- package/dist/branded/number/positive-int.d.mts.map +1 -0
- package/dist/branded/number/positive-int.mjs +23 -0
- package/dist/branded/number/positive-int.mjs.map +1 -0
- package/dist/branded/number/positive-safe-int.d.mts +3 -0
- package/dist/branded/number/positive-safe-int.d.mts.map +1 -0
- package/dist/branded/number/positive-safe-int.mjs +24 -0
- package/dist/branded/number/positive-safe-int.mjs.map +1 -0
- package/dist/branded/number/safe-int.d.mts +3 -0
- package/dist/branded/number/safe-int.d.mts.map +1 -0
- package/dist/branded/number/safe-int.mjs +14 -0
- package/dist/branded/number/safe-int.mjs.map +1 -0
- package/dist/branded/number/safe-uint.d.mts +3 -0
- package/dist/branded/number/safe-uint.d.mts.map +1 -0
- package/dist/branded/number/safe-uint.mjs +23 -0
- package/dist/branded/number/safe-uint.mjs.map +1 -0
- package/dist/branded/number/uint.d.mts +3 -0
- package/dist/branded/number/uint.d.mts.map +1 -0
- package/dist/branded/number/uint.mjs +22 -0
- package/dist/branded/number/uint.mjs.map +1 -0
- package/dist/branded/number/uint16.d.mts +3 -0
- package/dist/branded/number/uint16.d.mts.map +1 -0
- package/dist/branded/number/uint16.mjs +26 -0
- package/dist/branded/number/uint16.mjs.map +1 -0
- package/dist/branded/number/uint32.d.mts +3 -0
- package/dist/branded/number/uint32.d.mts.map +1 -0
- package/dist/branded/number/uint32.mjs +24 -0
- package/dist/branded/number/uint32.mjs.map +1 -0
- package/dist/branded/simple-branded-number.d.mts +3 -0
- package/dist/branded/simple-branded-number.d.mts.map +1 -0
- package/dist/branded/simple-branded-number.mjs +15 -0
- package/dist/branded/simple-branded-number.mjs.map +1 -0
- package/dist/branded/simple-branded-string.d.mts +3 -0
- package/dist/branded/simple-branded-string.d.mts.map +1 -0
- package/dist/branded/simple-branded-string.mjs +15 -0
- package/dist/branded/simple-branded-string.mjs.map +1 -0
- package/dist/compose/index.d.mts +4 -0
- package/dist/compose/index.d.mts.map +1 -0
- package/dist/compose/index.mjs +4 -0
- package/dist/compose/index.mjs.map +1 -0
- package/dist/compose/intersection.d.mts +19 -0
- package/dist/compose/intersection.d.mts.map +1 -0
- package/dist/compose/intersection.mjs +38 -0
- package/dist/compose/intersection.mjs.map +1 -0
- package/dist/compose/merge-records.d.mts +15 -0
- package/dist/compose/merge-records.d.mts.map +1 -0
- package/dist/compose/merge-records.mjs +48 -0
- package/dist/compose/merge-records.mjs.map +1 -0
- package/dist/compose/union.d.mts +14 -0
- package/dist/compose/union.d.mts.map +1 -0
- package/dist/compose/union.mjs +33 -0
- package/dist/compose/union.mjs.map +1 -0
- package/dist/enum/enum.d.mts +6 -0
- package/dist/enum/enum.d.mts.map +1 -0
- package/dist/enum/enum.mjs +34 -0
- package/dist/enum/enum.mjs.map +1 -0
- package/dist/enum/index.d.mts +3 -0
- package/dist/enum/index.d.mts.map +1 -0
- package/dist/enum/index.mjs +3 -0
- package/dist/enum/index.mjs.map +1 -0
- package/dist/enum/uint-range.d.mts +8 -0
- package/dist/enum/uint-range.d.mts.map +1 -0
- package/dist/enum/uint-range.mjs +40 -0
- package/dist/enum/uint-range.mjs.map +1 -0
- package/dist/globals.d.mts +3 -0
- package/dist/index.d.mts +10 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +50 -0
- package/dist/index.mjs.map +1 -0
- package/dist/primitives/bigint.d.mts +4 -0
- package/dist/primitives/bigint.d.mts.map +1 -0
- package/dist/primitives/bigint.mjs +12 -0
- package/dist/primitives/bigint.mjs.map +1 -0
- package/dist/primitives/boolean.d.mts +4 -0
- package/dist/primitives/boolean.d.mts.map +1 -0
- package/dist/primitives/boolean.mjs +12 -0
- package/dist/primitives/boolean.mjs.map +1 -0
- package/dist/primitives/index.d.mts +8 -0
- package/dist/primitives/index.d.mts.map +1 -0
- package/dist/primitives/index.mjs +8 -0
- package/dist/primitives/index.mjs.map +1 -0
- package/dist/primitives/null.d.mts +3 -0
- package/dist/primitives/null.d.mts.map +1 -0
- package/dist/primitives/null.mjs +11 -0
- package/dist/primitives/null.mjs.map +1 -0
- package/dist/primitives/number.d.mts +4 -0
- package/dist/primitives/number.d.mts.map +1 -0
- package/dist/primitives/number.mjs +12 -0
- package/dist/primitives/number.mjs.map +1 -0
- package/dist/primitives/string.d.mts +4 -0
- package/dist/primitives/string.d.mts.map +1 -0
- package/dist/primitives/string.mjs +12 -0
- package/dist/primitives/string.mjs.map +1 -0
- package/dist/primitives/symbol.d.mts +3 -0
- package/dist/primitives/symbol.d.mts.map +1 -0
- package/dist/primitives/symbol.mjs +11 -0
- package/dist/primitives/symbol.mjs.map +1 -0
- package/dist/primitives/undefined.d.mts +3 -0
- package/dist/primitives/undefined.d.mts.map +1 -0
- package/dist/primitives/undefined.mjs +11 -0
- package/dist/primitives/undefined.mjs.map +1 -0
- package/dist/record/index.d.mts +8 -0
- package/dist/record/index.d.mts.map +1 -0
- package/dist/record/index.mjs +8 -0
- package/dist/record/index.mjs.map +1 -0
- package/dist/record/key-value-record.d.mts +7 -0
- package/dist/record/key-value-record.d.mts.map +1 -0
- package/dist/record/key-value-record.mjs +52 -0
- package/dist/record/key-value-record.mjs.map +1 -0
- package/dist/record/keyof.d.mts +7 -0
- package/dist/record/keyof.d.mts.map +1 -0
- package/dist/record/keyof.mjs +15 -0
- package/dist/record/keyof.mjs.map +1 -0
- package/dist/record/omit.d.mts +8 -0
- package/dist/record/omit.d.mts.map +1 -0
- package/dist/record/omit.mjs +39 -0
- package/dist/record/omit.mjs.map +1 -0
- package/dist/record/optional.d.mts +5 -0
- package/dist/record/optional.d.mts.map +1 -0
- package/dist/record/optional.mjs +8 -0
- package/dist/record/optional.mjs.map +1 -0
- package/dist/record/partial.d.mts +13 -0
- package/dist/record/partial.d.mts.map +1 -0
- package/dist/record/partial.mjs +128 -0
- package/dist/record/partial.mjs.map +1 -0
- package/dist/record/pick.d.mts +8 -0
- package/dist/record/pick.d.mts.map +1 -0
- package/dist/record/pick.mjs +39 -0
- package/dist/record/pick.mjs.map +1 -0
- package/dist/record/record.d.mts +21 -0
- package/dist/record/record.d.mts.map +1 -0
- package/dist/record/record.mjs +53 -0
- package/dist/record/record.mjs.map +1 -0
- package/dist/tsconfig.json +1 -0
- package/dist/type.d.mts +27 -0
- package/dist/type.d.mts.map +1 -0
- package/dist/type.mjs +2 -0
- package/dist/type.mjs.map +1 -0
- package/dist/types.d.mts +2 -0
- package/dist/unknown.d.mts +3 -0
- package/dist/unknown.d.mts.map +1 -0
- package/dist/unknown.mjs +18 -0
- package/dist/unknown.mjs.map +1 -0
- package/dist/utils/create-assert-fn.d.mts +3 -0
- package/dist/utils/create-assert-fn.d.mts.map +1 -0
- package/dist/utils/create-assert-fn.mjs +12 -0
- package/dist/utils/create-assert-fn.mjs.map +1 -0
- package/dist/utils/create-cast-fn.d.mts +3 -0
- package/dist/utils/create-cast-fn.d.mts.map +1 -0
- package/dist/utils/create-cast-fn.mjs +13 -0
- package/dist/utils/create-cast-fn.mjs.map +1 -0
- package/dist/utils/create-is-fn.d.mts +3 -0
- package/dist/utils/create-is-fn.d.mts.map +1 -0
- package/dist/utils/create-is-fn.mjs +6 -0
- package/dist/utils/create-is-fn.mjs.map +1 -0
- package/dist/utils/create-primitive-type.d.mts +7 -0
- package/dist/utils/create-primitive-type.d.mts.map +1 -0
- package/dist/utils/create-primitive-type.mjs +24 -0
- package/dist/utils/create-primitive-type.mjs.map +1 -0
- package/dist/utils/create-type.d.mts +8 -0
- package/dist/utils/create-type.d.mts.map +1 -0
- package/dist/utils/create-type.mjs +19 -0
- package/dist/utils/create-type.mjs.map +1 -0
- package/dist/utils/index.d.mts +7 -0
- package/dist/utils/index.d.mts.map +1 -0
- package/dist/utils/index.mjs +7 -0
- package/dist/utils/index.mjs.map +1 -0
- package/dist/utils/validation-error-message.d.mts +2 -0
- package/dist/utils/validation-error-message.d.mts.map +1 -0
- package/dist/utils/validation-error-message.mjs +13 -0
- package/dist/utils/validation-error-message.mjs.map +1 -0
- package/package.json +102 -0
- package/src/array/array-of-length.mts +76 -0
- package/src/array/array-of-length.test.mts +113 -0
- package/src/array/array.mts +62 -0
- package/src/array/array.test.mts +84 -0
- package/src/array/index.mts +4 -0
- package/src/array/non-empty-array.mts +70 -0
- package/src/array/non-empty-array.test.mts +113 -0
- package/src/array/tuple.mts +72 -0
- package/src/array/tuple.test.mts +122 -0
- package/src/branded/brand.mts +70 -0
- package/src/branded/index.mts +4 -0
- package/src/branded/number/finite-number.mts +15 -0
- package/src/branded/number/index.mts +16 -0
- package/src/branded/number/int.mts +13 -0
- package/src/branded/number/int16.mts +25 -0
- package/src/branded/number/int32.mts +21 -0
- package/src/branded/number/non-negative-finite-number.mts +18 -0
- package/src/branded/number/non-zero-finite-number.mts +15 -0
- package/src/branded/number/non-zero-int.mts +15 -0
- package/src/branded/number/non-zero-safe-int.mts +15 -0
- package/src/branded/number/positive-finite-number.mts +23 -0
- package/src/branded/number/positive-int.mts +24 -0
- package/src/branded/number/positive-safe-int.mts +25 -0
- package/src/branded/number/safe-int.mts +13 -0
- package/src/branded/number/safe-uint.mts +24 -0
- package/src/branded/number/uint.mts +21 -0
- package/src/branded/number/uint16.mts +25 -0
- package/src/branded/number/uint32.mts +23 -0
- package/src/branded/simple-branded-number.mts +18 -0
- package/src/branded/simple-branded-string.mts +18 -0
- package/src/combination.test.mts +287 -0
- package/src/compose/index.mts +3 -0
- package/src/compose/intersection.mts +206 -0
- package/src/compose/intersection.test.mts +231 -0
- package/src/compose/merge-records.mts +218 -0
- package/src/compose/merge-records.test.mts +90 -0
- package/src/compose/union.mts +77 -0
- package/src/compose/union.test.mts +92 -0
- package/src/enum/enum.mts +53 -0
- package/src/enum/enum.test.mts +63 -0
- package/src/enum/index.mts +2 -0
- package/src/enum/uint-range.mts +63 -0
- package/src/enum/uint-range.test.mts +66 -0
- package/src/globals.d.mts +3 -0
- package/src/index.mts +9 -0
- package/src/primitives/bigint.mts +13 -0
- package/src/primitives/boolean.mts +13 -0
- package/src/primitives/index.mts +7 -0
- package/src/primitives/null.mts +9 -0
- package/src/primitives/number.mts +13 -0
- package/src/primitives/string.mts +13 -0
- package/src/primitives/symbol.mts +10 -0
- package/src/primitives/undefined.mts +9 -0
- package/src/record/index.mts +7 -0
- package/src/record/key-value-record.mts +84 -0
- package/src/record/key-value-record.test.mts +96 -0
- package/src/record/keyof.mts +31 -0
- package/src/record/keyof.test.mts +73 -0
- package/src/record/omit.mts +94 -0
- package/src/record/omit.test.mts +116 -0
- package/src/record/optional.mts +16 -0
- package/src/record/partial.mts +186 -0
- package/src/record/partial.test.mts +261 -0
- package/src/record/pick.mts +98 -0
- package/src/record/pick.test.mts +116 -0
- package/src/record/record.mts +105 -0
- package/src/record/record.test.mts +253 -0
- package/src/type.mts +30 -0
- package/src/unknown.mts +17 -0
- package/src/utils/create-assert-fn.mts +14 -0
- package/src/utils/create-cast-fn.mts +15 -0
- package/src/utils/create-is-fn.mts +7 -0
- package/src/utils/create-primitive-type.mts +35 -0
- package/src/utils/create-type.mts +28 -0
- package/src/utils/index.mts +6 -0
- package/src/utils/validation-error-message.mts +17 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { expectType } from 'ts-data-forge';
|
|
2
|
+
import { type TypeOf } from '../type.mjs';
|
|
3
|
+
import { uintRange } from './uint-range.mjs';
|
|
4
|
+
|
|
5
|
+
describe('uintRange', () => {
|
|
6
|
+
const month = uintRange({
|
|
7
|
+
start: 1,
|
|
8
|
+
end: 13,
|
|
9
|
+
defaultValue: 1,
|
|
10
|
+
typeName: 'month',
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
type Month = TypeOf<typeof month>;
|
|
14
|
+
|
|
15
|
+
expectType<Month, 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12>('=');
|
|
16
|
+
|
|
17
|
+
expectType<typeof month.defaultValue, Month>('=');
|
|
18
|
+
|
|
19
|
+
describe('is', () => {
|
|
20
|
+
test('truthy case', () => {
|
|
21
|
+
const x: number = Math.random() >= 0 ? 1 : 0; // the value is always 1
|
|
22
|
+
|
|
23
|
+
if (month.is(x)) {
|
|
24
|
+
expectType<typeof x, Month>('=');
|
|
25
|
+
} else {
|
|
26
|
+
expectType<typeof x, number>('=');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
expect(month.is(x)).toBe(true);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test('falsy case', () => {
|
|
33
|
+
const x: number = Math.random() >= 0 ? 13 : 0; // the value is always 13
|
|
34
|
+
|
|
35
|
+
if (month.is(x)) {
|
|
36
|
+
expectType<typeof x, Month>('=');
|
|
37
|
+
} else {
|
|
38
|
+
expectType<typeof x, number>('=');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
expect(month.is(x)).toBe(false);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe('validate', () => {
|
|
46
|
+
test('falsy case', () => {
|
|
47
|
+
expect(month.validate(13).value).toStrictEqual([
|
|
48
|
+
"The value is expected to be an integer between 1 and 12, but it is actually '13'.",
|
|
49
|
+
]);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
describe('fill', () => {
|
|
54
|
+
test('noop', () => {
|
|
55
|
+
const x: number = (() => 5)();
|
|
56
|
+
|
|
57
|
+
expect(month.fill(x)).toBe(5);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test('fill with the default value', () => {
|
|
61
|
+
const x: number = (() => 123)();
|
|
62
|
+
|
|
63
|
+
expect(month.fill(x)).toBe(1);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
});
|
package/src/index.mts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './array/index.mjs';
|
|
2
|
+
export * from './branded/index.mjs';
|
|
3
|
+
export * from './compose/index.mjs';
|
|
4
|
+
export * from './enum/index.mjs';
|
|
5
|
+
export * from './primitives/index.mjs';
|
|
6
|
+
export * from './record/index.mjs';
|
|
7
|
+
export * from './type.mjs';
|
|
8
|
+
export * from './unknown.mjs';
|
|
9
|
+
export * from './utils/index.mjs';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { isBigint } from 'ts-data-forge';
|
|
2
|
+
import { type Type } from '../type.mjs';
|
|
3
|
+
import { createPrimitiveType } from '../utils/index.mjs';
|
|
4
|
+
|
|
5
|
+
export const bigint = (defaultValue: bigint = 0n): Type<bigint> =>
|
|
6
|
+
createPrimitiveType({ typeName: 'bigint', defaultValue, is: isBigint });
|
|
7
|
+
|
|
8
|
+
export const bigintLiteral = <L extends bigint>(literal: L): Type<L> =>
|
|
9
|
+
createPrimitiveType({
|
|
10
|
+
typeName: `bigintLiteral(${literal})`,
|
|
11
|
+
defaultValue: literal,
|
|
12
|
+
is: (value: unknown): value is L => value === literal,
|
|
13
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { isBoolean } from 'ts-data-forge';
|
|
2
|
+
import { type Type } from '../type.mjs';
|
|
3
|
+
import { createPrimitiveType } from '../utils/index.mjs';
|
|
4
|
+
|
|
5
|
+
export const boolean = (defaultValue: boolean = false): Type<boolean> =>
|
|
6
|
+
createPrimitiveType({ typeName: 'boolean', defaultValue, is: isBoolean });
|
|
7
|
+
|
|
8
|
+
export const booleanLiteral = <L extends boolean>(literal: L): Type<L> =>
|
|
9
|
+
createPrimitiveType({
|
|
10
|
+
typeName: `booleanLiteral(${String(literal)})`,
|
|
11
|
+
defaultValue: literal,
|
|
12
|
+
is: (value: unknown): value is L => value === literal,
|
|
13
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { isNull } from 'ts-data-forge';
|
|
2
|
+
import { type Type } from '../type.mjs';
|
|
3
|
+
import { createPrimitiveType } from '../utils/index.mjs';
|
|
4
|
+
|
|
5
|
+
export const nullType: Type<null> = createPrimitiveType({
|
|
6
|
+
typeName: 'null',
|
|
7
|
+
defaultValue: null,
|
|
8
|
+
is: isNull,
|
|
9
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { isNumber } from 'ts-data-forge';
|
|
2
|
+
import { type Type } from '../type.mjs';
|
|
3
|
+
import { createPrimitiveType } from '../utils/index.mjs';
|
|
4
|
+
|
|
5
|
+
export const number = (defaultValue: number = 0): Type<number> =>
|
|
6
|
+
createPrimitiveType({ typeName: 'number', defaultValue, is: isNumber });
|
|
7
|
+
|
|
8
|
+
export const numberLiteral = <L extends number>(literal: L): Type<L> =>
|
|
9
|
+
createPrimitiveType({
|
|
10
|
+
typeName: `numberLiteral(${literal})`,
|
|
11
|
+
defaultValue: literal,
|
|
12
|
+
is: (value: unknown): value is L => value === literal,
|
|
13
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { isString } from 'ts-data-forge';
|
|
2
|
+
import { type Type } from '../type.mjs';
|
|
3
|
+
import { createPrimitiveType } from '../utils/index.mjs';
|
|
4
|
+
|
|
5
|
+
export const string = (defaultValue: string = ''): Type<string> =>
|
|
6
|
+
createPrimitiveType({ typeName: 'string', defaultValue, is: isString });
|
|
7
|
+
|
|
8
|
+
export const stringLiteral = <L extends string>(literal: L): Type<L> =>
|
|
9
|
+
createPrimitiveType({
|
|
10
|
+
typeName: `stringLiteral(${literal})`,
|
|
11
|
+
defaultValue: literal,
|
|
12
|
+
is: (value: unknown): value is L => value === literal,
|
|
13
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { isSymbol } from 'ts-data-forge';
|
|
2
|
+
import { type Type } from '../type.mjs';
|
|
3
|
+
import { createPrimitiveType } from '../utils/index.mjs';
|
|
4
|
+
|
|
5
|
+
export const symbol = (defaultValue: symbol): Type<symbol> =>
|
|
6
|
+
createPrimitiveType({
|
|
7
|
+
typeName: 'symbol',
|
|
8
|
+
defaultValue,
|
|
9
|
+
is: isSymbol,
|
|
10
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { isUndefined } from 'ts-data-forge';
|
|
2
|
+
import { type Type } from '../type.mjs';
|
|
3
|
+
import { createPrimitiveType } from '../utils/index.mjs';
|
|
4
|
+
|
|
5
|
+
export const undefinedType: Type<undefined> = createPrimitiveType({
|
|
6
|
+
typeName: 'undefined',
|
|
7
|
+
defaultValue: undefined,
|
|
8
|
+
is: isUndefined,
|
|
9
|
+
});
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { isRecord, Result } from 'ts-data-forge';
|
|
2
|
+
import { type Type, type TypeOf } from '../type.mjs';
|
|
3
|
+
import {
|
|
4
|
+
createAssertFn,
|
|
5
|
+
createCastFn,
|
|
6
|
+
createIsFn,
|
|
7
|
+
validationErrorMessage,
|
|
8
|
+
} from '../utils/index.mjs';
|
|
9
|
+
|
|
10
|
+
type RecordResultType<K extends Type<string>, V extends Type<unknown>> = Record<
|
|
11
|
+
TypeOf<K>,
|
|
12
|
+
TypeOf<V>
|
|
13
|
+
>;
|
|
14
|
+
|
|
15
|
+
export const keyValueRecord = <K extends Type<string>, V extends Type<unknown>>(
|
|
16
|
+
keyType: K,
|
|
17
|
+
valueType: V,
|
|
18
|
+
options?: Readonly<{ typeName?: string }>,
|
|
19
|
+
): Type<RecordResultType<K, V>> => {
|
|
20
|
+
type T = RecordResultType<K, V>;
|
|
21
|
+
|
|
22
|
+
const typeName = options?.typeName ?? 'key-value-record';
|
|
23
|
+
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion, @typescript-eslint/consistent-type-assertions
|
|
25
|
+
const defaultValue = {} as T;
|
|
26
|
+
|
|
27
|
+
const validate: Type<T>['validate'] = (a) => {
|
|
28
|
+
if (!isRecord(a)) {
|
|
29
|
+
return Result.err([
|
|
30
|
+
validationErrorMessage(a, 'The value is expected to be a record'),
|
|
31
|
+
]);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
for (const [k, v] of Object.entries(a)) {
|
|
35
|
+
{
|
|
36
|
+
const res = keyType.validate(k);
|
|
37
|
+
|
|
38
|
+
if (Result.isErr(res)) {
|
|
39
|
+
const message = validationErrorMessage(
|
|
40
|
+
k,
|
|
41
|
+
`The key of the record is expected to be <${keyType.typeName}>`,
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
return Result.err([message, ...res.value]);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
{
|
|
48
|
+
const res = valueType.validate(v);
|
|
49
|
+
|
|
50
|
+
if (Result.isErr(res)) {
|
|
51
|
+
const message = validationErrorMessage(
|
|
52
|
+
v,
|
|
53
|
+
`The value of the record is expected to be <${valueType.typeName}>`,
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
return Result.err([message, ...res.value]);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
62
|
+
return Result.ok(a as T);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const fill: Type<T>['fill'] = (a) =>
|
|
66
|
+
isRecord(a)
|
|
67
|
+
? // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
68
|
+
(Object.fromEntries(
|
|
69
|
+
Object.entries(a).filter(
|
|
70
|
+
([k, v]) => keyType.is(k) && valueType.is(v),
|
|
71
|
+
),
|
|
72
|
+
) as T)
|
|
73
|
+
: defaultValue;
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
typeName,
|
|
77
|
+
defaultValue,
|
|
78
|
+
fill,
|
|
79
|
+
validate,
|
|
80
|
+
is: createIsFn(validate),
|
|
81
|
+
assertIs: createAssertFn(validate),
|
|
82
|
+
cast: createCastFn(validate),
|
|
83
|
+
};
|
|
84
|
+
};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { expectType } from 'ts-data-forge';
|
|
2
|
+
import { number, string } from '../primitives/index.mjs';
|
|
3
|
+
import { type TypeOf } from '../type.mjs';
|
|
4
|
+
import { keyValueRecord } from './key-value-record.mjs';
|
|
5
|
+
|
|
6
|
+
describe('keyValueRecord', () => {
|
|
7
|
+
const strNumRecord = keyValueRecord(string(''), number(0));
|
|
8
|
+
|
|
9
|
+
type StrNumRecord = TypeOf<typeof strNumRecord>;
|
|
10
|
+
|
|
11
|
+
expectType<StrNumRecord, Record<string, number>>('=');
|
|
12
|
+
|
|
13
|
+
expectType<typeof strNumRecord.defaultValue, StrNumRecord>('=');
|
|
14
|
+
|
|
15
|
+
describe('is', () => {
|
|
16
|
+
test('truthy case', () => {
|
|
17
|
+
const x: UnknownRecord = {
|
|
18
|
+
year: 2000,
|
|
19
|
+
month: 12,
|
|
20
|
+
date: 12,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
if (strNumRecord.is(x)) {
|
|
24
|
+
expectType<typeof x, StrNumRecord>('=');
|
|
25
|
+
} else {
|
|
26
|
+
expectType<typeof x, UnknownRecord>('=');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
expect(strNumRecord.is(x)).toBe(true);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test('falsy case', () => {
|
|
33
|
+
const x: UnknownRecord = {
|
|
34
|
+
year: 2000,
|
|
35
|
+
month: 'ab',
|
|
36
|
+
date: 'cd',
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
if (strNumRecord.is(x)) {
|
|
40
|
+
expectType<typeof x, StrNumRecord>('=');
|
|
41
|
+
} else {
|
|
42
|
+
expectType<typeof x, UnknownRecord>('=');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
expect(strNumRecord.is(x)).toBe(false);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe('validate', () => {
|
|
50
|
+
test('falsy case', () => {
|
|
51
|
+
const x: UnknownRecord = {
|
|
52
|
+
year: 2000,
|
|
53
|
+
month: 'ab',
|
|
54
|
+
date: 'cd',
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
expect(strNumRecord.validate(x).value).toStrictEqual([
|
|
58
|
+
`The value of the record is expected to be <number>, but it is actually '"ab"'.`,
|
|
59
|
+
`The value is expected to be <number>, but it is actually '"ab"'.`,
|
|
60
|
+
]);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe('fill', () => {
|
|
65
|
+
test('from an empty record', () => {
|
|
66
|
+
const x: UnknownRecord = {};
|
|
67
|
+
|
|
68
|
+
expect(strNumRecord.fill(x)).toStrictEqual({});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('from a filled record', () => {
|
|
72
|
+
const x: UnknownRecord = {
|
|
73
|
+
year: 2000,
|
|
74
|
+
month: 999,
|
|
75
|
+
date: 999,
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
expect(strNumRecord.fill(x)).toStrictEqual({
|
|
79
|
+
year: 2000,
|
|
80
|
+
month: 999,
|
|
81
|
+
date: 999,
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test('from a record with wrong value', () => {
|
|
86
|
+
const x: UnknownRecord = {
|
|
87
|
+
year: 2000,
|
|
88
|
+
month: '12',
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
expect(strNumRecord.fill(x)).toStrictEqual({
|
|
92
|
+
year: 2000,
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Arr, expectType, pipe } from 'ts-data-forge';
|
|
2
|
+
import { enumType } from '../enum/index.mjs';
|
|
3
|
+
import { undefinedType } from '../primitives/index.mjs';
|
|
4
|
+
import { type Type, type TypeOf } from '../type.mjs';
|
|
5
|
+
|
|
6
|
+
export const keyof = <const R extends Type<UnknownRecord>>(
|
|
7
|
+
recordType: R,
|
|
8
|
+
options?: Partial<
|
|
9
|
+
Readonly<{
|
|
10
|
+
typeName: string;
|
|
11
|
+
}>
|
|
12
|
+
>,
|
|
13
|
+
): KeyofType<R> =>
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
15
|
+
pipe(Object.keys(recordType.defaultValue)).map((keys) =>
|
|
16
|
+
Arr.isNonEmpty(keys)
|
|
17
|
+
? enumType(keys, {
|
|
18
|
+
typeName: options?.typeName ?? `keyof ${recordType.typeName}`,
|
|
19
|
+
})
|
|
20
|
+
: undefinedType,
|
|
21
|
+
).value as KeyofType<R>;
|
|
22
|
+
|
|
23
|
+
type KeyofType<R extends Type<UnknownRecord>> = Type<keyof TypeOf<R>>;
|
|
24
|
+
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
26
|
+
expectType<KeyofType<Type<{}>>, Type<never>>('=');
|
|
27
|
+
|
|
28
|
+
expectType<
|
|
29
|
+
KeyofType<Type<{ a: Type<0>; b: Type<0>; c: Type<0> }>>,
|
|
30
|
+
Type<'a' | 'b' | 'c'>
|
|
31
|
+
>('=');
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { expectType } from 'ts-data-forge';
|
|
2
|
+
import { number } from '../primitives/index.mjs';
|
|
3
|
+
import { type Type, type TypeOf } from '../type.mjs';
|
|
4
|
+
import { keyof } from './keyof.mjs';
|
|
5
|
+
import { record } from './record.mjs';
|
|
6
|
+
|
|
7
|
+
describe('keyof', () => {
|
|
8
|
+
const ymdKey = keyof(
|
|
9
|
+
record({
|
|
10
|
+
year: number(1900),
|
|
11
|
+
month: number(1),
|
|
12
|
+
date: number(1),
|
|
13
|
+
}),
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
expectType<typeof ymdKey, Type<'year' | 'month' | 'date'>>('=');
|
|
17
|
+
|
|
18
|
+
type Ymd = TypeOf<typeof ymdKey>;
|
|
19
|
+
|
|
20
|
+
expectType<Ymd, 'year' | 'month' | 'date'>('=');
|
|
21
|
+
|
|
22
|
+
expectType<typeof ymdKey.defaultValue, Ymd>('=');
|
|
23
|
+
|
|
24
|
+
describe('is', () => {
|
|
25
|
+
test('truthy case', () => {
|
|
26
|
+
const x: unknown = 'year';
|
|
27
|
+
|
|
28
|
+
if (ymdKey.is(x)) {
|
|
29
|
+
expectType<typeof x, 'year' | 'month' | 'date'>('=');
|
|
30
|
+
} else {
|
|
31
|
+
expectType<typeof x, unknown>('=');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
expect(ymdKey.is(x)).toBe(true);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('falsy case', () => {
|
|
38
|
+
const x: unknown = 'minutes';
|
|
39
|
+
|
|
40
|
+
if (ymdKey.is(x)) {
|
|
41
|
+
expectType<typeof x, 'year' | 'month' | 'date'>('=');
|
|
42
|
+
} else {
|
|
43
|
+
expectType<typeof x, unknown>('=');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
expect(ymdKey.is(x)).toBe(false);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe('validate', () => {
|
|
51
|
+
test('falsy case', () => {
|
|
52
|
+
const x: unknown = 'minutes';
|
|
53
|
+
|
|
54
|
+
expect(ymdKey.validate(x).value).toStrictEqual([
|
|
55
|
+
`The value is expected to be one of the elements contained in { year, month, date }, but it is actually '"minutes"'.`,
|
|
56
|
+
]);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
describe('fill', () => {
|
|
61
|
+
test('from external value', () => {
|
|
62
|
+
const x: unknown = 'minutes';
|
|
63
|
+
|
|
64
|
+
expect(ymdKey.fill(x)).toBe('year');
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test('from key', () => {
|
|
68
|
+
const x = 'month';
|
|
69
|
+
|
|
70
|
+
expect(ymdKey.fill(x)).toBe('month');
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
});
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { expectType, isRecord, Obj, Result } from 'ts-data-forge';
|
|
2
|
+
import { type Type, type TypeOf } from '../type.mjs';
|
|
3
|
+
import {
|
|
4
|
+
createAssertFn,
|
|
5
|
+
createCastFn,
|
|
6
|
+
createIsFn,
|
|
7
|
+
validationErrorMessage,
|
|
8
|
+
} from '../utils/index.mjs';
|
|
9
|
+
|
|
10
|
+
/** Creates a record type with keys omitted. */
|
|
11
|
+
export const omit = <
|
|
12
|
+
const R extends Type<UnknownRecord>,
|
|
13
|
+
const KeysToOmit extends readonly (keyof TypeOf<R> & string)[],
|
|
14
|
+
>(
|
|
15
|
+
recordType: R,
|
|
16
|
+
keysToOmit: KeysToOmit,
|
|
17
|
+
options?: Partial<
|
|
18
|
+
Readonly<{
|
|
19
|
+
typeName: string;
|
|
20
|
+
}>
|
|
21
|
+
>,
|
|
22
|
+
): OmittedType<R, KeysToOmit> => {
|
|
23
|
+
type V = Omit<TypeOf<R>, ArrayElement<KeysToOmit>>;
|
|
24
|
+
|
|
25
|
+
const typeNameFilled: string =
|
|
26
|
+
options?.typeName ??
|
|
27
|
+
`Omit<${recordType.typeName}, ${keysToOmit.join('|')}>`;
|
|
28
|
+
|
|
29
|
+
const defaultValue: V = Obj.omit(recordType.defaultValue, keysToOmit);
|
|
30
|
+
|
|
31
|
+
const validate: Type<V>['validate'] = (a) => {
|
|
32
|
+
if (!isRecord(a)) {
|
|
33
|
+
return Result.err([
|
|
34
|
+
validationErrorMessage(a, 'The value is expected to be a record'),
|
|
35
|
+
]);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
39
|
+
const objectFilled = {
|
|
40
|
+
...Obj.pick(recordType.fill(a), keysToOmit),
|
|
41
|
+
...a,
|
|
42
|
+
} as TypeOf<R>;
|
|
43
|
+
|
|
44
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
45
|
+
return recordType.validate(objectFilled) as ReturnType<Type<V>['validate']>;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const fill: Type<V>['fill'] = (a) => Obj.omit(recordType.fill(a), keysToOmit);
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
typeName: typeNameFilled,
|
|
52
|
+
defaultValue,
|
|
53
|
+
fill,
|
|
54
|
+
validate,
|
|
55
|
+
is: createIsFn(validate),
|
|
56
|
+
assertIs: createAssertFn(validate),
|
|
57
|
+
cast: createCastFn(validate),
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
type OmittedType<
|
|
62
|
+
R extends Type<UnknownRecord>,
|
|
63
|
+
KeysToOmit extends readonly (keyof TypeOf<R>)[],
|
|
64
|
+
> = Type<Omit<TypeOf<R>, ArrayElement<KeysToOmit>>>;
|
|
65
|
+
|
|
66
|
+
expectType<
|
|
67
|
+
Omit<TypeOf<Type<{ a: Type<0>; b: Type<0>; c: Type<0> }>>, 'a' | 'b'>,
|
|
68
|
+
{
|
|
69
|
+
c: Type<0>;
|
|
70
|
+
}
|
|
71
|
+
>('=');
|
|
72
|
+
|
|
73
|
+
expectType<
|
|
74
|
+
Type<Omit<TypeOf<Type<{ a: Type<0>; b: Type<0>; c: Type<0> }>>, 'a' | 'b'>>,
|
|
75
|
+
Type<{
|
|
76
|
+
c: Type<0>;
|
|
77
|
+
}>
|
|
78
|
+
>('=');
|
|
79
|
+
|
|
80
|
+
expectType<
|
|
81
|
+
OmittedType<Type<{ a: Type<0>; b: Type<0>; c: Type<0> }>, ['a', 'b']>,
|
|
82
|
+
Type<{
|
|
83
|
+
c: Type<0>;
|
|
84
|
+
}>
|
|
85
|
+
>('=');
|
|
86
|
+
|
|
87
|
+
expectType<
|
|
88
|
+
OmittedType<
|
|
89
|
+
Type<{ a: Type<0>; b: Type<0>; c: Type<0> }>,
|
|
90
|
+
// @ts-expect-error key "d" doesn't exist
|
|
91
|
+
['a', 'd']
|
|
92
|
+
>,
|
|
93
|
+
0
|
|
94
|
+
>('!=');
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { expectType } from 'ts-data-forge';
|
|
2
|
+
import { number } from '../primitives/index.mjs';
|
|
3
|
+
import { type Type, type TypeOf } from '../type.mjs';
|
|
4
|
+
import { omit } from './omit.mjs';
|
|
5
|
+
import { record } from './record.mjs';
|
|
6
|
+
|
|
7
|
+
describe('omit', () => {
|
|
8
|
+
const ym = omit(
|
|
9
|
+
record({
|
|
10
|
+
year: number(1900),
|
|
11
|
+
month: number(1),
|
|
12
|
+
date: number(1),
|
|
13
|
+
}),
|
|
14
|
+
['date'],
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
expectType<typeof ym, Type<Readonly<{ year: number; month: number }>>>('=');
|
|
18
|
+
|
|
19
|
+
type Ym = TypeOf<typeof ym>;
|
|
20
|
+
|
|
21
|
+
expectType<Ym, Readonly<{ year: number; month: number }>>('=');
|
|
22
|
+
|
|
23
|
+
expectType<typeof ym.defaultValue, Ym>('=');
|
|
24
|
+
|
|
25
|
+
describe('is', () => {
|
|
26
|
+
test('truthy case', () => {
|
|
27
|
+
const x: UnknownRecord = {
|
|
28
|
+
year: 2000,
|
|
29
|
+
month: 12,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
if (ym.is(x)) {
|
|
33
|
+
expectType<typeof x, Ym>('=');
|
|
34
|
+
} else {
|
|
35
|
+
expectType<typeof x, UnknownRecord>('=');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
expect(ym.is(x)).toBe(true);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('falsy case', () => {
|
|
42
|
+
const x: UnknownRecord = {
|
|
43
|
+
year: 2000,
|
|
44
|
+
month: 'ab',
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
if (ym.is(x)) {
|
|
48
|
+
expectType<typeof x, Ym>('=');
|
|
49
|
+
} else {
|
|
50
|
+
expectType<typeof x, UnknownRecord>('=');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
expect(ym.is(x)).toBe(false);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe('validate', () => {
|
|
58
|
+
test('falsy case', () => {
|
|
59
|
+
const x: UnknownRecord = {
|
|
60
|
+
year: 2000,
|
|
61
|
+
month: 'ab',
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
expect(ym.validate(x).value).toStrictEqual([
|
|
65
|
+
`The value at record key "month" is expected to be <number>, but it is actually '"ab"'.`,
|
|
66
|
+
`The value is expected to be <number>, but it is actually '"ab"'.`,
|
|
67
|
+
]);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
describe('fill', () => {
|
|
72
|
+
test('from an empty record', () => {
|
|
73
|
+
const x: UnknownRecord = {};
|
|
74
|
+
|
|
75
|
+
expect(ym.fill(x)).toStrictEqual({
|
|
76
|
+
year: 1900,
|
|
77
|
+
month: 1,
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test('from a filled record', () => {
|
|
82
|
+
const x: UnknownRecord = {
|
|
83
|
+
year: 2000,
|
|
84
|
+
month: 999,
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
expect(ym.fill(x)).toStrictEqual({
|
|
88
|
+
year: 2000,
|
|
89
|
+
month: 999,
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test('from a partial record', () => {
|
|
94
|
+
const x: UnknownRecord = {
|
|
95
|
+
year: 2000,
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
expect(ym.fill(x)).toStrictEqual({
|
|
99
|
+
year: 2000,
|
|
100
|
+
month: 1,
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test('from a partial record with excess property', () => {
|
|
105
|
+
const x: UnknownRecord = {
|
|
106
|
+
year: 2000,
|
|
107
|
+
aaaaa: 9999,
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
expect(ym.fill(x)).toStrictEqual({
|
|
111
|
+
year: 2000,
|
|
112
|
+
month: 1,
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
});
|