@oliversalzburg/js-utils 0.0.4 → 0.0.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 (91) 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/mkdocs.yml +52 -0
  31. package/output/core.d.ts +18 -1
  32. package/output/core.js +1 -0
  33. package/output/core.js.map +1 -1
  34. package/output/error-serializer.d.ts +1 -1
  35. package/output/error-serializer.js +1 -1
  36. package/output/errors/AbstractError.d.ts +9 -1
  37. package/output/errors/AbstractError.js +10 -2
  38. package/output/errors/AbstractError.js.map +1 -1
  39. package/output/errors/InternalError.d.ts +6 -1
  40. package/output/errors/InternalError.js +6 -1
  41. package/output/errors/InternalError.js.map +1 -1
  42. package/output/errors/InvalidArgumentError.d.ts +1 -1
  43. package/output/errors/InvalidArgumentError.js +1 -1
  44. package/output/errors/InvalidOperationError.d.ts +1 -1
  45. package/output/errors/InvalidOperationError.js +1 -1
  46. package/output/errors/NotImplementedError.d.ts +1 -1
  47. package/output/errors/NotImplementedError.js +1 -1
  48. package/output/errors/PermissionViolationError.d.ts +1 -1
  49. package/output/errors/PermissionViolationError.js +1 -1
  50. package/output/errors/ResourceConflictError.d.ts +1 -1
  51. package/output/errors/ResourceConflictError.js +1 -1
  52. package/output/errors/UnknownError.d.ts +2 -2
  53. package/output/errors/UnknownError.js +2 -2
  54. package/output/graphics/canvas.d.ts +80 -0
  55. package/output/graphics/canvas.js +164 -0
  56. package/output/graphics/canvas.js.map +1 -0
  57. package/output/graphics/core.d.ts +94 -0
  58. package/output/graphics/core.js +479 -0
  59. package/output/graphics/core.js.map +1 -0
  60. package/output/graphics/index.d.ts +3 -0
  61. package/output/graphics/index.js +4 -0
  62. package/output/graphics/index.js.map +1 -0
  63. package/output/graphics/render-loop.d.ts +20 -0
  64. package/output/graphics/render-loop.js +51 -0
  65. package/output/graphics/render-loop.js.map +1 -0
  66. package/output/index.d.ts +4 -0
  67. package/output/index.js +4 -0
  68. package/output/index.js.map +1 -1
  69. package/output/math/core.d.ts +46 -0
  70. package/output/math/core.js +72 -0
  71. package/output/math/core.js.map +1 -0
  72. package/output/math/index.d.ts +2 -0
  73. package/output/math/index.js +3 -0
  74. package/output/math/index.js.map +1 -0
  75. package/output/math/vector.d.ts +33 -0
  76. package/output/math/vector.js +42 -0
  77. package/output/math/vector.js.map +1 -0
  78. package/output/nil.d.ts +13 -8
  79. package/output/nil.js +16 -11
  80. package/output/nil.js.map +1 -1
  81. package/output/random.d.ts +56 -0
  82. package/output/random.js +184 -0
  83. package/output/random.js.map +1 -0
  84. package/output/string-formatter.test.d.ts +1 -0
  85. package/output/string-formatter.test.js +17 -0
  86. package/output/string-formatter.test.js.map +1 -0
  87. package/output/vector.d.ts +10 -0
  88. package/output/vector.js +19 -0
  89. package/output/vector.js.map +1 -0
  90. package/package.json +23 -8
  91. package/typedoc.json +8 -0
@@ -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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,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,EAA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: number, y: number): number;
6
+ }
7
+ export declare class Vector3 extends Vector2 {
8
+ z: number;
9
+ constructor(x: number, y: number, z: number);
10
+ }
@@ -0,0 +1,19 @@
1
+ export class Vector2 {
2
+ x;
3
+ y;
4
+ constructor(x, y) {
5
+ this.x = x;
6
+ this.y = y;
7
+ }
8
+ dot2(x, y) {
9
+ return this.x * x + this.y * y;
10
+ }
11
+ }
12
+ export class Vector3 extends Vector2 {
13
+ z;
14
+ constructor(x, y, z) {
15
+ super(x, y);
16
+ this.z = z;
17
+ }
18
+ }
19
+ //# sourceMappingURL=vector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vector.js","sourceRoot":"","sources":["../source/vector.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,OAAO;IAClB,CAAC,CAAS;IACV,CAAC,CAAS;IAEV,YAAY,CAAS,EAAE,CAAS;QAC9B,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;QACX,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;IACb,CAAC;IAED,IAAI,CAAC,CAAS,EAAE,CAAS;QACvB,OAAO,IAAI,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;IACjC,CAAC;CACF;AAED,MAAM,OAAO,OAAQ,SAAQ,OAAO;IAClC,CAAC,CAAS;IAEV,YAAY,CAAS,EAAE,CAAS,EAAE,CAAS;QACzC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACZ,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;IACb,CAAC;CACF"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@oliversalzburg/js-utils",
4
- "version": "0.0.4",
4
+ "version": "0.0.5",
5
5
  "license": "MIT",
6
6
  "author": "Oliver Salzburg <oliver.salzburg@gmail.com>",
7
7
  "type": "module",
@@ -17,29 +17,44 @@
17
17
  "build": "yarn run build:tsc",
18
18
  "build:esbuild": "node build.js",
19
19
  "build:tsc": "tsc",
20
- "lint": "yarn run lint:eslint && yarn run lint:tsc",
20
+ "docs:typedoc": "typedoc --plugin typedoc-plugin-markdown",
21
+ "lint": "yarn run lint:eslint && yarn run lint:prettier && yarn run lint:tsc",
21
22
  "lint:eslint": "eslint source ./*js",
23
+ "lint:prettier": "prettier --check source ./*js",
22
24
  "lint:tsc": "tsc --noEmit",
23
25
  "npm:publish": "npm publish",
24
26
  "npm:publish:major": "npm version major && npm publish",
25
27
  "npm:publish:minor": "npm version minor && npm publish",
26
28
  "npm:publish:patch": "npm version patch && npm publish",
27
- "prepack": "yarn run build"
29
+ "prepack": "yarn run build",
30
+ "test": "node --enable-source-maps $(yarn bin mocha) ./output/*.test.js",
31
+ "test:coverage": "c8 --reporter html-spa --reporter text node --enable-source-maps $(yarn bin mocha)",
32
+ "test:inspect": "node $(yarn bin mocha) --inspect ./output/*.test.js"
28
33
  },
29
34
  "types": "./output/index.d.ts",
30
35
  "devDependencies": {
36
+ "@types/chai": "4.3.9",
37
+ "@types/chai-as-promised": "7.1.7",
31
38
  "@types/eslint": "8.44.6",
32
- "@types/node": "20.8.9",
33
- "@typescript-eslint/eslint-plugin": "6.9.0",
34
- "@typescript-eslint/parser": "6.9.0",
39
+ "@types/mocha": "10.0.3",
40
+ "@types/node": "20.8.10",
41
+ "@types/web": "0.0.119",
42
+ "@typescript-eslint/eslint-plugin": "6.9.1",
43
+ "@typescript-eslint/parser": "6.9.1",
44
+ "c8": "8.0.1",
45
+ "chai": "4.3.10",
46
+ "chai-as-promised": "7.1.1",
35
47
  "esbuild": "0.19.5",
36
- "eslint": "8.52.0",
48
+ "eslint": "8.53.0",
37
49
  "eslint-plugin-jsdoc": "46.8.2",
38
50
  "lint-staged": "15.0.2",
51
+ "mocha": "10.2.0",
39
52
  "prettier": "3.0.3",
40
53
  "prettier-package-json": "2.8.0",
41
54
  "prettier-plugin-organize-imports": "3.2.3",
55
+ "typedoc": "0.25.3",
56
+ "typedoc-plugin-markdown": "3.17.0",
42
57
  "typescript": "5.2.2"
43
58
  },
44
- "packageManager": "yarn@4.0.0"
59
+ "packageManager": "yarn@4.0.1"
45
60
  }
package/typedoc.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "$schema": "https://typedoc.org/schema.json",
3
+ "basePath": "./source",
4
+ "entryPoints": ["./source/index.ts"],
5
+ "excludePrivate": true,
6
+ "hideInPageTOC": true,
7
+ "out": "./docs"
8
+ }