@byloth/core 2.0.0-rc.11 → 2.0.0-rc.12

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.0.0-rc.11",
3
+ "version": "2.0.0-rc.12",
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",
@@ -48,7 +48,7 @@
48
48
  "types": "./src/index.ts",
49
49
  "devDependencies": {
50
50
  "@byloth/eslint-config-typescript": "^3.0.3",
51
- "@types/node": "^22.10.1",
51
+ "@types/node": "^22.10.2",
52
52
  "husky": "^9.1.7",
53
53
  "typescript": "^5.7.2",
54
54
  "vite": "^5.4.11"
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- export const VERSION = "2.0.0-rc.11";
1
+ export const VERSION = "2.0.0-rc.12";
2
2
 
3
3
  export type { Constructor, Interval, Timeout } from "./core/types.js";
4
4
 
@@ -78,6 +78,7 @@ export {
78
78
  capitalize,
79
79
  chain,
80
80
  count,
81
+ Curve,
81
82
  delay,
82
83
  dateDifference,
83
84
  dateRange,
@@ -2,16 +2,15 @@
2
2
 
3
3
  import type { Callback } from "./types.js";
4
4
 
5
- export const SmartFunction = (Function as unknown) as
6
- new<T extends Callback<any[], any> = () => void>(...args: string[]) =>
7
- (...args: Parameters<T>) => ReturnType<T>;
5
+ export const SmartFunction = (Function as unknown) as new<A extends unknown[] = [], R = void>(...args: string[])
6
+ => (...args: A) => R;
8
7
 
9
8
  export default abstract class CallableObject<T extends Callback<any[], any> = () => void>
10
- extends SmartFunction<T>
9
+ extends SmartFunction<Parameters<T>, ReturnType<T>>
11
10
  {
12
11
  public constructor()
13
12
  {
14
- super(`return this.invoke(...arguments);`);
13
+ super(`return this._invoke(...arguments);`);
15
14
 
16
15
  const self = this.bind(this);
17
16
  Object.setPrototypeOf(this, self);
@@ -19,7 +18,7 @@ export default abstract class CallableObject<T extends Callback<any[], any> = ()
19
18
  return self as this;
20
19
  }
21
20
 
22
- public abstract invoke(...args: Parameters<T>): ReturnType<T>;
21
+ protected abstract _invoke(...args: Parameters<T>): ReturnType<T>;
23
22
 
24
23
  public readonly [Symbol.toStringTag]: string = "CallableObject";
25
24
  }
@@ -15,7 +15,7 @@ export default class SwitchableCallback<T extends Callback<any[], any> = Callbac
15
15
  protected _key: string;
16
16
  public get key(): string { return this._key; }
17
17
 
18
- public readonly invoke: (...args: Parameters<T>) => ReturnType<T>;
18
+ protected readonly _invoke: (...args: Parameters<T>) => ReturnType<T>;
19
19
 
20
20
  public constructor()
21
21
  {
@@ -35,7 +35,7 @@ export default class SwitchableCallback<T extends Callback<any[], any> = Callbac
35
35
  this._isEnabled = true;
36
36
  this._key = "";
37
37
 
38
- this.invoke = (...args: Parameters<T>): ReturnType<T> => this._callback(...args);
38
+ this._invoke = (...args: Parameters<T>): ReturnType<T> => this._callback(...args);
39
39
  }
40
40
 
41
41
  public enable(): void
@@ -106,5 +106,5 @@ export default class SwitchableCallback<T extends Callback<any[], any> = Callbac
106
106
  }
107
107
  }
108
108
 
109
- public readonly [Symbol.toStringTag]: string = "SwitchableCallback";
109
+ public override readonly [Symbol.toStringTag]: string = "SwitchableCallback";
110
110
  }
@@ -55,7 +55,7 @@ export class FatalErrorException extends Exception
55
55
  super(message, cause, name);
56
56
  }
57
57
 
58
- public readonly [Symbol.toStringTag]: string = "FatalErrorException";
58
+ public override readonly [Symbol.toStringTag]: string = "FatalErrorException";
59
59
  }
60
60
  export class NotImplementedException extends FatalErrorException
61
61
  {
@@ -69,5 +69,5 @@ export class NotImplementedException extends FatalErrorException
69
69
  super(message, cause, name);
70
70
  }
71
71
 
72
- public readonly [Symbol.toStringTag]: string = "NotImplementedException";
72
+ public override readonly [Symbol.toStringTag]: string = "NotImplementedException";
73
73
  }
@@ -7,7 +7,7 @@ export class FileException extends Exception
7
7
  super(message, cause, name);
8
8
  }
9
9
 
10
- public readonly [Symbol.toStringTag]: string = "FileException";
10
+ public override readonly [Symbol.toStringTag]: string = "FileException";
11
11
  }
12
12
  export class FileExistsException extends FileException
13
13
  {
@@ -16,7 +16,7 @@ export class FileExistsException extends FileException
16
16
  super(message, cause, name);
17
17
  }
18
18
 
19
- public readonly [Symbol.toStringTag]: string = "FileExistsException";
19
+ public override readonly [Symbol.toStringTag]: string = "FileExistsException";
20
20
  }
21
21
  export class FileNotFoundException extends FileException
22
22
  {
@@ -25,7 +25,7 @@ export class FileNotFoundException extends FileException
25
25
  super(message, cause, name);
26
26
  }
27
27
 
28
- public readonly [Symbol.toStringTag]: string = "FileNotFoundException";
28
+ public override readonly [Symbol.toStringTag]: string = "FileNotFoundException";
29
29
  }
30
30
 
31
31
  export class KeyException extends Exception
@@ -35,7 +35,7 @@ export class KeyException extends Exception
35
35
  super(message, cause, name);
36
36
  }
37
37
 
38
- public readonly [Symbol.toStringTag]: string = "KeyException";
38
+ public override readonly [Symbol.toStringTag]: string = "KeyException";
39
39
  }
40
40
  export class NetworkException extends Exception
41
41
  {
@@ -44,7 +44,7 @@ export class NetworkException extends Exception
44
44
  super(message, cause, name);
45
45
  }
46
46
 
47
- public readonly [Symbol.toStringTag]: string = "NetworkException";
47
+ public override readonly [Symbol.toStringTag]: string = "NetworkException";
48
48
  }
49
49
  export class PermissionException extends Exception
50
50
  {
@@ -53,7 +53,7 @@ export class PermissionException extends Exception
53
53
  super(message, cause, name);
54
54
  }
55
55
 
56
- public readonly [Symbol.toStringTag]: string = "PermissionException";
56
+ public override readonly [Symbol.toStringTag]: string = "PermissionException";
57
57
  }
58
58
  export class ReferenceException extends Exception
59
59
  {
@@ -62,7 +62,7 @@ export class ReferenceException extends Exception
62
62
  super(message, cause, name);
63
63
  }
64
64
 
65
- public readonly [Symbol.toStringTag]: string = "ReferenceException";
65
+ public override readonly [Symbol.toStringTag]: string = "ReferenceException";
66
66
  }
67
67
 
68
68
  export class RuntimeException extends Exception
@@ -72,7 +72,7 @@ export class RuntimeException extends Exception
72
72
  super(message, cause, name);
73
73
  }
74
74
 
75
- public readonly [Symbol.toStringTag]: string = "RuntimeException";
75
+ public override readonly [Symbol.toStringTag]: string = "RuntimeException";
76
76
  }
77
77
  export class EnvironmentException extends RuntimeException
78
78
  {
@@ -81,7 +81,7 @@ export class EnvironmentException extends RuntimeException
81
81
  super(message, cause, name);
82
82
  }
83
83
 
84
- public readonly [Symbol.toStringTag]: string = "EnvironmentException";
84
+ public override readonly [Symbol.toStringTag]: string = "EnvironmentException";
85
85
  }
86
86
 
87
87
  export class TimeoutException extends Exception
@@ -91,7 +91,7 @@ export class TimeoutException extends Exception
91
91
  super(message, cause, name);
92
92
  }
93
93
 
94
- public readonly [Symbol.toStringTag]: string = "TimeoutException";
94
+ public override readonly [Symbol.toStringTag]: string = "TimeoutException";
95
95
  }
96
96
  export class TypeException extends Exception
97
97
  {
@@ -100,7 +100,7 @@ export class TypeException extends Exception
100
100
  super(message, cause, name);
101
101
  }
102
102
 
103
- public readonly [Symbol.toStringTag]: string = "TypeException";
103
+ public override readonly [Symbol.toStringTag]: string = "TypeException";
104
104
  }
105
105
 
106
106
  export class ValueException extends Exception
@@ -110,7 +110,7 @@ export class ValueException extends Exception
110
110
  super(message, cause, name);
111
111
  }
112
112
 
113
- public readonly [Symbol.toStringTag]: string = "ValueException";
113
+ public override readonly [Symbol.toStringTag]: string = "ValueException";
114
114
  }
115
115
  export class RangeException extends ValueException
116
116
  {
@@ -119,7 +119,7 @@ export class RangeException extends ValueException
119
119
  super(message, cause, name);
120
120
  }
121
121
 
122
- public readonly [Symbol.toStringTag]: string = "RangeException";
122
+ public override readonly [Symbol.toStringTag]: string = "RangeException";
123
123
  }
124
124
 
125
125
  export { Exception };
@@ -37,5 +37,5 @@ export default class DeferredPromise<T = void, F = T, R = never> extends SmartPr
37
37
  return this;
38
38
  }
39
39
 
40
- public readonly [Symbol.toStringTag]: string = "DeferredPromise";
40
+ public override readonly [Symbol.toStringTag]: string = "DeferredPromise";
41
41
  }
@@ -27,5 +27,5 @@ export default class TimedPromise<T = void> extends SmartPromise<T>
27
27
  });
28
28
  }
29
29
 
30
- public readonly [Symbol.toStringTag]: string = "TimedPromise";
30
+ public override readonly [Symbol.toStringTag]: string = "TimedPromise";
31
31
  }
@@ -22,7 +22,7 @@ export default class Clock extends GameLoop
22
22
  this._publisher = new Publisher();
23
23
  }
24
24
 
25
- public start(elapsedTime = 0): void
25
+ public override start(elapsedTime = 0): void
26
26
  {
27
27
  if (this._isRunning) { throw new RuntimeException("The clock has already been started."); }
28
28
 
@@ -31,7 +31,7 @@ export default class Clock extends GameLoop
31
31
  this._publisher.publish("start");
32
32
  }
33
33
 
34
- public stop(): void
34
+ public override stop(): void
35
35
  {
36
36
  if (!(this._isRunning)) { throw new RuntimeException("The clock hadn't yet started."); }
37
37
 
@@ -65,5 +65,5 @@ export default class Clock extends GameLoop
65
65
  });
66
66
  }
67
67
 
68
- public readonly [Symbol.toStringTag]: string = "Clock";
68
+ public override readonly [Symbol.toStringTag]: string = "Clock";
69
69
  }
@@ -64,7 +64,7 @@ export default class Countdown extends GameLoop
64
64
  this._deferrer = undefined;
65
65
  }
66
66
 
67
- public start(remainingTime: number = this.duration): SmartPromise<void>
67
+ public override start(remainingTime: number = this.duration): SmartPromise<void>
68
68
  {
69
69
  if (this._isRunning) { throw new RuntimeException("The countdown has already been started."); }
70
70
  if (this._deferrer) { throw new FatalErrorException(); }
@@ -76,7 +76,7 @@ export default class Countdown extends GameLoop
76
76
 
77
77
  return this._deferrer;
78
78
  }
79
- public stop(reason?: unknown): void
79
+ public override stop(reason?: unknown): void
80
80
  {
81
81
  this._deferrerStop(reason);
82
82
 
@@ -113,5 +113,5 @@ export default class Countdown extends GameLoop
113
113
  });
114
114
  }
115
115
 
116
- public readonly [Symbol.toStringTag]: string = "Countdown";
116
+ public override readonly [Symbol.toStringTag]: string = "Countdown";
117
117
  }
@@ -0,0 +1,27 @@
1
+ import { SmartIterator } from "../models/index.js";
2
+
3
+ export default class Curve
4
+ {
5
+ public static Linear(values: number): SmartIterator<number>
6
+ {
7
+ const step = (1 / values);
8
+
9
+ return new SmartIterator<number>(function* ()
10
+ {
11
+ for (let index = 0; index < values; index += 1) { yield index * step; }
12
+ });
13
+ }
14
+ public static Exponential(values: number, base = 2): SmartIterator<number>
15
+ {
16
+ const steps = (values - 1);
17
+
18
+ return new SmartIterator<number>(function* ()
19
+ {
20
+ for (let index = 0; index < values; index += 1) { yield Math.pow(index / steps, base); }
21
+ });
22
+ }
23
+
24
+ private constructor() { /* ... */ }
25
+
26
+ public readonly [Symbol.toStringTag]: string = "Curve";
27
+ }
@@ -1,3 +1,4 @@
1
+ import Curve from "./curve.js";
1
2
  import Random from "./random.js";
2
3
 
3
4
  export { delay, nextAnimationFrame, yieldToEventLoop } from "./async.js";
@@ -7,4 +8,4 @@ export { chain, count, enumerate, range, shuffle, unique, zip } from "./iterator
7
8
  export { average, hash, sum } from "./math.js";
8
9
  export { capitalize } from "./string.js";
9
10
 
10
- export { Random };
11
+ export { Curve, Random };