@limitlesspc/std 0.21.0 → 0.22.0

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,109 +1,107 @@
1
1
  {
2
2
  "name": "@limitlesspc/std",
3
3
  "type": "module",
4
- "version": "0.21.0",
4
+ "version": "0.22.0",
5
+ "packageManager": "pnpm@10.25.0",
5
6
  "description": "A standard library for JavaScript",
6
7
  "license": "MIT",
7
- "publishConfig": {
8
- "access": "public"
9
- },
10
8
  "exports": {
11
9
  "./package.json": "./package.json",
12
10
  "./async": {
13
- "default": "./dist/async/index.js",
14
- "types": "./dist/async/index.d.ts"
11
+ "types": "./dist/async/index.d.ts",
12
+ "default": "./dist/async/index.js"
15
13
  },
16
14
  "./cmath": {
17
- "default": "./dist/cmath/index.js",
18
- "types": "./dist/cmath/index.d.ts"
15
+ "types": "./dist/cmath/index.d.ts",
16
+ "default": "./dist/cmath/index.js"
19
17
  },
20
18
  "./fn": {
21
- "default": "./dist/fn/index.js",
22
- "types": "./dist/fn/index.d.ts"
19
+ "types": "./dist/fn/index.d.ts",
20
+ "default": "./dist/fn/index.js"
23
21
  },
24
22
  "./gfx": {
25
- "default": "./dist/gfx/index.js",
26
- "types": "./dist/gfx/index.d.ts"
23
+ "types": "./dist/gfx/index.d.ts",
24
+ "default": "./dist/gfx/index.js"
27
25
  },
28
26
  "./iter": {
29
- "default": "./dist/iter/index.js",
30
- "types": "./dist/iter/index.d.ts"
27
+ "types": "./dist/iter/index.d.ts",
28
+ "default": "./dist/iter/index.js"
31
29
  },
32
30
  "./math": {
33
- "default": "./dist/math/index.js",
34
- "types": "./dist/math/index.d.ts"
31
+ "types": "./dist/math/index.d.ts",
32
+ "default": "./dist/math/index.js"
35
33
  },
36
34
  "./string": {
37
- "default": "./dist/string/index.js",
38
- "types": "./dist/string/index.d.ts"
35
+ "types": "./dist/string/index.d.ts",
36
+ "default": "./dist/string/index.js"
39
37
  },
40
38
  "./structs": {
41
- "default": "./dist/structs/index.js",
42
- "types": "./dist/structs/index.d.ts"
39
+ "types": "./dist/structs/index.d.ts",
40
+ "default": "./dist/structs/index.js"
43
41
  },
44
42
  "./time": {
45
- "default": "./dist/time/index.js",
46
- "types": "./dist/time/index.d.ts"
43
+ "types": "./dist/time/index.d.ts",
44
+ "default": "./dist/time/index.js"
47
45
  },
48
46
  "./array": {
49
- "default": "./dist/array.js",
50
- "types": "./dist/array.d.ts"
47
+ "types": "./dist/array.d.ts",
48
+ "default": "./dist/array.js"
51
49
  },
52
50
  "./bytes": {
53
- "default": "./dist/bytes.js",
54
- "types": "./dist/bytes.d.ts"
51
+ "types": "./dist/bytes.d.ts",
52
+ "default": "./dist/bytes.js"
55
53
  },
56
54
  "./cmp": {
57
- "default": "./dist/cmp.js",
58
- "types": "./dist/cmp.d.ts"
55
+ "types": "./dist/cmp.d.ts",
56
+ "default": "./dist/cmp.js"
59
57
  },
60
58
  "./csv": {
61
- "default": "./dist/csv.js",
62
- "types": "./dist/csv.d.ts"
63
- },
64
- "./easing": {
65
- "default": "./dist/easing.js",
66
- "types": "./dist/easing.d.ts"
59
+ "types": "./dist/csv.d.ts",
60
+ "default": "./dist/csv.js"
67
61
  },
68
62
  "./events": {
69
- "default": "./dist/events.js",
70
- "types": "./dist/events.d.ts"
63
+ "types": "./dist/events.d.ts",
64
+ "default": "./dist/events.js"
71
65
  },
72
66
  "./object": {
73
- "default": "./dist/object.js",
74
- "types": "./dist/object.d.ts"
67
+ "types": "./dist/object.d.ts",
68
+ "default": "./dist/object.js"
75
69
  },
76
70
  "./random": {
77
- "default": "./dist/random.js",
78
- "types": "./dist/random.d.ts"
71
+ "types": "./dist/random.d.ts",
72
+ "default": "./dist/random.js"
79
73
  },
80
74
  "./types": {
81
- "default": "./dist/types.js",
82
- "types": "./dist/types.d.ts"
75
+ "types": "./dist/types.d.ts",
76
+ "default": "./dist/types.js"
83
77
  }
84
78
  },
85
79
  "files": [
86
80
  "dist"
87
81
  ],
88
82
  "prettier": "@limitlesspc/prettier-config",
89
- "devDependencies": {
90
- "@limitlesspc/eslint-config": "^0.16.2",
91
- "@limitlesspc/prettier-config": "^1.1.1",
92
- "bumpp": "^9.8.1",
93
- "tsup": "^8.3.5",
94
- "typescript": "^5.7.2",
95
- "vitest": "^2.1.6"
96
- },
97
83
  "scripts": {
98
84
  "build": "tsup",
99
- "test": "vitest",
100
85
  "fmt": "prettier . --write --cache --ignore-unknown",
101
86
  "fmt:check": "prettier . --check --cache --ignore-unknown",
102
87
  "lint": "eslint",
103
88
  "lint:fix": "eslint --fix",
104
89
  "lint:fix-dry": "eslint --fix-dry-run",
105
- "check-exports": "attw --pack . --ignore-rules=cjs-resolves-to-esm",
90
+ "test": "vitest",
91
+ "coverage": "vitest run --coverage",
92
+ "prepack": "nr build",
106
93
  "release": "bumpp && pnpm publish",
107
94
  "typecheck": "tsc --noEmit"
95
+ },
96
+ "devDependencies": {
97
+ "@limitlesspc/eslint-config": "^0.18.4",
98
+ "@limitlesspc/prettier-config": "^1.2.1",
99
+ "@vitest/coverage-v8": "^4.0.16",
100
+ "bumpp": "^10.3.2",
101
+ "eslint": "^9.39.2",
102
+ "prettier": "^3.7.4",
103
+ "tsup": "^8.5.1",
104
+ "typescript": "^5.9.3",
105
+ "vitest": "^4.0.15"
108
106
  }
109
- }
107
+ }
File without changes
@@ -1,523 +0,0 @@
1
- import {
2
- swap
3
- } from "./chunk-65SNM7MP.js";
4
- import {
5
- ascend,
6
- descend
7
- } from "./chunk-TMLWLR46.js";
8
-
9
- // src/structs/doubly-linked-list.ts
10
- var DoublyLinkedList = class _DoublyLinkedList {
11
- head;
12
- tail;
13
- size = 0;
14
- static from(values) {
15
- const list = new _DoublyLinkedList();
16
- for (const value of values) {
17
- list.push(value);
18
- }
19
- return list;
20
- }
21
- get length() {
22
- return this.size;
23
- }
24
- *[Symbol.iterator]() {
25
- let current = this.head;
26
- while (current) {
27
- yield current.value;
28
- current = current.next;
29
- }
30
- }
31
- getNode(index) {
32
- let current = this.head;
33
- let i = 0;
34
- while (current) {
35
- if (i === index) {
36
- return current;
37
- }
38
- current = current.next;
39
- i++;
40
- }
41
- return void 0;
42
- }
43
- get(index) {
44
- return this.getNode(index)?.value;
45
- }
46
- set(index, value) {
47
- const node = this.getNode(index);
48
- if (!node) {
49
- return void 0;
50
- }
51
- const { value: oldValue } = node;
52
- node.value = value;
53
- return oldValue;
54
- }
55
- push(value) {
56
- const node = { value };
57
- if (this.tail) {
58
- this.tail.next = node;
59
- this.tail = node;
60
- } else {
61
- this.head = node;
62
- this.tail = node;
63
- }
64
- return ++this.size;
65
- }
66
- pop() {
67
- if (!this.tail) {
68
- return void 0;
69
- }
70
- const { value } = this.tail;
71
- this.tail = this.tail.prev;
72
- if (!this.tail) {
73
- this.head = void 0;
74
- }
75
- this.size--;
76
- return value;
77
- }
78
- unshift(value) {
79
- const node = { value };
80
- if (this.head) {
81
- this.head.prev = node;
82
- this.head = node;
83
- } else {
84
- this.head = node;
85
- this.tail = node;
86
- }
87
- return ++this.size;
88
- }
89
- shift() {
90
- if (!this.head) {
91
- return void 0;
92
- }
93
- const { value } = this.head;
94
- this.head = this.head.next;
95
- if (!this.head) {
96
- this.tail = void 0;
97
- }
98
- this.size--;
99
- return value;
100
- }
101
- reverse() {
102
- let current = this.head;
103
- let previous;
104
- let next;
105
- while (current) {
106
- ({ next } = current);
107
- current.next = previous;
108
- current.prev = next;
109
- previous = current;
110
- current = next;
111
- }
112
- this.tail = this.head;
113
- this.head = previous;
114
- return this;
115
- }
116
- remove(index) {
117
- const node = this.getNode(index);
118
- if (!node) {
119
- return void 0;
120
- }
121
- if (node.prev) {
122
- node.prev.next = node.next;
123
- }
124
- if (node.next) {
125
- node.next.prev = node.prev;
126
- }
127
- if (node === this.head) {
128
- this.head = node.next;
129
- }
130
- if (node === this.tail) {
131
- this.tail = node.prev;
132
- }
133
- this.size--;
134
- return node.value;
135
- }
136
- splice(index, count, ...values) {
137
- const removed = [];
138
- for (let i = 0; i < count; i++) {
139
- const value = this.remove(index);
140
- if (value) {
141
- removed.push(value);
142
- }
143
- }
144
- for (const value of values) {
145
- this.set(index, value);
146
- }
147
- return removed;
148
- }
149
- };
150
-
151
- // src/structs/heaps/heap.ts
152
- var Heap = class _Heap {
153
- constructor(compare, data = [], heapify = true) {
154
- this.compare = compare;
155
- if (heapify) {
156
- this.data = [];
157
- this.push(...data);
158
- } else {
159
- this.data = data;
160
- }
161
- }
162
- data;
163
- get length() {
164
- return this.data.length;
165
- }
166
- get height() {
167
- return Math.floor(Math.log2(this.length)) + 1;
168
- }
169
- valueOf() {
170
- return this.peek();
171
- }
172
- copy() {
173
- return new _Heap(this.compare, [...this.data], false);
174
- }
175
- /**
176
- * Returns the first value in the heap
177
- */
178
- peek() {
179
- return this.data[0];
180
- }
181
- /**
182
- * Removes the first value from the heap and returns it
183
- */
184
- pop() {
185
- const first = this.data[0];
186
- swap(this.data, 0, this.length - 1);
187
- this.data.pop();
188
- this.heapify();
189
- return first;
190
- }
191
- /**
192
- * Inserts values into the heap and makes sure the first value is the min/max
193
- * @param values
194
- * @returns The new length of the heap
195
- */
196
- push(...values) {
197
- const { data, compare } = this;
198
- for (const value of values) {
199
- data.push(value);
200
- let i = data.length - 1;
201
- let parent = Math.floor((i - 1) / 2);
202
- while (i > 0 && compare(data[i], data[parent]) < 0) {
203
- swap(data, i, parent);
204
- i = parent;
205
- parent = Math.floor((i - 1) / 2);
206
- }
207
- }
208
- return data.length;
209
- }
210
- *drain() {
211
- while (this.length) {
212
- yield this.pop();
213
- }
214
- }
215
- [Symbol.iterator]() {
216
- return this.data.values();
217
- }
218
- heapify(i = 0) {
219
- const { length, compare, data } = this;
220
- const left = 2 * i + 1;
221
- const right = 2 * i + 2;
222
- let largest = i;
223
- if (left < length && compare(data[left], data[largest]) < 0) {
224
- largest = left;
225
- }
226
- if (right < length && compare(data[right], data[largest]) < 0) {
227
- largest = right;
228
- }
229
- if (largest !== i) {
230
- swap(data, i, largest);
231
- this.heapify(largest);
232
- }
233
- }
234
- };
235
-
236
- // src/structs/heaps/max-heap.ts
237
- var MaxHeap = class _MaxHeap extends Heap {
238
- constructor(data, heapify) {
239
- super(descend, data, heapify);
240
- }
241
- copy() {
242
- return new _MaxHeap([...this.data], false);
243
- }
244
- };
245
-
246
- // src/structs/heaps/min-heap.ts
247
- var MinHeap = class _MinHeap extends Heap {
248
- constructor(data, heapify) {
249
- super(ascend, data, heapify);
250
- }
251
- copy() {
252
- return new _MinHeap([...this.data], false);
253
- }
254
- };
255
-
256
- // src/structs/linked-list.ts
257
- var LinkedList = class _LinkedList {
258
- node;
259
- static from(values) {
260
- const list = new _LinkedList();
261
- let node;
262
- for (const value of values) {
263
- const child = { value };
264
- if (node) {
265
- node.next = child;
266
- }
267
- node = child;
268
- }
269
- list.node = node;
270
- return list;
271
- }
272
- get length() {
273
- let { node } = this;
274
- let length = 0;
275
- while (node) {
276
- length++;
277
- node = node.next;
278
- }
279
- return length;
280
- }
281
- *[Symbol.iterator]() {
282
- let { node } = this;
283
- while (node) {
284
- yield node.value;
285
- node = node.next;
286
- }
287
- }
288
- get tail() {
289
- let { node } = this;
290
- while (node) {
291
- node = node.next;
292
- }
293
- return node;
294
- }
295
- getNode(index) {
296
- let current = this.node;
297
- let i = 0;
298
- while (current) {
299
- if (i === index) {
300
- return current;
301
- }
302
- current = current.next;
303
- i++;
304
- }
305
- }
306
- get(index) {
307
- return this.getNode(index)?.value;
308
- }
309
- set(index, value) {
310
- const node = this.getNode(index);
311
- if (!node) {
312
- return;
313
- }
314
- const { value: oldValue } = node;
315
- node.value = value;
316
- return oldValue;
317
- }
318
- push(value) {
319
- const { tail } = this;
320
- const node = { value };
321
- if (tail) {
322
- tail.next = node;
323
- } else {
324
- this.node = node;
325
- }
326
- }
327
- pop() {
328
- let current = this.node;
329
- let parent;
330
- while (current) {
331
- if (!current.next) {
332
- delete parent?.next;
333
- return current;
334
- }
335
- parent = current;
336
- current = current.next;
337
- }
338
- }
339
- unshift(value) {
340
- const node = { value };
341
- if (this.node) {
342
- node.next = this.node;
343
- this.node = node;
344
- }
345
- this.node = node;
346
- }
347
- shift() {
348
- const { node } = this;
349
- this.node = node?.next;
350
- return node;
351
- }
352
- };
353
-
354
- // src/structs/queue.ts
355
- var Queue = class {
356
- constructor(items = []) {
357
- this.items = items;
358
- }
359
- get size() {
360
- return this.items.length;
361
- }
362
- enqueue(item) {
363
- return this.items.push(item);
364
- }
365
- dequeue() {
366
- return this.items.shift();
367
- }
368
- *[Symbol.iterator]() {
369
- let item;
370
- while (item = this.dequeue()) {
371
- yield item;
372
- }
373
- }
374
- };
375
-
376
- // src/structs/sorted-array.ts
377
- var SortedArray = class _SortedArray {
378
- constructor(data = [], compare = ascend, sort = true) {
379
- this.data = data;
380
- this.compare = compare;
381
- if (sort) {
382
- this.data.sort(compare);
383
- }
384
- }
385
- valueOf() {
386
- return this.at(0);
387
- }
388
- keys() {
389
- return this.data.keys();
390
- }
391
- values() {
392
- return this.data.values();
393
- }
394
- entries() {
395
- return this.data.entries();
396
- }
397
- [Symbol.iterator]() {
398
- return this.values();
399
- }
400
- length() {
401
- return this.data.length;
402
- }
403
- at(index) {
404
- return this.data[index];
405
- }
406
- copy() {
407
- return new _SortedArray([...this.data], this.compare, false);
408
- }
409
- /**
410
- * Returns the index of the value if it exists, otherwise -1
411
- * @param value
412
- */
413
- indexOf(value) {
414
- const { data } = this;
415
- let low = 0;
416
- let high = data.length - 1;
417
- while (low <= high) {
418
- const mid = Math.floor((low + high) / 2);
419
- const cmp = this.compare(value, data[mid]);
420
- if (cmp < 0) {
421
- high = mid - 1;
422
- } else if (cmp > 0) {
423
- low = mid + 1;
424
- } else {
425
- return mid;
426
- }
427
- }
428
- return -1;
429
- }
430
- /**
431
- * Returns if the array has the value
432
- * @param value
433
- */
434
- has(value) {
435
- return this.data.includes(value);
436
- }
437
- /**
438
- * Binary inserts a value into the array while maintaining sorted order
439
- * @param value
440
- * @returns the index of where the value was inserted
441
- */
442
- push(value) {
443
- const { data, compare } = this;
444
- let low = 0;
445
- let high = data.length - 1;
446
- while (low <= high) {
447
- const mid = Math.floor((low + high) / 2);
448
- const cmp = compare(value, data[mid]);
449
- if (cmp < 0) {
450
- high = mid - 1;
451
- } else if (cmp > 0) {
452
- low = mid + 1;
453
- } else {
454
- data.splice(mid, 0, value);
455
- return mid;
456
- }
457
- }
458
- data.splice(low, 0, value);
459
- return low;
460
- }
461
- };
462
-
463
- // src/structs/unordered-array.ts
464
- var UnorderedArray = class _UnorderedArray extends Array {
465
- copy() {
466
- return new _UnorderedArray(...this);
467
- }
468
- /**
469
- * Inserts new elements at the end of an unordered array, and returns the new length of the unordered array.
470
- * @param items Elements to insert at the end of the array.
471
- */
472
- unshift(...items) {
473
- return super.push(...items);
474
- }
475
- /**
476
- * Removes the last element from an array and returns it.
477
- * If the array is empty, undefined is returned and the array is not modified.
478
- */
479
- shift() {
480
- return super.pop();
481
- }
482
- /**
483
- * Removes an item by index
484
- * @param index the index of the item to remove
485
- * @returns the removed item, if it exists
486
- */
487
- removeIndex(index) {
488
- swap(this, index, this.length - 1);
489
- return this.pop();
490
- }
491
- splice(start, deleteCount = this.length - start, ...items) {
492
- const spliced = [];
493
- for (let i = 0; i < deleteCount; i++) {
494
- const replacement = items[i];
495
- let removed;
496
- if (replacement) {
497
- removed = this[start + i];
498
- this[start + i] = replacement;
499
- } else {
500
- removed = this.removeIndex(start);
501
- }
502
- if (removed) {
503
- spliced.push(removed);
504
- }
505
- }
506
- return spliced;
507
- }
508
- toSpliced(start, deleteCount = this.length - start, ...items) {
509
- const copy = this.copy();
510
- copy.splice(start, deleteCount, ...items);
511
- return copy;
512
- }
513
- };
514
-
515
- export {
516
- DoublyLinkedList,
517
- MaxHeap,
518
- MinHeap,
519
- LinkedList,
520
- Queue,
521
- SortedArray,
522
- UnorderedArray
523
- };