Skip to content

Commit 123572a

Browse files
authored
Merge pull request #97 from jsr-core/symbol-properties-wip
feat[is]: `is*` functions allows symbol properties
2 parents e9fd92e + 4a5dc04 commit 123572a

38 files changed

+1086
-87
lines changed

__snapshots__/_inspect_test.ts.snap

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,24 @@ snapshot[`inspect > record 3`] = `
3030

3131
snapshot[`inspect > record 4`] = `"{a: {b: {c: 0}}}"`;
3232

33+
snapshot[`inspect > record 5`] = `"{Symbol(a): 0}"`;
34+
35+
snapshot[`inspect > record 6`] = `
36+
"{
37+
a: 0,
38+
c: true,
39+
Symbol(b): 1
40+
}"
41+
`;
42+
43+
snapshot[`inspect > record 7`] = `
44+
"{
45+
Symbol(a): {
46+
Symbol(b): {Symbol(c): 0}
47+
}
48+
}"
49+
`;
50+
3351
snapshot[`inspect > function 1`] = `"inspect"`;
3452

3553
snapshot[`inspect > function 2`] = `"(anonymous)"`;

_inspect.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@ function inspectRecord(
4444
options: InspectOptions,
4545
): string {
4646
const { threshold = defaultThreshold } = options;
47-
const vs = Object.entries(value).map(([k, v]) =>
48-
`${k}: ${inspect(v, options)}`
49-
);
47+
const vs = [...Object.keys(value), ...Object.getOwnPropertySymbols(value)]
48+
.map((k) => `${k.toString()}: ${inspect(value[k], options)}`);
5049
const s = vs.join(", ");
5150
if (s.length <= threshold) return `{${s}}`;
5251
const m = vs.join(",\n");

_inspect_test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ Deno.test("inspect", async (t) => {
2525
await assertSnapshot(t, inspect({ a: 0, b: 1, c: 2 }));
2626
await assertSnapshot(t, inspect({ a: "a", b: 1, c: true }));
2727
await assertSnapshot(t, inspect({ a: { b: { c: 0 } } }));
28+
await assertSnapshot(t, inspect({ [Symbol("a")]: 0 }));
29+
await assertSnapshot(t, inspect({ a: 0, [Symbol("b")]: 1, c: true }));
30+
await assertSnapshot(
31+
t,
32+
inspect({ [Symbol("a")]: { [Symbol("b")]: { [Symbol("c")]: 0 } } }),
33+
);
2834
});
2935
await t.step("function", async (t) => {
3036
await assertSnapshot(t, inspect(inspect));

is/__snapshots__/intersection_of_test.ts.snap

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,19 @@ snapshot[`isIntersectionOf<T> > returns properly named predicate function 3`] =
1515
isObjectOf({b: isString})
1616
])"
1717
`;
18+
19+
snapshot[`isIntersectionOf<T> > with symbol properties > returns properly named predicate function 1`] = `"isString"`;
20+
21+
snapshot[`isIntersectionOf<T> > with symbol properties > returns properly named predicate function 2`] = `
22+
"isObjectOf({
23+
a: isNumber,
24+
Symbol(b): isString
25+
})"
26+
`;
27+
28+
snapshot[`isIntersectionOf<T> > with symbol properties > returns properly named predicate function 3`] = `
29+
"isIntersectionOf([
30+
isFunction,
31+
isObjectOf({Symbol(b): isString})
32+
])"
33+
`;

is/__snapshots__/object_of_test.ts.snap

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,19 @@ snapshot[`isObjectOf<T> > returns properly named predicate function 3`] = `
1717
})
1818
})"
1919
`;
20+
21+
snapshot[`isObjectOf<T> > with symbol properties > returns properly named predicate function 1`] = `
22+
"isObjectOf({
23+
a: isNumber,
24+
b: isString,
25+
Symbol(s): isBoolean
26+
})"
27+
`;
28+
29+
snapshot[`isObjectOf<T> > with symbol properties > returns properly named predicate function 2`] = `
30+
"isObjectOf({
31+
Symbol(a): isObjectOf({
32+
Symbol(b): isObjectOf({Symbol(c): isBoolean})
33+
})
34+
})"
35+
`;

is/__snapshots__/omit_of_test.ts.snap

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,12 @@ snapshot[`isOmitOf<T, K> > returns properly named predicate function 1`] = `
88
`;
99

1010
snapshot[`isOmitOf<T, K> > returns properly named predicate function 2`] = `"isObjectOf({a: isNumber})"`;
11+
12+
snapshot[`isOmitOf<T, K> > with symbol properties > returns properly named predicate function 1`] = `
13+
"isObjectOf({
14+
a: isNumber,
15+
Symbol(c): isBoolean
16+
})"
17+
`;
18+
19+
snapshot[`isOmitOf<T, K> > with symbol properties > returns properly named predicate function 2`] = `"isObjectOf({a: isNumber})"`;

is/__snapshots__/parameters_of_test.ts.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,19 @@ snapshot[`isParametersOf<T> > returns properly named predicate function 4`] = `
2424
])"
2525
`;
2626
27-
snapshot[`isParametersOf<T, E> > returns properly named predicate function 1`] = `
27+
snapshot[`isParametersOf<T, R> > returns properly named predicate function 1`] = `
2828
"isParametersOf([
2929
isNumber,
3030
isString,
3131
asOptional(isBoolean)
3232
], isArray)"
3333
`;
3434
35-
snapshot[`isParametersOf<T, E> > returns properly named predicate function 2`] = `"isParametersOf([(anonymous)], isArrayOf(isString))"`;
35+
snapshot[`isParametersOf<T, R> > returns properly named predicate function 2`] = `"isParametersOf([(anonymous)], isArrayOf(isString))"`;
3636
37-
snapshot[`isParametersOf<T, E> > returns properly named predicate function 3`] = `"isParametersOf([], isArrayOf(isString))"`;
37+
snapshot[`isParametersOf<T, R> > returns properly named predicate function 3`] = `"isParametersOf([], isArrayOf(isString))"`;
3838
39-
snapshot[`isParametersOf<T, E> > returns properly named predicate function 4`] = `
39+
snapshot[`isParametersOf<T, R> > returns properly named predicate function 4`] = `
4040
"isParametersOf([
4141
isParametersOf([
4242
isParametersOf([

is/__snapshots__/partial_of_test.ts.snap

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,27 @@ snapshot[`isPartialOf<T> > returns properly named predicate function 2`] = `
2323
d: asOptional(asReadonly(isString))
2424
})"
2525
`;
26+
27+
snapshot[`isPartialOf<T> > with symbol properties > returns properly named predicate function 1`] = `
28+
"isObjectOf({
29+
a: asOptional(isNumber),
30+
Symbol(b): asOptional(isUnionOf([
31+
isString,
32+
isUndefined
33+
])),
34+
Symbol(c): asOptional(isBoolean),
35+
Symbol(c): asOptional(asReadonly(isString))
36+
})"
37+
`;
38+
39+
snapshot[`isPartialOf<T> > with symbol properties > returns properly named predicate function 2`] = `
40+
"isObjectOf({
41+
a: asOptional(isNumber),
42+
Symbol(b): asOptional(isUnionOf([
43+
isString,
44+
isUndefined
45+
])),
46+
Symbol(c): asOptional(isBoolean),
47+
Symbol(c): asOptional(asReadonly(isString))
48+
})"
49+
`;

is/__snapshots__/pick_of_test.ts.snap

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,12 @@ snapshot[`isPickOf<T, K> > returns properly named predicate function 1`] = `
88
`;
99

1010
snapshot[`isPickOf<T, K> > returns properly named predicate function 2`] = `"isObjectOf({a: isNumber})"`;
11+
12+
snapshot[`isPickOf<T, K> > with symbol properties > returns properly named predicate function 1`] = `
13+
"isObjectOf({
14+
a: isNumber,
15+
Symbol(c): isBoolean
16+
})"
17+
`;
18+
19+
snapshot[`isPickOf<T, K> > with symbol properties > returns properly named predicate function 2`] = `"isObjectOf({Symbol(c): isBoolean})"`;

is/__snapshots__/readonly_of_test.ts.snap

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,25 @@ snapshot[`isReadonlyOf<T> > with isTupleOf > returns properly named predicate fu
4545
snapshot[`isReadonlyOf<T> > with isUniformTupleOf > returns properly named predicate function 1`] = `"isReadonlyOf(isUniformTupleOf(3, isNumber))"`;
4646
4747
snapshot[`isReadonlyOf<T> > with isUniformTupleOf > returns properly named predicate function 2`] = `"isReadonlyOf(isUniformTupleOf(3, isNumber))"`;
48+
49+
snapshot[`isReadonlyOf<T> > with symbol properties > with isObjectOf > returns properly named predicate function 1`] = `
50+
"isReadonlyOf(isObjectOf({
51+
a: isNumber,
52+
Symbol(b): isUnionOf([
53+
isString,
54+
isUndefined
55+
]),
56+
Symbol(c): asReadonly(isBoolean)
57+
}))"
58+
`;
59+
60+
snapshot[`isReadonlyOf<T> > with symbol properties > with isObjectOf > returns properly named predicate function 2`] = `
61+
"isReadonlyOf(isObjectOf({
62+
a: isNumber,
63+
Symbol(b): isUnionOf([
64+
isString,
65+
isUndefined
66+
]),
67+
Symbol(c): asReadonly(isBoolean)
68+
}))"
69+
`;

0 commit comments

Comments
 (0)