@oliversalzburg/js-utils 0.0.4 → 0.0.6

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 (112) hide show
  1. package/coverage/base.css +224 -0
  2. package/coverage/block-navigation.js +87 -0
  3. package/coverage/bundle.js +30 -0
  4. package/coverage/favicon.png +0 -0
  5. package/coverage/index.html +16 -0
  6. package/coverage/prettify.css +1 -0
  7. package/coverage/prettify.js +2 -0
  8. package/coverage/sort-arrow-sprite.png +0 -0
  9. package/coverage/sorter.js +196 -0
  10. package/coverage/spa.css +298 -0
  11. package/coverage/string-formatter.ts.html +187 -0
  12. package/coverage/tmp/coverage-4186-1699218521999-0.json +1 -0
  13. package/coverage/tmp/coverage-4196-1699218521967-0.json +1 -0
  14. package/docs/README.md +3 -0
  15. package/docs/classes/AbstractError.md +271 -0
  16. package/docs/classes/Canvas.md +177 -0
  17. package/docs/classes/InternalError.md +301 -0
  18. package/docs/classes/InvalidArgumentError.md +277 -0
  19. package/docs/classes/InvalidOperationError.md +277 -0
  20. package/docs/classes/NotImplementedError.md +276 -0
  21. package/docs/classes/PermissionViolationError.md +277 -0
  22. package/docs/classes/Random.md +109 -0
  23. package/docs/classes/RenderLoop.md +49 -0
  24. package/docs/classes/ResourceConflictError.md +276 -0
  25. package/docs/classes/UnexpectedNilError.md +169 -0
  26. package/docs/classes/UnknownError.md +280 -0
  27. package/docs/classes/Vector2.md +79 -0
  28. package/docs/classes/Vector3.md +106 -0
  29. package/docs/modules.md +1313 -0
  30. package/lib/core.d.ts +21 -0
  31. package/lib/core.js +3 -0
  32. package/{output → lib}/core.js.map +1 -1
  33. package/{output → lib}/error-serializer.d.ts +1 -1
  34. package/{output → lib}/error-serializer.js +1 -1
  35. package/{output → lib}/errors/AbstractError.d.ts +9 -1
  36. package/{output → lib}/errors/AbstractError.js +10 -2
  37. package/{output → lib}/errors/AbstractError.js.map +1 -1
  38. package/{output → lib}/errors/InternalError.d.ts +6 -1
  39. package/{output → lib}/errors/InternalError.js +6 -1
  40. package/lib/errors/InternalError.js.map +1 -0
  41. package/{output → lib}/errors/InvalidArgumentError.d.ts +1 -1
  42. package/{output → lib}/errors/InvalidArgumentError.js +1 -1
  43. package/{output → lib}/errors/InvalidOperationError.d.ts +1 -1
  44. package/{output → lib}/errors/InvalidOperationError.js +1 -1
  45. package/{output → lib}/errors/NotImplementedError.d.ts +1 -1
  46. package/{output → lib}/errors/NotImplementedError.js +1 -1
  47. package/{output → lib}/errors/PermissionViolationError.d.ts +1 -1
  48. package/{output → lib}/errors/PermissionViolationError.js +1 -1
  49. package/{output → lib}/errors/ResourceConflictError.d.ts +1 -1
  50. package/{output → lib}/errors/ResourceConflictError.js +1 -1
  51. package/{output → lib}/errors/UnknownError.d.ts +2 -2
  52. package/{output → lib}/errors/UnknownError.js +2 -2
  53. package/lib/graphics/canvas.d.ts +80 -0
  54. package/lib/graphics/canvas.js +164 -0
  55. package/lib/graphics/canvas.js.map +1 -0
  56. package/lib/graphics/core.d.ts +94 -0
  57. package/lib/graphics/core.js +479 -0
  58. package/lib/graphics/core.js.map +1 -0
  59. package/lib/graphics/index.d.ts +3 -0
  60. package/lib/graphics/index.js +4 -0
  61. package/lib/graphics/index.js.map +1 -0
  62. package/lib/graphics/render-loop.d.ts +20 -0
  63. package/lib/graphics/render-loop.js +51 -0
  64. package/lib/graphics/render-loop.js.map +1 -0
  65. package/{output → lib}/index.d.ts +4 -0
  66. package/{output → lib}/index.js +4 -0
  67. package/lib/index.js.map +1 -0
  68. package/lib/math/core.d.ts +46 -0
  69. package/lib/math/core.js +72 -0
  70. package/lib/math/core.js.map +1 -0
  71. package/lib/math/index.d.ts +2 -0
  72. package/lib/math/index.js +3 -0
  73. package/lib/math/index.js.map +1 -0
  74. package/lib/math/vector.d.ts +33 -0
  75. package/lib/math/vector.js +42 -0
  76. package/lib/math/vector.js.map +1 -0
  77. package/{output → lib}/nil.d.ts +13 -8
  78. package/{output → lib}/nil.js +16 -11
  79. package/lib/nil.js.map +1 -0
  80. package/lib/random.d.ts +56 -0
  81. package/lib/random.js +184 -0
  82. package/lib/random.js.map +1 -0
  83. package/lib/string-formatter.test.d.ts +1 -0
  84. package/lib/string-formatter.test.js +17 -0
  85. package/lib/string-formatter.test.js.map +1 -0
  86. package/mkdocs.yml +52 -0
  87. package/package.json +25 -13
  88. package/typedoc.json +8 -0
  89. package/output/core.d.ts +0 -4
  90. package/output/core.js +0 -2
  91. package/output/errors/InternalError.js.map +0 -1
  92. package/output/index.js.map +0 -1
  93. package/output/nil.js.map +0 -1
  94. /package/{output → lib}/array.d.ts +0 -0
  95. /package/{output → lib}/array.js +0 -0
  96. /package/{output → lib}/array.js.map +0 -0
  97. /package/{output → lib}/error-serializer.js.map +0 -0
  98. /package/{output → lib}/errors/InvalidArgumentError.js.map +0 -0
  99. /package/{output → lib}/errors/InvalidOperationError.js.map +0 -0
  100. /package/{output → lib}/errors/NotImplementedError.js.map +0 -0
  101. /package/{output → lib}/errors/PermissionViolationError.js.map +0 -0
  102. /package/{output → lib}/errors/ResourceConflictError.js.map +0 -0
  103. /package/{output → lib}/errors/UnknownError.js.map +0 -0
  104. /package/{output → lib}/errors/index.d.ts +0 -0
  105. /package/{output → lib}/errors/index.js +0 -0
  106. /package/{output → lib}/errors/index.js.map +0 -0
  107. /package/{output → lib}/sleep.d.ts +0 -0
  108. /package/{output → lib}/sleep.js +0 -0
  109. /package/{output → lib}/sleep.js.map +0 -0
  110. /package/{output → lib}/string-formatter.d.ts +0 -0
  111. /package/{output → lib}/string-formatter.js +0 -0
  112. /package/{output → lib}/string-formatter.js.map +0 -0
@@ -1,6 +1,10 @@
1
1
  export * from "./array.js";
2
+ export * from "./core.js";
2
3
  export * from "./error-serializer.js";
3
4
  export * from "./errors/index.js";
5
+ export * from "./graphics/index.js";
6
+ export * from "./math/index.js";
4
7
  export * from "./nil.js";
8
+ export * from "./random.js";
5
9
  export * from "./sleep.js";
6
10
  export * from "./string-formatter.js";
@@ -1,7 +1,11 @@
1
1
  export * from "./array.js";
2
+ export * from "./core.js";
2
3
  export * from "./error-serializer.js";
3
4
  export * from "./errors/index.js";
5
+ export * from "./graphics/index.js";
6
+ export * from "./math/index.js";
4
7
  export * from "./nil.js";
8
+ export * from "./random.js";
5
9
  export * from "./sleep.js";
6
10
  export * from "./string-formatter.js";
7
11
  //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,uBAAuB,CAAC"}
@@ -0,0 +1,46 @@
1
+ export declare const TWO_PI: number;
2
+ /**
3
+ * Converts the degrees to radians.
4
+ * @param degrees The degrees to convert to radians.
5
+ * @returns The degrees in radians.
6
+ */
7
+ export declare const deg2rad: (degrees: number) => number;
8
+ /**
9
+ * Convertrs the radians to degrees.
10
+ * @param radians The radians to convert to degrees.
11
+ * @returns The radians as degrees.
12
+ */
13
+ export declare const rad2deg: (radians: number) => number;
14
+ /**
15
+ * Calculates the sine for a given degree value.
16
+ * @param value The value in degrees to calculate the sine for.
17
+ * @returns The sine for the given value.
18
+ */
19
+ export declare const sinDeg: (value: number) => number;
20
+ /**
21
+ * Calculates the cosine for a given degree value.
22
+ * @param value The value in degrees to calculate the cosine for.
23
+ * @returns The cosine for the given value.
24
+ */
25
+ export declare const cosDeg: (value: number) => number;
26
+ /**
27
+ * Calculates the distance between two vectors.
28
+ * @param x1 The X component of the first vector.
29
+ * @param y1 The Y comoinent of the first vector.
30
+ * @param x2 The X component of the second vector.
31
+ * @param y2 The Y component of the second vector.
32
+ * @returns The distance between the two vectors.
33
+ */
34
+ export declare const distance: (x1: number, y1: number, x2: number, y2: number) => number;
35
+ /**
36
+ * Finds the integer square root of a positive number.
37
+ * @param value The value to calcuate the square root for.
38
+ * @returns The square root for the given value.
39
+ */
40
+ export declare const Isqrt: (value: number) => number;
41
+ /**
42
+ * Checks whether a number is an integer.
43
+ * @param value The value to check.
44
+ * @returns `true` when the value is an integer, `false` otherwise.
45
+ */
46
+ export declare const isInteger: (value: number) => boolean;
@@ -0,0 +1,72 @@
1
+ export const TWO_PI = Math.PI * 2;
2
+ /**
3
+ * Converts the degrees to radians.
4
+ * @param degrees The degrees to convert to radians.
5
+ * @returns The degrees in radians.
6
+ */
7
+ export const deg2rad = (degrees) => {
8
+ return degrees * (Math.PI / 180);
9
+ };
10
+ /**
11
+ * Convertrs the radians to degrees.
12
+ * @param radians The radians to convert to degrees.
13
+ * @returns The radians as degrees.
14
+ */
15
+ export const rad2deg = (radians) => {
16
+ return radians * (180 / Math.PI);
17
+ };
18
+ /**
19
+ * Calculates the sine for a given degree value.
20
+ * @param value The value in degrees to calculate the sine for.
21
+ * @returns The sine for the given value.
22
+ */
23
+ export const sinDeg = (value) => {
24
+ return Math.sin(deg2rad(value));
25
+ };
26
+ /**
27
+ * Calculates the cosine for a given degree value.
28
+ * @param value The value in degrees to calculate the cosine for.
29
+ * @returns The cosine for the given value.
30
+ */
31
+ export const cosDeg = (value) => {
32
+ return Math.cos(deg2rad(value));
33
+ };
34
+ /**
35
+ * Calculates the distance between two vectors.
36
+ * @param x1 The X component of the first vector.
37
+ * @param y1 The Y comoinent of the first vector.
38
+ * @param x2 The X component of the second vector.
39
+ * @param y2 The Y component of the second vector.
40
+ * @returns The distance between the two vectors.
41
+ */
42
+ export const distance = (x1, y1, x2, y2) => {
43
+ const distx = x2 - x1;
44
+ const disty = y2 - y1;
45
+ return Math.sqrt(distx * distx + disty * disty);
46
+ };
47
+ /**
48
+ * Finds the integer square root of a positive number.
49
+ * @param value The value to calcuate the square root for.
50
+ * @returns The square root for the given value.
51
+ */
52
+ export const Isqrt = (value) => {
53
+ if (0 === value) {
54
+ return 0;
55
+ } // Avoid zero divide
56
+ let n = value / 2 + 1; // Initial estimate, never low
57
+ let n1 = (n + value / n) / 2;
58
+ while (n1 < n) {
59
+ n = n1;
60
+ n1 = (n + value / n) / 2;
61
+ }
62
+ return n;
63
+ };
64
+ /**
65
+ * Checks whether a number is an integer.
66
+ * @param value The value to check.
67
+ * @returns `true` when the value is an integer, `false` otherwise.
68
+ */
69
+ export const isInteger = (value) => {
70
+ return Math.trunc(value) === value;
71
+ };
72
+ //# sourceMappingURL=core.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core.js","sourceRoot":"","sources":["../../source/math/core.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,MAAM,GAAG,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC;AAElC;;;;GAIG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,OAAe,EAAE,EAAE;IACzC,OAAO,OAAO,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,GAAG,CAAC,CAAC;AACnC,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,OAAe,EAAE,EAAE;IACzC,OAAO,OAAO,GAAG,CAAC,GAAG,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC;AACnC,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,KAAa,EAAE,EAAE;IACtC,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;AAClC,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,KAAa,EAAE,EAAE;IACtC,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;AAClC,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,EAAU,EAAE,EAAU,EAAE,EAAU,EAAE,EAAU,EAAE,EAAE;IACzE,MAAM,KAAK,GAAG,EAAE,GAAG,EAAE,CAAC;IACtB,MAAM,KAAK,GAAG,EAAE,GAAG,EAAE,CAAC;IACtB,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,CAAC,CAAC;AAClD,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,KAAa,EAAE,EAAE;IACrC,IAAI,CAAC,KAAK,KAAK,EAAE;QACf,OAAO,CAAC,CAAC;KACV,CAAC,oBAAoB;IACtB,IAAI,CAAC,GAAG,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,8BAA8B;IACrD,IAAI,EAAE,GAAG,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;IAC7B,OAAO,EAAE,GAAG,CAAC,EAAE;QACb,CAAC,GAAG,EAAE,CAAC;QACP,EAAE,GAAG,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;KAC1B;IACD,OAAO,CAAC,CAAC;AACX,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,KAAa,EAAE,EAAE;IACzC,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,KAAK,CAAC;AACrC,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from "./core.js";
2
+ export * from "./vector.js";
@@ -0,0 +1,3 @@
1
+ export * from "./core.js";
2
+ export * from "./vector.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/math/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * A vector with 2 components.
3
+ */
4
+ export declare class Vector2 {
5
+ x: number;
6
+ y: number;
7
+ /**
8
+ * Constructs a new {@link Vector2}.
9
+ * @param x The X component.
10
+ * @param y The Y component.
11
+ */
12
+ constructor(x: number, y: number);
13
+ /**
14
+ * Returns the dot product between the two vectors.
15
+ * @param x The X component of the other vector.
16
+ * @param y The Y component of the other vector.
17
+ * @returns The dot product between the two vectors.
18
+ */
19
+ dot2(x: number, y: number): number;
20
+ }
21
+ /**
22
+ * A vector with 3 components.
23
+ */
24
+ export declare class Vector3 extends Vector2 {
25
+ z: number;
26
+ /**
27
+ * Constructs a new {@link Vector3}.
28
+ * @param x The X component.
29
+ * @param y The Y component.
30
+ * @param z The Z component.
31
+ */
32
+ constructor(x: number, y: number, z: number);
33
+ }
@@ -0,0 +1,42 @@
1
+ /**
2
+ * A vector with 2 components.
3
+ */
4
+ export class Vector2 {
5
+ x;
6
+ y;
7
+ /**
8
+ * Constructs a new {@link Vector2}.
9
+ * @param x The X component.
10
+ * @param y The Y component.
11
+ */
12
+ constructor(x, y) {
13
+ this.x = x;
14
+ this.y = y;
15
+ }
16
+ /**
17
+ * Returns the dot product between the two vectors.
18
+ * @param x The X component of the other vector.
19
+ * @param y The Y component of the other vector.
20
+ * @returns The dot product between the two vectors.
21
+ */
22
+ dot2(x, y) {
23
+ return this.x * x + this.y * y;
24
+ }
25
+ }
26
+ /**
27
+ * A vector with 3 components.
28
+ */
29
+ export class Vector3 extends Vector2 {
30
+ z;
31
+ /**
32
+ * Constructs a new {@link Vector3}.
33
+ * @param x The X component.
34
+ * @param y The Y component.
35
+ * @param z The Z component.
36
+ */
37
+ constructor(x, y, z) {
38
+ super(x, y);
39
+ this.z = z;
40
+ }
41
+ }
42
+ //# sourceMappingURL=vector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vector.js","sourceRoot":"","sources":["../../source/math/vector.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,OAAO,OAAO;IAClB,CAAC,CAAS;IACV,CAAC,CAAS;IAEV;;;;OAIG;IACH,YAAY,CAAS,EAAE,CAAS;QAC9B,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;QACX,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;IACb,CAAC;IAED;;;;;OAKG;IACH,IAAI,CAAC,CAAS,EAAE,CAAS;QACvB,OAAO,IAAI,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;IACjC,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,OAAQ,SAAQ,OAAO;IAClC,CAAC,CAAS;IAEV;;;;;OAKG;IACH,YAAY,CAAS,EAAE,CAAS,EAAE,CAAS;QACzC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACZ,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;IACb,CAAC;CACF"}
@@ -8,6 +8,13 @@ export type Nil = null | undefined;
8
8
  * A type that could be either what you want, or `Nil`.
9
9
  */
10
10
  export type Maybe<T> = T | Nil;
11
+ /**
12
+ * Check if something is nil.
13
+ * Can be used as a typeguard.
14
+ * @param subject The subject that could be nil.
15
+ * @returns `true` if the subject is nil, `false` otherwise.
16
+ */
17
+ export declare function isNil<T>(subject: Maybe<T>): subject is Nil;
11
18
  /**
12
19
  * Check if something is a concrete value of the given type.
13
20
  * Can be used as a typeguard.
@@ -17,23 +24,21 @@ export type Maybe<T> = T | Nil;
17
24
  * `false` otherwise.
18
25
  */
19
26
  export declare function is<T>(nilable: Maybe<T>, InstanceType: ConstructorOf<T>): nilable is T;
20
- /**
21
- * Check if something is nil.
22
- * Can be used as a typeguard.
23
- * @param subject The subject that could be nil.
24
- * @returns `true` if the subject is nil, `false` otherwise.
25
- */
26
- export declare function isNil<T>(subject: Maybe<T>): subject is Nil;
27
27
  /**
28
28
  * Thrown when an unexpected nil value was encountered.
29
29
  */
30
30
  export declare class UnexpectedNilError extends Error {
31
+ /**
32
+ * Constructs a new {UnexpectedNilError}.
33
+ * @param message The error message.
34
+ */
31
35
  constructor(message?: string);
32
36
  }
33
37
  /**
34
38
  * Ensure that the passed subject is not nil; throw otherwise.
35
39
  * @param subject A subject that is possible nil.
40
+ * @param errorMessage An optional error message to throw when the subject is nil.
36
41
  * @returns The subject, if it isn't nil.
37
42
  * @throws {UnexpectedNilError} When the subject is nil.
38
43
  */
39
- export declare function mustExist<T>(subject: Maybe<T>): T;
44
+ export declare function mustExist<T>(subject: Maybe<T>, errorMessage?: string): T;
@@ -1,3 +1,12 @@
1
+ /**
2
+ * Check if something is nil.
3
+ * Can be used as a typeguard.
4
+ * @param subject The subject that could be nil.
5
+ * @returns `true` if the subject is nil, `false` otherwise.
6
+ */
7
+ export function isNil(subject) {
8
+ return subject === null || subject === undefined;
9
+ }
1
10
  /**
2
11
  * Check if something is a concrete value of the given type.
3
12
  * Can be used as a typeguard.
@@ -9,19 +18,14 @@
9
18
  export function is(nilable, InstanceType) {
10
19
  return !isNil(nilable) && nilable instanceof InstanceType;
11
20
  }
12
- /**
13
- * Check if something is nil.
14
- * Can be used as a typeguard.
15
- * @param subject The subject that could be nil.
16
- * @returns `true` if the subject is nil, `false` otherwise.
17
- */
18
- export function isNil(subject) {
19
- return subject === null || subject === undefined;
20
- }
21
21
  /**
22
22
  * Thrown when an unexpected nil value was encountered.
23
23
  */
24
24
  export class UnexpectedNilError extends Error {
25
+ /**
26
+ * Constructs a new {UnexpectedNilError}.
27
+ * @param message The error message.
28
+ */
25
29
  constructor(message = "unexpected nil value") {
26
30
  super(message);
27
31
  }
@@ -29,12 +33,13 @@ export class UnexpectedNilError extends Error {
29
33
  /**
30
34
  * Ensure that the passed subject is not nil; throw otherwise.
31
35
  * @param subject A subject that is possible nil.
36
+ * @param errorMessage An optional error message to throw when the subject is nil.
32
37
  * @returns The subject, if it isn't nil.
33
38
  * @throws {UnexpectedNilError} When the subject is nil.
34
39
  */
35
- export function mustExist(subject) {
40
+ export function mustExist(subject, errorMessage) {
36
41
  if (isNil(subject)) {
37
- throw new UnexpectedNilError();
42
+ throw new UnexpectedNilError(errorMessage);
38
43
  }
39
44
  return subject;
40
45
  }
package/lib/nil.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nil.js","sourceRoot":"","sources":["../source/nil.ts"],"names":[],"mappings":"AAaA;;;;;GAKG;AACH,MAAM,UAAU,KAAK,CAAI,OAAiB;IACxC,OAAO,OAAO,KAAK,IAAI,IAAI,OAAO,KAAK,SAAS,CAAC;AACnD,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,EAAE,CAAI,OAAiB,EAAE,YAA8B;IACrE,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,OAAO,YAAY,YAAY,CAAC;AAC5D,CAAC;AAED;;GAEG;AACH,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAC3C;;;OAGG;IACH,YAAY,OAAO,GAAG,sBAAsB;QAC1C,KAAK,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;CACF;AAED;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CAAI,OAAiB,EAAE,YAAqB;IACnE,IAAI,KAAK,CAAC,OAAO,CAAC,EAAE;QAClB,MAAM,IAAI,kBAAkB,CAAC,YAAY,CAAC,CAAC;KAC5C;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Helps with generating random numbers.
3
+ */
4
+ export declare class Random {
5
+ private _seed;
6
+ private _perm;
7
+ private _gradP;
8
+ private _F2;
9
+ private _G2;
10
+ /**
11
+ * Creates a pseudo-random value generator. The seed must be an integer.
12
+ *
13
+ * Uses an optimized version of the Park-Miller PRNG.
14
+ * http://www.firstpr.com.au/dsp/rand31/
15
+ * @param seed The seed for the random number generator.
16
+ */
17
+ constructor(seed?: number);
18
+ /**
19
+ * Returns a pseudo-random value between 1 and 2^32 - 2.
20
+ * @returns A pseudo-random value between 1 and 2^32 - 2.
21
+ */
22
+ next(): number;
23
+ /**
24
+ * Returns either `true` or `false`.
25
+ * @returns Either `true` or `false`.
26
+ */
27
+ nextBoolean(): boolean;
28
+ /**
29
+ * Returns a pseudo-random floating point number in range [0, 1).
30
+ * @returns a pseudo-random floating point number in range [0, 1).
31
+ */
32
+ nextFloat(): number;
33
+ /**
34
+ * Returns a 2D simplex noise value for a given input coordinate.
35
+ * @param xin The X input coordinate.
36
+ * @param yin The Y input coordinate.
37
+ * @returns The noise value for the input coordinates.
38
+ */
39
+ simplex2(xin: number, yin: number): number;
40
+ }
41
+ /**
42
+ * Returns a random value in a given range.
43
+ * Uses the JS-internal `Math.random()`. Use {MathHelper} for a PRNG with more features.
44
+ * @param min The lower bound.
45
+ * @param max The upper bound.
46
+ * @returns A random value between the lower and upper bound.
47
+ */
48
+ export declare const randomRange: (min: number, max: number) => number;
49
+ /**
50
+ * Generates a numberic seed, to be used as an input for a PRNG,
51
+ * from a string.
52
+ * @param input The string to use as a seed.
53
+ * @returns A numeric seed value for a PRNG.
54
+ */
55
+ export declare const seedFromString: (input: string) => number;
56
+ export declare const random: Random;
package/lib/random.js ADDED
@@ -0,0 +1,184 @@
1
+ import { Vector3 } from "./math/vector";
2
+ /**
3
+ * Helps with generating random numbers.
4
+ */
5
+ export class Random {
6
+ _seed;
7
+ _perm;
8
+ _gradP;
9
+ _F2;
10
+ _G2;
11
+ /**
12
+ * Creates a pseudo-random value generator. The seed must be an integer.
13
+ *
14
+ * Uses an optimized version of the Park-Miller PRNG.
15
+ * http://www.firstpr.com.au/dsp/rand31/
16
+ * @param seed The seed for the random number generator.
17
+ */
18
+ constructor(seed = 0) {
19
+ this._seed = Math.trunc(seed) % 2147483647;
20
+ if (this._seed <= 0) {
21
+ this._seed += 2147483646;
22
+ }
23
+ const grad3 = [
24
+ new Vector3(1, 1, 0),
25
+ new Vector3(-1, 1, 0),
26
+ new Vector3(1, -1, 0),
27
+ new Vector3(-1, -1, 0),
28
+ new Vector3(1, 0, 1),
29
+ new Vector3(-1, 0, 1),
30
+ new Vector3(1, 0, -1),
31
+ new Vector3(-1, 0, -1),
32
+ new Vector3(0, 1, 1),
33
+ new Vector3(0, -1, 1),
34
+ new Vector3(0, 1, -1),
35
+ new Vector3(0, -1, -1),
36
+ ];
37
+ const p = [
38
+ 151, 160, 137, 91, 90, 15, 131, 13, 201, 95, 96, 53, 194, 233, 7, 225, 140, 36, 103, 30, 69,
39
+ 142, 8, 99, 37, 240, 21, 10, 23, 190, 6, 148, 247, 120, 234, 75, 0, 26, 197, 62, 94, 252, 219,
40
+ 203, 117, 35, 11, 32, 57, 177, 33, 88, 237, 149, 56, 87, 174, 20, 125, 136, 171, 168, 68, 175,
41
+ 74, 165, 71, 134, 139, 48, 27, 166, 77, 146, 158, 231, 83, 111, 229, 122, 60, 211, 133, 230,
42
+ 220, 105, 92, 41, 55, 46, 245, 40, 244, 102, 143, 54, 65, 25, 63, 161, 1, 216, 80, 73, 209,
43
+ 76, 132, 187, 208, 89, 18, 169, 200, 196, 135, 130, 116, 188, 159, 86, 164, 100, 109, 198,
44
+ 173, 186, 3, 64, 52, 217, 226, 250, 124, 123, 5, 202, 38, 147, 118, 126, 255, 82, 85, 212,
45
+ 207, 206, 59, 227, 47, 16, 58, 17, 182, 189, 28, 42, 223, 183, 170, 213, 119, 248, 152, 2, 44,
46
+ 154, 163, 70, 221, 153, 101, 155, 167, 43, 172, 9, 129, 22, 39, 253, 19, 98, 108, 110, 79,
47
+ 113, 224, 232, 178, 185, 112, 104, 218, 246, 97, 228, 251, 34, 242, 193, 238, 210, 144, 12,
48
+ 191, 179, 162, 241, 81, 51, 145, 235, 249, 14, 239, 107, 49, 192, 214, 31, 181, 199, 106, 157,
49
+ 184, 84, 204, 176, 115, 121, 50, 45, 127, 4, 150, 254, 138, 236, 205, 93, 222, 114, 67, 29,
50
+ 24, 72, 243, 141, 128, 195, 78, 66, 215, 61, 156, 180,
51
+ ];
52
+ this._perm = new Array(512);
53
+ this._gradP = new Array(512);
54
+ for (let i = 0; i < 256; i++) {
55
+ let v;
56
+ if (i & 1) {
57
+ v = p[i] ^ (this._seed & 255);
58
+ }
59
+ else {
60
+ v = p[i] ^ ((this._seed >> 8) & 255);
61
+ }
62
+ this._perm[i] = this._perm[i + 256] = v;
63
+ this._gradP[i] = this._gradP[i + 256] = grad3[v % 12];
64
+ }
65
+ // Skewing and unskewing factors for 2, 3, and 4 dimensions
66
+ this._F2 = 0.5 * (Math.sqrt(3) - 1);
67
+ this._G2 = (3 - Math.sqrt(3)) / 6;
68
+ }
69
+ /**
70
+ * Returns a pseudo-random value between 1 and 2^32 - 2.
71
+ * @returns A pseudo-random value between 1 and 2^32 - 2.
72
+ */
73
+ next() {
74
+ return (this._seed = (this._seed * 16807) % 2147483647);
75
+ }
76
+ /**
77
+ * Returns either `true` or `false`.
78
+ * @returns Either `true` or `false`.
79
+ */
80
+ nextBoolean() {
81
+ return this.next() < 2147483646 / 2;
82
+ }
83
+ /**
84
+ * Returns a pseudo-random floating point number in range [0, 1).
85
+ * @returns a pseudo-random floating point number in range [0, 1).
86
+ */
87
+ nextFloat() {
88
+ // We know that result of next() will be 1 to 2147483646 (inclusive).
89
+ return (this.next() - 1) / 2147483646;
90
+ }
91
+ /**
92
+ * Returns a 2D simplex noise value for a given input coordinate.
93
+ * @param xin The X input coordinate.
94
+ * @param yin The Y input coordinate.
95
+ * @returns The noise value for the input coordinates.
96
+ */
97
+ simplex2(xin, yin) {
98
+ let n0, n1, n2; // Noise contributions from the three corners
99
+ // Skew the input space to determine which simplex cell we're in
100
+ const s = (xin + yin) * this._F2; // Hairy factor for 2D
101
+ let i = Math.floor(xin + s);
102
+ let j = Math.floor(yin + s);
103
+ const t = (i + j) * this._G2;
104
+ const x0 = xin - i + t; // The x,y distances from the cell origin, unskewed.
105
+ const y0 = yin - j + t;
106
+ // For the 2D case, the simplex shape is an equilateral triangle.
107
+ // Determine which simplex we are in.
108
+ let i1, j1; // Offsets for second (middle) corner of simplex in (i,j) coords
109
+ if (x0 > y0) {
110
+ // lower triangle, XY order: (0,0)->(1,0)->(1,1)
111
+ i1 = 1;
112
+ j1 = 0;
113
+ }
114
+ else {
115
+ // upper triangle, YX order: (0,0)->(0,1)->(1,1)
116
+ i1 = 0;
117
+ j1 = 1;
118
+ }
119
+ // A step of (1,0) in (i,j) means a step of (1-c,-c) in (x,y), and
120
+ // a step of (0,1) in (i,j) means a step of (-c,1-c) in (x,y), where
121
+ // c = (3-sqrt(3))/6
122
+ const x1 = x0 - i1 + this._G2; // Offsets for middle corner in (x,y) unskewed coords
123
+ const y1 = y0 - j1 + this._G2;
124
+ const x2 = x0 - 1 + 2 * this._G2; // Offsets for last corner in (x,y) unskewed coords
125
+ const y2 = y0 - 1 + 2 * this._G2;
126
+ // Work out the hashed gradient indices of the three simplex corners
127
+ i &= 255;
128
+ j &= 255;
129
+ const gi0 = this._gradP[i + this._perm[j]];
130
+ const gi1 = this._gradP[i + i1 + this._perm[j + j1]];
131
+ const gi2 = this._gradP[i + 1 + this._perm[j + 1]];
132
+ // Calculate the contribution from the three corners
133
+ let t0 = 0.5 - x0 * x0 - y0 * y0;
134
+ if (t0 < 0) {
135
+ n0 = 0;
136
+ }
137
+ else {
138
+ t0 *= t0;
139
+ n0 = t0 * t0 * gi0.dot2(x0, y0); // (x,y) of grad3 used for 2D gradient
140
+ }
141
+ let t1 = 0.5 - x1 * x1 - y1 * y1;
142
+ if (t1 < 0) {
143
+ n1 = 0;
144
+ }
145
+ else {
146
+ t1 *= t1;
147
+ n1 = t1 * t1 * gi1.dot2(x1, y1);
148
+ }
149
+ let t2 = 0.5 - x2 * x2 - y2 * y2;
150
+ if (t2 < 0) {
151
+ n2 = 0;
152
+ }
153
+ else {
154
+ t2 *= t2;
155
+ n2 = t2 * t2 * gi2.dot2(x2, y2);
156
+ }
157
+ // Add contributions from each corner to get the final noise value.
158
+ // The result is scaled to return values in the interval [-1,1].
159
+ return 70 * (n0 + n1 + n2);
160
+ }
161
+ }
162
+ /**
163
+ * Returns a random value in a given range.
164
+ * Uses the JS-internal `Math.random()`. Use {MathHelper} for a PRNG with more features.
165
+ * @param min The lower bound.
166
+ * @param max The upper bound.
167
+ * @returns A random value between the lower and upper bound.
168
+ */
169
+ export const randomRange = (min, max) => {
170
+ return Math.random() * (max - min) + min;
171
+ };
172
+ /**
173
+ * Generates a numberic seed, to be used as an input for a PRNG,
174
+ * from a string.
175
+ * @param input The string to use as a seed.
176
+ * @returns A numeric seed value for a PRNG.
177
+ */
178
+ export const seedFromString = (input) => {
179
+ return input
180
+ .split("")
181
+ .reduce((seed, char) => (seed = seed + ((char.charCodeAt(0) * 17989) % 2147483647)), 0);
182
+ };
183
+ export const random = new Random();
184
+ //# sourceMappingURL=random.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"random.js","sourceRoot":"","sources":["../source/random.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC;;GAEG;AACH,MAAM,OAAO,MAAM;IACT,KAAK,CAAS;IACd,KAAK,CAAgB;IACrB,MAAM,CAAiB;IACvB,GAAG,CAAS;IACZ,GAAG,CAAS;IAEpB;;;;;;OAMG;IACH,YAAY,IAAI,GAAG,CAAC;QAClB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC;QAC3C,IAAI,IAAI,CAAC,KAAK,IAAI,CAAC,EAAE;YACnB,IAAI,CAAC,KAAK,IAAI,UAAU,CAAC;SAC1B;QAED,MAAM,KAAK,GAAG;YACZ,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;YACpB,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;YACrB,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;YACrB,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;YACtB,IAAI,OAAO,CAAC,CAAC,EA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AE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;QACjC,IAAI,EAAE,GAAG,CAAC,EAAE;YACV,EAAE,GAAG,CAAC,CAAC;SACR;aAAM;YACL,EAAE,IAAI,EAAE,CAAC;YACT,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;SACjC;QACD,mEAAmE;QACnE,gEAAgE;QAChE,OAAO,EAAE,GAAG,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC;IAC7B,CAAC;CACF;AAED;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,GAAW,EAAE,GAAW,EAAE,EAAE;IACtD,OAAO,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC;AAC3C,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAa,EAAE,EAAE;IAC9C,OAAO,KAAK;SACT,KAAK,CAAC,EAAE,CAAC;SACT,MAAM,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,GAAG,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,GAAG,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAC5F,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,17 @@
1
+ import { expect } from "chai";
2
+ import { it } from "mocha";
3
+ import { formatString, formatStringTemplate } from "./string-formatter.js";
4
+ it("formats index-based template strings", () => {
5
+ expect(formatString("'{0}'", "foo")).to.equal("'foo'");
6
+ expect(formatString("'{0}': {1}", "foo", "bar")).to.equal("'foo': bar");
7
+ expect(formatString("'{0}': {1}", "foo")).to.equal("'foo': {1}");
8
+ });
9
+ it("formats literal-based template strings", () => {
10
+ expect(formatStringTemplate("'#{foo}'", { foo: "foo" })).to.equal("'foo'");
11
+ expect(formatStringTemplate("'#{foo}': #{bar}", { foo: "foo", bar: "bar" })).to.equal("'foo': bar");
12
+ expect(formatStringTemplate("'#{foo}': #{bar}", { foo: "foo" })).to.equal("'foo': <missing parameter>");
13
+ });
14
+ it("treats empty string appropriately", () => {
15
+ expect(formatString("'{0}'", "")).to.equal("''");
16
+ });
17
+ //# sourceMappingURL=string-formatter.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string-formatter.test.js","sourceRoot":"","sources":["../source/string-formatter.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAC3B,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAE3E,EAAE,CAAC,sCAAsC,EAAE,GAAG,EAAE;IAC9C,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACvD,MAAM,CAAC,YAAY,CAAC,YAAY,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IACxE,MAAM,CAAC,YAAY,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;AACnE,CAAC,CAAC,CAAC;AAEH,EAAE,CAAC,wCAAwC,EAAE,GAAG,EAAE;IAChD,MAAM,CAAC,oBAAoB,CAAC,UAAU,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC3E,MAAM,CAAC,oBAAoB,CAAC,kB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