ts-data-forge 5.1.1 → 6.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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"is-record.d.mts","sourceRoot":"","sources":["../../src/guard/is-record.mts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,eAAO,MAAM,QAAQ,GAAI,GAAG,OAAO,KAAG,CAAC,IAAI,
|
|
1
|
+
{"version":3,"file":"is-record.d.mts","sourceRoot":"","sources":["../../src/guard/is-record.mts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,eAAO,MAAM,QAAQ,GAAI,GAAG,OAAO,KAAG,CAAC,IAAI,aAAmC,CAAC;AAE/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,eAAO,MAAM,eAAe,EAAE,CAC5B,CAAC,EAAE,OAAO,KACP,CAAC,IAAI,aAAa,CAAC,MAAM,EAAE,OAAO,CAAY,CAAC"}
|
package/dist/guard/is-record.mjs
CHANGED
|
@@ -38,7 +38,7 @@ import { isNonNullObject } from './is-non-null-object.mjs';
|
|
|
38
38
|
* @see {@link isNonNullObject} - For checking any object type (includes arrays)
|
|
39
39
|
* @see {@link hasKey} - For checking if a record has specific keys
|
|
40
40
|
*/
|
|
41
|
-
const isRecord = (u) => isNonNullObject(u)
|
|
41
|
+
const isRecord = (u) => isNonNullObject(u);
|
|
42
42
|
/**
|
|
43
43
|
* Type guard that checks if a value is a mutable record (an object with mutable string keys).
|
|
44
44
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"is-record.mjs","sources":["../../src/guard/is-record.mts"],"sourcesContent":[null],"names":[],"mappings":";;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCG;
|
|
1
|
+
{"version":3,"file":"is-record.mjs","sources":["../../src/guard/is-record.mts"],"sourcesContent":[null],"names":[],"mappings":";;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCG;AACI,MAAM,QAAQ,GAAG,CAAC,CAAU,KAAyB,eAAe,CAAC,CAAC;AAE7E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BG;AACI,MAAM,eAAe,GAEe;;;;"}
|
package/package.json
CHANGED
package/src/guard/is-record.mts
CHANGED
|
@@ -38,8 +38,7 @@ import { isNonNullObject } from './is-non-null-object.mjs';
|
|
|
38
38
|
* @see {@link isNonNullObject} - For checking any object type (includes arrays)
|
|
39
39
|
* @see {@link hasKey} - For checking if a record has specific keys
|
|
40
40
|
*/
|
|
41
|
-
export const isRecord = (u: unknown): u is UnknownRecord =>
|
|
42
|
-
isNonNullObject(u) && !Array.isArray(u);
|
|
41
|
+
export const isRecord = (u: unknown): u is UnknownRecord => isNonNullObject(u);
|
|
43
42
|
|
|
44
43
|
/**
|
|
45
44
|
* Type guard that checks if a value is a mutable record (an object with mutable string keys).
|
|
@@ -2,110 +2,100 @@ import { expectType } from '../expect-type.mjs';
|
|
|
2
2
|
import { isRecord } from './is-record.mjs';
|
|
3
3
|
|
|
4
4
|
describe(isRecord, () => {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
describe('arrays are Records', () => {
|
|
6
|
+
test('number[] is assignable to Record<number, unknown>', () => {
|
|
7
|
+
const arr: Record<number, unknown> = [1, 2, 3];
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
const unk: unknown = arr;
|
|
9
10
|
|
|
10
|
-
|
|
11
|
+
assert.isTrue(isRecord(unk));
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
expectType<typeof unk, UnknownRecord>('<=');
|
|
14
|
+
});
|
|
13
15
|
|
|
14
|
-
|
|
16
|
+
test('string[] is assignable to Record<number, unknown>', () => {
|
|
17
|
+
const arr: Record<number, unknown> = ['1', '2', '3'];
|
|
15
18
|
|
|
16
|
-
|
|
17
|
-
expectType<typeof unk, UnknownRecord>('=');
|
|
18
|
-
}
|
|
19
|
+
const unk: unknown = arr;
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
test('{} is a record', () => {
|
|
24
|
-
const obj = {} as const;
|
|
25
|
-
|
|
26
|
-
const unk: unknown = obj;
|
|
21
|
+
assert.isTrue(isRecord(unk));
|
|
27
22
|
|
|
28
|
-
|
|
23
|
+
expectType<typeof unk, UnknownRecord>('<=');
|
|
24
|
+
});
|
|
29
25
|
|
|
30
|
-
|
|
26
|
+
test('[] is a record', () => {
|
|
27
|
+
const arr: unknown = [] as const;
|
|
31
28
|
|
|
32
|
-
|
|
29
|
+
const unk: unknown = arr;
|
|
33
30
|
|
|
34
|
-
|
|
35
|
-
expectType<typeof unk, UnknownRecord>('=');
|
|
36
|
-
}
|
|
31
|
+
assert.isTrue(isRecord(unk));
|
|
37
32
|
|
|
38
|
-
|
|
33
|
+
expectType<typeof unk, UnknownRecord>('<=');
|
|
34
|
+
});
|
|
39
35
|
});
|
|
40
36
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const unk: unknown = obj;
|
|
45
|
-
|
|
46
|
-
const res = isRecord(unk);
|
|
47
|
-
|
|
48
|
-
expectType<typeof obj, readonly never[]>('=');
|
|
37
|
+
describe('non-null objects are Records', () => {
|
|
38
|
+
test('{ x: 1 } is a record', () => {
|
|
39
|
+
const obj = { x: 1 } as const;
|
|
49
40
|
|
|
50
|
-
|
|
41
|
+
const unk: unknown = obj;
|
|
51
42
|
|
|
52
|
-
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
test('null is not a record', () => {
|
|
56
|
-
const obj = null;
|
|
43
|
+
assert.isTrue(isRecord(unk));
|
|
57
44
|
|
|
58
|
-
|
|
45
|
+
expectType<typeof unk, UnknownRecord>('<=');
|
|
46
|
+
});
|
|
59
47
|
|
|
60
|
-
|
|
48
|
+
test('{} is a record', () => {
|
|
49
|
+
const obj = {} as const;
|
|
61
50
|
|
|
62
|
-
|
|
51
|
+
const unk: unknown = obj;
|
|
63
52
|
|
|
64
|
-
|
|
53
|
+
assert.isTrue(isRecord(unk));
|
|
65
54
|
|
|
66
|
-
|
|
55
|
+
expectType<typeof unk, UnknownRecord>('<=');
|
|
56
|
+
});
|
|
67
57
|
});
|
|
68
58
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const unk: unknown = obj;
|
|
59
|
+
describe('primitives are not Records', () => {
|
|
60
|
+
test('null is not a record', () => {
|
|
61
|
+
const obj = null;
|
|
73
62
|
|
|
74
|
-
|
|
63
|
+
const unk: unknown = obj;
|
|
75
64
|
|
|
76
|
-
|
|
65
|
+
assert.isFalse(isRecord(unk));
|
|
77
66
|
|
|
78
|
-
|
|
67
|
+
expectType<typeof unk, UnknownRecord>('!<=');
|
|
68
|
+
});
|
|
79
69
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
test('3 is not a record', () => {
|
|
84
|
-
const obj = 3;
|
|
70
|
+
test('undefined is not a record', () => {
|
|
71
|
+
const prm = undefined;
|
|
85
72
|
|
|
86
|
-
|
|
73
|
+
const unk: unknown = prm;
|
|
87
74
|
|
|
88
|
-
|
|
75
|
+
assert.isFalse(isRecord(unk));
|
|
89
76
|
|
|
90
|
-
|
|
77
|
+
expectType<typeof unk, UnknownRecord>('!<=');
|
|
78
|
+
});
|
|
91
79
|
|
|
92
|
-
|
|
80
|
+
test('3 is not a record', () => {
|
|
81
|
+
const prm = 3;
|
|
93
82
|
|
|
94
|
-
|
|
95
|
-
});
|
|
83
|
+
const unk: unknown = prm;
|
|
96
84
|
|
|
97
|
-
|
|
98
|
-
const obj = 'str';
|
|
85
|
+
assert.isFalse(isRecord(unk));
|
|
99
86
|
|
|
100
|
-
|
|
87
|
+
expectType<typeof unk, UnknownRecord>('!<=');
|
|
88
|
+
});
|
|
101
89
|
|
|
102
|
-
|
|
90
|
+
test('"str" is not a record', () => {
|
|
91
|
+
const prm = 'str';
|
|
103
92
|
|
|
104
|
-
|
|
93
|
+
const unk: unknown = prm;
|
|
105
94
|
|
|
106
|
-
|
|
95
|
+
assert.isFalse(isRecord(unk));
|
|
107
96
|
|
|
108
|
-
|
|
97
|
+
expectType<typeof unk, UnknownRecord>('!<=');
|
|
98
|
+
});
|
|
109
99
|
});
|
|
110
100
|
|
|
111
101
|
// test('Map is not a record', () => {
|