@bitbeater/ecma-utils 2.7.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.
Files changed (90) hide show
  1. package/README.md +23 -0
  2. package/dist/bytes.d.ts +65 -0
  3. package/dist/bytes.d.ts.map +1 -0
  4. package/dist/bytes.js +68 -0
  5. package/dist/bytes.js.map +1 -0
  6. package/dist/collection/CircularArray.d.ts +98 -0
  7. package/dist/collection/CircularArray.d.ts.map +1 -0
  8. package/dist/collection/CircularArray.js +134 -0
  9. package/dist/collection/CircularArray.js.map +1 -0
  10. package/dist/collection/EvictingDequeue.d.ts +22 -0
  11. package/dist/collection/EvictingDequeue.d.ts.map +1 -0
  12. package/dist/collection/EvictingDequeue.js +57 -0
  13. package/dist/collection/EvictingDequeue.js.map +1 -0
  14. package/dist/collection/collection.d.ts +4 -0
  15. package/dist/collection/collection.d.ts.map +1 -0
  16. package/dist/collection/collection.js +23 -0
  17. package/dist/collection/collection.js.map +1 -0
  18. package/dist/collection/collectionOperations.d.ts +125 -0
  19. package/dist/collection/collectionOperations.d.ts.map +1 -0
  20. package/dist/collection/collectionOperations.js +193 -0
  21. package/dist/collection/collectionOperations.js.map +1 -0
  22. package/dist/cons.d.ts +34 -0
  23. package/dist/cons.d.ts.map +1 -0
  24. package/dist/cons.js +49 -0
  25. package/dist/cons.js.map +1 -0
  26. package/dist/consts.d.ts +2 -0
  27. package/dist/consts.d.ts.map +1 -0
  28. package/dist/consts.js +5 -0
  29. package/dist/consts.js.map +1 -0
  30. package/dist/index.d.ts +13 -0
  31. package/dist/index.d.ts.map +1 -0
  32. package/dist/index.js +49 -0
  33. package/dist/index.js.map +1 -0
  34. package/dist/logger.d.ts +95 -0
  35. package/dist/logger.d.ts.map +1 -0
  36. package/dist/logger.js +172 -0
  37. package/dist/logger.js.map +1 -0
  38. package/dist/math.d.ts +183 -0
  39. package/dist/math.d.ts.map +1 -0
  40. package/dist/math.js +263 -0
  41. package/dist/math.js.map +1 -0
  42. package/dist/net/http.d.ts +22 -0
  43. package/dist/net/http.d.ts.map +1 -0
  44. package/dist/net/http.js +74 -0
  45. package/dist/net/http.js.map +1 -0
  46. package/dist/object.d.ts +98 -0
  47. package/dist/object.d.ts.map +1 -0
  48. package/dist/object.js +127 -0
  49. package/dist/object.js.map +1 -0
  50. package/dist/path/path.d.ts +2 -0
  51. package/dist/path/path.d.ts.map +1 -0
  52. package/dist/path/path.js +8 -0
  53. package/dist/path/path.js.map +1 -0
  54. package/dist/promises.d.ts +3 -0
  55. package/dist/promises.d.ts.map +1 -0
  56. package/dist/promises.js +13 -0
  57. package/dist/promises.js.map +1 -0
  58. package/dist/random.d.ts +46 -0
  59. package/dist/random.d.ts.map +1 -0
  60. package/dist/random.js +76 -0
  61. package/dist/random.js.map +1 -0
  62. package/dist/revivers.d.ts +25 -0
  63. package/dist/revivers.d.ts.map +1 -0
  64. package/dist/revivers.js +34 -0
  65. package/dist/revivers.js.map +1 -0
  66. package/dist/strings.d.ts +16 -0
  67. package/dist/strings.d.ts.map +1 -0
  68. package/dist/strings.js +34 -0
  69. package/dist/strings.js.map +1 -0
  70. package/dist/time/time.d.ts +189 -0
  71. package/dist/time/time.d.ts.map +1 -0
  72. package/dist/time/time.js +315 -0
  73. package/dist/time/time.js.map +1 -0
  74. package/dist/time/timer.d.ts +93 -0
  75. package/dist/time/timer.d.ts.map +1 -0
  76. package/dist/time/timer.js +182 -0
  77. package/dist/time/timer.js.map +1 -0
  78. package/dist/time.d.ts +189 -0
  79. package/dist/time.d.ts.map +1 -0
  80. package/dist/time.js +308 -0
  81. package/dist/time.js.map +1 -0
  82. package/dist/utils/task_duration_tracker.d.ts +102 -0
  83. package/dist/utils/task_duration_tracker.d.ts.map +1 -0
  84. package/dist/utils/task_duration_tracker.js +144 -0
  85. package/dist/utils/task_duration_tracker.js.map +1 -0
  86. package/dist/utils/utils.d.ts +24 -0
  87. package/dist/utils/utils.d.ts.map +1 -0
  88. package/dist/utils/utils.js +47 -0
  89. package/dist/utils/utils.js.map +1 -0
  90. package/package.json +68 -0
package/README.md ADDED
@@ -0,0 +1,23 @@
1
+ # ecma-utils
2
+
3
+ [See Documentation](https://bitbeater.github.io/)
4
+
5
+ Simple, lightweight, dependenciesless, TypeScript generic helper library.
6
+
7
+ ---
8
+ Compatible with:
9
+ - Node.js
10
+ - Deno
11
+ - Browser
12
+
13
+ ## Installation
14
+
15
+ npm
16
+ ```bash
17
+ npm i @bitBeater/ecma-utils
18
+ ```
19
+
20
+ deno
21
+ ```bash
22
+ deno install npm:@bitBeater/ecma-utils
23
+ ```
@@ -0,0 +1,65 @@
1
+ /**
2
+ * one chilo byte as bytes.
3
+ *
4
+ * ```
5
+ * 2 ** 10
6
+ * ```
7
+ * */
8
+ export declare const kB: number;
9
+ /**
10
+ * one mega byte as bytes.
11
+ *
12
+ * ```
13
+ * 2 ** 20
14
+ * ```
15
+ * */
16
+ export declare const MB: number;
17
+ /**
18
+ * one giga byte as bytes.
19
+ *
20
+ * ```
21
+ * 2 ** 30
22
+ * ```
23
+ * */
24
+ export declare const GB: number;
25
+ /**
26
+ * one tera byte as bytes.
27
+ *
28
+ * ```
29
+ * 2 ** 40
30
+ * ```
31
+ * */
32
+ export declare const TB: number;
33
+ /**
34
+ * one peta byte as bytes.
35
+ *
36
+ * ```
37
+ * 2 ** 50
38
+ * ```
39
+ * */
40
+ export declare const PB: number;
41
+ /**
42
+ * one exa byte as bytes.
43
+ *
44
+ * ```
45
+ * 2 ** 60
46
+ * ```
47
+ * */
48
+ export declare const EB: number;
49
+ /**
50
+ * one zetta byte as bytes.
51
+ *
52
+ * ```
53
+ * 2 ** 70
54
+ * ```
55
+ * */
56
+ export declare const ZB: number;
57
+ /**
58
+ * one yotta byte as bytes.
59
+ *
60
+ * ```
61
+ * 2 ** 80
62
+ * ```
63
+ * */
64
+ export declare const YB: number;
65
+ //# sourceMappingURL=bytes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bytes.d.ts","sourceRoot":"","sources":["../src/bytes.ts"],"names":[],"mappings":"AAAA;;;;;;KAMK;AACL,eAAO,MAAM,EAAE,QAAU,CAAC;AAE1B;;;;;;KAMK;AACL,eAAO,MAAM,EAAE,QAAU,CAAC;AAE1B;;;;;;KAMK;AACL,eAAO,MAAM,EAAE,QAAU,CAAC;AAE1B;;;;;;KAMK;AACL,eAAO,MAAM,EAAE,QAAU,CAAC;AAE1B;;;;;;KAMK;AACL,eAAO,MAAM,EAAE,QAAU,CAAC;AAE1B;;;;;;KAMK;AACL,eAAO,MAAM,EAAE,QAAU,CAAC;AAE1B;;;;;;KAMK;AACL,eAAO,MAAM,EAAE,QAAU,CAAC;AAE1B;;;;;;KAMK;AACL,eAAO,MAAM,EAAE,QAAU,CAAC"}
package/dist/bytes.js ADDED
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.YB = exports.ZB = exports.EB = exports.PB = exports.TB = exports.GB = exports.MB = exports.kB = void 0;
4
+ /**
5
+ * one chilo byte as bytes.
6
+ *
7
+ * ```
8
+ * 2 ** 10
9
+ * ```
10
+ * */
11
+ exports.kB = 2 ** 10;
12
+ /**
13
+ * one mega byte as bytes.
14
+ *
15
+ * ```
16
+ * 2 ** 20
17
+ * ```
18
+ * */
19
+ exports.MB = 2 ** 20;
20
+ /**
21
+ * one giga byte as bytes.
22
+ *
23
+ * ```
24
+ * 2 ** 30
25
+ * ```
26
+ * */
27
+ exports.GB = 2 ** 30;
28
+ /**
29
+ * one tera byte as bytes.
30
+ *
31
+ * ```
32
+ * 2 ** 40
33
+ * ```
34
+ * */
35
+ exports.TB = 2 ** 40;
36
+ /**
37
+ * one peta byte as bytes.
38
+ *
39
+ * ```
40
+ * 2 ** 50
41
+ * ```
42
+ * */
43
+ exports.PB = 2 ** 50;
44
+ /**
45
+ * one exa byte as bytes.
46
+ *
47
+ * ```
48
+ * 2 ** 60
49
+ * ```
50
+ * */
51
+ exports.EB = 2 ** 60;
52
+ /**
53
+ * one zetta byte as bytes.
54
+ *
55
+ * ```
56
+ * 2 ** 70
57
+ * ```
58
+ * */
59
+ exports.ZB = 2 ** 70;
60
+ /**
61
+ * one yotta byte as bytes.
62
+ *
63
+ * ```
64
+ * 2 ** 80
65
+ * ```
66
+ * */
67
+ exports.YB = 2 ** 80;
68
+ //# sourceMappingURL=bytes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bytes.js","sourceRoot":"","sources":["../src/bytes.ts"],"names":[],"mappings":";;;AAAA;;;;;;KAMK;AACQ,QAAA,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC;AAE1B;;;;;;KAMK;AACQ,QAAA,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC;AAE1B;;;;;;KAMK;AACQ,QAAA,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC;AAE1B;;;;;;KAMK;AACQ,QAAA,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC;AAE1B;;;;;;KAMK;AACQ,QAAA,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC;AAE1B;;;;;;KAMK;AACQ,QAAA,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC;AAE1B;;;;;;KAMK;AACQ,QAAA,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC;AAE1B;;;;;;KAMK;AACQ,QAAA,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC"}
@@ -0,0 +1,98 @@
1
+ /**
2
+ * A circular array implementation that allows for wrapping around the ends.
3
+ * @example
4
+ * ```ts
5
+ * import { collection } from 'iggs-utils';
6
+ *
7
+ * const circularArray = new collection.CircularArray<string>(monday, tuesday, wednesday, thursday, friday, saturday, sunday);
8
+ *
9
+ * // accessing elements by position
10
+ * circularArray.get() // monday
11
+ * circularArray.get(0) // monday
12
+ * circularArray.get(1) // tuesday
13
+ * circularArray.get(2) // wednesday
14
+ * circularArray.get(-1) // sunday
15
+ * circularArray.get(7) // monday
16
+ * circularArray.get(-7) // monday
17
+ *
18
+ * // navigating the circular array
19
+ * circularArray.next() // tuesday
20
+ * circularArray.next() // wednesday
21
+ * circularArray.next() // thursday
22
+ * circularArray.next(10) // sunday
23
+ * circularArray.get() // sunday
24
+ * circularArray.previous() // saturday
25
+ * circularArray.previous() // friday
26
+ * circularArray.previous() // thursday
27
+ * circularArray.previous(10) // monday
28
+ * circularArray.get() // monday
29
+ *
30
+ * // working with positions
31
+ * circularArray.setIndex(2) // wednesday
32
+ * circularArray.setPosition(10) // thursday
33
+ * circularArray.getIndex() // 3
34
+ * circularArray.getPosition() // 10
35
+ * ```
36
+ */
37
+ export declare class CircularArray<T> {
38
+ private array;
39
+ private currentIndex;
40
+ private currentPosition;
41
+ constructor(...items: T[]);
42
+ /**
43
+ * Moves the current position forward by the specified number of steps (1 by default).
44
+ * @param steps The number of steps to move forward (default is 1).
45
+ * @returns The value at the new current position.
46
+ */
47
+ next(steps?: number): T;
48
+ /**
49
+ * Moves the current position backward by the specified number of steps (1 by default).
50
+ * @param steps The number of steps to move backward (default is 1).
51
+ * @returns The value at the new current position.
52
+ */
53
+ previous(steps?: number): T;
54
+ /**
55
+ * Returns the element at the specified position in the circular array.
56
+ * @param position The position to peek at (defaults to the current position).
57
+ * @returns The value at the specified position.
58
+ */
59
+ get(position?: number): T;
60
+ /**
61
+ * Returns the current index in the circular array.
62
+ * @returns The current index.
63
+ */
64
+ getIndex(): number;
65
+ /**
66
+ * Returns the current index in the circular array.
67
+ * @returns The current index.
68
+ */
69
+ getPosition(): number;
70
+ /**
71
+ * Returns the size of the circular array.
72
+ * @returns The size of the circular array.
73
+ */
74
+ getSize(): number;
75
+ /**
76
+ * Returns a shallow copy of the circular array as a regular array.
77
+ * @returns A regular array containing the elements of the circular array.
78
+ */
79
+ toArray(): T[];
80
+ /**
81
+ * Set the current position in the circular array.
82
+ * @param position The position to set.
83
+ */
84
+ setPosition(position: number): T;
85
+ /**
86
+ * Set the current index in the circular array.
87
+ * Also updates the current position at the index value.
88
+ * @param index The index to set.
89
+ */
90
+ setIndex(index: number): T;
91
+ /**
92
+ * it converts a given position to a valid index within the array bounds.
93
+ * @param position can be negative or greater than the array length
94
+ * @returns a valid index within the array bounds
95
+ */
96
+ private positionToIndex;
97
+ }
98
+ //# sourceMappingURL=CircularArray.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CircularArray.d.ts","sourceRoot":"","sources":["../../src/collection/CircularArray.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,qBAAa,aAAa,CAAC,CAAC;IAC3B,OAAO,CAAC,KAAK,CAAM;IAEnB,OAAO,CAAC,YAAY,CAAK;IACzB,OAAO,CAAC,eAAe,CAAK;gBAEhB,GAAG,KAAK,EAAE,CAAC,EAAE;IAIzB;;;;OAIG;IACH,IAAI,CAAC,KAAK,GAAE,MAAU,GAAG,CAAC;IAM1B;;;;OAIG;IACH,QAAQ,CAAC,KAAK,GAAE,MAAU,GAAG,CAAC;IAM9B;;;;OAIG;IACH,GAAG,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,CAAC;IAKzB;;;OAGG;IACH,QAAQ,IAAI,MAAM;IAIlB;;;OAGG;IACH,WAAW,IAAI,MAAM;IAIrB;;;OAGG;IACH,OAAO,IAAI,MAAM;IAIjB;;;OAGG;IACH,OAAO,IAAI,CAAC,EAAE;IAId;;;OAGG;IACH,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,CAAC;IAMhC;;;;OAIG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC;IAO1B;;;;OAIG;IACH,OAAO,CAAC,eAAe;CAGvB"}
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CircularArray = void 0;
4
+ /**
5
+ * A circular array implementation that allows for wrapping around the ends.
6
+ * @example
7
+ * ```ts
8
+ * import { collection } from 'iggs-utils';
9
+ *
10
+ * const circularArray = new collection.CircularArray<string>(monday, tuesday, wednesday, thursday, friday, saturday, sunday);
11
+ *
12
+ * // accessing elements by position
13
+ * circularArray.get() // monday
14
+ * circularArray.get(0) // monday
15
+ * circularArray.get(1) // tuesday
16
+ * circularArray.get(2) // wednesday
17
+ * circularArray.get(-1) // sunday
18
+ * circularArray.get(7) // monday
19
+ * circularArray.get(-7) // monday
20
+ *
21
+ * // navigating the circular array
22
+ * circularArray.next() // tuesday
23
+ * circularArray.next() // wednesday
24
+ * circularArray.next() // thursday
25
+ * circularArray.next(10) // sunday
26
+ * circularArray.get() // sunday
27
+ * circularArray.previous() // saturday
28
+ * circularArray.previous() // friday
29
+ * circularArray.previous() // thursday
30
+ * circularArray.previous(10) // monday
31
+ * circularArray.get() // monday
32
+ *
33
+ * // working with positions
34
+ * circularArray.setIndex(2) // wednesday
35
+ * circularArray.setPosition(10) // thursday
36
+ * circularArray.getIndex() // 3
37
+ * circularArray.getPosition() // 10
38
+ * ```
39
+ */
40
+ class CircularArray {
41
+ constructor(...items) {
42
+ this.currentIndex = 0;
43
+ this.currentPosition = 0;
44
+ this.array = items || [];
45
+ }
46
+ /**
47
+ * Moves the current position forward by the specified number of steps (1 by default).
48
+ * @param steps The number of steps to move forward (default is 1).
49
+ * @returns The value at the new current position.
50
+ */
51
+ next(steps = 1) {
52
+ this.currentPosition += steps;
53
+ this.currentIndex = this.positionToIndex(this.currentPosition);
54
+ return this.get();
55
+ }
56
+ /**
57
+ * Moves the current position backward by the specified number of steps (1 by default).
58
+ * @param steps The number of steps to move backward (default is 1).
59
+ * @returns The value at the new current position.
60
+ */
61
+ previous(steps = 1) {
62
+ this.currentPosition -= steps;
63
+ this.currentIndex = this.positionToIndex(this.currentPosition);
64
+ return this.get();
65
+ }
66
+ /**
67
+ * Returns the element at the specified position in the circular array.
68
+ * @param position The position to peek at (defaults to the current position).
69
+ * @returns The value at the specified position.
70
+ */
71
+ get(position) {
72
+ const index = position !== undefined ? this.positionToIndex(position) : this.currentIndex;
73
+ return this.array[index];
74
+ }
75
+ /**
76
+ * Returns the current index in the circular array.
77
+ * @returns The current index.
78
+ */
79
+ getIndex() {
80
+ return this.currentIndex;
81
+ }
82
+ /**
83
+ * Returns the current index in the circular array.
84
+ * @returns The current index.
85
+ */
86
+ getPosition() {
87
+ return this.currentPosition;
88
+ }
89
+ /**
90
+ * Returns the size of the circular array.
91
+ * @returns The size of the circular array.
92
+ */
93
+ getSize() {
94
+ return this.array.length;
95
+ }
96
+ /**
97
+ * Returns a shallow copy of the circular array as a regular array.
98
+ * @returns A regular array containing the elements of the circular array.
99
+ */
100
+ toArray() {
101
+ return this.array.slice();
102
+ }
103
+ /**
104
+ * Set the current position in the circular array.
105
+ * @param position The position to set.
106
+ */
107
+ setPosition(position) {
108
+ this.currentPosition = position;
109
+ this.currentIndex = this.positionToIndex(position);
110
+ return this.get();
111
+ }
112
+ /**
113
+ * Set the current index in the circular array.
114
+ * Also updates the current position at the index value.
115
+ * @param index The index to set.
116
+ */
117
+ setIndex(index) {
118
+ if (index < 0 || index >= this.array.length)
119
+ throw new Error(`CircularArray.setIndex(): Index out of bounds: ${index}. Accepted range is 0 to ${this.array.length - 1}`);
120
+ this.currentIndex = index;
121
+ this.currentPosition = index;
122
+ return this.get();
123
+ }
124
+ /**
125
+ * it converts a given position to a valid index within the array bounds.
126
+ * @param position can be negative or greater than the array length
127
+ * @returns a valid index within the array bounds
128
+ */
129
+ positionToIndex(position) {
130
+ return ((position % this.array.length) + this.array.length) % this.array.length;
131
+ }
132
+ }
133
+ exports.CircularArray = CircularArray;
134
+ //# sourceMappingURL=CircularArray.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CircularArray.js","sourceRoot":"","sources":["../../src/collection/CircularArray.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAa,aAAa;IAMzB,YAAY,GAAG,KAAU;QAHjB,iBAAY,GAAG,CAAC,CAAC;QACjB,oBAAe,GAAG,CAAC,CAAC;QAG3B,IAAI,CAAC,KAAK,GAAG,KAAK,IAAI,EAAE,CAAC;IAC1B,CAAC;IAED;;;;OAIG;IACH,IAAI,CAAC,QAAgB,CAAC;QACrB,IAAI,CAAC,eAAe,IAAI,KAAK,CAAC;QAC9B,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QAC/D,OAAO,IAAI,CAAC,GAAG,EAAE,CAAC;IACnB,CAAC;IAED;;;;OAIG;IACH,QAAQ,CAAC,QAAgB,CAAC;QACzB,IAAI,CAAC,eAAe,IAAI,KAAK,CAAC;QAC9B,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QAC/D,OAAO,IAAI,CAAC,GAAG,EAAE,CAAC;IACnB,CAAC;IAED;;;;OAIG;IACH,GAAG,CAAC,QAAiB;QACpB,MAAM,KAAK,GAAG,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC;QAC1F,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC1B,CAAC;IAED;;;OAGG;IACH,QAAQ;QACP,OAAO,IAAI,CAAC,YAAY,CAAC;IAC1B,CAAC;IAED;;;OAGG;IACH,WAAW;QACV,OAAO,IAAI,CAAC,eAAe,CAAC;IAC7B,CAAC;IAED;;;OAGG;IACH,OAAO;QACN,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;IAC1B,CAAC;IAED;;;OAGG;IACH,OAAO;QACN,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IAC3B,CAAC;IAED;;;OAGG;IACH,WAAW,CAAC,QAAgB;QAC3B,IAAI,CAAC,eAAe,GAAG,QAAQ,CAAC;QAChC,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;QACnD,OAAO,IAAI,CAAC,GAAG,EAAE,CAAC;IACnB,CAAC;IAED;;;;OAIG;IACH,QAAQ,CAAC,KAAa;QACrB,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM;YAAE,MAAM,IAAI,KAAK,CAAC,kDAAkD,KAAK,4BAA4B,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,CAAC;QACzK,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC;QAC1B,IAAI,CAAC,eAAe,GAAG,KAAK,CAAC;QAC7B,OAAO,IAAI,CAAC,GAAG,EAAE,CAAC;IACnB,CAAC;IAED;;;;OAIG;IACK,eAAe,CAAC,QAAgB;QACvC,OAAO,CAAC,CAAC,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;IACjF,CAAC;CACD;AAxGD,sCAwGC"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * A non-blocking de-queue which automatically evicts elements from queue when attempting to add new elements onto the queue and it is full
3
+ *
4
+ * @example
5
+ * ```js
6
+ * const maxSize=3;
7
+ * const evictingDequeue = new EvictingDequeue<number>(maxSize,[1,2,3]);
8
+ *
9
+ * evictingDequeue; // [1,2,3]
10
+ * evictingDequeue.push(4); // [2,3,4]
11
+ * evictingDequeue.unshift(5); // [5,2,3]
12
+ *
13
+ * ```
14
+ */
15
+ export declare class EvictingDequeue<T> extends Array<T> {
16
+ #private;
17
+ constructor(maxLenght: number, items?: T[]);
18
+ push(...item: T[]): number;
19
+ unshift(...item: T[]): number;
20
+ get maxLenght(): number;
21
+ }
22
+ //# sourceMappingURL=EvictingDequeue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EvictingDequeue.d.ts","sourceRoot":"","sources":["../../src/collection/EvictingDequeue.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,qBAAa,eAAe,CAAC,CAAC,CAAE,SAAQ,KAAK,CAAC,CAAC,CAAC;;gBAEnC,SAAS,EAAE,MAAM,EAAE,KAAK,GAAE,CAAC,EAAO;IAM9C,IAAI,CAAC,GAAG,IAAI,EAAE,CAAC,EAAE;IAQjB,OAAO,CAAC,GAAG,IAAI,EAAE,CAAC,EAAE;IAQpB,IAAI,SAAS,WAEZ;CACD"}
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _EvictingDequeue_maxLenght;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.EvictingDequeue = void 0;
16
+ /**
17
+ * A non-blocking de-queue which automatically evicts elements from queue when attempting to add new elements onto the queue and it is full
18
+ *
19
+ * @example
20
+ * ```js
21
+ * const maxSize=3;
22
+ * const evictingDequeue = new EvictingDequeue<number>(maxSize,[1,2,3]);
23
+ *
24
+ * evictingDequeue; // [1,2,3]
25
+ * evictingDequeue.push(4); // [2,3,4]
26
+ * evictingDequeue.unshift(5); // [5,2,3]
27
+ *
28
+ * ```
29
+ */
30
+ class EvictingDequeue extends Array {
31
+ constructor(maxLenght, items = []) {
32
+ super();
33
+ _EvictingDequeue_maxLenght.set(this, void 0);
34
+ __classPrivateFieldSet(this, _EvictingDequeue_maxLenght, maxLenght, "f");
35
+ this.push(...items);
36
+ }
37
+ push(...item) {
38
+ super.push(...item);
39
+ let overflow = this.length - __classPrivateFieldGet(this, _EvictingDequeue_maxLenght, "f");
40
+ for (; overflow > 0; overflow--)
41
+ this.shift();
42
+ return this.length;
43
+ }
44
+ unshift(...item) {
45
+ super.unshift(...item);
46
+ let overflow = this.length - __classPrivateFieldGet(this, _EvictingDequeue_maxLenght, "f");
47
+ for (; overflow > 0; overflow--)
48
+ this.pop();
49
+ return this.length;
50
+ }
51
+ get maxLenght() {
52
+ return __classPrivateFieldGet(this, _EvictingDequeue_maxLenght, "f");
53
+ }
54
+ }
55
+ exports.EvictingDequeue = EvictingDequeue;
56
+ _EvictingDequeue_maxLenght = new WeakMap();
57
+ //# sourceMappingURL=EvictingDequeue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EvictingDequeue.js","sourceRoot":"","sources":["../../src/collection/EvictingDequeue.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;GAaG;AACH,MAAa,eAAmB,SAAQ,KAAQ;IAE/C,YAAY,SAAiB,EAAE,QAAa,EAAE;QAC7C,KAAK,EAAE,CAAC;QAFA,6CAAmB;QAG3B,uBAAA,IAAI,8BAAc,SAAS,MAAA,CAAC;QAC5B,IAAI,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,CAAC;IACrB,CAAC;IAED,IAAI,CAAC,GAAG,IAAS;QAChB,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;QACpB,IAAI,QAAQ,GAAG,IAAI,CAAC,MAAM,GAAG,uBAAA,IAAI,kCAAW,CAAC;QAC7C,OAAO,QAAQ,GAAG,CAAC,EAAE,QAAQ,EAAE;YAAE,IAAI,CAAC,KAAK,EAAE,CAAC;QAE9C,OAAO,IAAI,CAAC,MAAM,CAAC;IACpB,CAAC;IAED,OAAO,CAAC,GAAG,IAAS;QACnB,KAAK,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC;QACvB,IAAI,QAAQ,GAAG,IAAI,CAAC,MAAM,GAAG,uBAAA,IAAI,kCAAW,CAAC;QAC7C,OAAO,QAAQ,GAAG,CAAC,EAAE,QAAQ,EAAE;YAAE,IAAI,CAAC,GAAG,EAAE,CAAC;QAE5C,OAAO,IAAI,CAAC,MAAM,CAAC;IACpB,CAAC;IAED,IAAI,SAAS;QACZ,OAAO,uBAAA,IAAI,kCAAW,CAAC;IACxB,CAAC;CACD;AA3BD,0CA2BC"}
@@ -0,0 +1,4 @@
1
+ export { CircularArray } from './CircularArray';
2
+ export { EvictingDequeue } from './EvictingDequeue';
3
+ export * from './collectionOperations';
4
+ //# sourceMappingURL=collection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collection.d.ts","sourceRoot":"","sources":["../../src/collection/collection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,cAAc,wBAAwB,CAAC"}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.EvictingDequeue = exports.CircularArray = void 0;
18
+ var CircularArray_1 = require("./CircularArray");
19
+ Object.defineProperty(exports, "CircularArray", { enumerable: true, get: function () { return CircularArray_1.CircularArray; } });
20
+ var EvictingDequeue_1 = require("./EvictingDequeue");
21
+ Object.defineProperty(exports, "EvictingDequeue", { enumerable: true, get: function () { return EvictingDequeue_1.EvictingDequeue; } });
22
+ __exportStar(require("./collectionOperations"), exports);
23
+ //# sourceMappingURL=collection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collection.js","sourceRoot":"","sources":["../../src/collection/collection.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,iDAAgD;AAAvC,8GAAA,aAAa,OAAA;AACtB,qDAAoD;AAA3C,kHAAA,eAAe,OAAA;AACxB,yDAAuC"}
@@ -0,0 +1,125 @@
1
+ /**
2
+ *
3
+ * Compute the element-wise absolute differences between two arrays of numbers.
4
+ * @example
5
+ * ```ts
6
+ * arrayDifferences([1,2,3],[3,2,1]); // [2,0,2]
7
+ * ```
8
+ * @param a1 array to compare
9
+ * @param a2 array to compare
10
+ * @returns return the array difference a1-a2
11
+ */
12
+ export declare function arrayDifferences(a1?: number[], a2?: number[]): number[];
13
+ /**
14
+ * executes the provided function fn once for each pair of consecutive elements of the provided array.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * const array=[1,2,3,4];
19
+ *
20
+ * forEachConsPairs(array,console.log);
21
+ *
22
+ * // prints
23
+ * // 1 2
24
+ * // 2 3
25
+ * // 3 4
26
+ * ```
27
+ *
28
+ */
29
+ export declare function forEachConsPairs<T>(array: T[], fn: (item1: T, item2: T) => void): void;
30
+ /**
31
+ * check if the givven array is sorted or not.
32
+ *
33
+ * @example check array of numbers
34
+ * ```ts
35
+ * isSorted([1,2,3]) //true
36
+ * isSorted([1,3,2]) //false
37
+ * ```
38
+ *
39
+ * @example check array of strings
40
+ *```ts
41
+ * isSorted(['a','b','c']) //true
42
+ * isSorted(['a','c','b']) //false
43
+ * ```
44
+ *
45
+ * @example check array of objects, with compareFn
46
+ * ```ts
47
+ * isSorted([{ x:1}, { x:2}, { x:3}], (o1,o2)=> o1.x-o2.x) // true
48
+ * isSorted([{ x:1}, { x:3}, { x:2}], (o1,o2)=> o1.x-o2.x) // false
49
+ * ```
50
+ *
51
+ * @param array array to check if is sorted
52
+ * @param compareFn function to use for comparison operation
53
+ */
54
+ export declare function isSorted<T>(array: T[], compareFn?: (item1: T, item2: T) => number): boolean;
55
+ /**
56
+ * get the last element of an aray.
57
+ *
58
+ * @example simply does:
59
+ * ```ts
60
+ * array[array.length - 1];
61
+ * ```
62
+ */
63
+ export declare function lastEl<T>(array: T[]): T;
64
+ /**
65
+ *
66
+ * like {@link https://lodash.com/docs/4.17.15#takeRight lodash's takeRight}, but also with offset.
67
+ *
68
+ *
69
+ *
70
+ *
71
+ ** * *
72
+ * simply does
73
+ * ```ts
74
+ * array?.slice(array.length - n - offset , array.length - offset);
75
+ * ```
76
+ * * * *
77
+ *
78
+ *
79
+ * @example
80
+ * ```ts
81
+ * takeRight([0, 1, 2, 3]) //=> [3]
82
+ * takeRight([0, 1, 2, 3], 2) //=> [2, 3]
83
+ * takeRight([0, 1, 2, 3], 2, 1) //=> [1, 2]
84
+ * ```
85
+ *
86
+ * @param array The array to query.
87
+ * @param n The number of elements to take.
88
+ * @param offset The offset to apply for elements to take.
89
+ * @returns Returns the slice of array.
90
+ */
91
+ export declare function takeRight<T>(array: T[], n?: number, offset?: number): T[];
92
+ /**
93
+ *
94
+ * Returns a random element from the provided array.
95
+ *
96
+ * @param array
97
+ * @returns a random element from the provided array.
98
+ */
99
+ export declare function pickRandomElement<T>(array: T[]): T;
100
+ /** *
101
+ * Returns an array of random elements from the provided array.
102
+ *
103
+ * @param array
104
+ * @param legth number of elements to pick
105
+ * @returns an array of random elements from the provided array.
106
+ */
107
+ export declare function pickRandomElements<T>(array: T[], legth: number): T[];
108
+ /**
109
+ * Returns a random element from the provided array,
110
+ * and **removes** the element from the array.
111
+ *
112
+ * @param array
113
+ * @returns a random element from the provided array.
114
+ */
115
+ export declare function takeRandomElement<T>(array: T[]): T;
116
+ /** *
117
+ * Returns an array of random elements from the provided array,
118
+ * and **removes** the elements from the array.
119
+ *
120
+ * @param array
121
+ * @param legth number of elements to pick
122
+ * @returns an array of random elements from the provided array.
123
+ */
124
+ export declare function takeRandomElements<T>(array: T[], legth: number): T[];
125
+ //# sourceMappingURL=collectionOperations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collectionOperations.d.ts","sourceRoot":"","sources":["../../src/collection/collectionOperations.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,GAAE,MAAM,EAAO,EAAE,EAAE,GAAE,MAAM,EAAO,GAAG,MAAM,EAAE,CAM/E;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,KAAK,IAAI,QAS/E;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,SAAS,GAAE,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,KAAK,MAA4B,GAAG,OAAO,CAWhH;AAUD;;;;;;;GAOG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,CAEvC;AAkBD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC,SAAI,EAAE,MAAM,SAAI,GAAG,CAAC,EAAE,CAE/D;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,CAElD;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,EAAE,CAEpE;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,CAElD;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,EAAE,CAEpE"}