@noeldemartin/utils 0.7.3 → 0.8.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 (234) hide show
  1. package/dist/_virtual/_rolldown/runtime.js +13 -0
  2. package/dist/fluent/FluentArray.d.ts +48 -0
  3. package/dist/fluent/FluentArray.js +48 -0
  4. package/dist/fluent/FluentArray.js.map +1 -0
  5. package/dist/fluent/FluentObject.d.ts +16 -0
  6. package/dist/fluent/FluentObject.js +45 -0
  7. package/dist/fluent/FluentObject.js.map +1 -0
  8. package/dist/fluent/FluentString.d.ts +21 -0
  9. package/dist/fluent/FluentString.js +28 -0
  10. package/dist/fluent/FluentString.js.map +1 -0
  11. package/dist/fluent/facade.d.ts +17 -0
  12. package/dist/fluent/facade.js +45 -0
  13. package/dist/fluent/facade.js.map +1 -0
  14. package/dist/fluent/index.d.ts +29 -0
  15. package/dist/fluent/index.js +41 -0
  16. package/dist/fluent/index.js.map +1 -0
  17. package/dist/fluent/invade.d.ts +6 -0
  18. package/dist/fluent/invade.js +8 -0
  19. package/dist/fluent/invade.js.map +1 -0
  20. package/dist/fluent/lazyFacade.d.ts +16 -0
  21. package/dist/fluent/lazyFacade.js +67 -0
  22. package/dist/fluent/lazyFacade.js.map +1 -0
  23. package/dist/fluent/noop.d.ts +4 -0
  24. package/dist/fluent/noop.js +6 -0
  25. package/dist/fluent/noop.js.map +1 -0
  26. package/dist/fluent/required.d.ts +5 -0
  27. package/dist/fluent/required.js +32 -0
  28. package/dist/fluent/required.js.map +1 -0
  29. package/dist/fluent/tap.d.ts +7 -0
  30. package/dist/fluent/tap.js +22 -0
  31. package/dist/fluent/tap.js.map +1 -0
  32. package/dist/fluent/value.d.ts +5 -0
  33. package/dist/fluent/value.js +8 -0
  34. package/dist/fluent/value.js.map +1 -0
  35. package/dist/fluent/when.d.ts +6 -0
  36. package/dist/fluent/when.js +11 -0
  37. package/dist/fluent/when.js.map +1 -0
  38. package/dist/helpers/InMemoryStorageService.d.ts +8 -0
  39. package/dist/helpers/InMemoryStorageService.js +16 -0
  40. package/dist/helpers/InMemoryStorageService.js.map +1 -0
  41. package/dist/helpers/IndexedDBMap.d.ts +17 -0
  42. package/dist/helpers/IndexedDBMap.js +52 -0
  43. package/dist/helpers/IndexedDBMap.js.map +1 -0
  44. package/dist/helpers/JSError.d.ts +14 -0
  45. package/dist/helpers/JSError.js +14 -0
  46. package/dist/helpers/JSError.js.map +1 -0
  47. package/dist/helpers/ListenersManager.d.ts +15 -0
  48. package/dist/helpers/ListenersManager.js +23 -0
  49. package/dist/helpers/ListenersManager.js.map +1 -0
  50. package/dist/helpers/MagicObject.d.ts +29 -0
  51. package/dist/helpers/MagicObject.js +77 -0
  52. package/dist/helpers/MagicObject.js.map +1 -0
  53. package/dist/helpers/ObjectsMap.d.ts +28 -0
  54. package/dist/helpers/ObjectsMap.js +86 -0
  55. package/dist/helpers/ObjectsMap.js.map +1 -0
  56. package/dist/helpers/PromisedValue.d.ts +32 -0
  57. package/dist/helpers/PromisedValue.js +68 -0
  58. package/dist/helpers/PromisedValue.js.map +1 -0
  59. package/dist/helpers/Semaphore.d.ts +14 -0
  60. package/dist/helpers/Semaphore.js +45 -0
  61. package/dist/helpers/Semaphore.js.map +1 -0
  62. package/dist/helpers/Storage.d.ts +17 -0
  63. package/dist/helpers/Storage.js +39 -0
  64. package/dist/helpers/Storage.js.map +1 -0
  65. package/dist/helpers/array_helpers.d.ts +57 -0
  66. package/dist/helpers/array_helpers.js +208 -0
  67. package/dist/helpers/array_helpers.js.map +1 -0
  68. package/dist/helpers/boolean_helpers.d.ts +4 -0
  69. package/dist/helpers/boolean_helpers.js +10 -0
  70. package/dist/helpers/boolean_helpers.js.map +1 -0
  71. package/dist/helpers/caching_helpers.d.ts +17 -0
  72. package/dist/helpers/caching_helpers.js +55 -0
  73. package/dist/helpers/caching_helpers.js.map +1 -0
  74. package/dist/helpers/chaos_helpers.d.ts +6 -0
  75. package/dist/helpers/chaos_helpers.js +11 -0
  76. package/dist/helpers/chaos_helpers.js.map +1 -0
  77. package/dist/helpers/date_helpers.d.ts +4 -0
  78. package/dist/helpers/date_helpers.js +15 -0
  79. package/dist/helpers/date_helpers.js.map +1 -0
  80. package/dist/helpers/deprecated.d.ts +24 -0
  81. package/dist/helpers/env.d.ts +9 -0
  82. package/dist/helpers/env.js +42 -0
  83. package/dist/helpers/env.js.map +1 -0
  84. package/dist/helpers/error_helpers.d.ts +12 -0
  85. package/dist/helpers/error_helpers.js +20 -0
  86. package/dist/helpers/error_helpers.js.map +1 -0
  87. package/dist/helpers/escape_helpers.d.ts +5 -0
  88. package/dist/helpers/escape_helpers.js +11 -0
  89. package/dist/helpers/escape_helpers.js.map +1 -0
  90. package/dist/helpers/file_helpers.d.ts +4 -0
  91. package/dist/helpers/file_helpers.js +16 -0
  92. package/dist/helpers/file_helpers.js.map +1 -0
  93. package/dist/helpers/format_helpers.d.ts +7 -0
  94. package/dist/helpers/format_helpers.js +28 -0
  95. package/dist/helpers/format_helpers.js.map +1 -0
  96. package/dist/helpers/hash_helpers.d.ts +4 -0
  97. package/dist/helpers/hash_helpers.js +156 -0
  98. package/dist/helpers/hash_helpers.js.map +1 -0
  99. package/dist/helpers/identity_helpers.d.ts +5 -0
  100. package/dist/helpers/identity_helpers.js +15 -0
  101. package/dist/helpers/identity_helpers.js.map +1 -0
  102. package/dist/helpers/location_helpers.d.ts +8 -0
  103. package/dist/helpers/location_helpers.js +37 -0
  104. package/dist/helpers/location_helpers.js.map +1 -0
  105. package/dist/helpers/logical_helpers.d.ts +4 -0
  106. package/dist/helpers/logical_helpers.js +13 -0
  107. package/dist/helpers/logical_helpers.js.map +1 -0
  108. package/dist/helpers/math_helpers.d.ts +5 -0
  109. package/dist/helpers/math_helpers.js +12 -0
  110. package/dist/helpers/math_helpers.js.map +1 -0
  111. package/dist/helpers/mixin_helpers.d.ts +20 -0
  112. package/dist/helpers/mixin_helpers.js +43 -0
  113. package/dist/helpers/mixin_helpers.js.map +1 -0
  114. package/dist/helpers/network_helpers.d.ts +4 -0
  115. package/dist/helpers/network_helpers.js +8 -0
  116. package/dist/helpers/network_helpers.js.map +1 -0
  117. package/dist/helpers/object_helpers.d.ts +58 -0
  118. package/dist/helpers/object_helpers.js +179 -0
  119. package/dist/helpers/object_helpers.js.map +1 -0
  120. package/dist/helpers/promise_helpers.d.ts +10 -0
  121. package/dist/helpers/promise_helpers.js +25 -0
  122. package/dist/helpers/promise_helpers.js.map +1 -0
  123. package/dist/helpers/replacements-scope.js +21 -0
  124. package/dist/helpers/replacements-scope.js.map +1 -0
  125. package/dist/helpers/replacements.d.ts +5 -0
  126. package/dist/helpers/replacements.js +34 -0
  127. package/dist/helpers/replacements.js.map +1 -0
  128. package/dist/helpers/runtime_helpers.d.ts +4 -0
  129. package/dist/helpers/runtime_helpers.js +8 -0
  130. package/dist/helpers/runtime_helpers.js.map +1 -0
  131. package/dist/helpers/string_helpers.d.ts +17 -0
  132. package/dist/helpers/string_helpers.js +42 -0
  133. package/dist/helpers/string_helpers.js.map +1 -0
  134. package/dist/helpers/time_constants.d.ts +15 -0
  135. package/dist/helpers/time_constants.js +17 -0
  136. package/dist/helpers/time_constants.js.map +1 -0
  137. package/dist/helpers/time_helpers.d.ts +24 -0
  138. package/dist/helpers/time_helpers.js +57 -0
  139. package/dist/helpers/time_helpers.js.map +1 -0
  140. package/dist/helpers/url_helpers.d.ts +24 -0
  141. package/dist/helpers/url_helpers.js +90 -0
  142. package/dist/helpers/url_helpers.js.map +1 -0
  143. package/dist/helpers/value_helpers.d.ts +7 -0
  144. package/dist/helpers/value_helpers.js +11 -0
  145. package/dist/helpers/value_helpers.js.map +1 -0
  146. package/dist/index.d.ts +53 -0
  147. package/dist/index.js +49 -0
  148. package/dist/types/arrays.d.ts +12 -0
  149. package/dist/types/classes.d.ts +12 -0
  150. package/dist/types/helpers.d.ts +36 -0
  151. package/dist/types/helpers.js +6 -0
  152. package/dist/types/helpers.js.map +1 -0
  153. package/dist/types/objects.d.ts +8 -0
  154. package/package.json +38 -52
  155. package/src/fluent/FluentArray.test.ts +2 -9
  156. package/src/fluent/FluentArray.ts +6 -5
  157. package/src/fluent/FluentObject.ts +2 -4
  158. package/src/fluent/FluentString.test.ts +1 -8
  159. package/src/fluent/FluentString.ts +0 -2
  160. package/src/fluent/facade.test.ts +16 -4
  161. package/src/fluent/facade.ts +6 -4
  162. package/src/fluent/index.test.ts +3 -8
  163. package/src/fluent/index.ts +3 -3
  164. package/src/fluent/invade.test.ts +1 -5
  165. package/src/fluent/invade.ts +1 -1
  166. package/src/fluent/lazyFacade.test.ts +191 -0
  167. package/src/fluent/lazyFacade.ts +115 -0
  168. package/src/fluent/required.test.ts +1 -5
  169. package/src/fluent/required.ts +2 -4
  170. package/src/fluent/tap.test.ts +2 -9
  171. package/src/fluent/tap.ts +4 -3
  172. package/src/fluent/value.test.ts +1 -4
  173. package/src/fluent/when.test.ts +1 -6
  174. package/src/fluent/when.ts +2 -2
  175. package/src/helpers/InMemoryStorageService.ts +13 -0
  176. package/src/helpers/IndexedDBMap.ts +0 -2
  177. package/src/helpers/JSError.test.ts +1 -6
  178. package/src/helpers/JSError.ts +0 -2
  179. package/src/helpers/ListenersManager.test.ts +3 -7
  180. package/src/helpers/ListenersManager.ts +2 -4
  181. package/src/helpers/MagicObject.test.ts +14 -8
  182. package/src/helpers/MagicObject.ts +12 -3
  183. package/src/helpers/ObjectsMap.test.ts +1 -3
  184. package/src/helpers/ObjectsMap.ts +1 -5
  185. package/src/helpers/PromisedValue.test.ts +1 -3
  186. package/src/helpers/PromisedValue.ts +5 -6
  187. package/src/helpers/Semaphore.test.ts +6 -10
  188. package/src/helpers/Semaphore.ts +0 -2
  189. package/src/helpers/Storage.test.ts +47 -0
  190. package/src/helpers/Storage.ts +11 -19
  191. package/src/helpers/array_helpers.test.ts +127 -38
  192. package/src/helpers/array_helpers.ts +137 -78
  193. package/src/helpers/caching_helpers.test.ts +1 -3
  194. package/src/helpers/caching_helpers.ts +2 -2
  195. package/src/helpers/date_helpers.test.ts +1 -4
  196. package/src/helpers/date_helpers.ts +1 -1
  197. package/src/helpers/env.ts +5 -1
  198. package/src/helpers/error_helpers.test.ts +9 -8
  199. package/src/helpers/error_helpers.ts +11 -11
  200. package/src/helpers/format_helpers.test.ts +2 -4
  201. package/src/helpers/hash_helpers.test.ts +1 -4
  202. package/src/helpers/hash_helpers.ts +3 -3
  203. package/src/helpers/identity_helpers.test.ts +1 -3
  204. package/src/helpers/index.ts +3 -0
  205. package/src/helpers/logical_helpers.test.ts +1 -3
  206. package/src/helpers/logical_helpers.ts +1 -1
  207. package/src/helpers/math_helpers.test.ts +1 -3
  208. package/src/helpers/mixin_helpers.stubs.ts +1 -13
  209. package/src/helpers/mixin_helpers.test.ts +2 -7
  210. package/src/helpers/mixin_helpers.ts +6 -9
  211. package/src/helpers/object_helpers.test.ts +32 -19
  212. package/src/helpers/object_helpers.ts +43 -21
  213. package/src/helpers/promise_helpers.test.ts +1 -4
  214. package/src/helpers/promise_helpers.ts +9 -9
  215. package/src/helpers/replacements-scope.ts +15 -0
  216. package/src/helpers/replacements.test.ts +23 -0
  217. package/src/helpers/replacements.ts +52 -0
  218. package/src/helpers/runtime_helpers.ts +3 -3
  219. package/src/helpers/string_helpers.test.ts +3 -5
  220. package/src/helpers/time_constants.ts +13 -0
  221. package/src/helpers/time_helpers.ts +35 -0
  222. package/src/helpers/url_helpers.test.ts +12 -4
  223. package/src/helpers/url_helpers.ts +9 -15
  224. package/src/helpers/value_helpers.test.ts +12 -0
  225. package/src/helpers/value_helpers.ts +6 -0
  226. package/src/types/arrays.test.ts +1 -4
  227. package/src/types/classes.ts +1 -0
  228. package/src/types/helpers.test.ts +1 -6
  229. package/src/types/helpers.ts +6 -5
  230. package/src/types/objects.test.ts +1 -4
  231. package/src/types/objects.ts +3 -3
  232. package/dist/noeldemartin-utils.d.ts +0 -901
  233. package/dist/noeldemartin-utils.js +0 -1473
  234. package/dist/noeldemartin-utils.js.map +0 -1
@@ -0,0 +1,14 @@
1
+ //#region src/helpers/Semaphore.d.ts
2
+ export default class Semaphore {
3
+ private count;
4
+ private listeners;
5
+ constructor(count?: number);
6
+ acquire(): Promise<void>;
7
+ release(): void;
8
+ isAvailable(): boolean;
9
+ run<T>(operation: () => Promise<T>): Promise<T>;
10
+ private waitAvailable;
11
+ private notifyAvailable;
12
+ }
13
+ //#endregion
14
+ //# sourceMappingURL=Semaphore.d.ts.map
@@ -0,0 +1,45 @@
1
+ //#region src/helpers/Semaphore.ts
2
+ var Semaphore = class {
3
+ count;
4
+ listeners;
5
+ constructor(count = 1) {
6
+ this.count = count;
7
+ this.listeners = /* @__PURE__ */ new Set();
8
+ }
9
+ acquire() {
10
+ if (this.count === 0) return this.waitAvailable().then(() => this.acquire());
11
+ this.count = Math.max(this.count - 1, 0);
12
+ return Promise.resolve();
13
+ }
14
+ release() {
15
+ this.count++;
16
+ this.notifyAvailable();
17
+ }
18
+ isAvailable() {
19
+ return this.count !== 0;
20
+ }
21
+ async run(operation) {
22
+ await this.acquire();
23
+ try {
24
+ return await operation();
25
+ } finally {
26
+ this.release();
27
+ }
28
+ }
29
+ async waitAvailable() {
30
+ while (!this.isAvailable()) await new Promise((resolve) => {
31
+ const listener = () => {
32
+ this.listeners.delete(listener);
33
+ resolve(null);
34
+ };
35
+ this.listeners.add(listener);
36
+ });
37
+ }
38
+ notifyAvailable() {
39
+ this.listeners.forEach((listener) => listener());
40
+ }
41
+ };
42
+ //#endregion
43
+ export { Semaphore as default };
44
+
45
+ //# sourceMappingURL=Semaphore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Semaphore.js","names":[],"sources":["../../src/helpers/Semaphore.ts"],"sourcesContent":["type Listener = () => void;\n\nexport default class Semaphore {\n private count: number;\n private listeners: Set<Listener>;\n\n public constructor(count: number = 1) {\n this.count = count;\n this.listeners = new Set();\n }\n\n public acquire(): Promise<void> {\n if (this.count === 0) {\n return this.waitAvailable().then(() => this.acquire());\n }\n\n this.count = Math.max(this.count - 1, 0);\n\n return Promise.resolve();\n }\n\n public release(): void {\n this.count++;\n\n this.notifyAvailable();\n }\n\n public isAvailable(): boolean {\n return this.count !== 0;\n }\n\n public async run<T>(operation: () => Promise<T>): Promise<T> {\n await this.acquire();\n\n try {\n const result = await operation();\n\n return result;\n } finally {\n this.release();\n }\n }\n\n private async waitAvailable(): Promise<void> {\n while (!this.isAvailable()) {\n await new Promise((resolve) => {\n const listener = () => {\n this.listeners.delete(listener);\n\n resolve(null);\n };\n\n this.listeners.add(listener);\n });\n }\n }\n\n private notifyAvailable(): void {\n this.listeners.forEach((listener) => listener());\n }\n}\n"],"mappings":";AAEA,IAAqB,YAArB,MAA+B;CAC3B;CACA;CAEA,YAAmB,QAAgB,GAAG;EAClC,KAAK,QAAQ;EACb,KAAK,4BAAY,IAAI,IAAI;CAC7B;CAEA,UAAgC;EAC5B,IAAI,KAAK,UAAU,GACf,OAAO,KAAK,cAAc,CAAC,CAAC,WAAW,KAAK,QAAQ,CAAC;EAGzD,KAAK,QAAQ,KAAK,IAAI,KAAK,QAAQ,GAAG,CAAC;EAEvC,OAAO,QAAQ,QAAQ;CAC3B;CAEA,UAAuB;EACnB,KAAK;EAEL,KAAK,gBAAgB;CACzB;CAEA,cAA8B;EAC1B,OAAO,KAAK,UAAU;CAC1B;CAEA,MAAa,IAAO,WAAyC;EACzD,MAAM,KAAK,QAAQ;EAEnB,IAAI;GAGA,OAAO,MAFc,UAAU;EAGnC,UAAU;GACN,KAAK,QAAQ;EACjB;CACJ;CAEA,MAAc,gBAA+B;EACzC,OAAO,CAAC,KAAK,YAAY,GACrB,MAAM,IAAI,SAAS,YAAY;GAC3B,MAAM,iBAAiB;IACnB,KAAK,UAAU,OAAO,QAAQ;IAE9B,QAAQ,IAAI;GAChB;GAEA,KAAK,UAAU,IAAI,QAAQ;EAC/B,CAAC;CAET;CAEA,kBAAgC;EAC5B,KAAK,UAAU,SAAS,aAAa,SAAS,CAAC;CACnD;AACJ"}
@@ -0,0 +1,17 @@
1
+ import { Facade } from "../fluent/facade.js";
2
+ //#region src/helpers/Storage.d.ts
3
+ export declare class StorageService {
4
+ set<T = unknown>(key: string, value: T): void;
5
+ get<T>(key: string): T | null;
6
+ get<T>(key: string, defaultValue: T): T;
7
+ require<T>(key: string): T;
8
+ has(key: string): boolean;
9
+ remove(key: string): void;
10
+ pull<T>(key: string): T | null;
11
+ pull<T>(key: string, defaultValue: T): T;
12
+ protected get storage(): Pick<Storage, 'getItem' | 'setItem' | 'removeItem'>;
13
+ }
14
+ declare const _default: Facade<StorageService>;
15
+ //#endregion
16
+ export { _default as default };
17
+ //# sourceMappingURL=Storage.d.ts.map
@@ -0,0 +1,39 @@
1
+ import { facade } from "../fluent/facade.js";
2
+ //#region src/helpers/Storage.ts
3
+ const DEFAULT_INSTANCE = {};
4
+ var StorageService = class {
5
+ set(key, value) {
6
+ this.storage.setItem(key, typeof value === "undefined" ? "__undefined__" : JSON.stringify(value));
7
+ }
8
+ get(key, defaultValue = null) {
9
+ const value = this.storage.getItem(key);
10
+ if (value === null) return defaultValue;
11
+ if (value === "__undefined__") return void 0;
12
+ return JSON.parse(value);
13
+ }
14
+ require(key) {
15
+ const value = this.get(key, DEFAULT_INSTANCE);
16
+ if (value === DEFAULT_INSTANCE) throw new Error(`Failed getting required key from local storage: '${key}'`);
17
+ return value;
18
+ }
19
+ has(key) {
20
+ return this.storage.getItem(key) !== null;
21
+ }
22
+ remove(key) {
23
+ this.storage.removeItem(key);
24
+ }
25
+ pull(key, defaultValue = null) {
26
+ if (!this.has(key)) return defaultValue;
27
+ const value = this.get(key);
28
+ this.remove(key);
29
+ return value;
30
+ }
31
+ get storage() {
32
+ return localStorage;
33
+ }
34
+ };
35
+ var Storage_default = facade(StorageService);
36
+ //#endregion
37
+ export { StorageService, Storage_default as default };
38
+
39
+ //# sourceMappingURL=Storage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Storage.js","names":[],"sources":["../../src/helpers/Storage.ts"],"sourcesContent":["import { facade } from '@noeldemartin/utils/fluent/facade';\n\nconst DEFAULT_INSTANCE = {};\n\nexport class StorageService {\n public set<T = unknown>(key: string, value: T): void {\n this.storage.setItem(key, typeof value === 'undefined' ? '__undefined__' : JSON.stringify(value));\n }\n\n public get<T>(key: string): T | null;\n public get<T>(key: string, defaultValue: T): T;\n public get<T>(key: string, defaultValue: T | null = null): T | null {\n const value = this.storage.getItem(key);\n\n if (value === null) return defaultValue;\n\n if (value === '__undefined__') return undefined as unknown as T;\n\n return JSON.parse(value);\n }\n\n public require<T>(key: string): T {\n const value = this.get(key, DEFAULT_INSTANCE);\n\n if (value === DEFAULT_INSTANCE) throw new Error(`Failed getting required key from local storage: '${key}'`);\n\n return value as T;\n }\n\n public has(key: string): boolean {\n return this.storage.getItem(key) !== null;\n }\n\n public remove(key: string): void {\n this.storage.removeItem(key);\n }\n\n public pull<T>(key: string): T | null;\n public pull<T>(key: string, defaultValue: T): T;\n public pull<T>(key: string, defaultValue: T | null = null): T | null {\n if (!this.has(key)) return defaultValue;\n\n const value = this.get<T>(key);\n\n this.remove(key);\n\n return value;\n }\n\n protected get storage(): Pick<Storage, 'getItem' | 'setItem' | 'removeItem'> {\n return localStorage;\n }\n}\n\nexport default facade(StorageService);\n"],"mappings":";;AAEA,MAAM,mBAAmB,CAAC;AAE1B,IAAa,iBAAb,MAA4B;CACxB,IAAwB,KAAa,OAAgB;EACjD,KAAK,QAAQ,QAAQ,KAAK,OAAO,UAAU,cAAc,kBAAkB,KAAK,UAAU,KAAK,CAAC;CACpG;CAIA,IAAc,KAAa,eAAyB,MAAgB;EAChE,MAAM,QAAQ,KAAK,QAAQ,QAAQ,GAAG;EAEtC,IAAI,UAAU,MAAM,OAAO;EAE3B,IAAI,UAAU,iBAAiB,OAAO,KAAA;EAEtC,OAAO,KAAK,MAAM,KAAK;CAC3B;CAEA,QAAkB,KAAgB;EAC9B,MAAM,QAAQ,KAAK,IAAI,KAAK,gBAAgB;EAE5C,IAAI,UAAU,kBAAkB,MAAM,IAAI,MAAM,oDAAoD,IAAI,EAAE;EAE1G,OAAO;CACX;CAEA,IAAW,KAAsB;EAC7B,OAAO,KAAK,QAAQ,QAAQ,GAAG,MAAM;CACzC;CAEA,OAAc,KAAmB;EAC7B,KAAK,QAAQ,WAAW,GAAG;CAC/B;CAIA,KAAe,KAAa,eAAyB,MAAgB;EACjE,IAAI,CAAC,KAAK,IAAI,GAAG,GAAG,OAAO;EAE3B,MAAM,QAAQ,KAAK,IAAO,GAAG;EAE7B,KAAK,OAAO,GAAG;EAEf,OAAO;CACX;CAEA,IAAc,UAA+D;EACzE,OAAO;CACX;AACJ;AAEA,IAAA,kBAAe,OAAO,cAAc"}
@@ -0,0 +1,57 @@
1
+ import { Falsy } from "../types/helpers.js";
2
+ import { DeepKeyOf } from "../types/objects.js";
3
+ //#region src/helpers/array_helpers.d.ts
4
+ export type ArrayFrom<T> = T extends Iterable<infer TItem> ? TItem[] : T[];
5
+ export type ArraySortDirection = 'asc' | 'desc';
6
+ export type ArraySortFieldDirection<T> = readonly [DeepKeyOf<T>, ArraySortDirection];
7
+ export type ArraySortCompare<T> = (a: T, b: T) => number;
8
+ export declare function arrayClear(items: unknown[]): void;
9
+ export declare function arrayDiff<T>(original: T[], updated: T[], compareValues?: (a: T, b: T) => boolean): {
10
+ added: T[];
11
+ removed: T[];
12
+ };
13
+ export declare function arrayChunk<T>(items: T[], chunkSize: number): T[][];
14
+ export declare function arrayEquals<T>(original: T[], updated: T[]): boolean;
15
+ export declare function arrayFilter<T>(items: (T | Falsy)[]): T[];
16
+ export declare function arrayFilter<T>(items: T[], filter: (item: T) => boolean): T[];
17
+ export declare function arrayFirst<T>(items: T[], filter: (item: T) => boolean): T | null;
18
+ export declare function arrayFlatMap<T, R>(items: T[], map: (item: T, index: number) => R[]): R[];
19
+ export declare function arrayWithItemAt<T>(items: T[], item: T, index: number): T[];
20
+ export declare function arrayGroupBy<TItem, TKey extends string>(items: TItem[], groupBy: (item: TItem) => TKey): Partial<Record<TKey, TItem[]>>;
21
+ export declare function arrayGroupBy<TItem, TKey extends keyof TItem>(items: TItem[], groupBy: TKey): Record<string, TItem[]>;
22
+ export declare function arrayIsEmpty(items: unknown[]): boolean;
23
+ export declare function arrayProject<T, S extends keyof T>(items: T[], property: S): T[S][];
24
+ export declare function arrayPull<T>(items: T[], index: number): T | undefined;
25
+ export declare function arrayRandomItem<T>(items: T[]): T | null;
26
+ export declare function arrayRandomItems<T>(items: T[], count: number): T[];
27
+ export declare function arrayRemove<T>(items: T[], item: T): boolean;
28
+ export declare function arrayRemoveIndex<T>(items: T[], index: number | string): boolean;
29
+ export declare function arrayReplace<T>(items: T[], original: T, replacement: T): boolean;
30
+ export declare function arrayReversed<T>(items: T[]): T[];
31
+ export declare function arrayShuffled<T>(items: T[]): T[];
32
+ export declare function arraySorted<T>(items: T[]): T[];
33
+ export declare function arraySorted<T>(items: T[], direction: ArraySortDirection): T[];
34
+ export declare function arraySorted<T>(items: T[], compareValues: ArraySortCompare<T>): T[];
35
+ export declare function arraySorted<T>(items: T[], field: DeepKeyOf<T>, direction?: ArraySortDirection): T[];
36
+ export declare function arraySorted<T>(items: T[], fields: DeepKeyOf<T>[], direction?: ArraySortDirection): T[];
37
+ export declare function arraySorted<T>(items: T[], fields: ArraySortFieldDirection<T>[]): T[];
38
+ export declare function arraySwap(items: unknown[], firstIndex: number, secondIndex: number): void;
39
+ export declare function arrayUnique<T>(items: T[], extractKey?: (item: T) => string): T[];
40
+ export declare function arrayFind<T, K extends keyof T>(items: T[], filter: string, value?: T[K]): T | undefined;
41
+ export declare function arrayWhere<T, K extends keyof T>(items: T[], filter: string, value?: T[K]): T[];
42
+ export declare function arrayWithout<T>(items: T[], exclude: T | T[]): T[];
43
+ export declare function arrayWithoutIndex<T>(items: T[], index: number): T[];
44
+ export declare function arrayWithoutIndexes<T>(items: T[], indexes: number[]): T[];
45
+ export declare function arrayZip<T>(...arrays: T[][]): T[][];
46
+ export declare function arrayFrom<TValue, TOptions extends {
47
+ ignoreEmptyValues?: boolean;
48
+ }>(value: TValue, options?: TOptions): TOptions extends {
49
+ ignoreEmptyValues: true;
50
+ } ? ArrayFrom<NonNullable<TValue>> : ArrayFrom<TValue>;
51
+ export declare function hasItems<T>(array: T[]): array is [T, ...T[]];
52
+ export declare function range(length: number): number[];
53
+ export declare function reduceBy<TItem, TKey extends keyof TItem, TProjection>(items: TItem[], key: TKey, project: (item: TItem) => TProjection): Record<string, TProjection>;
54
+ export declare function reduceBy<TItem, TKey extends keyof TItem>(items: TItem[], key: TKey): Record<string, TItem>;
55
+ export declare function shuffle(items: unknown[]): void;
56
+ //#endregion
57
+ //# sourceMappingURL=array_helpers.d.ts.map
@@ -0,0 +1,208 @@
1
+ import { compare } from "./logical_helpers.js";
2
+ import { deepGet, isIterable, isString, toString } from "./object_helpers.js";
3
+ //#region src/helpers/array_helpers.ts
4
+ function arrayClear(items) {
5
+ items.splice(0, items.length);
6
+ }
7
+ function arrayDiff(original, updated, compareValues) {
8
+ const removed = original.slice(0);
9
+ const added = [];
10
+ const search = compareValues ? (item, items) => items.findIndex((otherItem) => compareValues(item, otherItem)) : (item, items) => items.indexOf(item);
11
+ for (const updatedItem of updated) {
12
+ const index = search(updatedItem, removed);
13
+ index !== -1 ? removed.splice(index, 1) : added.push(updatedItem);
14
+ }
15
+ return {
16
+ added,
17
+ removed
18
+ };
19
+ }
20
+ function arrayChunk(items, chunkSize) {
21
+ const chunks = [];
22
+ for (let i = 0; i < items.length; i += chunkSize) chunks.push(items.slice(i, i + chunkSize));
23
+ return chunks;
24
+ }
25
+ function arrayEquals(original, updated) {
26
+ if (original.length !== updated.length) return false;
27
+ return !original.some((value, index) => updated[index] !== value);
28
+ }
29
+ function arrayFilter(items, filter) {
30
+ return filter ? items.filter(filter) : items.filter((item) => !!item);
31
+ }
32
+ function arrayFirst(items, filter) {
33
+ for (const item of items) {
34
+ if (!filter(item)) continue;
35
+ return item;
36
+ }
37
+ return null;
38
+ }
39
+ function arrayFlatMap(items, map) {
40
+ return [...items.entries()].flatMap(([index, item]) => map(item, index));
41
+ }
42
+ function arrayWithItemAt(items, item, index) {
43
+ return [
44
+ ...items.slice(0, index + 1),
45
+ item,
46
+ ...items.slice(index + 1)
47
+ ];
48
+ }
49
+ function arrayGroupBy(items, groupBy) {
50
+ const group = typeof groupBy === "string" ? (item) => toString(item[groupBy]) : groupBy;
51
+ return items.reduce((groups, item) => {
52
+ (groups[group(item)] ??= []).push(item);
53
+ return groups;
54
+ }, {});
55
+ }
56
+ function arrayIsEmpty(items) {
57
+ return items.length === 0;
58
+ }
59
+ function arrayProject(items, property) {
60
+ return items.map((item) => item[property]);
61
+ }
62
+ function arrayPull(items, index) {
63
+ const value = items[index];
64
+ items.splice(index, 1);
65
+ return value;
66
+ }
67
+ function arrayRandomItem(items) {
68
+ return items.length === 0 ? null : items[Math.floor(Math.random() * items.length)];
69
+ }
70
+ function arrayRandomItems(items, count) {
71
+ const itemsLeft = items.slice(0);
72
+ const randomItems = [];
73
+ while (itemsLeft.length > 0 && randomItems.length < count) {
74
+ const index = Math.floor(Math.random() * itemsLeft.length);
75
+ randomItems.push(itemsLeft[index]);
76
+ itemsLeft.splice(index, 1);
77
+ }
78
+ return randomItems;
79
+ }
80
+ function arrayRemove(items, item) {
81
+ const index = items.indexOf(item);
82
+ if (index === -1) return false;
83
+ items.splice(index, 1);
84
+ return true;
85
+ }
86
+ function arrayRemoveIndex(items, index) {
87
+ return items.splice(Number(index), 1).length > 0;
88
+ }
89
+ function arrayReplace(items, original, replacement) {
90
+ const index = items.indexOf(original);
91
+ if (index === -1) return false;
92
+ items[index] = replacement;
93
+ return true;
94
+ }
95
+ function arrayReversed(items) {
96
+ const reversed = items.slice(0);
97
+ reversed.reverse();
98
+ return reversed;
99
+ }
100
+ function arrayShuffled(items) {
101
+ const shuffled = items.slice(0);
102
+ shuffle(shuffled);
103
+ return shuffled;
104
+ }
105
+ function arraySorted(items, compareOrFieldOrDirection, direction) {
106
+ switch (compareOrFieldOrDirection) {
107
+ case void 0:
108
+ case "asc": return items.slice(0).sort(compare);
109
+ case "desc": return items.slice(0).sort((a, b) => compare(b, a));
110
+ }
111
+ if (typeof compareOrFieldOrDirection === "function") return items.slice(0).sort(compareOrFieldOrDirection);
112
+ return arraySortedByFields(items, typeof compareOrFieldOrDirection === "string" ? [[compareOrFieldOrDirection, direction ?? "asc"]] : compareOrFieldOrDirection.map((field) => typeof field === "string" ? [field, direction ?? "asc"] : field));
113
+ }
114
+ function getSortDefaultValue(values) {
115
+ const sample = values.find((value) => value !== void 0 && value !== null);
116
+ switch (typeof sample) {
117
+ case "string": return "";
118
+ case "number": return Number.MIN_SAFE_INTEGER;
119
+ case "boolean": return false;
120
+ default:
121
+ if (sample instanceof Date) return Number.MIN_SAFE_INTEGER;
122
+ return null;
123
+ }
124
+ }
125
+ function arraySortedByFields(items, fields) {
126
+ const sortKeys = fields.map(([field, fieldDirection]) => {
127
+ const values = items.map((item) => deepGet(item, field));
128
+ const defaultValue = getSortDefaultValue(values);
129
+ return {
130
+ values: values.map((value) => value instanceof Date ? value.getTime() : value ?? defaultValue),
131
+ directionSign: fieldDirection === "desc" ? -1 : 1
132
+ };
133
+ });
134
+ const indexes = items.map((_, index) => index);
135
+ indexes.sort((a, b) => {
136
+ for (const { values, directionSign } of sortKeys) {
137
+ const result = compare(values[a], values[b]);
138
+ if (result !== 0) return result * directionSign;
139
+ }
140
+ return 0;
141
+ });
142
+ return indexes.map((index) => items[index]);
143
+ }
144
+ function arraySwap(items, firstIndex, secondIndex) {
145
+ [items[firstIndex], items[secondIndex]] = [items[secondIndex], items[firstIndex]];
146
+ }
147
+ function arrayUnique(items, extractKey) {
148
+ return extractKey ? Object.values(items.reduce((unique, item) => {
149
+ const key = extractKey(item);
150
+ unique[key] = unique[key] ?? item;
151
+ return unique;
152
+ }, {})) : [...new Set(items)];
153
+ }
154
+ function arrayFind(items, filter, value) {
155
+ return items.find((item) => {
156
+ const property = item[filter];
157
+ const result = typeof property === "function" ? property.call(item) : property;
158
+ return value ? result === value : !!result;
159
+ });
160
+ }
161
+ function arrayWhere(items, filter, value) {
162
+ return items.filter((item) => {
163
+ const property = item[filter];
164
+ const result = typeof property === "function" ? property.call(item) : property;
165
+ return value ? result === value : !!result;
166
+ });
167
+ }
168
+ function arrayWithout(items, exclude) {
169
+ return Array.isArray(exclude) ? arrayFilter(items, (item) => exclude.indexOf(item) === -1) : arrayWithoutIndex(items, items.indexOf(exclude));
170
+ }
171
+ function arrayWithoutIndex(items, index) {
172
+ return arrayWithoutIndexes(items, [index]);
173
+ }
174
+ function arrayWithoutIndexes(items, indexes) {
175
+ return items.map((value, index) => [value, index]).filter(([_, index]) => !indexes.includes(index)).map(([value]) => value);
176
+ }
177
+ function arrayZip(...arrays) {
178
+ const zippedArrays = [];
179
+ const arraysLength = arrays[0]?.length ?? 0;
180
+ for (let i = 0; i < arraysLength; i++) zippedArrays.push(arrays.map((a) => a[i]));
181
+ return zippedArrays;
182
+ }
183
+ function arrayFrom(value, options) {
184
+ const ignoreEmptyValues = options?.ignoreEmptyValues ?? false;
185
+ return Array.isArray(value) || isIterable(value) && !isString(value) ? Array.from(value) : ignoreEmptyValues && (value === null || value === void 0) ? [] : [value];
186
+ }
187
+ function hasItems(array) {
188
+ return array.length > 0;
189
+ }
190
+ function range(length) {
191
+ return Array.from({ length }, (_, item) => item);
192
+ }
193
+ function reduceBy(items, key, project) {
194
+ return items.reduce((acc, item) => {
195
+ acc[toString(item[key])] = project ? project(item) : item;
196
+ return acc;
197
+ }, {});
198
+ }
199
+ function shuffle(items) {
200
+ for (let i = items.length - 1; i > 0; i--) {
201
+ const j = Math.floor(Math.random() * (i + 1));
202
+ [items[i], items[j]] = [items[j], items[i]];
203
+ }
204
+ }
205
+ //#endregion
206
+ export { arrayChunk, arrayClear, arrayDiff, arrayEquals, arrayFilter, arrayFind, arrayFirst, arrayFlatMap, arrayFrom, arrayGroupBy, arrayIsEmpty, arrayProject, arrayPull, arrayRandomItem, arrayRandomItems, arrayRemove, arrayRemoveIndex, arrayReplace, arrayReversed, arrayShuffled, arraySorted, arraySwap, arrayUnique, arrayWhere, arrayWithItemAt, arrayWithout, arrayWithoutIndex, arrayWithoutIndexes, arrayZip, hasItems, range, reduceBy, shuffle };
207
+
208
+ //# sourceMappingURL=array_helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array_helpers.js","names":[],"sources":["../../src/helpers/array_helpers.ts"],"sourcesContent":["import type { Falsy } from '@noeldemartin/utils/types/helpers';\nimport type { DeepKeyOf } from '@noeldemartin/utils/types/objects';\n\nimport { compare } from './logical_helpers';\nimport { deepGet, isIterable, isString, toString } from './object_helpers';\n\nexport type ArrayFrom<T> = T extends Iterable<infer TItem> ? TItem[] : T[];\nexport type ArraySortDirection = 'asc' | 'desc';\nexport type ArraySortFieldDirection<T> = readonly [DeepKeyOf<T>, ArraySortDirection];\nexport type ArraySortCompare<T> = (a: T, b: T) => number;\n\nexport function arrayClear(items: unknown[]): void {\n items.splice(0, items.length);\n}\n\nexport function arrayDiff<T>(\n original: T[],\n updated: T[],\n compareValues?: (a: T, b: T) => boolean,\n): { added: T[]; removed: T[] } {\n const removed = original.slice(0);\n const added = [];\n const search: (item: T, items: T[]) => number = compareValues\n ? (item, items) => items.findIndex((otherItem) => compareValues(item, otherItem))\n : (item, items) => items.indexOf(item);\n\n for (const updatedItem of updated) {\n const index = search(updatedItem, removed);\n\n index !== -1 ? removed.splice(index, 1) : added.push(updatedItem);\n }\n\n return { added, removed };\n}\n\nexport function arrayChunk<T>(items: T[], chunkSize: number): T[][] {\n const chunks = [];\n\n for (let i = 0; i < items.length; i += chunkSize) {\n chunks.push(items.slice(i, i + chunkSize));\n }\n\n return chunks;\n}\n\nexport function arrayEquals<T>(original: T[], updated: T[]): boolean {\n if (original.length !== updated.length) {\n return false;\n }\n\n return !original.some((value, index) => updated[index] !== value);\n}\n\nexport function arrayFilter<T>(items: (T | Falsy)[]): T[];\nexport function arrayFilter<T>(items: T[], filter: (item: T) => boolean): T[];\nexport function arrayFilter<T>(items: T[], filter?: (item: T) => boolean): T[] {\n return filter ? items.filter(filter) : items.filter((item) => !!item);\n}\n\nexport function arrayFirst<T>(items: T[], filter: (item: T) => boolean): T | null {\n for (const item of items) {\n if (!filter(item)) continue;\n\n return item;\n }\n\n return null;\n}\n\nexport function arrayFlatMap<T, R>(items: T[], map: (item: T, index: number) => R[]): R[] {\n return [...items.entries()].flatMap(([index, item]) => map(item, index));\n}\n\nexport function arrayWithItemAt<T>(items: T[], item: T, index: number): T[] {\n return [...items.slice(0, index + 1), item, ...items.slice(index + 1)];\n}\n\nexport function arrayGroupBy<TItem, TKey extends string>(\n items: TItem[],\n groupBy: (item: TItem) => TKey,\n): Partial<Record<TKey, TItem[]>>;\nexport function arrayGroupBy<TItem, TKey extends keyof TItem>(items: TItem[], groupBy: TKey): Record<string, TItem[]>;\nexport function arrayGroupBy<TItem>(\n items: TItem[],\n groupBy: string | ((item: TItem) => string),\n): Partial<Record<string, TItem[]>> {\n const group =\n typeof groupBy === 'string' ? (item: TItem) => toString(item[groupBy as unknown as keyof TItem]) : groupBy;\n\n return items.reduce(\n (groups, item) => {\n (groups[group(item)] ??= []).push(item);\n\n return groups;\n },\n {} as Record<string, TItem[]>,\n );\n}\n\nexport function arrayIsEmpty(items: unknown[]): boolean {\n return items.length === 0;\n}\n\nexport function arrayProject<T, S extends keyof T>(items: T[], property: S): T[S][] {\n return items.map((item) => item[property]);\n}\n\nexport function arrayPull<T>(items: T[], index: number): T | undefined {\n const value = items[index];\n\n items.splice(index, 1);\n\n return value;\n}\n\nexport function arrayRandomItem<T>(items: T[]): T | null {\n return items.length === 0 ? null : (items[Math.floor(Math.random() * items.length)] as T);\n}\n\nexport function arrayRandomItems<T>(items: T[], count: number): T[] {\n const itemsLeft = items.slice(0);\n const randomItems = [] as T[];\n\n while (itemsLeft.length > 0 && randomItems.length < count) {\n const index = Math.floor(Math.random() * itemsLeft.length);\n\n randomItems.push(itemsLeft[index] as T);\n itemsLeft.splice(index, 1);\n }\n\n return randomItems;\n}\n\nexport function arrayRemove<T>(items: T[], item: T): boolean {\n const index = items.indexOf(item);\n\n if (index === -1) return false;\n\n items.splice(index, 1);\n\n return true;\n}\n\nexport function arrayRemoveIndex<T>(items: T[], index: number | string): boolean {\n return items.splice(Number(index), 1).length > 0;\n}\n\nexport function arrayReplace<T>(items: T[], original: T, replacement: T): boolean {\n const index = items.indexOf(original);\n\n if (index === -1) return false;\n\n items[index] = replacement;\n\n return true;\n}\n\nexport function arrayReversed<T>(items: T[]): T[] {\n const reversed = items.slice(0);\n\n reversed.reverse();\n\n return reversed;\n}\n\nexport function arrayShuffled<T>(items: T[]): T[] {\n const shuffled = items.slice(0);\n\n shuffle(shuffled);\n\n return shuffled;\n}\n\nexport function arraySorted<T>(items: T[]): T[];\nexport function arraySorted<T>(items: T[], direction: ArraySortDirection): T[];\nexport function arraySorted<T>(items: T[], compareValues: ArraySortCompare<T>): T[];\nexport function arraySorted<T>(items: T[], field: DeepKeyOf<T>, direction?: ArraySortDirection): T[];\nexport function arraySorted<T>(items: T[], fields: DeepKeyOf<T>[], direction?: ArraySortDirection): T[];\nexport function arraySorted<T>(items: T[], fields: ArraySortFieldDirection<T>[]): T[];\nexport function arraySorted<T>(\n items: T[],\n compareOrFieldOrDirection?:\n | ArraySortDirection\n | ArraySortCompare<T>\n | DeepKeyOf<T>\n | DeepKeyOf<T>[]\n | ArraySortFieldDirection<T>[],\n direction?: ArraySortDirection,\n): T[] {\n switch (compareOrFieldOrDirection) {\n case undefined:\n case 'asc':\n return items.slice(0).sort(compare);\n case 'desc':\n return items.slice(0).sort((a, b) => compare(b, a));\n }\n\n if (typeof compareOrFieldOrDirection === 'function') {\n return items.slice(0).sort(compareOrFieldOrDirection);\n }\n\n const fields =\n typeof compareOrFieldOrDirection === 'string'\n ? [[compareOrFieldOrDirection, direction ?? 'asc'] as const]\n : compareOrFieldOrDirection.map((field) =>\n typeof field === 'string' ? ([field, direction ?? 'asc'] as const) : field,\n );\n\n return arraySortedByFields(items, fields);\n}\n\nfunction getSortDefaultValue(values: unknown[]): unknown {\n const sample = values.find((value) => value !== undefined && value !== null);\n\n switch (typeof sample) {\n case 'string':\n return '';\n case 'number':\n return Number.MIN_SAFE_INTEGER;\n case 'boolean':\n return false;\n default:\n if (sample instanceof Date) {\n return Number.MIN_SAFE_INTEGER;\n }\n\n return null;\n }\n}\n\nfunction arraySortedByFields<T>(items: T[], fields: readonly ArraySortFieldDirection<T>[]): T[] {\n const sortKeys = fields.map(([field, fieldDirection]) => {\n const values = items.map((item) => deepGet(item as object, field as never) as unknown);\n const defaultValue = getSortDefaultValue(values);\n\n return {\n values: values.map((value) => (value instanceof Date ? value.getTime() : (value ?? defaultValue))),\n directionSign: fieldDirection === 'desc' ? -1 : 1,\n };\n });\n const indexes = items.map((_, index) => index);\n\n indexes.sort((a, b) => {\n for (const { values, directionSign } of sortKeys) {\n const result = compare(values[a], values[b]);\n\n if (result !== 0) return result * directionSign;\n }\n\n return 0;\n });\n\n return indexes.map((index) => items[index] as T);\n}\n\nexport function arraySwap(items: unknown[], firstIndex: number, secondIndex: number): void {\n [items[firstIndex], items[secondIndex]] = [items[secondIndex], items[firstIndex]];\n}\n\nexport function arrayUnique<T>(items: T[], extractKey?: (item: T) => string): T[] {\n return extractKey\n ? Object.values(\n items.reduce(\n (unique, item) => {\n const key = extractKey(item);\n\n unique[key] = unique[key] ?? item;\n\n return unique;\n },\n {} as Record<string, T>,\n ),\n )\n : [...new Set(items)];\n}\n\nexport function arrayFind<T, K extends keyof T>(items: T[], filter: string, value?: T[K]): T | undefined {\n return items.find((item) => {\n const property = item[filter as keyof T];\n const result = typeof property === 'function' ? property.call(item) : property;\n\n return value ? result === value : !!result;\n });\n}\n\nexport function arrayWhere<T, K extends keyof T>(items: T[], filter: string, value?: T[K]): T[] {\n return items.filter((item) => {\n const property = item[filter as keyof T];\n const result = typeof property === 'function' ? property.call(item) : property;\n\n return value ? result === value : !!result;\n });\n}\n\nexport function arrayWithout<T>(items: T[], exclude: T | T[]): T[] {\n return Array.isArray(exclude)\n ? arrayFilter(items, (item) => exclude.indexOf(item) === -1)\n : arrayWithoutIndex(items, items.indexOf(exclude));\n}\n\nexport function arrayWithoutIndex<T>(items: T[], index: number): T[] {\n return arrayWithoutIndexes(items, [index]);\n}\n\nexport function arrayWithoutIndexes<T>(items: T[], indexes: number[]): T[] {\n return items\n .map((value, index) => [value, index] as [T, number])\n .filter(([_, index]) => !indexes.includes(index))\n .map(([value]) => value);\n}\n\nexport function arrayZip<T>(...arrays: T[][]): T[][] {\n const zippedArrays: T[][] = [];\n const arraysLength = arrays[0]?.length ?? 0;\n\n for (let i = 0; i < arraysLength; i++) zippedArrays.push(arrays.map((a) => a[i] as T));\n\n return zippedArrays;\n}\n\nexport function arrayFrom<TValue, TOptions extends { ignoreEmptyValues?: boolean }>(\n value: TValue,\n options?: TOptions,\n): TOptions extends { ignoreEmptyValues: true } ? ArrayFrom<NonNullable<TValue>> : ArrayFrom<TValue> {\n const ignoreEmptyValues = options?.ignoreEmptyValues ?? false;\n const items =\n Array.isArray(value) || (isIterable(value) && !isString(value))\n ? Array.from(value)\n : ignoreEmptyValues && (value === null || value === undefined)\n ? []\n : [value];\n\n return items as TOptions extends { ignoreEmptyValues: true } ? ArrayFrom<NonNullable<TValue>> : ArrayFrom<TValue>;\n}\n\nexport function hasItems<T>(array: T[]): array is [T, ...T[]] {\n return array.length > 0;\n}\n\nexport function range(length: number): number[] {\n return Array.from({ length }, (_, item) => item);\n}\n\nexport function reduceBy<TItem, TKey extends keyof TItem, TProjection>(\n items: TItem[],\n key: TKey,\n project: (item: TItem) => TProjection,\n): Record<string, TProjection>;\nexport function reduceBy<TItem, TKey extends keyof TItem>(items: TItem[], key: TKey): Record<string, TItem>;\nexport function reduceBy<TItem, TKey extends keyof TItem, TProjection>(\n items: TItem[],\n key: TKey,\n project?: (item: TItem) => TProjection,\n): Record<string, TProjection> {\n return items.reduce(\n (acc, item) => {\n acc[toString(item[key])] = project ? project(item) : (item as unknown as TProjection);\n\n return acc;\n },\n {} as Record<string, TProjection>,\n );\n}\n\nexport function shuffle(items: unknown[]): void {\n for (let i = items.length - 1; i > 0; i--) {\n const j = Math.floor(Math.random() * (i + 1));\n\n [items[i], items[j]] = [items[j], items[i]];\n }\n}\n"],"mappings":";;;AAWA,SAAgB,WAAW,OAAwB;CAC/C,MAAM,OAAO,GAAG,MAAM,MAAM;AAChC;AAEA,SAAgB,UACZ,UACA,SACA,eAC4B;CAC5B,MAAM,UAAU,SAAS,MAAM,CAAC;CAChC,MAAM,QAAQ,CAAC;CACf,MAAM,SAA0C,iBACzC,MAAM,UAAU,MAAM,WAAW,cAAc,cAAc,MAAM,SAAS,CAAC,KAC7E,MAAM,UAAU,MAAM,QAAQ,IAAI;CAEzC,KAAK,MAAM,eAAe,SAAS;EAC/B,MAAM,QAAQ,OAAO,aAAa,OAAO;EAEzC,UAAU,KAAK,QAAQ,OAAO,OAAO,CAAC,IAAI,MAAM,KAAK,WAAW;CACpE;CAEA,OAAO;EAAE;EAAO;CAAQ;AAC5B;AAEA,SAAgB,WAAc,OAAY,WAA0B;CAChE,MAAM,SAAS,CAAC;CAEhB,KAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK,WACnC,OAAO,KAAK,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC;CAG7C,OAAO;AACX;AAEA,SAAgB,YAAe,UAAe,SAAuB;CACjE,IAAI,SAAS,WAAW,QAAQ,QAC5B,OAAO;CAGX,OAAO,CAAC,SAAS,MAAM,OAAO,UAAU,QAAQ,WAAW,KAAK;AACpE;AAIA,SAAgB,YAAe,OAAY,QAAoC;CAC3E,OAAO,SAAS,MAAM,OAAO,MAAM,IAAI,MAAM,QAAQ,SAAS,CAAC,CAAC,IAAI;AACxE;AAEA,SAAgB,WAAc,OAAY,QAAwC;CAC9E,KAAK,MAAM,QAAQ,OAAO;EACtB,IAAI,CAAC,OAAO,IAAI,GAAG;EAEn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EA,SAAgB,SAAY,OAAkC;CAC1D,OAAO,MAAM,SAAS;AAC1B;AAEA,SAAgB,MAAM,QAA0B;CAC5C,OAAO,MAAM,KAAK,EAAE,OAAO,IAAI,GAAG,SAAS,IAAI;AACnD;AAQA,SAAgB,SACZ,OACA,KACA,SAC2B;CAC3B,OAAO,MAAM,QACR,KAAK,SAAS;EACX,IAAI,SAAS,KAAK,IAAI,KAAK,UAAU,QAAQ,IAAI,IAAK;EAEtD,OAAO;CACX,GACA,CAAC,CACL;AACJ;AAEA,SAAgB,QAAQ,OAAwB;CAC5C,KAAK,IAAI,IAAI,MAAM,SAAS,GAAG,IAAI,GAAG,KAAK;EACvC,MAAM,IAAI,KAAK,MAAM,KAAK,OAAO,KAAK,IAAI,EAAE;EAE5C,CAAC,MAAM,IAAI,MAAM,MAAM,CAAC,MAAM,IAAI,MAAM,EAAE;CAC9C;AACJ"}
@@ -0,0 +1,4 @@
1
+ //#region src/helpers/boolean_helpers.d.ts
2
+ export declare function parseBoolean(value: unknown): boolean;
3
+ //#endregion
4
+ //# sourceMappingURL=boolean_helpers.d.ts.map
@@ -0,0 +1,10 @@
1
+ //#region src/helpers/boolean_helpers.ts
2
+ function parseBoolean(value) {
3
+ if (!value) return false;
4
+ if (["0", "false"].includes(value)) return false;
5
+ return true;
6
+ }
7
+ //#endregion
8
+ export { parseBoolean };
9
+
10
+ //# sourceMappingURL=boolean_helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"boolean_helpers.js","names":[],"sources":["../../src/helpers/boolean_helpers.ts"],"sourcesContent":["export function parseBoolean(value: unknown): boolean {\n if (!value) {\n return false;\n }\n\n if ((['0', 'false'] as unknown[]).includes(value)) {\n return false;\n }\n\n return true;\n}\n"],"mappings":";AAAA,SAAgB,aAAa,OAAyB;CAClD,IAAI,CAAC,OACD,OAAO;CAGX,IAAK,CAAC,KAAK,OAAO,CAAC,CAAe,SAAS,KAAK,GAC5C,OAAO;CAGX,OAAO;AACX"}
@@ -0,0 +1,17 @@
1
+ import { Closure, ClosureArgs } from "../types/helpers.js";
2
+ //#region src/helpers/caching_helpers.d.ts
3
+ export declare function asyncMemo<T>(key: string, operation: () => Promise<T>): Promise<T>;
4
+ export declare function memo<T>(key: string, operation: () => T): T;
5
+ export declare function once<P extends ClosureArgs, R>(operation: Closure<P, R>): Closure<P, R>;
6
+ export declare function weakMemo<T>(name: string, key: object, operation: () => T): T;
7
+ export declare function getAsyncMemo<T>(key: string): Promise<T | null>;
8
+ export declare function getMemo<T>(key: string): T | null;
9
+ export declare function getWeakMemo<T>(name: string, key: object): T | null;
10
+ export declare function resetAsyncMemo(key?: string): void;
11
+ export declare function resetMemo(key?: string): void;
12
+ export declare function resetWeakMemo(name: string, key: object): void;
13
+ export declare function setAsyncMemo(key: string, value: unknown): void;
14
+ export declare function setMemo(key: string, value: unknown): void;
15
+ export declare function setWeakMemo(name: string, key: object, value: unknown): void;
16
+ //#endregion
17
+ //# sourceMappingURL=caching_helpers.d.ts.map
@@ -0,0 +1,55 @@
1
+ import { fail } from "./error_helpers.js";
2
+ import { arrayFrom } from "./array_helpers.js";
3
+ import PromisedValue from "./PromisedValue.js";
4
+ //#region src/helpers/caching_helpers.ts
5
+ const cache = {};
6
+ const asyncCache = {};
7
+ const weakCache = {};
8
+ function asyncMemo(key, operation) {
9
+ asyncCache[key] = asyncCache[key] ?? PromisedValue.from(operation());
10
+ return asyncCache[key];
11
+ }
12
+ function memo(key, operation) {
13
+ cache[key] = cache[key] ?? operation();
14
+ return cache[key];
15
+ }
16
+ function once(operation) {
17
+ const memory = {};
18
+ return (...params) => "result" in memory ? memory.result : memory.result = operation(...params);
19
+ }
20
+ function weakMemo(name, key, operation) {
21
+ if (!weakCache[name]?.has(key)) setWeakMemo(name, key, operation());
22
+ return weakCache[name]?.get(key) ?? fail();
23
+ }
24
+ function getAsyncMemo(key) {
25
+ return Promise.resolve(asyncCache[key] ?? null);
26
+ }
27
+ function getMemo(key) {
28
+ return cache[key] ?? null;
29
+ }
30
+ function getWeakMemo(name, key) {
31
+ return weakCache[name]?.get(key) ?? null;
32
+ }
33
+ function resetAsyncMemo(key) {
34
+ arrayFrom(key ?? Object.keys(asyncCache)).forEach((k) => delete asyncCache[k]);
35
+ }
36
+ function resetMemo(key) {
37
+ arrayFrom(key ?? Object.keys(cache)).forEach((k) => delete cache[k]);
38
+ }
39
+ function resetWeakMemo(name, key) {
40
+ weakCache[name]?.delete(key);
41
+ }
42
+ function setAsyncMemo(key, value) {
43
+ asyncCache[key] = asyncCache[key] ?? new PromisedValue();
44
+ asyncCache[key]?.resolve(value);
45
+ }
46
+ function setMemo(key, value) {
47
+ cache[key] = value;
48
+ }
49
+ function setWeakMemo(name, key, value) {
50
+ (weakCache[name] ??= /* @__PURE__ */ new WeakMap()).set(key, value);
51
+ }
52
+ //#endregion
53
+ export { asyncMemo, getAsyncMemo, getMemo, getWeakMemo, memo, once, resetAsyncMemo, resetMemo, resetWeakMemo, setAsyncMemo, setMemo, setWeakMemo, weakMemo };
54
+
55
+ //# sourceMappingURL=caching_helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"caching_helpers.js","names":[],"sources":["../../src/helpers/caching_helpers.ts"],"sourcesContent":["import { arrayFrom } from '@noeldemartin/utils/helpers/array_helpers';\nimport { fail } from '@noeldemartin/utils/helpers/error_helpers';\nimport PromisedValue from '@noeldemartin/utils/helpers/PromisedValue';\nimport type { Closure, ClosureArgs } from '@noeldemartin/utils/types';\n\nconst cache: Record<string, unknown> = {};\nconst asyncCache: Record<string, PromisedValue> = {};\nconst weakCache: Record<string, WeakMap<object, unknown>> = {};\n\nexport function asyncMemo<T>(key: string, operation: () => Promise<T>): Promise<T> {\n asyncCache[key] = asyncCache[key] ?? PromisedValue.from<unknown>(operation());\n\n return asyncCache[key] as Promise<T>;\n}\n\nexport function memo<T>(key: string, operation: () => T): T {\n cache[key] = cache[key] ?? operation();\n\n return cache[key] as T;\n}\n\nexport function once<P extends ClosureArgs, R>(operation: Closure<P, R>): Closure<P, R> {\n const memory: { result?: R } = {};\n\n // oxlint-disable-next-line typescript/no-explicit-any\n return (...params) => ('result' in memory ? memory.result : ((memory.result = operation(...params)) as any));\n}\n\nexport function weakMemo<T>(name: string, key: object, operation: () => T): T {\n if (!weakCache[name]?.has(key)) {\n setWeakMemo(name, key, operation());\n }\n\n return (weakCache[name]?.get(key) as T) ?? fail();\n}\n\nexport function getAsyncMemo<T>(key: string): Promise<T | null> {\n return Promise.resolve((asyncCache[key] as T) ?? null);\n}\n\nexport function getMemo<T>(key: string): T | null {\n return (cache[key] as T) ?? null;\n}\n\nexport function getWeakMemo<T>(name: string, key: object): T | null {\n return (weakCache[name]?.get(key) as T) ?? null;\n}\n\nexport function resetAsyncMemo(key?: string): void {\n const keys = arrayFrom(key ?? Object.keys(asyncCache));\n\n keys.forEach((k) => delete asyncCache[k]);\n}\n\nexport function resetMemo(key?: string): void {\n const keys = arrayFrom(key ?? Object.keys(cache));\n\n keys.forEach((k) => delete cache[k]);\n}\n\nexport function resetWeakMemo(name: string, key: object): void {\n weakCache[name]?.delete(key);\n}\n\nexport function setAsyncMemo(key: string, value: unknown): void {\n asyncCache[key] = asyncCache[key] ?? new PromisedValue();\n\n asyncCache[key]?.resolve(value);\n}\n\nexport function setMemo(key: string, value: unknown): void {\n cache[key] = value;\n}\n\nexport function setWeakMemo(name: string, key: object, value: unknown): void {\n const itemCache = (weakCache[name] ??= new WeakMap());\n\n itemCache.set(key, value);\n}\n"],"mappings":";;;;AAKA,MAAM,QAAiC,CAAC;AACxC,MAAM,aAA4C,CAAC;AACnD,MAAM,YAAsD,CAAC;AAE7D,SAAgB,UAAa,KAAa,WAAyC;CAC/E,WAAW,OAAO,WAAW,QAAQ,cAAc,KAAc,UAAU,CAAC;CAE5E,OAAO,WAAW;AACtB;AAEA,SAAgB,KAAQ,KAAa,WAAuB;CACxD,MAAM,OAAO,MAAM,QAAQ,UAAU;CAErC,OAAO,MAAM;AACjB;AAEA,SAAgB,KAA+B,WAAyC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: number): number;
4
+ export declare function randomInt(min: number, max: number): number;
5
+ //#endregion
6
+ //# sourceMappingURL=chaos_helpers.d.ts.map
@@ -0,0 +1,11 @@
1
+ //#region src/helpers/chaos_helpers.ts
2
+ function randomInt(minOrMax, max) {
3
+ const maxProvided = typeof max === "number";
4
+ const min = maxProvided ? minOrMax : 0;
5
+ max = maxProvided ? max : minOrMax ?? Number.MAX_SAFE_INTEGER;
6
+ return Math.round(Math.random() * (max - min) + min);
7
+ }
8
+ //#endregion
9
+ export { randomInt };
10
+
11
+ //# sourceMappingURL=chaos_helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chaos_helpers.js","names":[],"sources":["../../src/helpers/chaos_helpers.ts"],"sourcesContent":["export function randomInt(): number;\nexport function randomInt(max: number): number;\nexport function randomInt(min: number, max: number): number;\nexport function randomInt(minOrMax?: number, max?: number): number {\n const maxProvided = typeof max === 'number';\n const min = maxProvided ? (minOrMax as number) : 0;\n max = maxProvided ? (max as number) : (minOrMax ?? Number.MAX_SAFE_INTEGER);\n\n return Math.round(Math.random() * (max - min) + min);\n}\n"],"mappings":";AAGA,SAAgB,UAAU,UAAmB,KAAsB;CAC/D,MAAM,cAAc,OAAO,QAAQ;CACnC,MAAM,MAAM,cAAe,WAAsB;CACjD,MAAM,cAAe,MAAkB,YAAY,OAAO;CAE1D,OAAO,KAAK,MAAM,KAAK,OAAO,KAAK,MAAM,OAAO,GAAG;AACvD"}
@@ -0,0 +1,4 @@
1
+ //#region src/helpers/date_helpers.d.ts
2
+ export declare function parseDate(value?: unknown): Date | null;
3
+ //#endregion
4
+ //# sourceMappingURL=date_helpers.d.ts.map
@@ -0,0 +1,15 @@
1
+ //#region src/helpers/date_helpers.ts
2
+ function parseDate(value) {
3
+ if (!value) return null;
4
+ try {
5
+ const date = new Date(value);
6
+ const time = date.getTime();
7
+ return isNaN(time) || time === 0 ? null : date;
8
+ } catch {
9
+ return null;
10
+ }
11
+ }
12
+ //#endregion
13
+ export { parseDate };
14
+
15
+ //# sourceMappingURL=date_helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"date_helpers.js","names":[],"sources":["../../src/helpers/date_helpers.ts"],"sourcesContent":["export function parseDate(value?: unknown): Date | null {\n if (!value) return null;\n\n try {\n const date = new Date(value as string | number | Date);\n const time = date.getTime();\n\n return isNaN(time) || time === 0 ? null : date;\n } catch {\n return null;\n }\n}\n"],"mappings":";AAAA,SAAgB,UAAU,OAA8B;CACpD,IAAI,CAAC,OAAO,OAAO;CAEnB,IAAI;EACA,MAAM,OAAO,IAAI,KAAK,KAA+B;EACrD,MAAM,OAAO,KAAK,QAAQ;EAE1B,OAAO,MAAM,IAAI,KAAK,SAAS,IAAI,OAAO;CAC9C,QAAQ;EACJ,OAAO;CACX;AACJ"}
@@ -0,0 +1,24 @@
1
+ import { Equals } from "../types/helpers.js";
2
+ //#region src/helpers/deprecated.d.ts
3
+ /**
4
+ * @deprecated use NonNullable<T> instead.
5
+ */
6
+ export type ValueWithoutEmpty<T> = T extends null | undefined ? never : T;
7
+ /**
8
+ * @deprecated use ReplaceValues<T, null | undefined> instead.
9
+ */
10
+ export type ReplaceEmpty<T> = { [K in keyof T]: ValueWithoutEmpty<T[K]>; };
11
+ /**
12
+ * @deprecated use GetRequiredKeysWithout<T, null | undefined> instead.
13
+ */
14
+ export type GetRequiredKeysWithoutEmpty<T, U extends Record<keyof T, unknown> = ReplaceEmpty<T>> = { [K in keyof T]: Record<string, never> extends Pick<T, K> ? never : U[K] extends never ? never : Equals<T[K], U[K]> extends true ? K : never; }[keyof T];
15
+ /**
16
+ * @deprecated use GetOptionalKeysWithout<T, null | undefined> instead.
17
+ */
18
+ export type GetOptionalKeysWithoutEmpty<T, U extends Record<keyof T, unknown> = ReplaceEmpty<T>> = { [K in keyof T]: Record<string, never> extends Pick<T, K> ? K : U[K] extends never ? never : Equals<T[K], U[K]> extends true ? never : K; }[keyof T];
19
+ /**
20
+ * @deprecated use ObjectWithout<T, null | undefined> instead.
21
+ */
22
+ export type ObjectWithoutEmpty<T> = { [K in GetRequiredKeysWithoutEmpty<T>]: ValueWithoutEmpty<T[K]>; } & { [K in GetOptionalKeysWithoutEmpty<T>]?: ValueWithoutEmpty<T[K]>; };
23
+ //#endregion
24
+ //# sourceMappingURL=deprecated.d.ts.map
@@ -0,0 +1,9 @@
1
+ //#region src/helpers/env.d.ts
2
+ export declare function forceEnv(env: string): void;
3
+ export declare function getEnv(): string | null;
4
+ export declare function isDevelopment(): boolean;
5
+ export declare function isTesting(type?: 'unit' | 'e2e'): boolean;
6
+ export declare function isProduction(): boolean;
7
+ export declare function applyStrictChecks(): boolean;
8
+ //#endregion
9
+ //# sourceMappingURL=env.d.ts.map