deep-guards 1.1.0 → 1.3.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 +1 -1
- package/README.md +12 -7
- package/dist/compound.d.ts +2 -1
- package/dist/compound.js +73 -23
- package/dist/compound.js.map +1 -1
- package/dist/primitives.js +1 -3
- package/dist/primitives.js.map +1 -1
- package/eslint.config.js +3 -1
- package/package.json +17 -30
- package/src/compound.test.ts +254 -0
- package/src/compound.ts +121 -33
- package/src/errors.ts +1 -1
- package/src/helpers.ts +2 -2
- package/{tests → src}/macros.test.ts +6 -4
- package/src/macros.ts +4 -4
- package/{tests → src}/primitives.test.ts +2 -2
- package/src/primitives.ts +1 -1
- package/{tests → src}/structures.test.ts +9 -12
- package/src/structures.ts +18 -18
- package/src/types.ts +2 -3
- package/tsconfig.json +1 -0
- package/tsconfig.test.json +1 -4
- package/.yarn/plugins/@yarnpkg/plugin-typescript.cjs +0 -9
- package/.yarn/plugins/@yarnpkg/plugin-version.cjs +0 -523
- package/.yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs +0 -28
- package/.yarn/releases/yarn-3.8.2.cjs +0 -875
- package/babel.config.cjs +0 -6
- package/tests/compound.test.ts +0 -154
package/babel.config.cjs
DELETED
package/tests/compound.test.ts
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "@jest/globals";
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
isExact,
|
|
5
|
-
isIntersectionOf,
|
|
6
|
-
isNonNullable,
|
|
7
|
-
isNot,
|
|
8
|
-
isNullable,
|
|
9
|
-
isNumber,
|
|
10
|
-
isOneOf,
|
|
11
|
-
isOptional,
|
|
12
|
-
isString,
|
|
13
|
-
isUnionOf,
|
|
14
|
-
} from "../dist";
|
|
15
|
-
|
|
16
|
-
describe("isOptional", () => {
|
|
17
|
-
const guard = isOptional(isString);
|
|
18
|
-
|
|
19
|
-
it("succeeds for the expected type or undefined", () => {
|
|
20
|
-
expect(guard("foo")).toBe(true);
|
|
21
|
-
expect(guard(undefined)).toBe(true);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it("fails for any other value", () => {
|
|
25
|
-
expect(guard(null)).toBe(false);
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
describe("isNullable", () => {
|
|
30
|
-
const guard = isNullable(isString);
|
|
31
|
-
|
|
32
|
-
it("succeeds for the expected type, null, or undefined", () => {
|
|
33
|
-
expect(guard("foo")).toBe(true);
|
|
34
|
-
expect(guard(null)).toBe(true);
|
|
35
|
-
expect(guard(undefined)).toBe(true);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it("fails any other value", () => {
|
|
39
|
-
expect(guard(1)).toBe(false);
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
describe("isNonNullable", () => {
|
|
44
|
-
it("succeeds for the expected type, null, or undefined", () => {
|
|
45
|
-
expect(isNonNullable("foo")).toBe(true);
|
|
46
|
-
expect(isNonNullable(1)).toBe(true);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it("fails any other value", () => {
|
|
50
|
-
expect(isNonNullable(null)).toBe(false);
|
|
51
|
-
expect(isNonNullable(undefined)).toBe(false);
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
describe("isNot", () => {
|
|
56
|
-
const guard = isNot(isString);
|
|
57
|
-
|
|
58
|
-
it("succeeds for any other value", () => {
|
|
59
|
-
expect(guard(1)).toBe(true);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it("fails for the isNot type", () => {
|
|
63
|
-
expect(guard("foo")).toBe(false);
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
describe("isOneOf", () => {
|
|
68
|
-
const guard = isOneOf(1, "foo", true);
|
|
69
|
-
|
|
70
|
-
it("succeeds for all of the values", () => {
|
|
71
|
-
expect(guard(1)).toBe(true);
|
|
72
|
-
expect(guard("foo")).toBe(true);
|
|
73
|
-
expect(guard(true)).toBe(true);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
expect(guard(2)).toBe(false);
|
|
77
|
-
it("fails any other value", () => {
|
|
78
|
-
expect(guard(null)).toBe(false);
|
|
79
|
-
expect(guard("bar")).toBe(false);
|
|
80
|
-
expect(guard(false)).toBe(false);
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
describe("isUnionOf", () => {
|
|
85
|
-
const guard = isUnionOf(isString, isNumber);
|
|
86
|
-
it("succeeds for the union types", () => {
|
|
87
|
-
expect(guard(1)).toBe(true);
|
|
88
|
-
expect(guard("foo")).toBe(true);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it("fails for any other type", () => {
|
|
92
|
-
expect(guard(true)).toBe(false);
|
|
93
|
-
expect(guard(null)).toBe(false);
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
describe("isIntersectionOf", () => {
|
|
98
|
-
const guard = isIntersectionOf(
|
|
99
|
-
isOneOf("foo", "bar", "baz"),
|
|
100
|
-
isExact("foo", false)
|
|
101
|
-
);
|
|
102
|
-
|
|
103
|
-
it("succeeds for the intersection", () => {
|
|
104
|
-
expect(guard("foo")).toBe(true);
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it("fails for any other type", () => {
|
|
108
|
-
expect(guard("bar")).toBe(false);
|
|
109
|
-
expect(guard(1)).toBe(false);
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
describe("isExact", () => {
|
|
114
|
-
describe("deep", () => {
|
|
115
|
-
const guard = isExact(
|
|
116
|
-
{ foo: "bar", hello: ["world", { key: "test" }] },
|
|
117
|
-
true
|
|
118
|
-
);
|
|
119
|
-
|
|
120
|
-
it("succeeds for the exact value", () => {
|
|
121
|
-
expect(guard({ foo: "bar", hello: ["world", { key: "test" }] })).toBe(
|
|
122
|
-
true
|
|
123
|
-
);
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it("fails for any other value", () => {
|
|
127
|
-
expect(guard({ foo: "baz", hello: ["world", { key: "test" }] })).toBe(
|
|
128
|
-
false
|
|
129
|
-
);
|
|
130
|
-
expect(guard({ foo: "bar", hello: ["world", { key: "tester" }] })).toBe(
|
|
131
|
-
false
|
|
132
|
-
);
|
|
133
|
-
expect(guard(1)).toBe(false);
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
describe("shallow", () => {
|
|
138
|
-
const guard = isExact("foo", false);
|
|
139
|
-
|
|
140
|
-
it("succeeds for the exact value", () => {
|
|
141
|
-
expect(guard("foo")).toBe(true);
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
it("fails for deep equality", () => {
|
|
145
|
-
const guard = isExact(["foo", "bar", "baz", 1, 2, 3], false);
|
|
146
|
-
expect(guard(["foo", "bar", "baz", 1, 2, 3])).toBe(false);
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
it("fails for any other value", () => {
|
|
150
|
-
expect(guard("bar")).toBe(false);
|
|
151
|
-
expect(guard(1)).toBe(false);
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
});
|