@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.
Files changed (49) hide show
  1. package/build/main.js +6 -3
  2. package/build/utils/assert.js +42 -15
  3. package/build/utils/is.js +33 -4
  4. package/build/utils/isNonNullable.js +23 -4
  5. package/build/utils/tuple.js +6 -4
  6. package/package.json +5 -5
  7. package/build/main.js.map +0 -7
  8. package/build/types/AtLeastOneRequired.js +0 -2
  9. package/build/types/AtLeastOneRequired.js.map +0 -7
  10. package/build/types/DeepPartial.js +0 -2
  11. package/build/types/DeepPartial.js.map +0 -7
  12. package/build/types/DeepReadonly.js +0 -2
  13. package/build/types/DeepReadonly.js.map +0 -7
  14. package/build/types/If.js +0 -2
  15. package/build/types/If.js.map +0 -7
  16. package/build/types/IsEqual.js +0 -2
  17. package/build/types/IsEqual.js.map +0 -7
  18. package/build/types/LiteralUnion.js +0 -2
  19. package/build/types/LiteralUnion.js.map +0 -7
  20. package/build/types/NonArray.js +0 -2
  21. package/build/types/NonArray.js.map +0 -7
  22. package/build/types/NonArrayLike.js +0 -2
  23. package/build/types/NonArrayLike.js.map +0 -7
  24. package/build/types/OptionalKeys.js +0 -2
  25. package/build/types/OptionalKeys.js.map +0 -7
  26. package/build/types/Parameters.js +0 -2
  27. package/build/types/Parameters.js.map +0 -7
  28. package/build/types/Primitive.js +0 -2
  29. package/build/types/Primitive.js.map +0 -7
  30. package/build/types/RequiredKeys.js +0 -2
  31. package/build/types/RequiredKeys.js.map +0 -7
  32. package/build/types/ReturnType.js +0 -2
  33. package/build/types/ReturnType.js.map +0 -7
  34. package/build/types/Simplify.js +0 -2
  35. package/build/types/Simplify.js.map +0 -7
  36. package/build/types/TupleToUnion.js +0 -2
  37. package/build/types/TupleToUnion.js.map +0 -7
  38. package/build/types/UnionToIntersection.js +0 -2
  39. package/build/types/UnionToIntersection.js.map +0 -7
  40. package/build/types/Writable.js +0 -2
  41. package/build/types/Writable.js.map +0 -7
  42. package/build/types.js +0 -2
  43. package/build/types.js.map +0 -7
  44. package/build/utils/assert.js.map +0 -7
  45. package/build/utils/is.js.map +0 -7
  46. package/build/utils/isNonNullable.js.map +0 -7
  47. package/build/utils/tuple.js.map +0 -7
  48. package/build/utils.js +0 -6
  49. package/build/utils.js.map +0 -7
package/build/main.js CHANGED
@@ -1,3 +1,6 @@
1
- "use strict";
2
- export * from "./utils.js";
3
- //# sourceMappingURL=main.js.map
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 };
@@ -1,16 +1,43 @@
1
- "use strict";
2
- export class AssertionError extends Error {
3
- /**
4
- * @param message Message added to the default error message
5
- */
6
- constructor(message) {
7
- super(`Wrong assertion encountered${message ? `: "${message}"` : ""}!`);
8
- this.name = "AssertionError";
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
- export function assert(condition, errorMessage) {
12
- if (!condition) {
13
- throw new AssertionError(errorMessage);
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
- "use strict";
2
- export function is(value, isMatched) {
3
- return isMatched;
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
- //# sourceMappingURL=is.js.map
32
+
33
+ //#endregion
34
+ export { is };
@@ -1,5 +1,24 @@
1
- "use strict";
2
- export function isNonNullable(value) {
3
- return value !== void 0 && value !== null;
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
- //# sourceMappingURL=isNonNullable.js.map
22
+
23
+ //#endregion
24
+ export { isNonNullable };
@@ -1,5 +1,7 @@
1
- "use strict";
2
- export function tuple(...values) {
3
- return values;
1
+ //#region source/utils/tuple.ts
2
+ function tuple(...values) {
3
+ return values;
4
4
  }
5
- //# sourceMappingURL=tuple.js.map
5
+
6
+ //#endregion
7
+ export { tuple };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jakubmazanec/ts-utils",
3
- "version": "3.0.16",
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 && esbuild \"source/**/*\" --platform=node --target=node24.3 --outdir=build --sourcemap && tsc",
20
+ "build": "del-cli build tsconfig.tsbuildinfo && tsdown && tsc",
21
21
  "clean": "del-cli coverage build *.tsbuildinfo",
22
- "develop": "concurrently \"esbuild \"source/**/*\" --platform=node --target=node24.3 --outdir=build --sourcemap --watch\" \"tsc --watch\"",
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": "^4.1.0",
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
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../source/main.ts"],
4
- "sourcesContent": ["export type * from './types.js';\nexport * from './utils.js';\n"],
5
- "mappings": ";AACA,cAAc;",
6
- "names": []
7
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- //# sourceMappingURL=AtLeastOneRequired.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": [],
4
- "sourcesContent": [],
5
- "mappings": "",
6
- "names": []
7
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- //# sourceMappingURL=DeepPartial.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": [],
4
- "sourcesContent": [],
5
- "mappings": "",
6
- "names": []
7
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- //# sourceMappingURL=DeepReadonly.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": [],
4
- "sourcesContent": [],
5
- "mappings": "",
6
- "names": []
7
- }
package/build/types/If.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- //# sourceMappingURL=If.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": [],
4
- "sourcesContent": [],
5
- "mappings": "",
6
- "names": []
7
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- //# sourceMappingURL=IsEqual.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": [],
4
- "sourcesContent": [],
5
- "mappings": "",
6
- "names": []
7
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- //# sourceMappingURL=LiteralUnion.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": [],
4
- "sourcesContent": [],
5
- "mappings": "",
6
- "names": []
7
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- //# sourceMappingURL=NonArray.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": [],
4
- "sourcesContent": [],
5
- "mappings": "",
6
- "names": []
7
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- //# sourceMappingURL=NonArrayLike.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": [],
4
- "sourcesContent": [],
5
- "mappings": "",
6
- "names": []
7
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- //# sourceMappingURL=OptionalKeys.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": [],
4
- "sourcesContent": [],
5
- "mappings": "",
6
- "names": []
7
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- //# sourceMappingURL=Parameters.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": [],
4
- "sourcesContent": [],
5
- "mappings": "",
6
- "names": []
7
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- //# sourceMappingURL=Primitive.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": [],
4
- "sourcesContent": [],
5
- "mappings": "",
6
- "names": []
7
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- //# sourceMappingURL=RequiredKeys.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": [],
4
- "sourcesContent": [],
5
- "mappings": "",
6
- "names": []
7
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- //# sourceMappingURL=ReturnType.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": [],
4
- "sourcesContent": [],
5
- "mappings": "",
6
- "names": []
7
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- //# sourceMappingURL=Simplify.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": [],
4
- "sourcesContent": [],
5
- "mappings": "",
6
- "names": []
7
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- //# sourceMappingURL=TupleToUnion.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": [],
4
- "sourcesContent": [],
5
- "mappings": "",
6
- "names": []
7
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- //# sourceMappingURL=UnionToIntersection.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": [],
4
- "sourcesContent": [],
5
- "mappings": "",
6
- "names": []
7
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- //# sourceMappingURL=Writable.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": [],
4
- "sourcesContent": [],
5
- "mappings": "",
6
- "names": []
7
- }
package/build/types.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- //# sourceMappingURL=types.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": [],
4
- "sourcesContent": [],
5
- "mappings": "",
6
- "names": []
7
- }
@@ -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
- }
@@ -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
- }
@@ -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
@@ -1,6 +0,0 @@
1
- "use strict";
2
- export * from "./utils/assert.js";
3
- export * from "./utils/is.js";
4
- export * from "./utils/isNonNullable.js";
5
- export * from "./utils/tuple.js";
6
- //# sourceMappingURL=utils.js.map
@@ -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
- }