@jakubmazanec/ts-utils 3.0.16 → 3.0.17-unstable.2468857d
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/build/main.js +6 -3
- package/build/utils/assert.js +42 -15
- package/build/utils/is.js +33 -4
- package/build/utils/isNonNullable.js +23 -4
- package/build/utils/tuple.js +6 -4
- package/package.json +5 -5
- package/build/main.js.map +0 -7
- package/build/types/AtLeastOneRequired.js +0 -2
- package/build/types/AtLeastOneRequired.js.map +0 -7
- package/build/types/DeepPartial.js +0 -2
- package/build/types/DeepPartial.js.map +0 -7
- package/build/types/DeepReadonly.js +0 -2
- package/build/types/DeepReadonly.js.map +0 -7
- package/build/types/If.js +0 -2
- package/build/types/If.js.map +0 -7
- package/build/types/IsEqual.js +0 -2
- package/build/types/IsEqual.js.map +0 -7
- package/build/types/LiteralUnion.js +0 -2
- package/build/types/LiteralUnion.js.map +0 -7
- package/build/types/NonArray.js +0 -2
- package/build/types/NonArray.js.map +0 -7
- package/build/types/NonArrayLike.js +0 -2
- package/build/types/NonArrayLike.js.map +0 -7
- package/build/types/OptionalKeys.js +0 -2
- package/build/types/OptionalKeys.js.map +0 -7
- package/build/types/Parameters.js +0 -2
- package/build/types/Parameters.js.map +0 -7
- package/build/types/Primitive.js +0 -2
- package/build/types/Primitive.js.map +0 -7
- package/build/types/RequiredKeys.js +0 -2
- package/build/types/RequiredKeys.js.map +0 -7
- package/build/types/ReturnType.js +0 -2
- package/build/types/ReturnType.js.map +0 -7
- package/build/types/Simplify.js +0 -2
- package/build/types/Simplify.js.map +0 -7
- package/build/types/TupleToUnion.js +0 -2
- package/build/types/TupleToUnion.js.map +0 -7
- package/build/types/UnionToIntersection.js +0 -2
- package/build/types/UnionToIntersection.js.map +0 -7
- package/build/types/Writable.js +0 -2
- package/build/types/Writable.js.map +0 -7
- package/build/types.js +0 -2
- package/build/types.js.map +0 -7
- package/build/utils/assert.js.map +0 -7
- package/build/utils/is.js.map +0 -7
- package/build/utils/isNonNullable.js.map +0 -7
- package/build/utils/tuple.js.map +0 -7
- package/build/utils.js +0 -6
- package/build/utils.js.map +0 -7
package/build/main.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { AssertionError, assert } from "./utils/assert.js";
|
|
2
|
+
import { is } from "./utils/is.js";
|
|
3
|
+
import { isNonNullable } from "./utils/isNonNullable.js";
|
|
4
|
+
import { tuple } from "./utils/tuple.js";
|
|
5
|
+
|
|
6
|
+
export { AssertionError, assert, is, isNonNullable, tuple };
|
package/build/utils/assert.js
CHANGED
|
@@ -1,16 +1,43 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
//#region source/utils/assert.ts
|
|
2
|
+
/**
|
|
3
|
+
* A subclass of `Error` that indicates an assertion failure.
|
|
4
|
+
*/
|
|
5
|
+
var AssertionError = class extends Error {
|
|
6
|
+
/**
|
|
7
|
+
* @param message Message added to the default error message
|
|
8
|
+
*/
|
|
9
|
+
constructor(message) {
|
|
10
|
+
super(`Wrong assertion encountered${message ? `: "${message}"` : ""}!`);
|
|
11
|
+
this.name = "AssertionError";
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* A function that throws {@link AssertionError} (with optional message defined with `errorMessage`) if
|
|
16
|
+
* `condition` is falsy.
|
|
17
|
+
* You can use it to narrow types:
|
|
18
|
+
*
|
|
19
|
+
* ```TypeScript
|
|
20
|
+
* interface Foo {
|
|
21
|
+
* kind: 'Foo';
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* interface Bar {
|
|
25
|
+
* kind: 'Bar';
|
|
26
|
+
* }
|
|
27
|
+
*
|
|
28
|
+
* declare const foobar: Foo | Bar;
|
|
29
|
+
*
|
|
30
|
+
* assert(is<Foo>(foobar, foobar.kind === 'Foo'));
|
|
31
|
+
*
|
|
32
|
+
* // `typeof foobar` is now `Foo`
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @param condition Condition we're asserting isn't falsy
|
|
36
|
+
* @param errorMessage Message for the `AssertionError`
|
|
37
|
+
*/
|
|
38
|
+
function assert(condition, errorMessage) {
|
|
39
|
+
if (!condition) throw new AssertionError(errorMessage);
|
|
10
40
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
//# sourceMappingURL=assert.js.map
|
|
41
|
+
|
|
42
|
+
//#endregion
|
|
43
|
+
export { AssertionError, assert };
|
package/build/utils/is.js
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
//#region source/utils/is.ts
|
|
2
|
+
/**
|
|
3
|
+
* A generic type guard. If `isMatched` is `true`, TypeScript assumes `value` is of type `T`.
|
|
4
|
+
* You can use it to narrow types:
|
|
5
|
+
*
|
|
6
|
+
* ```TypeScript
|
|
7
|
+
* interface Foo {
|
|
8
|
+
* value: string;
|
|
9
|
+
* }
|
|
10
|
+
*
|
|
11
|
+
* interface Bar {
|
|
12
|
+
* value: number;
|
|
13
|
+
* }
|
|
14
|
+
*
|
|
15
|
+
* declare let foobar: Foo | Bar;
|
|
16
|
+
*
|
|
17
|
+
* if (is<Foo>(foobar, typeof foobar.value === 'string')) {
|
|
18
|
+
* // `typeof foobar` is now `Foo`
|
|
19
|
+
* } else {
|
|
20
|
+
* // `typeof foobar` is now `Bar`
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @typeParam T Potential type of `value`
|
|
25
|
+
* @param value Value being checked
|
|
26
|
+
* @param isMatched Specifies if `value` is of type `T`
|
|
27
|
+
* @return Value of `isMatched`
|
|
28
|
+
*/
|
|
29
|
+
function is(value, isMatched) {
|
|
30
|
+
return isMatched;
|
|
4
31
|
}
|
|
5
|
-
|
|
32
|
+
|
|
33
|
+
//#endregion
|
|
34
|
+
export { is };
|
|
@@ -1,5 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
//#region source/utils/isNonNullable.ts
|
|
2
|
+
/**
|
|
3
|
+
* A type guard that checks whether variable is not `null` or `undefined`:
|
|
4
|
+
*
|
|
5
|
+
* ```TypeScript
|
|
6
|
+
* declare let foobar: string | null;
|
|
7
|
+
*
|
|
8
|
+
* if (isNonNullable(foobar)) {
|
|
9
|
+
* // `typeof foobar` is now `string`
|
|
10
|
+
* } else {
|
|
11
|
+
* // `typeof foobar` is now `null`
|
|
12
|
+
* }
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* @typeParam T Type of `value`
|
|
16
|
+
* @param value Value being checked
|
|
17
|
+
* @return `true` if `value` is non-nullable
|
|
18
|
+
*/
|
|
19
|
+
function isNonNullable(value) {
|
|
20
|
+
return value !== void 0 && value !== null;
|
|
4
21
|
}
|
|
5
|
-
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
export { isNonNullable };
|
package/build/utils/tuple.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jakubmazanec/ts-utils",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.17-unstable.2468857d",
|
|
4
4
|
"description": "Collection of TypeScript types and utilities.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
"source"
|
|
18
18
|
],
|
|
19
19
|
"scripts": {
|
|
20
|
-
"build": "del-cli build tsconfig.tsbuildinfo &&
|
|
20
|
+
"build": "del-cli build tsconfig.tsbuildinfo && tsdown && tsc",
|
|
21
21
|
"clean": "del-cli coverage build *.tsbuildinfo",
|
|
22
|
-
"develop": "concurrently \"
|
|
22
|
+
"develop": "concurrently \"tsdown --watch\" \"tsc --watch\"",
|
|
23
23
|
"document": "del-cli docs && typedoc --options typedoc.config.cjs",
|
|
24
24
|
"format": "prettier . --write --ignore-unknown",
|
|
25
25
|
"lint": "eslint .",
|
|
@@ -27,17 +27,17 @@
|
|
|
27
27
|
"typecheck": "tsc --project tsconfig.typecheck.json"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@jakubmazanec/eslint-config": "
|
|
30
|
+
"@jakubmazanec/eslint-config": "4.1.10-unstable.2468857d",
|
|
31
31
|
"@types/lodash": "^4.17.21",
|
|
32
32
|
"@types/node": "^24.0.4",
|
|
33
33
|
"@vitest/coverage-v8": "^3.2.4",
|
|
34
34
|
"concurrently": "^9.2.1",
|
|
35
35
|
"del-cli": "^6.0.0",
|
|
36
|
-
"esbuild": "^0.27.0",
|
|
37
36
|
"eslint": "^9.33.0",
|
|
38
37
|
"lodash": "^4.17.21",
|
|
39
38
|
"prettier": "^3.6.2",
|
|
40
39
|
"prettier-plugin-packagejson": "^2.5.19",
|
|
40
|
+
"tsdown": "^0.17.2",
|
|
41
41
|
"typedoc": "^0.28.14",
|
|
42
42
|
"typedoc-plugin-markdown": "^4.9.0",
|
|
43
43
|
"typescript": "^5.9.3",
|
package/build/main.js.map
DELETED
package/build/types/If.js
DELETED
package/build/types/If.js.map
DELETED
package/build/types/IsEqual.js
DELETED
package/build/types/NonArray.js
DELETED
package/build/types/Primitive.js
DELETED
package/build/types/Simplify.js
DELETED
package/build/types/Writable.js
DELETED
package/build/types.js
DELETED
package/build/types.js.map
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../source/utils/assert.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * A subclass of `Error` that indicates an assertion failure.\n */\nexport class AssertionError extends Error {\n /**\n * @param message Message added to the default error message\n */\n constructor(message?: string) {\n super(`Wrong assertion encountered${message ? `: \"${message}\"` : ''}!`);\n\n this.name = 'AssertionError';\n }\n}\n\n/**\n * A function that throws {@link AssertionError} (with optional message defined with `errorMessage`) if\n * `condition` is falsy.\n * You can use it to narrow types:\n *\n * ```TypeScript\n * interface Foo {\n * kind: 'Foo';\n * }\n *\n * interface Bar {\n * kind: 'Bar';\n * }\n *\n * declare const foobar: Foo | Bar;\n *\n * assert(is<Foo>(foobar, foobar.kind === 'Foo'));\n *\n * // `typeof foobar` is now `Foo`\n * ```\n *\n * @param condition Condition we're asserting isn't falsy\n * @param errorMessage Message for the `AssertionError`\n */\nexport function assert(condition: unknown, errorMessage?: string): asserts condition {\n // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions -- we don't mind here\n if (!condition) {\n throw new AssertionError(errorMessage);\n }\n}\n"],
|
|
5
|
-
"mappings": ";AAGO,aAAM,uBAAuB,MAAM;AAAA;AAAA;AAAA;AAAA,EAIxC,YAAY,SAAkB;AAC5B,UAAM,8BAA8B,UAAU,MAAM,OAAO,MAAM,EAAE,GAAG;AAEtE,SAAK,OAAO;AAAA,EACd;AACF;AA0BO,gBAAS,OAAO,WAAoB,cAA0C;AAEnF,MAAI,CAAC,WAAW;AACd,UAAM,IAAI,eAAe,YAAY;AAAA,EACvC;AACF;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
package/build/utils/is.js.map
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../source/utils/is.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * A generic type guard. If `isMatched` is `true`, TypeScript assumes `value` is of type `T`.\n * You can use it to narrow types:\n *\n * ```TypeScript\n * interface Foo {\n * value: string;\n * }\n *\n * interface Bar {\n * value: number;\n * }\n *\n * declare let foobar: Foo | Bar;\n *\n * if (is<Foo>(foobar, typeof foobar.value === 'string')) {\n * // `typeof foobar` is now `Foo`\n * } else {\n * // `typeof foobar` is now `Bar`\n * }\n * ```\n *\n * @typeParam T Potential type of `value`\n * @param value Value being checked\n * @param isMatched Specifies if `value` is of type `T`\n * @return Value of `isMatched`\n */\nexport function is<T>(value: unknown, isMatched: boolean): value is T {\n return isMatched;\n}\n"],
|
|
5
|
-
"mappings": ";AA2BO,gBAAS,GAAM,OAAgB,WAAgC;AACpE,SAAO;AACT;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../source/utils/isNonNullable.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * A type guard that checks whether variable is not `null` or `undefined`:\n *\n * ```TypeScript\n * declare let foobar: string | null;\n *\n * if (isNonNullable(foobar)) {\n * // `typeof foobar` is now `string`\n * } else {\n * // `typeof foobar` is now `null`\n * }\n * ```\n *\n * @typeParam T Type of `value`\n * @param value Value being checked\n * @return `true` if `value` is non-nullable\n */\nexport function isNonNullable<T>(value: T): value is NonNullable<T> {\n return value !== undefined && value !== null;\n}\n"],
|
|
5
|
-
"mappings": ";AAiBO,gBAAS,cAAiB,OAAmC;AAClE,SAAO,UAAU,UAAa,UAAU;AAC1C;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
package/build/utils/tuple.js.map
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../source/utils/tuple.ts"],
|
|
4
|
-
"sourcesContent": ["import {type Primitive} from '../types.js';\n\n// eslint-disable-next-line @typescript-eslint/no-empty-object-type -- this is intended\nexport function tuple<T extends Array<Primitive | {}>>(...values: T) {\n return values;\n}\n"],
|
|
5
|
-
"mappings": ";AAGO,gBAAS,SAA0C,QAAW;AACnE,SAAO;AACT;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
package/build/utils.js
DELETED
package/build/utils.js.map
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../source/utils.ts"],
|
|
4
|
-
"sourcesContent": ["export * from './utils/assert.js';\nexport * from './utils/is.js';\nexport * from './utils/isNonNullable.js';\nexport * from './utils/tuple.js';\n"],
|
|
5
|
-
"mappings": ";AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|