deep-guards 1.3.0 → 1.4.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/dist/compound.d.ts +2 -0
- package/dist/compound.js +3 -1
- package/dist/compound.js.map +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/helpers.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/macros.js.map +1 -1
- package/dist/primitives.js.map +1 -1
- package/dist/structures.js.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +44 -21
- package/.yarn.yml +0 -11
- package/.yarnrc.yml +0 -5
- package/eslint.config.js +0 -68
- package/scripts/bump-and-release.ps1 +0 -2
- package/scripts/release.ps1 +0 -10
- package/src/compound.test.ts +0 -254
- package/src/compound.ts +0 -197
- package/src/errors.ts +0 -17
- package/src/helpers.ts +0 -22
- package/src/index.ts +0 -6
- package/src/macros.test.ts +0 -42
- package/src/macros.ts +0 -30
- package/src/primitives.test.ts +0 -94
- package/src/primitives.ts +0 -25
- package/src/structures.test.ts +0 -172
- package/src/structures.ts +0 -110
- package/src/types.ts +0 -4
- package/tsconfig.common.json +0 -24
- package/tsconfig.json +0 -9
- package/tsconfig.test.json +0 -4
package/dist/compound.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ import type { Guard } from "./types.js";
|
|
|
3
3
|
export declare function isOptional<T>(guard: Guard<T>): Guard<T | undefined>;
|
|
4
4
|
export declare function isNullable<T>(guard: Guard<T>): Guard<T | null | undefined>;
|
|
5
5
|
export declare function isNonNullable<T extends NonNullable<unknown>>(value: T | null | undefined): value is T;
|
|
6
|
+
type Falsey = undefined | false | null | "" | 0n | 0;
|
|
7
|
+
export declare function isFalsey(value: unknown): value is Falsey;
|
|
6
8
|
export declare function isNot<const N>(guard: Guard<N>): <const T>(value: T | N) => value is T;
|
|
7
9
|
export declare function isOneOf<const T extends (string | number | boolean | symbol | null | undefined)[]>(...values: T): Guard<T[number]>;
|
|
8
10
|
export declare function isUnionOf<T extends readonly unknown[]>(...guards: GuardSchemaOf<T>): Guard<T[number]>;
|
package/dist/compound.js
CHANGED
|
@@ -14,6 +14,9 @@ export function isNullable(guard) {
|
|
|
14
14
|
export function isNonNullable(value) {
|
|
15
15
|
return value != null;
|
|
16
16
|
}
|
|
17
|
+
export function isFalsey(value) {
|
|
18
|
+
return !value;
|
|
19
|
+
}
|
|
17
20
|
export function isNot(guard) {
|
|
18
21
|
if (typeof guard !== "function") {
|
|
19
22
|
throw new TypeError(`isNot expects a guard parameter. Got instead: ${guard}`);
|
|
@@ -104,7 +107,6 @@ export function isExact(expected) {
|
|
|
104
107
|
return (value) => typeof value === "object" &&
|
|
105
108
|
value != null &&
|
|
106
109
|
!Array.isArray(value) &&
|
|
107
|
-
objectKeys(value).length === guards.length &&
|
|
108
110
|
objectEntriesChecks(value);
|
|
109
111
|
}
|
|
110
112
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
package/dist/compound.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compound.js","sourceRoot":"
|
|
1
|
+
{"version":3,"file":"compound.js","sourceRoot":"","sources":["../src/compound.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAK1C,MAAM,UAAU,UAAU,CAAI,KAAe;IAC3C,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE,CAAC;QAChC,MAAM,IAAI,SAAS,CACjB,sDAAsD,KAAK,EAAE,CAC9D,CAAC;IACJ,CAAC;IAED,OAAO,CAAC,KAAK,EAA0B,EAAE,CAAC,KAAK,KAAK,SAAS,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC;AAChF,CAAC;AAED,MAAM,UAAU,UAAU,CAAI,KAAe;IAC3C,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE,CAAC;QAChC,MAAM,IAAI,SAAS,CACjB,sDAAsD,KAAK,EAAE,CAC9D,CAAC;IACJ,CAAC;IAED,OAAO,CAAC,KAAc,E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AAS,mBAAmB,CAAC,KAAa;QACxC,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,KAAK,CAAgB,CAAC,CAAC;QAC5D,OAAO,CACL,MAAM,CAAC,MAAM,KAAK,SAAS,CAAC,IAAI;YAChC,MAAM,CAAC,KAAK,CACV,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CACb,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAE,KAAoC,CAAC,CAAC,CAAC,CAAC,CACtE,CACF,CAAC;IACJ,CAAC;IAED,OAAO,CAAC,KAAK,EAAc,EAAE,CAC3B,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,IAAI,IAAI;QACb,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QACrB,mBAAmB,CAAC,KAAK,CAAC,CAAC;AAC/B,CAAC;AAED,8DAA8D;AAC9D,MAAM,UAAU,UAAU,CACxB,GAAM;IAEN,OAAO,CAAC,KAAK,EAA4B,EAAE,CAAC,KAAK,YAAY,GAAG,CAAC;AACnE,CAAC"}
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,UAAW,SAAQ,KAAK;IACnC,IAAI,GAAG,YAAY,CAAC;CACrB;AAED,MAAM,UAAU,YAAY,CAC1B,KAAc,EACd,KAAe,EACf,IAAa;IAEb,IAAI,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;QACjB,OAAO,KAAK,CAAC;IACf,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,UAAU,CAAC,IAAI,IAAI,aAAa,CAAC,CAAC;IAC9C,CAAC;AACH,CAAC"}
|
package/dist/helpers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAQA,MAAM,CAAC,MAAM,UAAU,GAAG,CAAsB,GAAuB,EAAO,EAAE,CAC7E,MAAM,CAAC,mBAAmB,CAAC,GAAG,CAAS,CAAC,MAAM,CAC7C,MAAM,CAAC,qBAAqB,CAAC,GAAG,CAAQ,CACzC,CAAC;AAEJ,MAAM,UAAU,IAAI,CAClB,GAAM,EACN,GAAY;IAEZ,MAAM,OAAO,GAAG,EAAE,GAAG,GAAG,EAAE,CAAC;IAC3B,gEAAgE;IAChE,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC;IACpB,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC"}
|
package/dist/macros.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"macros.js","sourceRoot":"
|
|
1
|
+
{"version":3,"file":"macros.js","sourceRoot":"","sources":["../src/macros.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAc7C,MAAM,UAAU,uBAAuB,CAIrC,KAAQ,EACR,KAAe,EACf,MAAiB,MAAM;IAEvB,MAAM,kBAAkB,GAAG,UAAU,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,EAAE,CAE9D,CAAC;IACF,OAAO,CAAC,KAAK,EAAqC,EAAE,CAClD,kBAAkB,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC;AACzD,CAAC"}
|
package/dist/primitives.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"primitives.js","sourceRoot":"
|
|
1
|
+
{"version":3,"file":"primitives.js","sourceRoot":"","sources":["../src/primitives.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,SAAS,GAAmB,CAAC,MAAM,EAAqB,EAAE,CAAC,IAAI,CAAC;AAE7E,MAAM,CAAC,MAAM,MAAM,GAAgB,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,IAAI,CAAC;AAE7D,MAAM,CAAC,MAAM,WAAW,GAAqB,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,SAAS,CAAC;AAE5E,MAAM,CAAC,MAAM,QAAQ,GAAkB,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC;AAE5E,MAAM,CAAC,MAAM,SAAS,GAAkB,CAAC,KAAK,EAAmB,EAAE,CACjE,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AAE1B,MAAM,CAAC,MAAM,QAAQ,GAAkB,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC;AAE5E,MAAM,CAAC,MAAM,QAAQ,GAAkB,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC;AAE5E,MAAM,CAAC,MAAM,SAAS,GAAmB,CAAC,KAAK,EAAE,EAAE,CACjD,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,KAAK,CAAC;AAEpC,8DAA8D;AAC9D,MAAM,CAAC,MAAM,UAAU,GAAuC,CAC5D,KAAK,EAEiC,EAAE,CAAC,OAAO,KAAK,KAAK,UAAU,CAAC"}
|
package/dist/structures.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"structures.js","sourceRoot":"
|
|
1
|
+
{"version":3,"file":"structures.js","sourceRoot":"","sources":["../src/structures.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAK1C,MAAM,CAAC,MAAM,UAAU,GAAqB,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAE5E,MAAM,CAAC,MAAM,WAAW,GAAsC,CAC5D,KAAK,EACgC,EAAE,CACvC,KAAK,IAAI,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAEtE,MAAM,UAAU,SAAS,CAAI,KAAe;IAC1C,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE,CAAC;QAChC,MAAM,IAAI,SAAS,CACjB,qDAAqD,KAAK,EAAE,CAC7D,CAAC;IACJ,CAAC;IAED,OAAO,CAAC,KAAK,EAAgB,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AAC7E,CAAC;AAED,MAAM,UAAU,SAAS,CACvB,GAAG,WAA6B;IAEhC,IAAI,WAAW,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,KAAK,KAAK,UAAU,CAAC,EAAE,CAAC;QAC7D,MAAM,IAAI,SAAS,CACjB,oDAAoD,IAAI,CAAC,SAAS,CAChE,WAAW,CACZ,EAAE,CACJ,CAAC;IACJ,CAAC;IAED,OAAO,CAAC,KAAK,EAAc,EAAE,CAC3B,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QACpB,KAAK,CAAC,MAAM,KAAK,WAAW,CAAC,MAAM;QACnC,WAAW,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,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IAAI,SAAS,CACjB,yDAAyD,IAAI,CAAC,SAAS,CACrE,MAAM,CACP,EAAE,CACJ,CAAC;IACJ,CAAC;SAAM,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACnC,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;IACzD,CAAC;IAED,OAAO,CAAC,CAAC,KAAK,EAAc,EAAE,CAC5B,KAAK,IAAI,IAAI;QACb,OAAO,KAAK,KAAK,QAAQ;QACzB,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QACrB,CAAC,CAAC,SAAS,IAAI,UAAU,CAAC,MAAM,KAAK,UAAU,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC;QAC9D,UAAU,CAAC,KAAK,CACd,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,IAAI,KAAK,IAAI,MAAM,CAAC,GAAG,CAAC,CAAE,KAAW,CAAC,GAAG,CAAC,CAAC,CACxD,CAAuB,CAAC;AAC7B,CAAC"}
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -2,40 +2,63 @@
|
|
|
2
2
|
"author": "eniallator",
|
|
3
3
|
"description": "Deep guarding package",
|
|
4
4
|
"engines": {
|
|
5
|
-
"node": ">=
|
|
5
|
+
"node": ">=18"
|
|
6
6
|
},
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/eniallator/Deep-Guards.git"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/eniallator/Deep-Guards/issues"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"validation",
|
|
16
|
+
"typescript",
|
|
17
|
+
"guarding",
|
|
18
|
+
"guards"
|
|
19
|
+
],
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"import": "./dist/index.js"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist"
|
|
28
|
+
],
|
|
29
|
+
"sideEffects": false,
|
|
7
30
|
"license": "Apache-2.0",
|
|
8
31
|
"main": "dist/index.js",
|
|
9
32
|
"name": "deep-guards",
|
|
10
|
-
"packageManager": "yarn@4.
|
|
33
|
+
"packageManager": "yarn@4.16.0",
|
|
11
34
|
"type": "module",
|
|
12
35
|
"types": "dist/index.d.ts",
|
|
13
36
|
"homepage": "https://github.com/eniallator/Deep-Guards",
|
|
14
|
-
"version": "1.
|
|
37
|
+
"version": "1.4.0",
|
|
15
38
|
"scripts": {
|
|
16
39
|
"test": "vitest run --passWithNoTests",
|
|
17
40
|
"build": "tsc",
|
|
18
41
|
"lint": "eslint ./src",
|
|
19
42
|
"typecheck": "tsc --noEmit",
|
|
20
43
|
"findissues": "yarn typecheck && yarn lint",
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
44
|
+
"bump-and-release": "./scripts/bump-and-release.sh",
|
|
45
|
+
"release": "./scripts/release.sh",
|
|
46
|
+
"publint": "publint run",
|
|
47
|
+
"attw": "attw --pack .",
|
|
48
|
+
"check-output": "./scripts/check-output.sh",
|
|
49
|
+
"prepublish": "yarn typecheck && yarn lint && yarn build && yarn test && yarn publint && yarn check-output"
|
|
25
50
|
},
|
|
26
51
|
"devDependencies": {
|
|
27
|
-
"@
|
|
28
|
-
"@eslint/
|
|
29
|
-
"@
|
|
30
|
-
"@
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"eslint
|
|
37
|
-
"
|
|
38
|
-
"typescript-eslint": "^8.55.0",
|
|
39
|
-
"vitest": "^4.0.18"
|
|
52
|
+
"@arethetypeswrong/cli": "^0.18.3",
|
|
53
|
+
"@eslint/compat": "^2.1.0",
|
|
54
|
+
"@eslint/js": "^10.0.1",
|
|
55
|
+
"@stylistic/eslint-plugin": "^5.10.0",
|
|
56
|
+
"eslint": "^10.4.1",
|
|
57
|
+
"eslint-config-prettier": "^10.1.8",
|
|
58
|
+
"prettier": "^3.8.3",
|
|
59
|
+
"publint": "^0.3.21",
|
|
60
|
+
"typescript": "^6.0.3",
|
|
61
|
+
"typescript-eslint": "^8.60.1",
|
|
62
|
+
"vitest": "^4.1.8"
|
|
40
63
|
}
|
|
41
|
-
}
|
|
64
|
+
}
|
package/.yarn.yml
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
nodeLinker: node-modules
|
|
2
|
-
|
|
3
|
-
plugins:
|
|
4
|
-
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
|
|
5
|
-
spec: "@yarnpkg/plugin-workspace-tools"
|
|
6
|
-
- path: .yarn/plugins/@yarnpkg/plugin-typescript.cjs
|
|
7
|
-
spec: "@yarnpkg/plugin-typescript"
|
|
8
|
-
- path: .yarn/plugins/@yarnpkg/plugin-version.cjs
|
|
9
|
-
spec: "@yarnpkg/plugin-version"
|
|
10
|
-
|
|
11
|
-
yarnPath: .yarn/releases/yarn-3.8.2.cjs
|
package/.yarnrc.yml
DELETED
package/eslint.config.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import typescriptParser from "@typescript-eslint/parser";
|
|
2
|
-
import jslint from "@eslint/js";
|
|
3
|
-
import tslint from "typescript-eslint";
|
|
4
|
-
import tsPlugin from "@typescript-eslint/eslint-plugin";
|
|
5
|
-
import stylistic from "@stylistic/eslint-plugin";
|
|
6
|
-
|
|
7
|
-
export default tslint.config(
|
|
8
|
-
jslint.configs.recommended,
|
|
9
|
-
stylistic.configs.customize({
|
|
10
|
-
braceStyle: "1tbs",
|
|
11
|
-
commaDangle: "only-multiline",
|
|
12
|
-
indent: 2,
|
|
13
|
-
semi: true,
|
|
14
|
-
}),
|
|
15
|
-
...tslint.configs.recommended,
|
|
16
|
-
...tslint.configs.recommendedTypeChecked,
|
|
17
|
-
...tslint.configs.strictTypeChecked,
|
|
18
|
-
{
|
|
19
|
-
languageOptions: {
|
|
20
|
-
parser: typescriptParser,
|
|
21
|
-
parserOptions: { project: ["./tsconfig.json", "./tsconfig.test.json"] },
|
|
22
|
-
},
|
|
23
|
-
|
|
24
|
-
plugins: { tsPlugin },
|
|
25
|
-
|
|
26
|
-
rules: {
|
|
27
|
-
"@typescript-eslint/consistent-type-imports": "error",
|
|
28
|
-
"@typescript-eslint/no-unnecessary-condition": "error",
|
|
29
|
-
"@stylistic/arrow-parens": "off",
|
|
30
|
-
"@stylistic/indent": "off",
|
|
31
|
-
"@stylistic/indent-binary-ops": "off",
|
|
32
|
-
"@stylistic/generator-star-spacing": "off",
|
|
33
|
-
"@stylistic/quotes": "off",
|
|
34
|
-
"@stylistic/quote-props": "off",
|
|
35
|
-
"@stylistic/operator-linebreak": "off",
|
|
36
|
-
|
|
37
|
-
// CORE
|
|
38
|
-
// According to https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/indent.md
|
|
39
|
-
// the default indentation rule can cause eslint to report erroneous style errors.
|
|
40
|
-
indent: "off",
|
|
41
|
-
"no-console": "off",
|
|
42
|
-
eqeqeq: ["warn", "smart"],
|
|
43
|
-
"require-yield": "off",
|
|
44
|
-
"prettier/prettier": "off",
|
|
45
|
-
// "eslint-comments/disable-enable-pair": ["warn", { allowWholeFile: true }],
|
|
46
|
-
// TYPESCRIPT
|
|
47
|
-
"@typescript-eslint/prefer-reduce-type-parameter": "off",
|
|
48
|
-
// We use ts-ignore because we want to suppress type errors... don't warn us about it, please
|
|
49
|
-
"@typescript-eslint/ban-ts-comment": "off",
|
|
50
|
-
// We don't want to specify the return type everywhere as we get the type safety without it
|
|
51
|
-
"@typescript-eslint/explicit-function-return-type": "off",
|
|
52
|
-
// We don't want to have to specify accessibility modifiers on every method, but they are part of
|
|
53
|
-
// the "recommended" config. This turns it off. Rational: https://github.com/typescript-eslint/typescript-eslint/issues/201
|
|
54
|
-
"@typescript-eslint/explicit-member-accessibility": "off",
|
|
55
|
-
"@typescript-eslint/restrict-template-expressions": "off",
|
|
56
|
-
// Use prettier for indentation, not typescript-eslint:
|
|
57
|
-
"@typescript-eslint/indent": "off",
|
|
58
|
-
// We want to only warn about empty interfaces as they might just be placeholders for the future
|
|
59
|
-
"@typescript-eslint/no-empty-interface": "off",
|
|
60
|
-
"@typescript-eslint/no-empty-function": "warn",
|
|
61
|
-
"@typescript-eslint/no-inferrable-types": "off",
|
|
62
|
-
"@typescript-eslint/no-unused-vars": [
|
|
63
|
-
"warn",
|
|
64
|
-
{ varsIgnorePattern: "^_", argsIgnorePattern: "^_" },
|
|
65
|
-
],
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
);
|
package/scripts/release.ps1
DELETED
package/src/compound.test.ts
DELETED
|
@@ -1,254 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
isExact,
|
|
5
|
-
isInstance,
|
|
6
|
-
isIntersectionOf,
|
|
7
|
-
isNonNullable,
|
|
8
|
-
isNot,
|
|
9
|
-
isNullable,
|
|
10
|
-
isOneOf,
|
|
11
|
-
isOptional,
|
|
12
|
-
isUnionOf,
|
|
13
|
-
} from "./compound.ts";
|
|
14
|
-
import { isNumber, isString } from "./primitives.ts";
|
|
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(isOneOf("foo", "bar", "baz"), isExact("foo"));
|
|
99
|
-
|
|
100
|
-
it("succeeds for the intersection", () => {
|
|
101
|
-
expect(guard("foo")).toBe(true);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it("fails for any other type", () => {
|
|
105
|
-
expect(guard("bar")).toBe(false);
|
|
106
|
-
expect(guard(1)).toBe(false);
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
describe("isExact", () => {
|
|
111
|
-
describe("deep", () => {
|
|
112
|
-
const guard = isExact({ foo: "bar", hello: ["world", { key: "test" }] });
|
|
113
|
-
|
|
114
|
-
it("succeeds for the exact value", () => {
|
|
115
|
-
expect(guard({ foo: "bar", hello: ["world", { key: "test" }] })).toBe(
|
|
116
|
-
true,
|
|
117
|
-
);
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it("fails for any other value", () => {
|
|
121
|
-
expect(guard({ foo: "baz", hello: ["world", { key: "test" }] })).toBe(
|
|
122
|
-
false,
|
|
123
|
-
);
|
|
124
|
-
expect(guard({ foo: "bar", hello: ["world", { key: "tester" }] })).toBe(
|
|
125
|
-
false,
|
|
126
|
-
);
|
|
127
|
-
expect(guard(1)).toBe(false);
|
|
128
|
-
});
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
describe("shallow", () => {
|
|
132
|
-
const guard = isExact("foo");
|
|
133
|
-
|
|
134
|
-
it("succeeds for the exact value", () => {
|
|
135
|
-
expect(guard("foo")).toBe(true);
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
it("fails for any other value", () => {
|
|
139
|
-
expect(guard("bar")).toBe(false);
|
|
140
|
-
expect(guard(1)).toBe(false);
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
describe("Date", () => {
|
|
145
|
-
const date = new Date("2000-01-01");
|
|
146
|
-
const guard = isExact(date);
|
|
147
|
-
|
|
148
|
-
it("succeeds for the exact same date", () => {
|
|
149
|
-
expect(guard(new Date("2000-01-01"))).toBe(true);
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
it("fails for different dates", () => {
|
|
153
|
-
expect(guard(new Date("2000-01-02"))).toBe(false);
|
|
154
|
-
expect(guard(date.getTime())).toBe(false);
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
describe("RegExp", () => {
|
|
159
|
-
const regex = /test/gi;
|
|
160
|
-
const guard = isExact(regex);
|
|
161
|
-
|
|
162
|
-
it("succeeds for the exact same regex", () => {
|
|
163
|
-
expect(guard(/test/gi)).toBe(true);
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
it("fails for different regexes", () => {
|
|
167
|
-
expect(guard(/test/i)).toBe(false);
|
|
168
|
-
expect(guard(/test2/gi)).toBe(false);
|
|
169
|
-
expect(guard("test")).toBe(false);
|
|
170
|
-
});
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
describe("Error", () => {
|
|
174
|
-
const error = new Error("test error");
|
|
175
|
-
const guard = isExact(error);
|
|
176
|
-
|
|
177
|
-
it("succeeds for the exact same error", () => {
|
|
178
|
-
expect(guard(new Error("test error"))).toBe(true);
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
it("fails for different errors", () => {
|
|
182
|
-
expect(guard(new Error("other error"))).toBe(false);
|
|
183
|
-
expect(guard(new TypeError("test error"))).toBe(false);
|
|
184
|
-
expect(guard("test error")).toBe(false);
|
|
185
|
-
});
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
describe("Map", () => {
|
|
189
|
-
const map = new Map([["key", "value"]]);
|
|
190
|
-
const guard = isExact(map);
|
|
191
|
-
|
|
192
|
-
it("succeeds for the exact same map", () => {
|
|
193
|
-
expect(guard(new Map([["key", "value"]]))).toBe(true);
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
it("fails for different maps", () => {
|
|
197
|
-
expect(guard(new Map([["key", "other"]]))).toBe(false);
|
|
198
|
-
expect(guard(new Map([["other", "value"]]))).toBe(false);
|
|
199
|
-
expect(guard(new Map())).toBe(false);
|
|
200
|
-
expect(guard({})).toBe(false);
|
|
201
|
-
});
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
describe("Set", () => {
|
|
205
|
-
const set = new Set([1, 2, 3]);
|
|
206
|
-
const guard = isExact(set);
|
|
207
|
-
|
|
208
|
-
it("succeeds for the exact same set", () => {
|
|
209
|
-
expect(guard(new Set([1, 2, 3]))).toBe(true);
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
it("fails for different sets", () => {
|
|
213
|
-
expect(guard(new Set([1, 2]))).toBe(false);
|
|
214
|
-
expect(guard(new Set([1, 2, 4]))).toBe(false);
|
|
215
|
-
expect(guard([1, 2, 3])).toBe(false);
|
|
216
|
-
});
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
describe("Typed Array", () => {
|
|
220
|
-
const array = new Uint8Array([1, 2, 3]);
|
|
221
|
-
const guard = isExact(array);
|
|
222
|
-
|
|
223
|
-
it("succeeds for the exact same typed array", () => {
|
|
224
|
-
expect(guard(new Uint8Array([1, 2, 3]))).toBe(true);
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
it("fails for different typed arrays", () => {
|
|
228
|
-
expect(guard(new Uint8Array([1, 2]))).toBe(false);
|
|
229
|
-
expect(guard(new Uint8Array([1, 2, 4]))).toBe(false);
|
|
230
|
-
expect(guard(new Int8Array([1, 2, 3]))).toBe(false);
|
|
231
|
-
expect(guard([1, 2, 3])).toBe(false);
|
|
232
|
-
});
|
|
233
|
-
});
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
describe("isInstance", () => {
|
|
237
|
-
class Test {
|
|
238
|
-
foo: string = "bar";
|
|
239
|
-
|
|
240
|
-
constructor(foo: string) {
|
|
241
|
-
this.foo = foo;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
const guard = isInstance(Test);
|
|
245
|
-
|
|
246
|
-
it("succeeds for an instance", () => {
|
|
247
|
-
expect(guard(new Test("baz"))).toBe(true);
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
it("fails for any other type", () => {
|
|
251
|
-
expect(guard({})).toBe(false);
|
|
252
|
-
expect(guard(null)).toBe(false);
|
|
253
|
-
});
|
|
254
|
-
});
|