@byloth/core 2.1.2 → 2.1.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@byloth/core",
3
- "version": "2.1.2",
3
+ "version": "2.1.3",
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",
@@ -51,14 +51,14 @@
51
51
  "devDependencies": {
52
52
  "@byloth/eslint-config-typescript": "^3.1.0",
53
53
  "@eslint/compat": "^1.2.9",
54
- "@types/node": "^22.15.21",
55
- "@vitest/coverage-v8": "^3.1.4",
56
- "eslint": "^9.27.0",
54
+ "@types/node": "^22.15.30",
55
+ "@vitest/coverage-v8": "^3.2.2",
56
+ "eslint": "^9.28.0",
57
57
  "husky": "^9.1.7",
58
58
  "jsdom": "^26.1.0",
59
59
  "typescript": "^5.8.3",
60
60
  "vite": "^6.3.5",
61
- "vitest": "^3.1.4"
61
+ "vitest": "^3.2.2"
62
62
  },
63
63
  "scripts": {
64
64
  "dev": "vite",
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- export const VERSION = "2.1.2";
1
+ export const VERSION = "2.1.3";
2
2
 
3
3
  export type { Constructor, Interval, Timeout, ValueOf } from "./core/types.js";
4
4
 
@@ -1,5 +1,3 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
-
3
1
  import type { Callback } from "./types.js";
4
2
 
5
3
  const SmartFunction = (Function as unknown) as new<A extends unknown[] = [], R = void>(...args: string[])
@@ -34,6 +32,7 @@ const SmartFunction = (Function as unknown) as new<A extends unknown[] = [], R =
34
32
  * The type signature of the callback function.
35
33
  * It must be a function. Default is `(...args: any[]) => any`.
36
34
  */
35
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
37
36
  export default abstract class CallableObject<T extends Callback<any[], any> = () => void>
38
37
  extends SmartFunction<Parameters<T>, ReturnType<T>>
39
38
  {
@@ -148,11 +148,11 @@ export default class Publisher<T extends CallbackMap<T> = CallbackMap>
148
148
  */
149
149
  public subscribe<K extends keyof T>(event: K & string, subscriber: T[K]): () => void
150
150
  {
151
- if (!(this._subscribers.has(event))) { this._subscribers.set(event, []); }
152
-
153
- const subscribers = this._subscribers.get(event)!;
151
+ const subscribers = this._subscribers.get(event) ?? [];
154
152
  subscribers.push(subscriber);
155
153
 
154
+ this._subscribers.set(event, subscribers);
155
+
156
156
  return () =>
157
157
  {
158
158
  const index = subscribers.indexOf(subscriber);
@@ -189,7 +189,11 @@ export default class Publisher<T extends CallbackMap<T> = CallbackMap>
189
189
  public unsubscribe<K extends keyof T>(event: K & string, subscriber: T[K]): void
190
190
  {
191
191
  const subscribers = this._subscribers.get(event);
192
- if (!(subscribers)) { return; }
192
+ if (!(subscribers))
193
+ {
194
+ throw new ReferenceException("Unable to unsubscribe the required subscriber. " +
195
+ "The subscription was already unsubscribed or was never subscribed.");
196
+ }
193
197
 
194
198
  const index = subscribers.indexOf(subscriber);
195
199
  if (index < 0)
@@ -199,6 +203,7 @@ export default class Publisher<T extends CallbackMap<T> = CallbackMap>
199
203
  }
200
204
 
201
205
  subscribers.splice(index, 1);
206
+ if (subscribers.length === 0) { this._subscribers.delete(event); }
202
207
  }
203
208
 
204
209
  public readonly [Symbol.toStringTag]: string = "Publisher";
@@ -1,5 +1,6 @@
1
1
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
2
2
  import type MapView from "./map-view.js";
3
+
3
4
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
4
5
  import type SetView from "./set-view.js";
5
6
 
package/src/utils/date.ts CHANGED
@@ -1,3 +1,4 @@
1
+ /* eslint-disable @typescript-eslint/prefer-literal-enum-member */
1
2
 
2
3
  import { RangeException, SmartIterator } from "../models/index.js";
3
4
 
@@ -15,8 +16,6 @@ import { RangeException, SmartIterator } from "../models/index.js";
15
16
  */
16
17
  export enum TimeUnit
17
18
  {
18
- /* eslint-disable @typescript-eslint/prefer-literal-enum-member */
19
-
20
19
  /**
21
20
  * A millisecond: the base time unit.
22
21
  */