deep-guards 1.0.4 → 1.1.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/dist/compound.d.ts +4 -4
- package/dist/compound.js +1 -1
- package/dist/compound.js.map +1 -1
- package/dist/errors.d.ts +1 -1
- package/dist/helpers.d.ts +2 -2
- package/dist/index.d.ts +6 -6
- package/dist/index.js +6 -6
- package/dist/index.js.map +1 -1
- package/dist/macros.d.ts +2 -2
- package/dist/macros.js +3 -3
- package/dist/macros.js.map +1 -1
- package/dist/primitives.d.ts +2 -2
- package/dist/primitives.js +4 -1
- package/dist/primitives.js.map +1 -1
- package/dist/structures.d.ts +2 -2
- package/dist/structures.js +1 -1
- package/dist/structures.js.map +1 -1
- package/eslint.config.js +16 -1
- package/package.json +35 -23
- package/scripts/bump-and-release.ps1 +2 -0
- package/scripts/release.ps1 +10 -0
- package/src/compound.ts +9 -6
- package/src/errors.ts +1 -1
- package/src/helpers.ts +2 -2
- package/src/index.ts +6 -6
- package/src/macros.ts +11 -9
- package/src/primitives.ts +5 -3
- package/src/structures.ts +4 -2
- package/tests/compound.test.ts +3 -1
- package/tests/macros.test.ts +3 -1
- package/tests/primitives.test.ts +4 -1
- package/tests/structures.test.ts +3 -1
- package/tsconfig.common.json +24 -0
- package/tsconfig.json +2 -19
- package/tsconfig.test.json +7 -0
package/.yarnrc.yml
ADDED
package/dist/compound.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { GuardSchemaOf } from "./helpers";
|
|
2
|
-
import { Guard } from "./types";
|
|
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,
|
package/dist/compound.js
CHANGED
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,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mBAAmB,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;AACjD,CAAC"}
|
package/dist/errors.d.ts
CHANGED
package/dist/helpers.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Guard } from "./types";
|
|
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/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from "./compound";
|
|
2
|
-
export * from "./errors";
|
|
3
|
-
export * from "./macros";
|
|
4
|
-
export * from "./primitives";
|
|
5
|
-
export * from "./structures";
|
|
6
|
-
export * from "./types";
|
|
1
|
+
export * from "./compound.js";
|
|
2
|
+
export * from "./errors.js";
|
|
3
|
+
export * from "./macros.js";
|
|
4
|
+
export * from "./primitives.js";
|
|
5
|
+
export * from "./structures.js";
|
|
6
|
+
export * from "./types.js";
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export * from "./compound";
|
|
2
|
-
export * from "./errors";
|
|
3
|
-
export * from "./macros";
|
|
4
|
-
export * from "./primitives";
|
|
5
|
-
export * from "./structures";
|
|
6
|
-
export * from "./types";
|
|
1
|
+
export * from "./compound.js";
|
|
2
|
+
export * from "./errors.js";
|
|
3
|
+
export * from "./macros.js";
|
|
4
|
+
export * from "./primitives.js";
|
|
5
|
+
export * from "./structures.js";
|
|
6
|
+
export * from "./types.js";
|
|
7
7
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["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.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ObjectKey } from "./helpers";
|
|
2
|
-
import { Guard } from "./types";
|
|
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { isExact } from "./compound";
|
|
2
|
-
import { omit } from "./helpers";
|
|
3
|
-
import { isObjectOf } from "./structures";
|
|
1
|
+
import { isExact } from "./compound.js";
|
|
2
|
+
import { omit } from "./helpers.js";
|
|
3
|
+
import { isObjectOf } from "./structures.js";
|
|
4
4
|
export function isDiscriminatedObjectOf(value, guard, key = "type") {
|
|
5
5
|
const discriminatorGuard = isObjectOf({ [key]: isExact(value) });
|
|
6
6
|
return (value) => discriminatorGuard(value) && guard(omit(value, key));
|
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,
|
|
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";
|
|
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,8 @@ 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
|
-
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
|
+
export const isFunction = (value
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
|
+
) => typeof value === "function";
|
|
10
13
|
//# 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,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,MAAM,CAAC,MAAM,UAAU,
|
|
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,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;AACL,8DAA8D;EACxB,EAAE,CAAC,OAAO,KAAK,KAAK,UAAU,CAAC"}
|
package/dist/structures.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { GuardSchemaOf, ObjectKey } from "./helpers";
|
|
2
|
-
import { Guard } from "./types";
|
|
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
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { objectKeys } from "./helpers";
|
|
1
|
+
import { objectKeys } from "./helpers.js";
|
|
2
2
|
export const isAnyArray = (value) => Array.isArray(value);
|
|
3
3
|
export const isAnyRecord = (value) => value != null && typeof value === "object" && !Array.isArray(value);
|
|
4
4
|
export function isArrayOf(guard) {
|
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,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,KAA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B,UAAU,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,MAAM,CAAC,GAAG,CAAC,KAAK,UAAU,CAAC,EAC3D,CAAC;QACD,MAAM,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/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
|
@@ -4,39 +4,51 @@
|
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"name": "deep-guards",
|
|
7
|
-
"packageManager": "yarn@
|
|
7
|
+
"packageManager": "yarn@4.9.2",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"types": "dist/index.d.ts",
|
|
10
10
|
"homepage": "https://github.com/eniallator/Deep-Guards",
|
|
11
|
-
"version": "1.0
|
|
11
|
+
"version": "1.1.0",
|
|
12
12
|
"scripts": {
|
|
13
13
|
"test": "jest",
|
|
14
14
|
"build": "tsc",
|
|
15
|
-
"lint": "eslint ./src",
|
|
15
|
+
"lint": "eslint ./src ./tests",
|
|
16
16
|
"typecheck": "tsc --noEmit",
|
|
17
|
-
"findissues": "yarn typecheck && yarn lint"
|
|
17
|
+
"findissues": "yarn typecheck && yarn lint",
|
|
18
|
+
"publish": "npm publish --tolerate-republish",
|
|
19
|
+
"prepublish": "yarn typecheck && yarn lint && yarn build && yarn test",
|
|
20
|
+
"bump-and-release": "powershell -ExecutionPolicy Bypass -File ./scripts/bump-and-release.ps1",
|
|
21
|
+
"release": "powershell -ExecutionPolicy Bypass -File ./scripts/release.ps1"
|
|
18
22
|
},
|
|
19
23
|
"devDependencies": {
|
|
20
|
-
"@babel/core": "^7.
|
|
21
|
-
"@babel/preset-env": "^7.
|
|
22
|
-
"@babel/preset-typescript": "^7.
|
|
23
|
-
"@eslint/compat": "^1.2
|
|
24
|
-
"@eslint/js": "^9.
|
|
25
|
-
"@jest/globals": "^
|
|
24
|
+
"@babel/core": "^7.28.3",
|
|
25
|
+
"@babel/preset-env": "^7.28.3",
|
|
26
|
+
"@babel/preset-typescript": "^7.27.1",
|
|
27
|
+
"@eslint/compat": "^1.3.2",
|
|
28
|
+
"@eslint/js": "^9.33.0",
|
|
29
|
+
"@jest/globals": "^30.0.5",
|
|
30
|
+
"@stylistic/eslint-plugin": "^5.2.3",
|
|
26
31
|
"@types/babel__core": "^7.20.5",
|
|
27
|
-
"@types/babel__preset-env": "^7.
|
|
28
|
-
"@types/
|
|
29
|
-
"@types/
|
|
30
|
-
"@
|
|
31
|
-
"@typescript-eslint/
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"eslint": "^9.15.0",
|
|
32
|
+
"@types/babel__preset-env": "^7.10.0",
|
|
33
|
+
"@types/eslint__js": "^9.14.0",
|
|
34
|
+
"@types/jest": "^30.0.0",
|
|
35
|
+
"@typescript-eslint/eslint-plugin": "^8.39.1",
|
|
36
|
+
"@typescript-eslint/parser": "^8.39.1",
|
|
37
|
+
"babel-jest": "^30.0.5",
|
|
38
|
+
"eslint": "^9.33.0",
|
|
35
39
|
"eslint-plugin-eslint-comments": "^3.2.0",
|
|
36
|
-
"eslint-plugin-import": "^2.
|
|
37
|
-
"eslint-plugin-jest": "^
|
|
38
|
-
"jest": "^
|
|
39
|
-
"
|
|
40
|
-
"typescript
|
|
40
|
+
"eslint-plugin-import": "^2.32.0",
|
|
41
|
+
"eslint-plugin-jest": "^29.0.1",
|
|
42
|
+
"jest": "^30.0.5",
|
|
43
|
+
"ts-jest": "^29.4.1",
|
|
44
|
+
"typescript": "^5.9.2",
|
|
45
|
+
"typescript-eslint": "^8.39.1"
|
|
46
|
+
},
|
|
47
|
+
"jest": {
|
|
48
|
+
"globals": {
|
|
49
|
+
"ts-jest": {
|
|
50
|
+
"tsConfig": "tsconfig.test.json"
|
|
51
|
+
}
|
|
52
|
+
}
|
|
41
53
|
}
|
|
42
54
|
}
|
package/src/compound.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
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") {
|
|
@@ -22,7 +24,9 @@ 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
|
|
|
@@ -38,10 +42,9 @@ export function isNot<const N>(guard: Guard<N>) {
|
|
|
38
42
|
|
|
39
43
|
export function isOneOf<
|
|
40
44
|
const T extends (string | number | boolean | symbol | null | undefined)[]
|
|
41
|
-
>(...values: T): Guard<
|
|
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[]>(
|
package/src/errors.ts
CHANGED
package/src/helpers.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Guard } from "./types";
|
|
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]>;
|
|
@@ -11,7 +11,7 @@ export const objectKeys = <K extends ObjectKey>(obj: Record<K, unknown>): K[] =>
|
|
|
11
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
16
|
key: keyof O
|
|
17
17
|
): { [K in keyof O as K extends typeof key ? never : K]: O[K] } {
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from "./compound";
|
|
2
|
-
export * from "./errors";
|
|
3
|
-
export * from "./macros";
|
|
4
|
-
export * from "./primitives";
|
|
5
|
-
export * from "./structures";
|
|
6
|
-
export * from "./types";
|
|
1
|
+
export * from "./compound.js";
|
|
2
|
+
export * from "./errors.js";
|
|
3
|
+
export * from "./macros.js";
|
|
4
|
+
export * from "./primitives.js";
|
|
5
|
+
export * from "./structures.js";
|
|
6
|
+
export * from "./types.js";
|
package/src/macros.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { isExact } from "./compound";
|
|
2
|
-
import {
|
|
3
|
-
import { isObjectOf } from "./structures";
|
|
4
|
-
|
|
1
|
+
import { isExact } from "./compound.js";
|
|
2
|
+
import { omit } from "./helpers.js";
|
|
3
|
+
import { isObjectOf } from "./structures.js";
|
|
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,
|
|
@@ -19,10 +21,10 @@ export function isDiscriminatedObjectOf<
|
|
|
19
21
|
value: T,
|
|
20
22
|
guard: Guard<O>,
|
|
21
23
|
key: ObjectKey = "type"
|
|
22
|
-
): Guard<
|
|
23
|
-
const discriminatorGuard = isObjectOf({ [key]: isExact(value) }) as Guard<
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return (value): value is
|
|
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
|
}
|
package/src/primitives.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Guard } from "./types";
|
|
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
|
-
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
22
|
+
export const isFunction: Guard<(...args: any[]) => unknown> = (
|
|
22
23
|
value
|
|
23
|
-
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
25
|
+
): value is (...args: any[]) => unknown => typeof value === "function";
|
package/src/structures.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { objectKeys } from "./helpers.js";
|
|
2
|
+
|
|
3
|
+
import type { GuardSchemaOf, ObjectKey } from "./helpers.js";
|
|
4
|
+
import type { Guard } from "./types.js";
|
|
3
5
|
|
|
4
6
|
export const isAnyArray: Guard<unknown[]> = (value) => Array.isArray(value);
|
|
5
7
|
|
package/tests/compound.test.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { describe, expect, it } from "@jest/globals";
|
|
2
|
+
|
|
1
3
|
import {
|
|
2
4
|
isExact,
|
|
3
5
|
isIntersectionOf,
|
|
@@ -9,7 +11,7 @@ import {
|
|
|
9
11
|
isOptional,
|
|
10
12
|
isString,
|
|
11
13
|
isUnionOf,
|
|
12
|
-
} from "../
|
|
14
|
+
} from "../dist";
|
|
13
15
|
|
|
14
16
|
describe("isOptional", () => {
|
|
15
17
|
const guard = isOptional(isString);
|
package/tests/macros.test.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { describe, expect, it } from "@jest/globals";
|
|
2
|
+
|
|
3
|
+
import { isDiscriminatedObjectOf, isObjectOf, isString } from "../dist";
|
|
2
4
|
|
|
3
5
|
describe("isDiscriminatedObjectOf", () => {
|
|
4
6
|
describe("no key override", () => {
|
package/tests/primitives.test.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { describe, expect, it } from "@jest/globals";
|
|
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 "../dist";
|
|
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/tests/structures.test.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { describe, expect, it } from "@jest/globals";
|
|
2
|
+
|
|
1
3
|
import {
|
|
2
4
|
isAnyArray,
|
|
3
5
|
isAnyRecord,
|
|
@@ -9,7 +11,7 @@ import {
|
|
|
9
11
|
isString,
|
|
10
12
|
isSymbol,
|
|
11
13
|
isTupleOf,
|
|
12
|
-
} from "../
|
|
14
|
+
} from "../dist";
|
|
13
15
|
|
|
14
16
|
describe("isAnyArray", () => {
|
|
15
17
|
it("succeeds for an array", () => {
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"allowJs": false,
|
|
4
|
+
"allowSyntheticDefaultImports": true,
|
|
5
|
+
"declaration": true,
|
|
6
|
+
"downlevelIteration": true,
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
"forceConsistentCasingInFileNames": true,
|
|
9
|
+
"isolatedModules": true,
|
|
10
|
+
"lib": ["dom", "dom.iterable", "esnext"],
|
|
11
|
+
"module": "esnext",
|
|
12
|
+
"moduleResolution": "Bundler",
|
|
13
|
+
"noErrorTruncation": true,
|
|
14
|
+
"noFallthroughCasesInSwitch": true,
|
|
15
|
+
"noUncheckedIndexedAccess": true,
|
|
16
|
+
"resolveJsonModule": true,
|
|
17
|
+
"rewriteRelativeImportExtensions": true,
|
|
18
|
+
"skipLibCheck": true,
|
|
19
|
+
"sourceMap": true,
|
|
20
|
+
"strict": true,
|
|
21
|
+
"target": "esnext",
|
|
22
|
+
"types": ["node"]
|
|
23
|
+
}
|
|
24
|
+
}
|
package/tsconfig.json
CHANGED
|
@@ -1,25 +1,8 @@
|
|
|
1
1
|
{
|
|
2
|
+
"extends": "./tsconfig.common.json",
|
|
2
3
|
"include": ["src"],
|
|
3
4
|
"compilerOptions": {
|
|
4
|
-
"allowJs": false,
|
|
5
|
-
"allowSyntheticDefaultImports": true,
|
|
6
|
-
"declaration": true,
|
|
7
|
-
"downlevelIteration": true,
|
|
8
|
-
"esModuleInterop": true,
|
|
9
|
-
"forceConsistentCasingInFileNames": true,
|
|
10
|
-
"isolatedModules": true,
|
|
11
|
-
"lib": ["esnext"],
|
|
12
|
-
"module": "esnext",
|
|
13
|
-
"sourceRoot": "src",
|
|
14
|
-
"moduleResolution": "Bundler",
|
|
15
|
-
"noErrorTruncation": true,
|
|
16
|
-
"noFallthroughCasesInSwitch": true,
|
|
17
|
-
"noUncheckedIndexedAccess": true,
|
|
18
5
|
"outDir": "dist",
|
|
19
|
-
"
|
|
20
|
-
"skipLibCheck": true,
|
|
21
|
-
"sourceMap": true,
|
|
22
|
-
"strict": true,
|
|
23
|
-
"target": "esnext"
|
|
6
|
+
"sourceRoot": "src"
|
|
24
7
|
}
|
|
25
8
|
}
|