@byloth/core 2.0.0 → 2.0.2

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 (39) hide show
  1. package/README.md +1 -0
  2. package/dist/core.js +900 -187
  3. package/dist/core.js.map +1 -1
  4. package/dist/core.umd.cjs +2 -2
  5. package/dist/core.umd.cjs.map +1 -1
  6. package/package.json +13 -10
  7. package/src/core/types.ts +43 -10
  8. package/src/index.ts +3 -2
  9. package/src/models/aggregators/aggregated-async-iterator.ts +161 -1
  10. package/src/models/aggregators/aggregated-iterator.ts +146 -1
  11. package/src/models/aggregators/reduced-iterator.ts +148 -8
  12. package/src/models/aggregators/types.ts +35 -0
  13. package/src/models/callbacks/callable-object.ts +7 -0
  14. package/src/models/callbacks/publisher.ts +33 -8
  15. package/src/models/callbacks/switchable-callback.ts +102 -21
  16. package/src/models/callbacks/types.ts +32 -0
  17. package/src/models/exceptions/core.ts +29 -0
  18. package/src/models/exceptions/index.ts +105 -1
  19. package/src/models/iterators/smart-async-iterator.ts +145 -0
  20. package/src/models/iterators/smart-iterator.ts +130 -0
  21. package/src/models/iterators/types.ts +79 -1
  22. package/src/models/json/json-storage.ts +123 -0
  23. package/src/models/json/types.ts +1 -1
  24. package/src/models/promises/deferred-promise.ts +15 -0
  25. package/src/models/promises/smart-promise.ts +45 -0
  26. package/src/models/promises/timed-promise.ts +10 -0
  27. package/src/models/promises/types.ts +30 -0
  28. package/src/models/timers/clock.ts +21 -0
  29. package/src/models/timers/countdown.ts +30 -0
  30. package/src/models/timers/game-loop.ts +26 -0
  31. package/src/models/types.ts +1 -1
  32. package/src/utils/async.ts +15 -0
  33. package/src/utils/curve.ts +11 -1
  34. package/src/utils/date.ts +36 -6
  35. package/src/utils/dom.ts +5 -0
  36. package/src/utils/iterator.ts +40 -0
  37. package/src/utils/math.ts +15 -0
  38. package/src/utils/random.ts +34 -0
  39. package/src/utils/string.ts +5 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@byloth/core",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "An unopinionated collection of useful functions and classes that I use widely in all my projects. 🔧",
5
5
  "keywords": [
6
6
  "Core",
@@ -31,8 +31,8 @@
31
31
  "dist",
32
32
  "src"
33
33
  ],
34
- "main": "./dist/core.umd.cjs",
35
- "module": "./dist/core.js",
34
+ "main": "dist/core.umd.cjs",
35
+ "module": "dist/core.js",
36
36
  "exports": {
37
37
  ".": {
38
38
  "import": {
@@ -45,16 +45,18 @@
45
45
  }
46
46
  }
47
47
  },
48
- "types": "./src/index.ts",
48
+ "types": "src/index.ts",
49
49
  "devDependencies": {
50
50
  "@byloth/eslint-config-typescript": "^3.1.0",
51
- "@eslint/compat": "^1.2.6",
52
- "@types/node": "^22.13.0",
51
+ "@eslint/compat": "^1.2.8",
52
+ "@types/node": "^22.14.1",
53
+ "@vitest/coverage-v8": "^3.1.1",
54
+ "eslint": "^9.25.0",
53
55
  "husky": "^9.1.7",
54
- "jsdom": "^26.0.0",
55
- "typescript": "^5.7.3",
56
- "vite": "^6.0.11",
57
- "vitest": "^3.0.4"
56
+ "jsdom": "^26.1.0",
57
+ "typescript": "^5.8.3",
58
+ "vite": "^6.3.2",
59
+ "vitest": "^3.1.1"
58
60
  },
59
61
  "scripts": {
60
62
  "dev": "vite",
@@ -63,6 +65,7 @@
63
65
  "typecheck": "tsc",
64
66
  "lint": "eslint .",
65
67
  "test": "vitest run",
68
+ "test:coverage": "vitest run --coverage",
66
69
  "ci": "pnpm install --frozen-lockfile"
67
70
  }
68
71
  }
package/src/core/types.ts CHANGED
@@ -1,7 +1,10 @@
1
1
  /**
2
- * A utility type that allows to define a class constructor of a specific type.
3
- * Is the counterpart of the native `InstanceType` utility type.
2
+ * An utility type that allows to define a class constructor of a specific type.
3
+ * Is the counterpart of the native {@link InstanceType} utility type.
4
4
  *
5
+ * ---
6
+ *
7
+ * @example
5
8
  * ```ts
6
9
  * function factory<T extends object>(Factory: Constructor<T>): T { [...] }
7
10
  *
@@ -12,14 +15,17 @@
12
15
  export type Constructor<T extends object, P extends unknown[] = any[]> = new (...args: P) => T;
13
16
 
14
17
  /**
15
- * A type that represents the return value of `setInterval` function,
18
+ * A type that represents the return value of {@link setInterval} function,
16
19
  * indipendently from the platform it's currently running on.
17
20
  *
18
- * For instance, in a browser environment, it's a `number` value representing the interval ID.
19
- * In a Node.js environment, on the other hand, it's an object of type `NodeJS.Timeout`.
21
+ * For instance, in a browser environment, it's a {@link Number} value representing the interval ID.
22
+ * In a Node.js environment, on the other hand, it's an object of type {@link NodeJS.Timeout}.
23
+ *
24
+ * This allows to seamlessly use the same code in both environments, without having to deal with the differences.
20
25
  *
21
- * This allows to seamlessly use the same code in both environments, without having to deal with the differences:
26
+ * ---
22
27
  *
28
+ * @example
23
29
  * ```ts
24
30
  * const intervalId: Interval = setInterval(() => { [...] }, 1_000);
25
31
  *
@@ -29,14 +35,17 @@ export type Constructor<T extends object, P extends unknown[] = any[]> = new (..
29
35
  export type Interval = ReturnType<typeof setInterval>;
30
36
 
31
37
  /**
32
- * A type that represents the return value of `setTimeout` function,
38
+ * A type that represents the return value of {@link setTimeout} function,
33
39
  * indipendently from the platform it's currently running on.
34
40
  *
35
- * For instance, in a browser environment, it's a `number` value representing the timeout ID.
36
- * In a Node.js environment, on the other hand, it's an object of type `NodeJS.Timeout`.
41
+ * For instance, in a browser environment, it's a {@link Number} value representing the timeout ID.
42
+ * In a Node.js environment, on the other hand, it's an object of type {@link NodeJS.Timeout}.
37
43
  *
38
- * This allows to seamlessly use the same code in both environments, without having to deal with the differences:
44
+ * This allows to seamlessly use the same code in both environments, without having to deal with the differences.
39
45
  *
46
+ * ---
47
+ *
48
+ * @example
40
49
  * ```ts
41
50
  * const timeoutId: Timeout = setTimeout(() => { [...] }, 1_000);
42
51
  *
@@ -44,3 +53,27 @@ export type Interval = ReturnType<typeof setInterval>;
44
53
  * ```
45
54
  */
46
55
  export type Timeout = ReturnType<typeof setTimeout>;
56
+
57
+ /**
58
+ * An utility type that allows to extract the union of the values of a given type.
59
+ * It can be used to extract the values of all the properties of an object type.
60
+ *
61
+ * ---
62
+ *
63
+ * @example
64
+ * ```ts
65
+ * class MyObject
66
+ * {
67
+ * protected secret = "Sssh! That's a secret!";
68
+ * public answer = 42;
69
+ * public greet() { console.log("Hello, world!"); }
70
+ * }
71
+ *
72
+ * type MyObjectProperties = ValueOf<MyObject>; // number | (() => void)
73
+ * ```
74
+ *
75
+ * ---
76
+ *
77
+ * @template T The type to extract the values from.
78
+ */
79
+ export type ValueOf<T> = T[keyof T];
package/src/index.ts CHANGED
@@ -1,6 +1,6 @@
1
- export const VERSION = "2.0.0";
1
+ export const VERSION = "2.0.2";
2
2
 
3
- export type { Constructor, Interval, Timeout } from "./core/types.js";
3
+ export type { Constructor, Interval, Timeout, ValueOf } from "./core/types.js";
4
4
 
5
5
  export { isBrowser, isNode, isWorker } from "./helpers.js";
6
6
 
@@ -47,6 +47,7 @@ export type {
47
47
  AsyncKeyedReducer,
48
48
  AsyncReducer,
49
49
  Callback,
50
+ CallbackMap,
50
51
  FulfilledHandler,
51
52
  GeneratorFunction,
52
53
  Iteratee,