adaptive-extender 0.2.5

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 (45) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/README.md +1 -0
  3. package/dist/core/array.d.ts +42 -0
  4. package/dist/core/array.js +40 -0
  5. package/dist/core/array.js.map +1 -0
  6. package/dist/core/boolean.d.ts +14 -0
  7. package/dist/core/boolean.js +8 -0
  8. package/dist/core/boolean.js.map +1 -0
  9. package/dist/core/color.d.ts +369 -0
  10. package/dist/core/color.js +541 -0
  11. package/dist/core/color.js.map +1 -0
  12. package/dist/core/date.d.ts +27 -0
  13. package/dist/core/date.js +18 -0
  14. package/dist/core/date.js.map +1 -0
  15. package/dist/core/error.d.ts +20 -0
  16. package/dist/core/error.js +20 -0
  17. package/dist/core/error.js.map +1 -0
  18. package/dist/core/global.d.ts +14 -0
  19. package/dist/core/global.js +13 -0
  20. package/dist/core/global.js.map +1 -0
  21. package/dist/core/index.d.ts +17 -0
  22. package/dist/core/index.js +16 -0
  23. package/dist/core/index.js.map +1 -0
  24. package/dist/core/math.d.ts +44 -0
  25. package/dist/core/math.js +43 -0
  26. package/dist/core/math.js.map +1 -0
  27. package/dist/core/number.d.ts +59 -0
  28. package/dist/core/number.js +51 -0
  29. package/dist/core/number.js.map +1 -0
  30. package/dist/core/object.d.ts +30 -0
  31. package/dist/core/object.js +21 -0
  32. package/dist/core/object.js.map +1 -0
  33. package/dist/core/primitives.d.ts +10 -0
  34. package/dist/core/primitives.js +3 -0
  35. package/dist/core/primitives.js.map +1 -0
  36. package/dist/core/promise.d.ts +28 -0
  37. package/dist/core/promise.js +58 -0
  38. package/dist/core/promise.js.map +1 -0
  39. package/dist/core/random.d.ts +103 -0
  40. package/dist/core/random.js +114 -0
  41. package/dist/core/random.js.map +1 -0
  42. package/dist/core/string.d.ts +67 -0
  43. package/dist/core/string.js +44 -0
  44. package/dist/core/string.js.map +1 -0
  45. package/package.json +42 -0
@@ -0,0 +1,14 @@
1
+ declare global {
2
+ /**
3
+ * Returns the prototype of the given non-nullable value.
4
+ * @param value The value whose prototype is to be retrieved. It cannot be null or undefined.
5
+ */
6
+ function prototype<T>(value: NonNullable<T>): Function;
7
+ /**
8
+ * Gets the type name of a value.
9
+ * @param value The value to get the type name of.
10
+ * @returns The type name of the value.
11
+ */
12
+ function typename(value: any): string;
13
+ }
14
+ export {};
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ globalThis.prototype = function (value) {
3
+ return value.constructor;
4
+ };
5
+ globalThis.typename = function (value) {
6
+ switch (value) {
7
+ case undefined: return "Undefined";
8
+ case null: return "Null";
9
+ default: return prototype(value).name;
10
+ }
11
+ };
12
+ export {};
13
+ //# sourceMappingURL=global.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"global.js","sourceRoot":"","sources":["../../src/core/global.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAgBb,UAAU,CAAC,SAAS,GAAG,UAAa,KAAqB;IACxD,OAAO,KAAK,CAAC,WAAW,CAAC;AAC1B,CAAC,CAAC;AAEF,UAAU,CAAC,QAAQ,GAAG,UAAU,KAAU;IACzC,QAAQ,KAAK,EAAE,CAAC;QACf,KAAK,SAAS,CAAC,CAAC,OAAO,WAAW,CAAC;QACnC,KAAK,IAAI,CAAC,CAAC,OAAO,MAAM,CAAC;QACzB,OAAO,CAAC,CAAC,OAAO,SAAS,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC;IACvC,CAAC;AACF,CAAC,CAAC"}
@@ -0,0 +1,17 @@
1
+ import "./global.js";
2
+ import { PrimitivesHintMap } from "./primitives.js";
3
+ import "./number.js";
4
+ import "./string.js";
5
+ import "./boolean.js";
6
+ import "./date.js";
7
+ import "./math.js";
8
+ import "./array.js";
9
+ import "./object.js";
10
+ import "./error.js";
11
+ import { ImplementationError } from "./error.js";
12
+ import "./promise.js";
13
+ import { Promisable } from "./promise.js";
14
+ import { Random } from "./random.js";
15
+ import { ColorFormats, ColorProperties, Color } from "./color.js";
16
+ export { PrimitivesHintMap, Promisable, ColorProperties };
17
+ export { ImplementationError, Random, ColorFormats, Color };
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ import "./global.js";
3
+ import "./number.js";
4
+ import "./string.js";
5
+ import "./boolean.js";
6
+ import "./date.js";
7
+ import "./math.js";
8
+ import "./array.js";
9
+ import "./object.js";
10
+ import "./error.js";
11
+ import { ImplementationError } from "./error.js";
12
+ import "./promise.js";
13
+ import { Random } from "./random.js";
14
+ import { ColorFormats, Color } from "./color.js";
15
+ export { ImplementationError, Random, ColorFormats, Color };
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,aAAa,CAAC;AAErB,OAAO,aAAa,CAAC;AACrB,OAAO,aAAa,CAAC;AACrB,OAAO,cAAc,CAAC;AACtB,OAAO,WAAW,CAAC;AACnB,OAAO,WAAW,CAAC;AACnB,OAAO,YAAY,CAAC;AACpB,OAAO,aAAa,CAAC;AACrB,OAAO,YAAY,CAAC;AACpB,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,cAAc,CAAC;AAEtB,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,YAAY,EAAmB,KAAK,EAAE,MAAM,YAAY,CAAC;AAGlE,OAAO,EAAE,mBAAmB,EAAE,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC"}
@@ -0,0 +1,44 @@
1
+ declare global {
2
+ interface Math {
3
+ /**
4
+ * Splits a number into its integer and fractional parts.
5
+ * @param x The number to be split.
6
+ * @returns A tuple where the first element is the integer part and the second element is the fractional part.
7
+ * ```ts
8
+ * const [integer, fractional] = Math.split(x);
9
+ * ```
10
+ */
11
+ split(x: number): [number, number];
12
+ /**
13
+ * Calculates the square of a number.
14
+ * @param x The number to square.
15
+ */
16
+ sqpw(x: number): number;
17
+ /**
18
+ * Converts radians to degrees.
19
+ * @param radians The angle in radians.
20
+ */
21
+ toDegrees(radians: number): number;
22
+ /**
23
+ * Converts degrees to radians.
24
+ * @param degrees The angle in degrees.
25
+ */
26
+ toRadians(degrees: number): number;
27
+ /**
28
+ * Calculates the arithmetic mean of the given numbers.
29
+ * @param values The numbers to calculate the mean from.
30
+ */
31
+ meanArithmetic(...values: number[]): number;
32
+ /**
33
+ * Calculates the geometric mean of the given numbers.
34
+ * @param values The numbers to calculate the mean from.
35
+ */
36
+ meanGeometric(...values: number[]): number;
37
+ /**
38
+ * Calculates the harmonic mean of the given numbers.
39
+ * @param values The numbers to calculate the mean from.
40
+ */
41
+ meanHarmonic(...values: number[]): number;
42
+ }
43
+ }
44
+ export {};
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ const { PI, trunc, pow } = Math;
3
+ Math.split = function (x) {
4
+ const integer = trunc(x);
5
+ return [integer, (x - integer)];
6
+ };
7
+ Math.sqpw = function (x) {
8
+ return x * x;
9
+ };
10
+ const toDegreeFactor = 180 / PI;
11
+ Math.toDegrees = function (radians) {
12
+ return radians * toDegreeFactor;
13
+ };
14
+ const toRadianFactor = PI / 180;
15
+ Math.toRadians = function (degrees) {
16
+ return degrees * toRadianFactor;
17
+ };
18
+ Math.meanArithmetic = function (...values) {
19
+ let summary = 0;
20
+ for (let index = 0; index < values.length; index++) {
21
+ summary += values[index];
22
+ }
23
+ return summary / values.length;
24
+ };
25
+ Math.meanGeometric = function (...values) {
26
+ let product = 1;
27
+ for (let index = 0; index < values.length; index++) {
28
+ product *= values[index];
29
+ }
30
+ return pow(product, 1 / values.length);
31
+ };
32
+ Math.meanHarmonic = function (...values) {
33
+ let summary = 0;
34
+ for (let index = 0; index < values.length; index++) {
35
+ const value = values[index];
36
+ if (value === 0)
37
+ return NaN;
38
+ summary += 1 / value;
39
+ }
40
+ return values.length / summary;
41
+ };
42
+ export {};
43
+ //# sourceMapp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AAE,KAAK,EAAE,EAAE,CAAC;QACpD,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC;IAC1B,CAAC;IACD,OAAO,GAAG,CAAC,OAAO,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;AACxC,CAAC,CAAC;AAEF,IAAI,CAAC,YAAY,GAAG,UAAU,GAAG,MAAgB;IAChD,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;QACpD,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;QAC5B,IAAI,KAAK,KAAK,CAAC;YAAE,OAAO,GAAG,CAAC;QAC5B,OAAO,IAAI,CAAC,GAAG,KAAK,CAAC;IACtB,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,GAAG,OAAO,CAAC;AAChC,CAAC,CAAC"}
@@ -0,0 +1,59 @@
1
+ import "./global.js";
2
+ declare global {
3
+ interface NumberConstructor {
4
+ /**
5
+ * Imports a number from a source.
6
+ * @param source The source value to import.
7
+ * @param name The name of the source value.
8
+ * @returns The imported number value.
9
+ * @throws {TypeError} If the source is not a number.
10
+ */
11
+ import(source: any, name?: string): number;
12
+ }
13
+ interface Number {
14
+ /**
15
+ * Clamps a value between a minimum and maximum.
16
+ * @param min The minimum value.
17
+ * @param max The maximum value.
18
+ * @returns The clamped value.
19
+ */
20
+ clamp(min: number, max: number): number;
21
+ /**
22
+ * Interpolates the number from one range to another.
23
+ * @param min1 The minimum value of the original range.
24
+ * @param max1 The maximum value of the original range.
25
+ * @param min2 The minimum value of the target range. Defaults to 0.
26
+ * @param max2 The maximum value of the target range. Defaults to 1.
27
+ * @returns The interpolated value within the target range.
28
+ * @throws {Error} If the minimum and maximum of either range are equal.
29
+ */
30
+ interpolate(min1: number, max1: number, min2?: number, max2?: number): number;
31
+ /**
32
+ * Modulates the current number within a specified range.
33
+ * @param length The range length.
34
+ * @param start The start of the range. Defaults to 0.
35
+ * @returns The number constrained within the range.
36
+ * @throws {Error} If the range is zero.
37
+ */
38
+ modulate(length: number, start?: number): number;
39
+ /**
40
+ * Returns the current number unless it is NaN, replacing it with the provided value.
41
+ * @param value The fallback value.
42
+ * @returns The original number or the fallback.
43
+ */
44
+ insteadNaN<T>(value: T): number | T;
45
+ /**
46
+ * Returns the current number unless it is NaN or infinite, replacing it with the provided value.
47
+ * @param value The fallback value.
48
+ * @returns The original number or the fallback.
49
+ */
50
+ insteadInfinity<T>(value: T): number | T;
51
+ /**
52
+ * Returns the current number unless it is zero, NaN, or infinite, replacing it with the provided value.
53
+ * @param value The fallback value.
54
+ * @returns The original number or the fallback.
55
+ */
56
+ insteadZero<T>(value: T): number | T;
57
+ }
58
+ }
59
+ export {};
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ import "./global.js";
3
+ Number.import = function (source, name = "[source]") {
4
+ if (typeof (source) !== "number")
5
+ throw new TypeError(`Unable to import number from ${name} due its ${typename(source)} type`);
6
+ return source.valueOf();
7
+ };
8
+ Number.prototype.clamp = function (min, max) {
9
+ let value = this.valueOf();
10
+ if (value < min)
11
+ return min;
12
+ if (value > max)
13
+ return max;
14
+ return value;
15
+ };
16
+ Number.prototype.interpolate = function (min1, max1, min2 = 0, max2 = 1) {
17
+ if (min1 === max1)
18
+ throw new Error("Minimum and maximum of the original range cant be equal");
19
+ if (min2 === max2)
20
+ throw new Error("Minimum and maximum of the target range cant be equal");
21
+ return min2 + (max2 - min2) * ((this.valueOf() - min1) / (max1 - min1));
22
+ };
23
+ Number.prototype.modulate = function (length, start = 0) {
24
+ if (length === 0)
25
+ throw new Error("Range can't be zero");
26
+ let value = (this.valueOf() - start) % length;
27
+ if (value < 0)
28
+ value += length;
29
+ return value + start;
30
+ };
31
+ Number.prototype.insteadNaN = function (value) {
32
+ const current = this.valueOf();
33
+ if (Number.isNaN(current))
34
+ return value;
35
+ return current;
36
+ };
37
+ Number.prototype.insteadInfinity = function (value) {
38
+ const current = this.valueOf();
39
+ if (!Number.isFinite(current))
40
+ return value;
41
+ return current;
42
+ };
43
+ Number.prototype.insteadZero = function (value) {
44
+ const current = this.valueOf();
45
+ if (!Number.isFinite(current))
46
+ return value;
47
+ if (current === 0)
48
+ return value;
49
+ return current;
50
+ };
51
+ //# sourceMappingURL=number.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"number.js","sourceRoot":"","sources":["../../src/core/number.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,aAAa,CAAC;AA6DrB,MAAM,CAAC,MAAM,GAAG,UAAU,MAAW,EAAE,OAAe,UAAU;IAC/D,IAAI,OAAO,CAAC,MAAM,CAAC,KAAK,QAAQ;QAAE,MAAM,IAAI,SAAS,CAAC,gCAAgC,IAAI,YAAY,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC/H,OAAO,MAAM,CAAC,OAAO,EAAE,CAAC;AACzB,CAAC,CAAC;AAEF,MAAM,CAAC,SAAS,CAAC,KAAK,GAAG,UAAU,GAAW,EAAE,GAAW;IAC1D,IAAI,KAAK,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;IAC3B,IAAI,KAAK,GAAG,GAAG;QAAE,OAAO,GAAG,CAAC;IAC5B,IAAI,KAAK,GAAG,GAAG;QAAE,OAAO,GAAG,CAAC;IAC5B,OAAO,KAAK,CAAC;AACd,CAAC,CAAC;AAEF,MAAM,CAAC,SAAS,CAAC,WAAW,GAAG,UAAU,IAAY,EAAE,IAAY,EAAE,OAAe,CAAC,EAAE,OAAe,CAAC;IACtG,IAAI,IAAI,KAAK,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;IAC9F,IAAI,IAAI,KAAK,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;IAC5F,OAAO,IAAI,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,C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 -0,0 +1,30 @@
1
+ declare global {
2
+ interface ObjectConstructor {
3
+ /**
4
+ * Imports an object from a source.
5
+ * @param source The source to import from.
6
+ * @param name The name of the source.
7
+ * @returns The imported object.
8
+ * @throws {TypeError} If the source is not an object or null.
9
+ */
10
+ import(source: any, name?: string): object;
11
+ /**
12
+ * Applies a callback function to a non-nullable value, or returns the original nullable value.
13
+ * @template T The type of the input value.
14
+ * @template N The type representing nullable.
15
+ * @template R The return type of the callback function.
16
+ * @param value The value to map.
17
+ * @param callback The function to apply if the value is non-nullable.
18
+ * @returns The mapped result.
19
+ */
20
+ map<T, N extends Exclude<T, NonNullable<T>>, R>(value: NonNullable<T> | N, callback: (object: NonNullable<T>) => R): R | N;
21
+ /**
22
+ * Ensures that the given value is neither null nor undefined.
23
+ * @param value The value to check.
24
+ * @param message Optional error message.
25
+ * @throws {ReferenceError} If the value is null or undefined.
26
+ */
27
+ suppress<T>(value: T, message?: string): NonNullable<T>;
28
+ }
29
+ }
30
+ export {};
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.import = function (source, name = "[source]") {
3
+ if (typeof (source) !== "object" || source === null)
4
+ throw new TypeError(`Unable to import object from ${name} due its ${typename(source)} type`);
5
+ return source;
6
+ };
7
+ Object.map = function (value, callback) {
8
+ if (value === null || value === undefined)
9
+ return value;
10
+ else
11
+ return callback(value);
12
+ };
13
+ Object.suppress = function (value, message) {
14
+ switch (value) {
15
+ case null: throw new ReferenceError(message ?? "Value mustn't be null");
16
+ case undefined: throw new ReferenceError(message ?? "Value mustn't be undefined");
17
+ default: return value;
18
+ }
19
+ };
20
+ export {};
21
+ //# sourceMappingURL=object.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"object.js","sourceRoot":"","sources":["../../src/core/object.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAgCb,MAAM,CAAC,MAAM,GAAG,UAAU,MAAW,EAAE,OAAe,UAAU;IAC/D,IAAI,OAAO,CAAC,MAAM,CAAC,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI;QAAE,MAAM,IAAI,SAAS,CAAC,gCAAgC,IAAI,YAAY,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAClJ,OAAO,MAAM,CAAC;AACf,CAAC,CAAC;AAEF,MAAM,CAAC,GAAG,GAAG,UAAmB,KAAyB,EAAE,QAAuC;IACjG,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC;;QACnD,OAAO,QAAQ,CAAC,KAAuB,CAAC,CAAC;AAC/C,CAAC,CAAC;AAEF,MAAM,CAAC,QAAQ,GAAG,UAAa,KAAQ,EAAE,OAA2B;IACnE,QAAQ,KAAK,EAAE,CAAC;QACf,KAAK,IAAI,CAAC,CAAC,MAAM,IAAI,cAAc,CAAC,OAAO,IAAI,uBAAuB,CAAC,CAAC;QACxE,KAAK,SAAS,CAAC,CAAC,MAAM,IAAI,cAAc,CAAC,OAAO,IAAI,4BAA4B,CAAC,CAAC;QAClF,OAAO,CAAC,CAAC,OAAQ,KAAwB,CAAC;IAC3C,CAAC;AACF,CAAC,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * A mapping interface that associates primitive types with string keys.
3
+ * This is used to handle conversions to different primitive types.
4
+ */
5
+ interface PrimitivesHintMap {
6
+ "number": number;
7
+ "boolean": boolean;
8
+ "string": string;
9
+ }
10
+ export { PrimitivesHintMap };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ export {};
3
+ //# sourceMappingURL=primitives.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"primitives.js","sourceRoot":"","sources":["../../src/core/primitives.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC"}
@@ -0,0 +1,28 @@
1
+ declare global {
2
+ interface Promise<T> {
3
+ /**
4
+ * Checks if the promise is settled.
5
+ */
6
+ readonly isSettled: Promise<boolean>;
7
+ /**
8
+ * Checks if the promise is resolved.
9
+ */
10
+ readonly isResolved: Promise<boolean>;
11
+ /**
12
+ * Checks if the promise is rejected.
13
+ */
14
+ readonly isRejected: Promise<boolean>;
15
+ /**
16
+ * Retrieves the value of a resolved promise.
17
+ * @throws {Error} Throws an error if the promise is rejected.
18
+ */
19
+ readonly value: Promise<T>;
20
+ /**
21
+ * Retrieves the reason of a rejected promise.
22
+ * @throws {Error} Throws an error if the promise is fulfilled.
23
+ */
24
+ readonly reason: Promise<any>;
25
+ }
26
+ }
27
+ type Promisable<T> = T | Promise<T>;
28
+ export { Promisable };
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(Promise.prototype, "isSettled", {
3
+ async get() {
4
+ const symbol = Symbol();
5
+ try {
6
+ const result = (await Promise.race([this, symbol]) !== symbol);
7
+ return result;
8
+ }
9
+ catch {
10
+ return true;
11
+ }
12
+ }
13
+ });
14
+ Object.defineProperty(Promise.prototype, "isResolved", {
15
+ async get() {
16
+ try {
17
+ await this;
18
+ return true;
19
+ }
20
+ catch {
21
+ return false;
22
+ }
23
+ }
24
+ });
25
+ Object.defineProperty(Promise.prototype, "isRejected", {
26
+ async get() {
27
+ try {
28
+ await this;
29
+ return false;
30
+ }
31
+ catch {
32
+ return true;
33
+ }
34
+ }
35
+ });
36
+ Object.defineProperty(Promise.prototype, "value", {
37
+ async get() {
38
+ try {
39
+ return await this;
40
+ }
41
+ catch {
42
+ throw new Error("Unable to get value of rejected promise");
43
+ }
44
+ }
45
+ });
46
+ Object.defineProperty(Promise.prototype, "reason", {
47
+ async get() {
48
+ try {
49
+ await this;
50
+ }
51
+ catch (reason) {
52
+ return reason;
53
+ }
54
+ throw new Error("Unable to get reason of resolved promise");
55
+ }
56
+ });
57
+ export {};
58
+ //# sourceMappingURL=promise.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"promise.js","sourceRoot":"","sources":["../../src/core/promise.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AA6Bb,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,SAAS,EAAE,WAAW,EA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AAE,CAAC;YACjB,OAAO,MAAM,CAAC;QACf,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;IAC7D,CAAC;CACD,CAAC,CAAC"}
@@ -0,0 +1,103 @@
1
+ /**
2
+ * Provides utility methods for generating random values.
3
+ */
4
+ declare class Random {
5
+ #private;
6
+ /**
7
+ * Gets the global shared random generator instance.
8
+ * @readonly
9
+ */
10
+ static get global(): Random;
11
+ /**
12
+ * Generates a random boolean with a 50% probability of being `true`.
13
+ * @returns A random boolean value.
14
+ */
15
+ boolean(): boolean;
16
+ /**
17
+ * Generates a random boolean with the given probability of being `true`.
18
+ * @param factor Probability of returning `true` [0 – 1].
19
+ * @returns A random boolean value.
20
+ * @throws {Error} If `factor` is not a finite number.
21
+ * @throws {RangeError} If `factor` is outside the range.
22
+ */
23
+ boolean(factor: number): boolean;
24
+ /**
25
+ * Generates a random floating-point number between the smallest and largest possible number.
26
+ * @returns A random floating-point number.
27
+ */
28
+ number(): number;
29
+ /**
30
+ * Generates a random floating-point number between 0 and the specified maximum.
31
+ * @param max The maximum value (exclusive).
32
+ * @returns A random floating-point number.
33
+ */
34
+ number(max: number): number;
35
+ /**
36
+ * Generates a random floating-point number between the specified minimum and maximum.
37
+ * @param min The minimum value (inclusive).
38
+ * @param max The maximum value (exclusive).
39
+ * @returns A random floating-point number.
40
+ */
41
+ number(min: number, max: number): number;
42
+ /**
43
+ * Generates a random integer between the minimum safe integer and the maximum safe integer.
44
+ * @returns A random integer value.
45
+ */
46
+ integer(): number;
47
+ /**
48
+ * Generates a random integer between 0 and the specified maximum.
49
+ * @param max The maximum value (inclusive).
50
+ * @returns A random integer value.
51
+ */
52
+ integer(max: number): number;
53
+ /**
54
+ * Generates a random integer between the specified minimum and maximum.
55
+ * @param min The minimum value (inclusive).
56
+ * @param max The maximum value (inclusive).
57
+ * @returns A random integer value.
58
+ */
59
+ integer(min: number, max: number): number;
60
+ /**
61
+ * Selects a random item from a non-empty array.
62
+ * @param array The array to pick from.
63
+ * @returns A random element from the array.
64
+ * @throws {Error} If the array is empty.
65
+ */
66
+ item<T>(array: readonly T[]): T;
67
+ /**
68
+ * Creates a shuffled range of numbers between `min` and `max`.
69
+ * @param min Minimum value (inclusive).
70
+ * @param max Maximum value (inclusive).
71
+ * @returns An array of shuffled numbers in the specified range.
72
+ */
73
+ range(min: number, max: number): number[];
74
+ /**
75
+ * Returns all elements of the array in random order.
76
+ * @param array The source array.
77
+ * @returns A shuffled copy of the array.
78
+ */
79
+ subarray<T>(array: readonly T[]): T[];
80
+ /**
81
+ * Returns a random subset of the given size from the array.
82
+ * @param array The source array.
83
+ * @param count The number of elements to select.
84
+ * @returns A shuffled array containing the selected elements.
85
+ * @throws {Error} If `count` is not an integer.
86
+ * @throws {RangeError} If `count` is outside the valid range.
87
+ */
88
+ subarray<T>(array: readonly T[], count: number): T[];
89
+ /**
90
+ * Randomly shuffles the order of elements in an array in place.
91
+ * @param array The array to shuffle.
92
+ */
93
+ shuffle<T>(array: T[]): void;
94
+ /**
95
+ * Selects a random key from a map based on assigned weights.
96
+ * @param cases A map of items to their respective weights.
97
+ * @returns A randomly selected item based on weights.
98
+ * @throws {Error} If the map is empty.
99
+ * @throws {Error} If no item can be selected.
100
+ */
101
+ case<T>(cases: Readonly<Map<T, number>>): T;
102
+ }
103
+ export { Random };
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ const { random, trunc } = Math;
3
+ //#region Random
4
+ /**
5
+ * Provides utility methods for generating random values.
6
+ */
7
+ class Random {
8
+ static #global = new Random();
9
+ /**
10
+ * Gets the global shared random generator instance.
11
+ * @readonly
12
+ */
13
+ static get global() {
14
+ return Random.#global;
15
+ }
16
+ boolean(factor = 0.5) {
17
+ if (!Number.isFinite(factor))
18
+ throw new Error(`The factor ${factor} must be a finite number`);
19
+ if (0 > factor || factor > 1)
20
+ throw new RangeError(`The factor ${factor} is out of range [0 - 1]`);
21
+ return random() < factor;
22
+ }
23
+ #number(min, max) {
24
+ return random() * (max - min) + min;
25
+ }
26
+ number(arg1, arg2) {
27
+ if (arg1 === undefined)
28
+ return this.#number(-Number.MAX_VALUE, Number.MAX_VALUE);
29
+ if (arg2 === undefined)
30
+ return this.#number(0, arg1);
31
+ return this.#number(arg1, arg2);
32
+ }
33
+ #integer(min, max) {
34
+ return trunc(this.#number(min, max + 1));
35
+ }
36
+ integer(arg1, arg2) {
37
+ if (arg1 === undefined)
38
+ return this.#integer(Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER);
39
+ if (arg2 === undefined)
40
+ return this.#integer(0, arg1);
41
+ return this.#integer(arg1, arg2);
42
+ }
43
+ /**
44
+ * Selects a random item from a non-empty array.
45
+ * @param array The array to pick from.
46
+ * @returns A random element from the array.
47
+ * @throws {Error} If the array is empty.
48
+ */
49
+ item(array) {
50
+ if (array.length < 1)
51
+ throw new Error(`Array must have at least 1 item`);
52
+ return array[this.#integer(0, array.length - 1)];
53
+ }
54
+ /**
55
+ * Creates a shuffled range of numbers between `min` and `max`.
56
+ * @param min Minimum value (inclusive).
57
+ * @param max Maximum value (inclusive).
58
+ * @returns An array of shuffled numbers in the specified range.
59
+ */
60
+ range(min, max) {
61
+ const array = Array.range(min, max);
62
+ this.shuffle(array);
63
+ return array;
64
+ }
65
+ subarray(array, count = array.length) {
66
+ if (!Number.isInteger(count))
67
+ throw new Error(`The count ${count} must be a finite integer number`);
68
+ if (0 > count || count > array.length)
69
+ throw new RangeError(`The count ${count} is out of range [0 - ${array.length}]`);
70
+ const clone = Array.from(array);
71
+ const subarray = [];
72
+ for (let index = 0; index < count; index++) {
73
+ subarray.push(...clone.splice(this.#integer(0, clone.length - 1), 1));
74
+ }
75
+ return subarray;
76
+ }
77
+ /**
78
+ * Randomly shuffles the order of elements in an array in place.
79
+ * @param array The array to shuffle.
80
+ */
81
+ shuffle(array) {
82
+ for (let index = 0; index < array.length - 1; index++) {
83
+ const pair = this.#integer(index, array.length - 1);
84
+ if (pair === index)
85
+ continue;
86
+ array.swap(index, pair);
87
+ }
88
+ }
89
+ /**
90
+ * Selects a random key from a map based on assigned weights.
91
+ * @param cases A map of items to their respective weights.
92
+ * @returns A randomly selected item based on weights.
93
+ * @throws {Error} If the map is empty.
94
+ * @throws {Error} If no item can be selected.
95
+ */
96
+ case(cases) {
97
+ if (1 > cases.size)
98
+ throw new Error(`The cases must have at least 1 item`);
99
+ const summary = Array.from(cases).reduce((previous, [, weight]) => previous + weight, 0);
100
+ const random = this.#number(0, summary);
101
+ let begin = 0;
102
+ for (const [item, weight] of cases) {
103
+ const end = begin + weight;
104
+ if (begin <= random && random < end)
105
+ return item;
106
+ begin = end;
107
+ }
108
+ throw new Error(`Unable to select element with value ${random}`);
109
+ }
110
+ ;
111
+ }
112
+ //#endregion
113
+ export { Random };
114
+ //# sourceMappingURL=random.js.map