deep-guards 1.0.5 → 1.2.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/.yarnrc.yml +5 -0
- package/LICENSE +1 -1
- package/dist/compound.d.ts +5 -4
- package/dist/compound.js +4 -0
- package/dist/compound.js.map +1 -1
- package/dist/errors.d.ts +1 -1
- package/dist/helpers.d.ts +2 -2
- package/dist/macros.d.ts +2 -2
- package/dist/macros.js.map +1 -1
- package/dist/primitives.d.ts +2 -2
- package/dist/primitives.js +1 -0
- package/dist/primitives.js.map +1 -1
- package/dist/structures.d.ts +2 -2
- package/dist/structures.js.map +1 -1
- package/eslint.config.js +16 -1
- package/package.json +23 -24
- package/scripts/bump-and-release.ps1 +2 -0
- package/scripts/release.ps1 +10 -0
- package/{tests → src}/compound.test.ts +30 -8
- package/src/compound.ts +23 -13
- package/src/errors.ts +2 -2
- package/src/helpers.ts +4 -4
- package/{tests → src}/macros.test.ts +7 -3
- package/src/macros.ts +13 -11
- package/{tests → src}/primitives.test.ts +4 -1
- package/src/primitives.ts +6 -4
- package/{tests → src}/structures.test.ts +10 -11
- package/src/structures.ts +22 -20
- package/src/types.ts +2 -3
- package/tsconfig.common.json +24 -0
- package/tsconfig.json +3 -19
- package/tsconfig.test.json +4 -0
- 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/.yarnrc.yml
ADDED
package/LICENSE
CHANGED
|
@@ -186,7 +186,7 @@
|
|
|
186
186
|
same "printed page" as the copyright notice for easier
|
|
187
187
|
identification within third-party archives.
|
|
188
188
|
|
|
189
|
-
Copyright
|
|
189
|
+
Copyright 2024 Niall Coleman-Clarke
|
|
190
190
|
|
|
191
191
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
192
|
you may not use this file except in compliance with the License.
|
package/dist/compound.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { GuardSchemaOf } from "./helpers.js";
|
|
2
|
-
import { Guard } from "./types.js";
|
|
1
|
+
import type { GuardSchemaOf } from "./helpers.js";
|
|
2
|
+
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
|
-
export declare function isNonNullable<T
|
|
5
|
+
export declare function isNonNullable<T extends NonNullable<unknown>>(value: T | null | undefined): value is T;
|
|
6
6
|
export declare function isNot<const N>(guard: Guard<N>): <const T>(value: T | N) => value is T;
|
|
7
|
-
export declare function isOneOf<const T extends (string | number | boolean | symbol | null | undefined)[]>(...values: T): Guard<
|
|
7
|
+
export declare function isOneOf<const T extends (string | number | boolean | symbol | null | undefined)[]>(...values: T): Guard<T[number]>;
|
|
8
8
|
export declare function isUnionOf<T extends readonly unknown[]>(...guards: GuardSchemaOf<T>): Guard<T[number]>;
|
|
9
9
|
type ArrayToIntersection<A extends readonly unknown[]> = A extends [
|
|
10
10
|
infer T,
|
|
@@ -12,4 +12,5 @@ type ArrayToIntersection<A extends readonly unknown[]> = A extends [
|
|
|
12
12
|
] ? T & ArrayToIntersection<R> : unknown;
|
|
13
13
|
export declare function isIntersectionOf<T extends readonly unknown[]>(...guards: GuardSchemaOf<T>): Guard<ArrayToIntersection<T>>;
|
|
14
14
|
export declare function isExact<const T>(expected: T, deep?: boolean): Guard<T>;
|
|
15
|
+
export declare function isInstance<C extends abstract new (...args: any) => unknown>(cls: C): Guard<InstanceType<C>>;
|
|
15
16
|
export {};
|
package/dist/compound.js
CHANGED
|
@@ -61,4 +61,8 @@ export function isExact(expected, deep = true) {
|
|
|
61
61
|
!Array.isArray(value) &&
|
|
62
62
|
objectEntriesChecks(expected, value)));
|
|
63
63
|
}
|
|
64
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
65
|
+
export function isInstance(cls) {
|
|
66
|
+
return (value) => value instanceof cls;
|
|
67
|
+
}
|
|
64
68
|
//# sourceMappingURL=compound.js.map
|
package/dist/compound.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compound.js","sourceRoot":"src/","sources":["compound.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"compound.js","sourceRoot":"src/","sources":["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,EAAiC,EAAE,CACvD,KAAK,IAAI,IAAI,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC;AAClC,CAAC;AAED,MAAM,UAAU,aAAa,CAC3B,KAA2B;IAE3B,OAAO,KAAK,IAAI,IAAI,CAAC;AACvB,CAAC;AAED,MAAM,UAAU,KAAK,CAAU,KAAe;IAC5C,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE,CAAC;QAChC,MAAM,IAAI,SAAS,CACjB,iDAAiD,KAAK,EAAE,CACzD,CAAC;IACJ,CAAC;IAED,OAAO,CAAU,KAAY,EAAc,EAAE,CAAC,CAAC,KAAK,CAA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|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Guard } from "./types.js";
|
|
1
|
+
import type { Guard } from "./types.js";
|
|
2
2
|
export type GuardSchemaOf<O extends object> = {
|
|
3
3
|
[K in keyof O]: Guard<O[K]>;
|
|
4
4
|
};
|
|
5
5
|
export type ObjectKey = string | number | symbol;
|
|
6
6
|
export declare const objectKeys: <K extends ObjectKey>(obj: Record<K, unknown>) => K[];
|
|
7
|
-
export declare function omit<O extends
|
|
7
|
+
export declare function omit<O extends NonNullable<unknown>>(obj: O, key: keyof O): {
|
|
8
8
|
[K in keyof O as K extends typeof key ? never : K]: O[K];
|
|
9
9
|
};
|
package/dist/macros.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ObjectKey } from "./helpers.js";
|
|
2
|
-
import { Guard } from "./types.js";
|
|
1
|
+
import type { ObjectKey } from "./helpers.js";
|
|
2
|
+
import type { Guard } from "./types.js";
|
|
3
3
|
export declare function isDiscriminatedObjectOf<const T extends string, O extends object>(value: T, guard: Guard<O>): Guard<{
|
|
4
4
|
type: T;
|
|
5
5
|
} & O>;
|
package/dist/macros.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"macros.js","sourceRoot":"src/","sources":["macros.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,
|
|
1
|
+
{"version":3,"file":"macros.js","sourceRoot":"src/","sources":["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.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Guard } from "./types.js";
|
|
1
|
+
import type { Guard } from "./types.js";
|
|
2
2
|
export declare const isUnknown: Guard<unknown>;
|
|
3
3
|
export declare const isNull: Guard<null>;
|
|
4
4
|
export declare const isUndefined: Guard<undefined>;
|
|
@@ -7,4 +7,4 @@ export declare const isInteger: Guard<number>;
|
|
|
7
7
|
export declare const isString: Guard<string>;
|
|
8
8
|
export declare const isSymbol: Guard<symbol>;
|
|
9
9
|
export declare const isBoolean: Guard<boolean>;
|
|
10
|
-
export declare const isFunction: Guard<(...args:
|
|
10
|
+
export declare const isFunction: Guard<(...args: any[]) => unknown>;
|
package/dist/primitives.js
CHANGED
|
@@ -6,5 +6,6 @@ export const isInteger = (value) => Number.isInteger(value);
|
|
|
6
6
|
export const isString = (value) => typeof value === "string";
|
|
7
7
|
export const isSymbol = (value) => typeof value === "symbol";
|
|
8
8
|
export const isBoolean = (value) => value === true || value === false;
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
10
|
export const isFunction = (value) => typeof value === "function";
|
|
10
11
|
//# sourceMappingURL=primitives.js.map
|
package/dist/primitives.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"primitives.js","sourceRoot":"src/","sources":["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,CA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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.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { GuardSchemaOf, ObjectKey } from "./helpers.js";
|
|
2
|
-
import { Guard } from "./types.js";
|
|
1
|
+
import type { GuardSchemaOf, ObjectKey } from "./helpers.js";
|
|
2
|
+
import type { Guard } from "./types.js";
|
|
3
3
|
export declare const isAnyArray: Guard<unknown[]>;
|
|
4
4
|
export declare const isAnyRecord: Guard<Record<ObjectKey, unknown>>;
|
|
5
5
|
export declare function isArrayOf<T>(guard: Guard<T>): Guard<T[]>;
|
package/dist/structures.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"structures.js","sourceRoot":"src/","sources":["structures.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"structures.js","sourceRoot":"src/","sources":["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,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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/eslint.config.js
CHANGED
|
@@ -2,21 +2,36 @@ import typescriptParser from "@typescript-eslint/parser";
|
|
|
2
2
|
import jslint from "@eslint/js";
|
|
3
3
|
import tslint from "typescript-eslint";
|
|
4
4
|
import tsPlugin from "@typescript-eslint/eslint-plugin";
|
|
5
|
+
import stylistic from "@stylistic/eslint-plugin";
|
|
5
6
|
|
|
6
7
|
export default tslint.config(
|
|
7
8
|
jslint.configs.recommended,
|
|
9
|
+
stylistic.configs.customize({
|
|
10
|
+
braceStyle: "1tbs",
|
|
11
|
+
commaDangle: "only-multiline",
|
|
12
|
+
indent: 2,
|
|
13
|
+
semi: true,
|
|
14
|
+
}),
|
|
8
15
|
...tslint.configs.recommended,
|
|
9
16
|
...tslint.configs.recommendedTypeChecked,
|
|
10
17
|
...tslint.configs.strictTypeChecked,
|
|
11
18
|
{
|
|
12
19
|
languageOptions: {
|
|
13
20
|
parser: typescriptParser,
|
|
14
|
-
parserOptions: { project: "./tsconfig.json" },
|
|
21
|
+
parserOptions: { project: ["./tsconfig.json", "./tsconfig.test.json"] },
|
|
15
22
|
},
|
|
16
23
|
|
|
17
24
|
plugins: { tsPlugin },
|
|
18
25
|
|
|
19
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/generator-star-spacing": "off",
|
|
32
|
+
"@stylistic/quotes": "off",
|
|
33
|
+
"@stylistic/operator-linebreak": "off",
|
|
34
|
+
|
|
20
35
|
// CORE
|
|
21
36
|
// According to https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/indent.md
|
|
22
37
|
// the default indentation rule can cause eslint to report erroneous style errors.
|
package/package.json
CHANGED
|
@@ -1,42 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "eniallator",
|
|
3
3
|
"description": "Deep guarding package",
|
|
4
|
+
"engines": {
|
|
5
|
+
"node": ">=25.4.0"
|
|
6
|
+
},
|
|
4
7
|
"license": "Apache-2.0",
|
|
5
8
|
"main": "dist/index.js",
|
|
6
9
|
"name": "deep-guards",
|
|
7
|
-
"packageManager": "yarn@
|
|
10
|
+
"packageManager": "yarn@4.12.0",
|
|
8
11
|
"type": "module",
|
|
9
12
|
"types": "dist/index.d.ts",
|
|
10
13
|
"homepage": "https://github.com/eniallator/Deep-Guards",
|
|
11
|
-
"version": "1.0
|
|
14
|
+
"version": "1.2.0",
|
|
12
15
|
"scripts": {
|
|
13
|
-
"test": "
|
|
16
|
+
"test": "vitest run --passWithNoTests",
|
|
14
17
|
"build": "tsc",
|
|
15
18
|
"lint": "eslint ./src",
|
|
16
19
|
"typecheck": "tsc --noEmit",
|
|
17
|
-
"findissues": "yarn typecheck && yarn lint"
|
|
20
|
+
"findissues": "yarn typecheck && yarn lint",
|
|
21
|
+
"publish": "npm publish --tolerate-republish",
|
|
22
|
+
"prepublish": "yarn typecheck && yarn lint && yarn build && yarn test",
|
|
23
|
+
"bump-and-release": "powershell -ExecutionPolicy Bypass -File ./scripts/bump-and-release.ps1",
|
|
24
|
+
"release": "powershell -ExecutionPolicy Bypass -File ./scripts/release.ps1"
|
|
18
25
|
},
|
|
19
26
|
"devDependencies": {
|
|
20
|
-
"@
|
|
21
|
-
"@
|
|
22
|
-
"@
|
|
23
|
-
"@
|
|
24
|
-
"@
|
|
25
|
-
"@
|
|
26
|
-
"@
|
|
27
|
-
"
|
|
28
|
-
"@types/eslint": "^9.6.1",
|
|
29
|
-
"@types/eslint__js": "^8.42.3",
|
|
30
|
-
"@types/jest": "^29.5.14",
|
|
31
|
-
"@typescript-eslint/eslint-plugin": "^8.16.0",
|
|
32
|
-
"@typescript-eslint/parser": "^8.16.0",
|
|
33
|
-
"babel-jest": "^29.7.0",
|
|
34
|
-
"eslint": "^9.15.0",
|
|
27
|
+
"@eslint/compat": "^2.0.2",
|
|
28
|
+
"@eslint/js": "^9.39.2",
|
|
29
|
+
"@stylistic/eslint-plugin": "^5.8.0",
|
|
30
|
+
"@types/eslint__js": "^9.14.0",
|
|
31
|
+
"@types/node": "^25.2.3",
|
|
32
|
+
"@typescript-eslint/eslint-plugin": "^8.55.0",
|
|
33
|
+
"@typescript-eslint/parser": "^8.55.0",
|
|
34
|
+
"eslint": "^9.39.2",
|
|
35
35
|
"eslint-plugin-eslint-comments": "^3.2.0",
|
|
36
|
-
"eslint-plugin-import": "^2.
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"typescript-eslint": "^8.16.0"
|
|
36
|
+
"eslint-plugin-import": "^2.32.0",
|
|
37
|
+
"typescript": "^5.9.3",
|
|
38
|
+
"typescript-eslint": "^8.55.0",
|
|
39
|
+
"vitest": "^4.0.18"
|
|
41
40
|
}
|
|
42
41
|
}
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
|
|
1
3
|
import {
|
|
2
4
|
isExact,
|
|
5
|
+
isInstance,
|
|
3
6
|
isIntersectionOf,
|
|
4
7
|
isNonNullable,
|
|
5
8
|
isNot,
|
|
6
9
|
isNullable,
|
|
7
|
-
isNumber,
|
|
8
10
|
isOneOf,
|
|
9
11
|
isOptional,
|
|
10
|
-
isString,
|
|
11
12
|
isUnionOf,
|
|
12
|
-
} from "
|
|
13
|
+
} from "./compound.ts";
|
|
14
|
+
import { isNumber, isString } from "./primitives.ts";
|
|
13
15
|
|
|
14
16
|
describe("isOptional", () => {
|
|
15
17
|
const guard = isOptional(isString);
|
|
@@ -95,7 +97,7 @@ describe("isUnionOf", () => {
|
|
|
95
97
|
describe("isIntersectionOf", () => {
|
|
96
98
|
const guard = isIntersectionOf(
|
|
97
99
|
isOneOf("foo", "bar", "baz"),
|
|
98
|
-
isExact("foo", false)
|
|
100
|
+
isExact("foo", false),
|
|
99
101
|
);
|
|
100
102
|
|
|
101
103
|
it("succeeds for the intersection", () => {
|
|
@@ -112,21 +114,21 @@ describe("isExact", () => {
|
|
|
112
114
|
describe("deep", () => {
|
|
113
115
|
const guard = isExact(
|
|
114
116
|
{ foo: "bar", hello: ["world", { key: "test" }] },
|
|
115
|
-
true
|
|
117
|
+
true,
|
|
116
118
|
);
|
|
117
119
|
|
|
118
120
|
it("succeeds for the exact value", () => {
|
|
119
121
|
expect(guard({ foo: "bar", hello: ["world", { key: "test" }] })).toBe(
|
|
120
|
-
true
|
|
122
|
+
true,
|
|
121
123
|
);
|
|
122
124
|
});
|
|
123
125
|
|
|
124
126
|
it("fails for any other value", () => {
|
|
125
127
|
expect(guard({ foo: "baz", hello: ["world", { key: "test" }] })).toBe(
|
|
126
|
-
false
|
|
128
|
+
false,
|
|
127
129
|
);
|
|
128
130
|
expect(guard({ foo: "bar", hello: ["world", { key: "tester" }] })).toBe(
|
|
129
|
-
false
|
|
131
|
+
false,
|
|
130
132
|
);
|
|
131
133
|
expect(guard(1)).toBe(false);
|
|
132
134
|
});
|
|
@@ -150,3 +152,23 @@ describe("isExact", () => {
|
|
|
150
152
|
});
|
|
151
153
|
});
|
|
152
154
|
});
|
|
155
|
+
|
|
156
|
+
describe("isInstance", () => {
|
|
157
|
+
class Test {
|
|
158
|
+
foo: string = "bar";
|
|
159
|
+
|
|
160
|
+
constructor(foo: string) {
|
|
161
|
+
this.foo = foo;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
const guard = isInstance(Test);
|
|
165
|
+
|
|
166
|
+
it("succeeds for an instance", () => {
|
|
167
|
+
expect(guard(new Test("baz"))).toBe(true);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it("fails for any other type", () => {
|
|
171
|
+
expect(guard({})).toBe(false);
|
|
172
|
+
expect(guard(null)).toBe(false);
|
|
173
|
+
});
|
|
174
|
+
});
|
package/src/compound.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { objectKeys } from "./helpers.js";
|
|
2
|
+
|
|
3
|
+
import type { GuardSchemaOf } from "./helpers.js";
|
|
4
|
+
import type { Guard } from "./types.js";
|
|
3
5
|
|
|
4
6
|
export function isOptional<T>(guard: Guard<T>): Guard<T | undefined> {
|
|
5
7
|
if (typeof guard !== "function") {
|
|
6
8
|
throw new TypeError(
|
|
7
|
-
`isOptional expects a guard parameter. Got instead: ${guard}
|
|
9
|
+
`isOptional expects a guard parameter. Got instead: ${guard}`,
|
|
8
10
|
);
|
|
9
11
|
}
|
|
10
12
|
|
|
@@ -14,7 +16,7 @@ export function isOptional<T>(guard: Guard<T>): Guard<T | undefined> {
|
|
|
14
16
|
export function isNullable<T>(guard: Guard<T>): Guard<T | null | undefined> {
|
|
15
17
|
if (typeof guard !== "function") {
|
|
16
18
|
throw new TypeError(
|
|
17
|
-
`isNullable expects a guard parameter. Got instead: ${guard}
|
|
19
|
+
`isNullable expects a guard parameter. Got instead: ${guard}`,
|
|
18
20
|
);
|
|
19
21
|
}
|
|
20
22
|
|
|
@@ -22,14 +24,16 @@ export function isNullable<T>(guard: Guard<T>): Guard<T | null | undefined> {
|
|
|
22
24
|
value == null || guard(value);
|
|
23
25
|
}
|
|
24
26
|
|
|
25
|
-
export function isNonNullable<T
|
|
27
|
+
export function isNonNullable<T extends NonNullable<unknown>>(
|
|
28
|
+
value: T | null | undefined,
|
|
29
|
+
): value is T {
|
|
26
30
|
return value != null;
|
|
27
31
|
}
|
|
28
32
|
|
|
29
33
|
export function isNot<const N>(guard: Guard<N>) {
|
|
30
34
|
if (typeof guard !== "function") {
|
|
31
35
|
throw new TypeError(
|
|
32
|
-
`isNot expects a guard parameter. Got instead: ${guard}
|
|
36
|
+
`isNot expects a guard parameter. Got instead: ${guard}`,
|
|
33
37
|
);
|
|
34
38
|
}
|
|
35
39
|
|
|
@@ -37,11 +41,10 @@ export function isNot<const N>(guard: Guard<N>) {
|
|
|
37
41
|
}
|
|
38
42
|
|
|
39
43
|
export function isOneOf<
|
|
40
|
-
const T extends (string | number | boolean | symbol | null | undefined)[]
|
|
41
|
-
>(...values: T): Guard<
|
|
44
|
+
const T extends (string | number | boolean | symbol | null | undefined)[],
|
|
45
|
+
>(...values: T): Guard<T[number]> {
|
|
42
46
|
const valueSet = new Set(values);
|
|
43
|
-
return (value
|
|
44
|
-
valueSet.has(value as T[number]);
|
|
47
|
+
return (value) => (valueSet.has as Guard<T[number]>)(value);
|
|
45
48
|
}
|
|
46
49
|
|
|
47
50
|
export function isUnionOf<T extends readonly unknown[]>(
|
|
@@ -49,7 +52,7 @@ export function isUnionOf<T extends readonly unknown[]>(
|
|
|
49
52
|
): Guard<T[number]> {
|
|
50
53
|
if (guards.every((guard) => typeof guard !== "function")) {
|
|
51
54
|
throw new TypeError(
|
|
52
|
-
`isUnionOf expects N guard parameters. Got instead: ${guards}
|
|
55
|
+
`isUnionOf expects N guard parameters. Got instead: ${guards}`,
|
|
53
56
|
);
|
|
54
57
|
}
|
|
55
58
|
|
|
@@ -58,7 +61,7 @@ export function isUnionOf<T extends readonly unknown[]>(
|
|
|
58
61
|
|
|
59
62
|
type ArrayToIntersection<A extends readonly unknown[]> = A extends [
|
|
60
63
|
infer T,
|
|
61
|
-
...infer R
|
|
64
|
+
...infer R,
|
|
62
65
|
]
|
|
63
66
|
? T & ArrayToIntersection<R>
|
|
64
67
|
: unknown;
|
|
@@ -68,7 +71,7 @@ export function isIntersectionOf<T extends readonly unknown[]>(
|
|
|
68
71
|
): Guard<ArrayToIntersection<T>> {
|
|
69
72
|
if (guards.every((guard) => typeof guard !== "function")) {
|
|
70
73
|
throw new TypeError(
|
|
71
|
-
`isIntersectionOf expects N guard parameters. Got instead: ${guards}
|
|
74
|
+
`isIntersectionOf expects N guard parameters. Got instead: ${guards}`,
|
|
72
75
|
);
|
|
73
76
|
}
|
|
74
77
|
|
|
@@ -104,3 +107,10 @@ export function isExact<const T>(expected: T, deep: boolean = true): Guard<T> {
|
|
|
104
107
|
!Array.isArray(value) &&
|
|
105
108
|
objectEntriesChecks(expected, value)));
|
|
106
109
|
}
|
|
110
|
+
|
|
111
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
112
|
+
export function isInstance<C extends abstract new (...args: any) => unknown>(
|
|
113
|
+
cls: C,
|
|
114
|
+
): Guard<InstanceType<C>> {
|
|
115
|
+
return (value): value is InstanceType<C> => value instanceof cls;
|
|
116
|
+
}
|
package/src/errors.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Guard } from "./types.js";
|
|
1
|
+
import type { Guard } from "./types.js";
|
|
2
2
|
|
|
3
3
|
export class GuardError extends Error {
|
|
4
4
|
name = "GuardError";
|
|
@@ -7,7 +7,7 @@ export class GuardError extends Error {
|
|
|
7
7
|
export function guardOrThrow<T>(
|
|
8
8
|
value: unknown,
|
|
9
9
|
guard: Guard<T>,
|
|
10
|
-
hint?: string
|
|
10
|
+
hint?: string,
|
|
11
11
|
): T {
|
|
12
12
|
if (guard(value)) {
|
|
13
13
|
return value;
|
package/src/helpers.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Guard } from "./types.js";
|
|
1
|
+
import type { Guard } from "./types.js";
|
|
2
2
|
|
|
3
3
|
export type GuardSchemaOf<O extends object> = {
|
|
4
4
|
[K in keyof O]: Guard<O[K]>;
|
|
@@ -8,12 +8,12 @@ export type ObjectKey = string | number | symbol;
|
|
|
8
8
|
|
|
9
9
|
export const objectKeys = <K extends ObjectKey>(obj: Record<K, unknown>): K[] =>
|
|
10
10
|
(Object.getOwnPropertyNames(obj) as K[]).concat(
|
|
11
|
-
Object.getOwnPropertySymbols(obj) as K[]
|
|
11
|
+
Object.getOwnPropertySymbols(obj) as K[],
|
|
12
12
|
);
|
|
13
13
|
|
|
14
|
-
export function omit<O extends
|
|
14
|
+
export function omit<O extends NonNullable<unknown>>(
|
|
15
15
|
obj: O,
|
|
16
|
-
key: keyof O
|
|
16
|
+
key: keyof O,
|
|
17
17
|
): { [K in keyof O as K extends typeof key ? never : K]: O[K] } {
|
|
18
18
|
const omitted = { ...obj };
|
|
19
19
|
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { isDiscriminatedObjectOf } from "./macros.ts";
|
|
4
|
+
import { isString } from "./primitives.ts";
|
|
5
|
+
import { isObjectOf } from "./structures.ts";
|
|
2
6
|
|
|
3
7
|
describe("isDiscriminatedObjectOf", () => {
|
|
4
8
|
describe("no key override", () => {
|
|
5
9
|
const guard = isDiscriminatedObjectOf(
|
|
6
10
|
"foo",
|
|
7
|
-
isObjectOf({ bar: isString }, true)
|
|
11
|
+
isObjectOf({ bar: isString }, true),
|
|
8
12
|
);
|
|
9
13
|
|
|
10
14
|
it("succeeds for an object of the value", () => {
|
|
@@ -22,7 +26,7 @@ describe("isDiscriminatedObjectOf", () => {
|
|
|
22
26
|
const guard = isDiscriminatedObjectOf(
|
|
23
27
|
"foo",
|
|
24
28
|
isObjectOf({ bar: isString }, true),
|
|
25
|
-
"test"
|
|
29
|
+
"test",
|
|
26
30
|
);
|
|
27
31
|
|
|
28
32
|
it("succeeds for an object of the value", () => {
|
package/src/macros.ts
CHANGED
|
@@ -1,28 +1,30 @@
|
|
|
1
1
|
import { isExact } from "./compound.js";
|
|
2
|
-
import {
|
|
2
|
+
import { omit } from "./helpers.js";
|
|
3
3
|
import { isObjectOf } from "./structures.js";
|
|
4
|
-
|
|
4
|
+
|
|
5
|
+
import type { ObjectKey } from "./helpers.js";
|
|
6
|
+
import type { Guard } from "./types.js";
|
|
5
7
|
|
|
6
8
|
export function isDiscriminatedObjectOf<
|
|
7
9
|
const T extends string,
|
|
8
|
-
O extends object
|
|
10
|
+
O extends object,
|
|
9
11
|
>(value: T, guard: Guard<O>): Guard<{ type: T } & O>;
|
|
10
12
|
export function isDiscriminatedObjectOf<
|
|
11
13
|
const T extends string,
|
|
12
14
|
O extends object,
|
|
13
|
-
const K extends ObjectKey
|
|
15
|
+
const K extends ObjectKey,
|
|
14
16
|
>(value: T, guard: Guard<O>, key: K): Guard<{ [S in K]: T } & O>;
|
|
15
17
|
export function isDiscriminatedObjectOf<
|
|
16
18
|
const T extends string,
|
|
17
|
-
O extends object
|
|
19
|
+
O extends object,
|
|
18
20
|
>(
|
|
19
21
|
value: T,
|
|
20
22
|
guard: Guard<O>,
|
|
21
|
-
key: ObjectKey = "type"
|
|
22
|
-
): Guard<
|
|
23
|
-
const discriminatorGuard = isObjectOf({ [key]: isExact(value) }) as Guard<
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return (value): value is
|
|
23
|
+
key: ObjectKey = "type",
|
|
24
|
+
): Guard<Record<ObjectKey, T> & O> {
|
|
25
|
+
const discriminatorGuard = isObjectOf({ [key]: isExact(value) }) as Guard<
|
|
26
|
+
Record<ObjectKey, T>
|
|
27
|
+
>;
|
|
28
|
+
return (value): value is Record<ObjectKey, T> & O =>
|
|
27
29
|
discriminatorGuard(value) && guard(omit(value, key));
|
|
28
30
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
|
|
1
3
|
import {
|
|
2
4
|
isBoolean,
|
|
3
5
|
isFunction,
|
|
@@ -7,7 +9,7 @@ import {
|
|
|
7
9
|
isString,
|
|
8
10
|
isUndefined,
|
|
9
11
|
isUnknown,
|
|
10
|
-
} from "
|
|
12
|
+
} from "./primitives.ts";
|
|
11
13
|
|
|
12
14
|
describe("isUnknown", () => {
|
|
13
15
|
it("succeeds for any value", () => {
|
|
@@ -17,6 +19,7 @@ describe("isUnknown", () => {
|
|
|
17
19
|
|
|
18
20
|
describe("isAnyFunction", () => {
|
|
19
21
|
it("succeeds for a function", () => {
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
20
23
|
expect(isFunction(() => {})).toBe(true);
|
|
21
24
|
});
|
|
22
25
|
|
package/src/primitives.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Guard } from "./types.js";
|
|
1
|
+
import type { Guard } from "./types.js";
|
|
2
2
|
|
|
3
3
|
export const isUnknown: Guard<unknown> = (_value): _value is unknown => true;
|
|
4
4
|
|
|
@@ -18,6 +18,8 @@ export const isSymbol: Guard<symbol> = (value) => typeof value === "symbol";
|
|
|
18
18
|
export const isBoolean: Guard<boolean> = (value) =>
|
|
19
19
|
value === true || value === false;
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
22
|
+
export const isFunction: Guard<(...args: any[]) => unknown> = (
|
|
23
|
+
value,
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
25
|
+
): value is (...args: any[]) => unknown => typeof value === "function";
|