@inrixia/helpers 2.0.11 → 3.1.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 (163) hide show
  1. package/dist/conv.d.ts +27 -27
  2. package/dist/conv.d.ts.map +1 -1
  3. package/dist/conv.js +41 -41
  4. package/dist/{logic.d.ts → fn/Promize.d.ts} +16 -23
  5. package/dist/fn/Promize.d.ts.map +1 -0
  6. package/dist/fn/Promize.js +25 -0
  7. package/dist/fn/Promize.js.map +1 -0
  8. package/dist/fn/Semaphore.d.ts +7 -0
  9. package/dist/fn/Semaphore.d.ts.map +1 -0
  10. package/dist/fn/Semaphore.js +31 -0
  11. package/dist/fn/Semaphore.js.map +1 -0
  12. package/dist/fn/asyncDebounce.d.ts +2 -0
  13. package/dist/fn/asyncDebounce.d.ts.map +1 -0
  14. package/dist/fn/asyncDebounce.js +26 -0
  15. package/dist/fn/asyncDebounce.js.map +1 -0
  16. package/dist/fn/debounce.d.ts +2 -0
  17. package/dist/fn/debounce.d.ts.map +1 -0
  18. package/dist/fn/debounce.js +13 -0
  19. package/dist/fn/debounce.js.map +1 -0
  20. package/dist/fn/loopError.d.ts +11 -0
  21. package/dist/fn/loopError.d.ts.map +1 -0
  22. package/dist/fn/loopError.js +14 -0
  23. package/dist/fn/loopError.js.map +1 -0
  24. package/dist/fn/memoize.d.ts +2 -0
  25. package/dist/fn/memoize.d.ts.map +1 -0
  26. package/dist/fn/memoize.js +18 -0
  27. package/dist/fn/memoize.js.map +1 -0
  28. package/dist/fn/retry.d.ts +7 -0
  29. package/dist/fn/retry.d.ts.map +1 -0
  30. package/dist/{logic.js → fn/retry.js} +26 -50
  31. package/dist/fn/retry.js.map +1 -0
  32. package/dist/fn/runFor.d.ts +2 -0
  33. package/dist/fn/runFor.d.ts.map +1 -0
  34. package/dist/fn/runFor.js +11 -0
  35. package/dist/fn/runFor.js.map +1 -0
  36. package/dist/{react.d.ts → fn/toBase64Image.d.ts} +2 -2
  37. package/dist/fn/toBase64Image.d.ts.map +1 -0
  38. package/dist/{react.js → fn/toBase64Image.js} +14 -14
  39. package/dist/fn/toBase64Image.js.map +1 -0
  40. package/dist/fn/toRange.d.ts +9 -0
  41. package/dist/fn/toRange.d.ts.map +1 -0
  42. package/dist/fn/toRange.js +26 -0
  43. package/dist/fn/toRange.js.map +1 -0
  44. package/dist/fs/exists.d.ts +2 -0
  45. package/dist/fs/exists.d.ts.map +1 -0
  46. package/dist/fs/exists.js +12 -0
  47. package/dist/fs/exists.js.map +1 -0
  48. package/dist/geo.d.ts +18 -18
  49. package/dist/geo.d.ts.map +1 -1
  50. package/dist/geo.js +31 -31
  51. package/dist/index.d.ts +36 -8
  52. package/dist/index.d.ts.map +1 -1
  53. package/dist/index.js +36 -8
  54. package/dist/index.js.map +1 -1
  55. package/dist/math/angleDifference.d.ts +9 -0
  56. package/dist/math/angleDifference.d.ts.map +1 -0
  57. package/dist/math/angleDifference.js +16 -0
  58. package/dist/math/angleDifference.js.map +1 -0
  59. package/dist/math/nPad.d.ts +14 -0
  60. package/dist/math/nPad.d.ts.map +1 -0
  61. package/dist/math/nPad.js +19 -0
  62. package/dist/math/nPad.js.map +1 -0
  63. package/dist/math/qRnd.d.ts +8 -0
  64. package/dist/math/qRnd.d.ts.map +1 -0
  65. package/dist/math/qRnd.js +11 -0
  66. package/dist/math/qRnd.js.map +1 -0
  67. package/dist/math/to360.d.ts +7 -0
  68. package/dist/math/to360.d.ts.map +1 -0
  69. package/dist/math/to360.js +10 -0
  70. package/dist/math/to360.js.map +1 -0
  71. package/dist/obj/RecursiveUpdateOptions.d.ts +15 -0
  72. package/dist/obj/RecursiveUpdateOptions.d.ts.map +1 -0
  73. package/dist/obj/RecursiveUpdateOptions.js +23 -0
  74. package/dist/obj/RecursiveUpdateOptions.js.map +1 -0
  75. package/dist/obj/chunkArray.d.ts +9 -0
  76. package/dist/obj/chunkArray.d.ts.map +1 -0
  77. package/dist/obj/chunkArray.js +17 -0
  78. package/dist/obj/chunkArray.js.map +1 -0
  79. package/dist/obj/compare.d.ts +24 -0
  80. package/dist/obj/compare.d.ts.map +1 -0
  81. package/dist/obj/compare.js +59 -0
  82. package/dist/obj/compare.js.map +1 -0
  83. package/dist/obj/deepGet.d.ts +17 -0
  84. package/dist/obj/deepGet.d.ts.map +1 -0
  85. package/dist/obj/deepGet.js +21 -0
  86. package/dist/obj/deepGet.js.map +1 -0
  87. package/dist/obj/deepMerge.d.ts +8 -0
  88. package/dist/obj/deepMerge.d.ts.map +1 -0
  89. package/dist/obj/deepMerge.js +23 -0
  90. package/dist/obj/deepMerge.js.map +1 -0
  91. package/dist/obj/envOrThrow.d.ts +5 -0
  92. package/dist/obj/envOrThrow.d.ts.map +1 -0
  93. package/dist/obj/envOrThrow.js +10 -0
  94. package/dist/obj/envOrThrow.js.map +1 -0
  95. package/dist/obj/fillTemplate.d.ts +18 -0
  96. package/dist/obj/fillTemplate.d.ts.map +1 -0
  97. package/dist/obj/fillTemplate.js +27 -0
  98. package/dist/obj/fillTemplate.js.map +1 -0
  99. package/dist/obj/getEnv.d.ts +11 -0
  100. package/dist/obj/getEnv.d.ts.map +1 -0
  101. package/dist/obj/getEnv.js +43 -0
  102. package/dist/obj/getEnv.js.map +1 -0
  103. package/dist/obj/hash.d.ts +2 -0
  104. package/dist/obj/hash.d.ts.map +1 -0
  105. package/dist/obj/hash.js +12 -0
  106. package/dist/obj/hash.js.map +1 -0
  107. package/dist/{inspect.d.ts → obj/inspect.d.ts} +25 -25
  108. package/dist/obj/inspect.d.ts.map +1 -0
  109. package/dist/{inspect.js → obj/inspect.js} +35 -35
  110. package/dist/obj/inspect.js.map +1 -0
  111. package/dist/obj/objectify.d.ts +15 -0
  112. package/dist/obj/objectify.d.ts.map +1 -0
  113. package/dist/obj/objectify.js +14 -0
  114. package/dist/obj/objectify.js.map +1 -0
  115. package/dist/obj/rebuildTypes.d.ts +6 -0
  116. package/dist/obj/rebuildTypes.d.ts.map +1 -0
  117. package/dist/obj/rebuildTypes.js +24 -0
  118. package/dist/obj/rebuildTypes.js.map +1 -0
  119. package/dist/test.d.ts +26 -26
  120. package/dist/test.d.ts.map +1 -1
  121. package/dist/test.js +68 -68
  122. package/dist/test.js.map +1 -1
  123. package/dist/ts/isKeyOf.d.ts +6 -0
  124. package/dist/ts/isKeyOf.d.ts.map +1 -0
  125. package/dist/ts/isKeyOf.js +5 -0
  126. package/dist/ts/isKeyOf.js.map +1 -0
  127. package/dist/ts/isTypeOf.d.ts +12 -0
  128. package/dist/ts/isTypeOf.d.ts.map +1 -0
  129. package/dist/ts/isTypeOf.js +12 -0
  130. package/dist/ts/isTypeOf.js.map +1 -0
  131. package/dist/ts/math.d.ts +11 -11
  132. package/dist/ts/math.d.ts.map +1 -1
  133. package/dist/ts/math.js +1 -1
  134. package/dist/ts/numRange.d.ts +11 -11
  135. package/dist/ts/numRange.d.ts.map +1 -1
  136. package/dist/ts/numRange.js +1 -1
  137. package/dist/ts/typeOf.d.ts +24 -0
  138. package/dist/ts/typeOf.d.ts.map +1 -0
  139. package/dist/ts/typeOf.js +28 -0
  140. package/dist/ts/typeOf.js.map +1 -0
  141. package/dist/ts/types.d.ts +31 -0
  142. package/dist/ts/types.d.ts.map +1 -0
  143. package/dist/ts/types.js +2 -0
  144. package/dist/ts/types.js.map +1 -0
  145. package/package.json +23 -62
  146. package/dist/inspect.d.ts.map +0 -1
  147. package/dist/inspect.js.map +0 -1
  148. package/dist/logic.d.ts.map +0 -1
  149. package/dist/logic.js.map +0 -1
  150. package/dist/math.d.ts +0 -35
  151. package/dist/math.d.ts.map +0 -1
  152. package/dist/math.js +0 -53
  153. package/dist/math.js.map +0 -1
  154. package/dist/object.d.ts +0 -142
  155. package/dist/object.d.ts.map +0 -1
  156. package/dist/object.js +0 -315
  157. package/dist/object.js.map +0 -1
  158. package/dist/react.d.ts.map +0 -1
  159. package/dist/react.js.map +0 -1
  160. package/dist/ts.d.ts +0 -29
  161. package/dist/ts.d.ts.map +0 -1
  162. package/dist/ts.js +0 -6
  163. package/dist/ts.js.map +0 -1
package/dist/conv.d.ts CHANGED
@@ -1,28 +1,28 @@
1
- /**
2
- * Get `dryBulbTemp` from `dewBulbTemp` and `relativeHumidity`
3
- * @param dewPointTemp Dew point temperature in degrees celsius
4
- * @param relativeHumidity Relative humidity in whole number percent 0-100
5
- * @returns `dryBulbTemp` - Dry bulb temperature in degrees celsius
6
- *
7
- * @url https://bmcnoldy.rsmas.miami.edu/humidity_conversions.pdf
8
- */
9
- export declare const dryBulbTemp: (dewPointTemp: number, relativeHumidity: number) => number;
10
- /**
11
- * Get `dewPointTemp` from `dryBulbTemp` and `relativeHumidity`
12
- * @param dryBulbTemp Dry bulb temperature in degrees celsius
13
- * @param relativeHumidity Relative humidity in whole number percent 0-100
14
- * @returns `dewPointTemp` - Dew point temperature in degrees celsius
15
- *
16
- * @url https://bmcnoldy.rsmas.miami.edu/humidity_conversions.pdf
17
- */
18
- export declare const dewPointTemp: (dryBulbTemp: number, relativeHumidity: number) => number;
19
- /**
20
- * Get `relativeHumidity` from `dryBulbTemp` and `dewPointTemp`
21
- * @param dryBulbTemp Dry bulb temperature in degrees celsius
22
- * @param dewPointTemp Dew point temperature in degrees celsius
23
- * @returns `dryBulbTemp` - Relative humidity in whole number percent 0-100
24
- *
25
- * @url https://bmcnoldy.rsmas.miami.edu/humidity_conversions.pdf
26
- */
27
- export declare const relativeHumidity: (dryBulbTemp: number, dewPointTemp: number) => number;
1
+ /**
2
+ * Get `dryBulbTemp` from `dewBulbTemp` and `relativeHumidity`
3
+ * @param dewPointTemp Dew point temperature in degrees celsius
4
+ * @param relativeHumidity Relative humidity in whole number percent 0-100
5
+ * @returns `dryBulbTemp` - Dry bulb temperature in degrees celsius
6
+ *
7
+ * @url https://bmcnoldy.rsmas.miami.edu/humidity_conversions.pdf
8
+ */
9
+ export declare const dryBulbTemp: (dewPointTemp: number, relativeHumidity: number) => number;
10
+ /**
11
+ * Get `dewPointTemp` from `dryBulbTemp` and `relativeHumidity`
12
+ * @param dryBulbTemp Dry bulb temperature in degrees celsius
13
+ * @param relativeHumidity Relative humidity in whole number percent 0-100
14
+ * @returns `dewPointTemp` - Dew point temperature in degrees celsius
15
+ *
16
+ * @url https://bmcnoldy.rsmas.miami.edu/humidity_conversions.pdf
17
+ */
18
+ export declare const dewPointTemp: (dryBulbTemp: number, relativeHumidity: number) => number;
19
+ /**
20
+ * Get `relativeHumidity` from `dryBulbTemp` and `dewPointTemp`
21
+ * @param dryBulbTemp Dry bulb temperature in degrees celsius
22
+ * @param dewPointTemp Dew point temperature in degrees celsius
23
+ * @returns `dryBulbTemp` - Relative humidity in whole number percent 0-100
24
+ *
25
+ * @url https://bmcnoldy.rsmas.miami.edu/humidity_conversions.pdf
26
+ */
27
+ export declare const relativeHumidity: (dryBulbTemp: number, dewPointTemp: number) => number;
28
28
  //# sourceMappingURL=conv.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"conv.d.ts","sourceRoot":"","sources":["../src/conv.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW,iBAAkB,MAAM,oBAAoB,MAAM,KAAG,MAI5E,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,YAAY,gBAAiB,MAAM,oBAAoB,MAAM,KAAG,MAI5E,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,gBAAiB,MAAM,gBAAgB,MAAM,KAAG,MAI5E,CAAC"}
1
+ {"version":3,"file":"conv.d.ts","sourceRoot":"","sources":["../src/conv.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW,GAAI,cAAc,MAAM,EAAE,kBAAkB,MAAM,KAAG,MAI5E,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,YAAY,GAAI,aAAa,MAAM,EAAE,kBAAkB,MAAM,KAAG,MAI5E,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,GAAI,aAAa,MAAM,EAAE,cAAc,MAAM,KAAG,MAI5E,CAAC"}
package/dist/conv.js CHANGED
@@ -1,42 +1,42 @@
1
- const a = 17.625;
2
- const b = 243.04;
3
- /**
4
- * Get `dryBulbTemp` from `dewBulbTemp` and `relativeHumidity`
5
- * @param dewPointTemp Dew point temperature in degrees celsius
6
- * @param relativeHumidity Relative humidity in whole number percent 0-100
7
- * @returns `dryBulbTemp` - Dry bulb temperature in degrees celsius
8
- *
9
- * @url https://bmcnoldy.rsmas.miami.edu/humidity_conversions.pdf
10
- */
11
- export const dryBulbTemp = (dewPointTemp, relativeHumidity) => {
12
- const lnRH = Math.log(relativeHumidity / 100);
13
- const aTdbTd = (a * dewPointTemp) / (b + dewPointTemp);
14
- return (b * (aTdbTd - lnRH)) / (a + lnRH - aTdbTd);
15
- };
16
- /**
17
- * Get `dewPointTemp` from `dryBulbTemp` and `relativeHumidity`
18
- * @param dryBulbTemp Dry bulb temperature in degrees celsius
19
- * @param relativeHumidity Relative humidity in whole number percent 0-100
20
- * @returns `dewPointTemp` - Dew point temperature in degrees celsius
21
- *
22
- * @url https://bmcnoldy.rsmas.miami.edu/humidity_conversions.pdf
23
- */
24
- export const dewPointTemp = (dryBulbTemp, relativeHumidity) => {
25
- const lnRH = Math.log(relativeHumidity / 100);
26
- const aTbT = (a * dryBulbTemp) / (b + dryBulbTemp);
27
- return (b * (lnRH + aTbT)) / (a - lnRH - aTbT);
28
- };
29
- /**
30
- * Get `relativeHumidity` from `dryBulbTemp` and `dewPointTemp`
31
- * @param dryBulbTemp Dry bulb temperature in degrees celsius
32
- * @param dewPointTemp Dew point temperature in degrees celsius
33
- * @returns `dryBulbTemp` - Relative humidity in whole number percent 0-100
34
- *
35
- * @url https://bmcnoldy.rsmas.miami.edu/humidity_conversions.pdf
36
- */
37
- export const relativeHumidity = (dryBulbTemp, dewPointTemp) => {
38
- const aTdbTd = (a * dewPointTemp) / (b + dewPointTemp);
39
- const aTbT = (a * dryBulbTemp) / (b + dryBulbTemp);
40
- return 100 * (Math.exp(aTdbTd) / Math.exp(aTbT));
41
- };
1
+ const a = 17.625;
2
+ const b = 243.04;
3
+ /**
4
+ * Get `dryBulbTemp` from `dewBulbTemp` and `relativeHumidity`
5
+ * @param dewPointTemp Dew point temperature in degrees celsius
6
+ * @param relativeHumidity Relative humidity in whole number percent 0-100
7
+ * @returns `dryBulbTemp` - Dry bulb temperature in degrees celsius
8
+ *
9
+ * @url https://bmcnoldy.rsmas.miami.edu/humidity_conversions.pdf
10
+ */
11
+ export const dryBulbTemp = (dewPointTemp, relativeHumidity) => {
12
+ const lnRH = Math.log(relativeHumidity / 100);
13
+ const aTdbTd = (a * dewPointTemp) / (b + dewPointTemp);
14
+ return (b * (aTdbTd - lnRH)) / (a + lnRH - aTdbTd);
15
+ };
16
+ /**
17
+ * Get `dewPointTemp` from `dryBulbTemp` and `relativeHumidity`
18
+ * @param dryBulbTemp Dry bulb temperature in degrees celsius
19
+ * @param relativeHumidity Relative humidity in whole number percent 0-100
20
+ * @returns `dewPointTemp` - Dew point temperature in degrees celsius
21
+ *
22
+ * @url https://bmcnoldy.rsmas.miami.edu/humidity_conversions.pdf
23
+ */
24
+ export const dewPointTemp = (dryBulbTemp, relativeHumidity) => {
25
+ const lnRH = Math.log(relativeHumidity / 100);
26
+ const aTbT = (a * dryBulbTemp) / (b + dryBulbTemp);
27
+ return (b * (lnRH + aTbT)) / (a - lnRH - aTbT);
28
+ };
29
+ /**
30
+ * Get `relativeHumidity` from `dryBulbTemp` and `dewPointTemp`
31
+ * @param dryBulbTemp Dry bulb temperature in degrees celsius
32
+ * @param dewPointTemp Dew point temperature in degrees celsius
33
+ * @returns `dryBulbTemp` - Relative humidity in whole number percent 0-100
34
+ *
35
+ * @url https://bmcnoldy.rsmas.miami.edu/humidity_conversions.pdf
36
+ */
37
+ export const relativeHumidity = (dryBulbTemp, dewPointTemp) => {
38
+ const aTdbTd = (a * dewPointTemp) / (b + dewPointTemp);
39
+ const aTbT = (a * dryBulbTemp) / (b + dryBulbTemp);
40
+ return 100 * (Math.exp(aTdbTd) / Math.exp(aTbT));
41
+ };
42
42
  //# sourceMappingURL=conv.js.map
@@ -1,23 +1,16 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
- export declare const sleep: typeof import("timers/promises").setTimeout;
3
- export declare class Promize<T> {
4
- p: Promise<T>;
5
- res: (value: T) => void;
6
- rej: (reason?: any) => void;
7
- /**
8
- * Returns a new instance of a `Promize`, a externally resolvable Promise.
9
- * @param resValue If not undefined, resolves the internal promise with given value on creation.
10
- */
11
- constructor(resValue?: T);
12
- /**
13
- * Recreate the promise
14
- * @param resValue If not undefined, resolves the internal promise with given value on creation.
15
- */
16
- set(resValue?: T): void;
17
- }
18
- export declare const retry: <T>(func: () => T | Promise<T>, options?: {
19
- onErr?: ((error: unknown, retryCount: number) => void) | undefined;
20
- timeoutMultiplier?: number | undefined;
21
- maxRetries?: number | undefined;
22
- } | undefined) => () => Promise<T>;
23
- //# sourceMappingURL=logic.d.ts.map
1
+ export declare class Promize<T> {
2
+ p: Promise<T>;
3
+ res: (value: T) => void;
4
+ rej: (reason?: any) => void;
5
+ /**
6
+ * Returns a new instance of a `Promize`, a externally resolvable Promise.
7
+ * @param resValue If not undefined, resolves the internal promise with given value on creation.
8
+ */
9
+ constructor(resValue?: T);
10
+ /**
11
+ * Recreate the promise
12
+ * @param resValue If not undefined, resolves the internal promise with given value on creation.
13
+ */
14
+ set(resValue?: T): void;
15
+ }
16
+ //# sourceMappingURL=Promize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Promize.d.ts","sourceRoot":"","sources":["../../src/fn/Promize.ts"],"names":[],"mappings":"AAAA,qBAAa,OAAO,CAAC,CAAC;IACd,CAAC,EAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACtB,GAAG,EAAG,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;IACzB,GAAG,EAAG,CAAC,MAAM,CAAC,EAAE,GAAG,KAAK,IAAI,CAAC;IAE7B;;;OAGG;gBACS,QAAQ,CAAC,EAAE,CAAC;IAIxB;;;OAGG;IACH,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,GAAG,IAAI;CAOvB"}
@@ -0,0 +1,25 @@
1
+ export class Promize {
2
+ p;
3
+ res;
4
+ rej;
5
+ /**
6
+ * Returns a new instance of a `Promize`, a externally resolvable Promise.
7
+ * @param resValue If not undefined, resolves the internal promise with given value on creation.
8
+ */
9
+ constructor(resValue) {
10
+ this.set(resValue);
11
+ }
12
+ /**
13
+ * Recreate the promise
14
+ * @param resValue If not undefined, resolves the internal promise with given value on creation.
15
+ */
16
+ set(resValue) {
17
+ this.p = new Promise((res, rej) => {
18
+ this.res = res;
19
+ this.rej = rej;
20
+ });
21
+ if (resValue !== undefined)
22
+ this.res(resValue);
23
+ }
24
+ }
25
+ //# sourceMappingURL=Promize.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Promize.js","sourceRoot":"","sources":["../../src/fn/Promize.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,OAAO;IACZ,CAAC,CAAc;IACtB,GAAG,CAAsB;IACzB,GAAG,CAA0B;IAE7B;;;OAGG;IACH,YAAY,QAAY;QACvB,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACpB,CAAC;IAED;;;OAGG;IACH,GAAG,CAAC,QAAY;QACf,IAAI,CAAC,CAAC,GAAG,IAAI,OAAO,CAAI,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;YACpC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;YACf,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QAChB,CAAC,CAAC,CAAC;QACH,IAAI,QAAQ,KAAK,SAAS;YAAE,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAChD,CAAC;CACD"}
@@ -0,0 +1,7 @@
1
+ export declare class Semaphore {
2
+ private avalibleSlots;
3
+ private readonly _queue;
4
+ constructor(avalibleSlots: number);
5
+ obtain(): Promise<() => void>;
6
+ }
7
+ //# sourceMappingURL=Semaphore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Semaphore.d.ts","sourceRoot":"","sources":["../../src/fn/Semaphore.ts"],"names":[],"mappings":"AAAA,qBAAa,SAAS;IAET,OAAO,CAAC,aAAa;IADjC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAsB;gBACzB,aAAa,EAAE,MAAM;IAE5B,MAAM,IAAI,OAAO,CAAC,MAAM,IAAI,CAAC;CAuB1C"}
@@ -0,0 +1,31 @@
1
+ export class Semaphore {
2
+ avalibleSlots;
3
+ _queue = [];
4
+ constructor(avalibleSlots) {
5
+ this.avalibleSlots = avalibleSlots;
6
+ }
7
+ async obtain() {
8
+ let released = false;
9
+ const release = () => {
10
+ if (released)
11
+ return;
12
+ released = true;
13
+ this.avalibleSlots++;
14
+ // If there are queued requests, resolve the first one in the queue
15
+ this._queue.shift()?.();
16
+ };
17
+ // If there is an available request slot, proceed immediately
18
+ if (this.avalibleSlots > 0) {
19
+ this.avalibleSlots--;
20
+ return release;
21
+ }
22
+ // Otherwise, wait for a request slot to become available
23
+ return new Promise((r) => {
24
+ this._queue.push(() => {
25
+ this.avalibleSlots--;
26
+ r(release);
27
+ });
28
+ });
29
+ }
30
+ }
31
+ //# sourceMappingURL=Semaphore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Semaphore.js","sourceRoot":"","sources":["../../src/fn/Semaphore.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,SAAS;IAED;IADH,MAAM,GAAmB,EAAE,CAAC;IAC7C,YAAoB,aAAqB;QAArB,kBAAa,GAAb,aAAa,CAAQ;IAAG,CAAC;IAEtC,KAAK,CAAC,MAAM;QAClB,IAAI,QAAQ,GAAG,KAAK,CAAC;QACrB,MAAM,OAAO,GAAG,GAAG,EAAE;YACpB,IAAI,QAAQ;gBAAE,OAAO;YACrB,QAAQ,GAAG,IAAI,CAAC;YAChB,IAAI,CAAC,aAAa,EAAE,CAAC;YACrB,mEAAmE;YACnE,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,EAAE,CAAC;QACzB,CAAC,CAAC;QACF,6DAA6D;QAC7D,IAAI,IAAI,CAAC,aAAa,GAAG,CAAC,EAAE,CAAC;YAC5B,IAAI,CAAC,aAAa,EAAE,CAAC;YACrB,OAAO,OAAO,CAAC;QAChB,CAAC;QAED,yDAAyD;QACzD,OAAO,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;YACxB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE;gBACrB,IAAI,CAAC,aAAa,EAAE,CAAC;gBACrB,CAAC,CAAC,OAAO,CAAC,CAAC;YACZ,CAAC,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC;IACJ,CAAC;CACD"}
@@ -0,0 +1,2 @@
1
+ export declare const asyncDebounce: <A extends any[], V>(generator: (...args: A) => Promise<V>) => (...args: A) => Promise<V>;
2
+ //# sourceMappingURL=asyncDebounce.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asyncDebounce.d.ts","sourceRoot":"","sources":["../../src/fn/asyncDebounce.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,GAAI,CAAC,SAAS,GAAG,EAAE,EAAE,CAAC,EAAE,WAAW,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,eAY7D,CAAC,KAAG,OAAO,CAAC,CAAC,CAStC,CAAC"}
@@ -0,0 +1,26 @@
1
+ export const asyncDebounce = (generator) => {
2
+ if (generator.length === 0) {
3
+ let _current;
4
+ const _func = () => {
5
+ if (_current)
6
+ return _current;
7
+ _current = generator();
8
+ _current.finally(() => (_current = undefined));
9
+ return _current;
10
+ };
11
+ return _func;
12
+ }
13
+ else {
14
+ const _current = {};
15
+ const _func = (...args) => {
16
+ const key = JSON.stringify(args);
17
+ if (key in _current)
18
+ return _current[key];
19
+ _current[key] = generator(...args);
20
+ _current[key].finally(() => delete _current[key]);
21
+ return _current[key];
22
+ };
23
+ return _func;
24
+ }
25
+ };
26
+ //# sourceMappingURL=asyncDebounce.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asyncDebounce.js","sourceRoot":"","sources":["../../src/fn/asyncDebounce.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,aAAa,GAAG,CAAqB,SAAqC,EAAE,EAAE;IAC1F,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC5B,IAAI,QAAgC,CAAC;QACrC,MAAM,KAAK,GAAG,GAAe,EAAE;YAC9B,IAAI,QAAQ;gBAAE,OAAO,QAAQ,CAAC;YAC9B,QAAQ,GAAI,SAA8B,EAAE,CAAC;YAC7C,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,QAAQ,GAAG,SAAS,CAAC,CAAC,CAAC;YAC/C,OAAO,QAAQ,CAAC;QACjB,CAAC,CAAC;QACF,OAAO,KAAK,CAAC;IACd,CAAC;SAAM,CAAC;QACP,MAAM,QAAQ,GAA+B,EAAE,CAAC;QAChD,MAAM,KAAK,GAAG,CAAC,GAAG,IAAO,EAAc,EAAE;YACxC,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;YACjC,IAAI,GAAG,IAAI,QAAQ;gBAAE,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC;YAC1C,QAAQ,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,GAAG,IAAI,CAAC,CAAC;YACnC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;YAClD,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC;QACtB,CAAC,CAAC;QACF,OAAO,KAAK,CAAC;IACd,CAAC;AACF,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const debounce: <T extends (...args: any[]) => any>(func: T, wait: number) => ((...args: Parameters<T>) => void);
2
+ //# sourceMappingURL=debounce.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debounce.d.ts","sourceRoot":"","sources":["../../src/fn/debounce.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,QAAQ,GAAI,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAAE,MAAM,CAAC,EAAE,MAAM,MAAM,KAAG,CAAC,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI,CAUpH,CAAC"}
@@ -0,0 +1,13 @@
1
+ export const debounce = (func, wait) => {
2
+ let timeout;
3
+ return async function (...args) {
4
+ const context = this;
5
+ if (timeout)
6
+ clearTimeout(timeout);
7
+ timeout = setTimeout(async () => {
8
+ timeout = null;
9
+ func.apply(context, args);
10
+ }, wait);
11
+ };
12
+ };
13
+ //# sourceMappingURL=debounce.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debounce.js","sourceRoot":"","sources":["../../src/fn/debounce.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAoC,IAAO,EAAE,IAAY,EAAsC,EAAE;IACxH,IAAI,OAA8B,CAAC;IACnC,OAAO,KAAK,WAAuC,GAAG,IAAmB;QACxE,MAAM,OAAO,GAAG,IAAI,CAAC;QACrB,IAAI,OAAO;YAAE,YAAY,CAAC,OAAO,CAAC,CAAC;QACnC,OAAO,GAAG,UAAU,CAAC,KAAK,IAAI,EAAE;YAC/B,OAAO,GAAG,IAAI,CAAC;YACf,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAC3B,CAAC,EAAE,IAAI,CAAC,CAAC;IACV,CAAC,CAAC;AACH,CAAC,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { AsyncFunction } from "../ts/types.js";
2
+ type ErrorHandler = (err: Error) => Promise<void>;
3
+ /**
4
+ * Recursively runs `func` and handles errors with `errorHandler` until `func` successfully finishes.
5
+ * @param func Function to execute
6
+ * @param errorHandler Function to execute when a error occours
7
+ * @returns Return value of `func` on success
8
+ */
9
+ export declare const loopError: <F extends AsyncFunction>(func: F, errorHandler?: ErrorHandler) => ReturnType<F>;
10
+ export {};
11
+ //# sourceMappingURL=loopError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loopError.d.ts","sourceRoot":"","sources":["../../src/fn/loopError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,KAAK,YAAY,GAAG,CAAC,GAAG,EAAE,KAAK,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAClD;;;;;GAKG;AAEH,eAAO,MAAM,SAAS,GAAI,CAAC,SAAS,aAAa,EAAE,MAAM,CAAC,EAAE,eAAc,YAA+D,KAAG,UAAU,CAAC,CAAC,CAOpI,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Recursively runs `func` and handles errors with `errorHandler` until `func` successfully finishes.
3
+ * @param func Function to execute
4
+ * @param errorHandler Function to execute when a error occours
5
+ * @returns Return value of `func` on success
6
+ */
7
+ export const loopError = (func, errorHandler = (err) => new Promise((_res, r) => r(err))) => new Promise((resolve) => {
8
+ func()
9
+ .then(resolve)
10
+ .catch(async (err) => {
11
+ errorHandler(err).then(() => resolve(loopError(func, errorHandler)));
12
+ });
13
+ });
14
+ //# sourceMappingURL=loopError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loopError.js","sourceRoot":"","sources":["../../src/fn/loopError.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,SAAS,GAAG,CAA0B,IAAO,EAAE,eAA6B,CAAC,GAAU,EAAE,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,EAAiB,EAAE,CAC3J,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;IACvB,IAAI,EAAE;SACJ,IAAI,CAAC,OAAO,CAAC;SACb,KAAK,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;QACpB,YAAY,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;IACtE,CAAC,CAAC,CAAC;AACL,CAAC,CAAkB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const memoize: <G extends Function>(generator: G) => G;
2
+ //# sourceMappingURL=memoize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memoize.d.ts","sourceRoot":"","sources":["../../src/fn/memoize.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,GAAI,CAAC,SAAS,QAAQ,EAAE,WAAW,CAAC,KAAG,CAc1D,CAAC"}
@@ -0,0 +1,18 @@
1
+ export const memoize = (generator) => {
2
+ if (generator.length === 0) {
3
+ let cache;
4
+ return (() => {
5
+ if (cache)
6
+ return cache;
7
+ return (cache = generator());
8
+ });
9
+ }
10
+ const cache = {};
11
+ return ((...args) => {
12
+ const key = JSON.stringify(args);
13
+ if (key in cache)
14
+ return cache[key];
15
+ return (cache[key] ??= generator(...args));
16
+ });
17
+ };
18
+ //# sourceMappingURL=memoize.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memoize.js","sourceRoot":"","sources":["../../src/fn/memoize.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,CAAqB,SAAY,EAAK,EAAE;IAC9D,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC5B,IAAI,KAAc,CAAC;QACnB,OAAO,CAAC,GAAG,EAAE;YACZ,IAAI,KAAK;gBAAE,OAAO,KAAK,CAAC;YACxB,OAAO,CAAC,KAAK,GAAG,SAAS,EAAE,CAAC,CAAC;QAC9B,CAAC,CAAiB,CAAC;IACpB,CAAC;IACD,MAAM,KAAK,GAA4B,EAAE,CAAC;IAC1C,OAAO,CAAC,CAAC,GAAG,IAAe,EAAE,EAAE;QAC9B,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QACjC,IAAI,GAAG,IAAI,KAAK;YAAE,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC;QACpC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,SAAS,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;IAC5C,CAAC,CAAiB,CAAC;AACpB,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ export declare const sleep: typeof import("timers/promises").setTimeout;
2
+ export declare const retry: <T>(func: () => Promise<T> | T, options?: {
3
+ onErr?: (error: unknown, retryCount: number) => void;
4
+ timeoutMultiplier?: number;
5
+ maxRetries?: number;
6
+ }) => (() => Promise<T>);
7
+ //# sourceMappingURL=retry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../../src/fn/retry.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,KAAK,6CAAwB,CAAC;AAE3C,eAAO,MAAM,KAAK,GAAI,CAAC,EACtB,MAAM,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,EAC1B,UAAU;IAAE,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;IAAC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,KACjH,CAAC,MAAM,OAAO,CAAC,CAAC,CAAC,CAmBnB,CAAC"}
@@ -1,50 +1,26 @@
1
- import { promisify } from "util";
2
- export const sleep = promisify(setTimeout);
3
- export class Promize {
4
- p;
5
- res;
6
- rej;
7
- /**
8
- * Returns a new instance of a `Promize`, a externally resolvable Promise.
9
- * @param resValue If not undefined, resolves the internal promise with given value on creation.
10
- */
11
- constructor(resValue) {
12
- this.set(resValue);
13
- }
14
- /**
15
- * Recreate the promise
16
- * @param resValue If not undefined, resolves the internal promise with given value on creation.
17
- */
18
- set(resValue) {
19
- this.p = new Promise((res, rej) => {
20
- this.res = res;
21
- this.rej = rej;
22
- });
23
- if (resValue !== undefined)
24
- this.res(resValue);
25
- }
26
- }
27
- export const retry = (func, options) => {
28
- let retryCount = 0;
29
- const maxRetries = options?.maxRetries ?? 10;
30
- const timeoutMultiplier = options?.timeoutMultiplier ?? 1000;
31
- const onErr = options?.onErr;
32
- const tryAgain = async () => {
33
- try {
34
- return await func();
35
- }
36
- catch (e) {
37
- if (onErr !== undefined)
38
- onErr(e, retryCount);
39
- if (retryCount < maxRetries) {
40
- retryCount++;
41
- if (timeoutMultiplier > 0)
42
- await sleep(Math.random() * timeoutMultiplier);
43
- return tryAgain();
44
- }
45
- throw e;
46
- }
47
- };
48
- return tryAgain;
49
- };
50
- //# sourceMappingURL=logic.js.map
1
+ import { promisify } from "util";
2
+ export const sleep = promisify(setTimeout);
3
+ export const retry = (func, options) => {
4
+ let retryCount = 0;
5
+ const maxRetries = options?.maxRetries ?? 10;
6
+ const timeoutMultiplier = options?.timeoutMultiplier ?? 1000;
7
+ const onErr = options?.onErr;
8
+ const tryAgain = async () => {
9
+ try {
10
+ return await func();
11
+ }
12
+ catch (e) {
13
+ if (onErr !== undefined)
14
+ onErr(e, retryCount);
15
+ if (retryCount < maxRetries) {
16
+ retryCount++;
17
+ if (timeoutMultiplier > 0)
18
+ await sleep(Math.random() * timeoutMultiplier);
19
+ return tryAgain();
20
+ }
21
+ throw e;
22
+ }
23
+ };
24
+ return tryAgain;
25
+ };
26
+ //# sourceMappingURL=retry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retry.js","sourceRoot":"","sources":["../../src/fn/retry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AACjC,MAAM,CAAC,MAAM,KAAK,GAAG,SAAS,CAAC,UAAU,CAAC,CAAC;AAE3C,MAAM,CAAC,MAAM,KAAK,GAAG,CACpB,IAA0B,EAC1B,OAAmH,EAC9F,EAAE;IACvB,IAAI,UAAU,GAAG,CAAC,CAAC;IACnB,MAAM,UAAU,GAAG,OAAO,EAAE,UAAU,IAAI,EAAE,CAAC;IAC7C,MAAM,iBAAiB,GAAG,OAAO,EAAE,iBAAiB,IAAI,IAAI,CAAC;IAC7D,MAAM,KAAK,GAAG,OAAO,EAAE,KAAK,CAAC;IAC7B,MAAM,QAAQ,GAAG,KAAK,IAAgB,EAAE;QACvC,IAAI,CAAC;YACJ,OAAO,MAAM,IAAI,EAAE,CAAC;QACrB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACZ,IAAI,KAAK,KAAK,SAAS;gBAAE,KAAK,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC;YAC9C,IAAI,UAAU,GAAG,UAAU,EAAE,CAAC;gBAC7B,UAAU,EAAE,CAAC;gBACb,IAAI,iBAAiB,GAAG,CAAC;oBAAE,MAAM,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,iBAAiB,CAAC,CAAC;gBAC1E,OAAO,QAAQ,EAAE,CAAC;YACnB,CAAC;YACD,MAAM,CAAC,CAAC;QACT,CAAC;IACF,CAAC,CAAC;IACF,OAAO,QAAQ,CAAC;AACjB,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const runFor: (fn: () => true | undefined, timeoutMs: number) => Promise<void>;
2
+ //# sourceMappingURL=runFor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runFor.d.ts","sourceRoot":"","sources":["../../src/fn/runFor.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,MAAM,GAAU,IAAI,MAAM,IAAI,GAAG,SAAS,EAAE,WAAW,MAAM,kBAOzE,CAAC"}
@@ -0,0 +1,11 @@
1
+ export const runFor = async (fn, timeoutMs) => {
2
+ const expires = Date.now() + timeoutMs;
3
+ while (true) {
4
+ if (fn())
5
+ return;
6
+ if (Date.now() > expires)
7
+ return;
8
+ await new Promise((res) => setTimeout(res));
9
+ }
10
+ };
11
+ //# sourceMappingURL=runFor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runFor.js","sourceRoot":"","sources":["../../src/fn/runFor.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,MAAM,GAAG,KAAK,EAAE,EAA0B,EAAE,SAAiB,EAAE,EAAE;IAC7E,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC;IACvC,OAAO,IAAI,EAAE,CAAC;QACb,IAAI,EAAE,EAAE;YAAE,OAAO;QACjB,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO;YAAE,OAAO;QACjC,MAAM,IAAI,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7C,CAAC;AACF,CAAC,CAAC"}
@@ -1,2 +1,2 @@
1
- export declare const toBase64: (file: File) => Promise<string | ArrayBuffer>;
2
- //# sourceMappingURL=react.d.ts.map
1
+ export declare const toBase64: (file: File) => Promise<string | ArrayBuffer>;
2
+ //# sourceMappingURL=toBase64Image.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toBase64Image.d.ts","sourceRoot":"","sources":["../../src/fn/toBase64Image.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,QAAQ,GAAU,MAAM,IAAI,KAAG,OAAO,CAAC,MAAM,GAAG,WAAW,CAUvE,CAAC"}
@@ -1,14 +1,14 @@
1
- export const toBase64 = async (file) => {
2
- const base64Image = await new Promise((resolve, reject) => {
3
- const reader = new FileReader();
4
- reader.readAsDataURL(file);
5
- reader.onload = () => resolve(reader.result);
6
- reader.onerror = reject;
7
- }).catch((err) => err);
8
- if (base64Image instanceof Error)
9
- throw new Error(`Failed to convert file ${file.name} to base64.\n${base64Image.message}`);
10
- if (base64Image === undefined || base64Image === null)
11
- throw new Error(`Failed to convert file ${file.name} to base64.`);
12
- return base64Image;
13
- };
14
- //# sourceMappingURL=react.js.map
1
+ export const toBase64 = async (file) => {
2
+ const base64Image = await new Promise((resolve, reject) => {
3
+ const reader = new FileReader();
4
+ reader.readAsDataURL(file);
5
+ reader.onload = () => resolve(reader.result);
6
+ reader.onerror = reject;
7
+ }).catch((err) => err);
8
+ if (base64Image instanceof Error)
9
+ throw new Error(`Failed to convert file ${file.name} to base64.\n${base64Image.message}`);
10
+ if (base64Image === undefined || base64Image === null)
11
+ throw new Error(`Failed to convert file ${file.name} to base64.`);
12
+ return base64Image;
13
+ };
14
+ //# sourceMappingURL=toBase64Image.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toBase64Image.js","sourceRoot":"","sources":["../../src/fn/toBase64Image.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,QAAQ,GAAG,KAAK,EAAE,IAAU,EAAiC,EAAE;IAC3E,MAAM,WAAW,GAAG,MAAM,IAAI,OAAO,CAA8B,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACtF,MAAM,MAAM,GAAG,IAAI,UAAU,EAAE,CAAC;QAChC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;QAC3B,MAAM,CAAC,MAAM,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC7C,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC;IACzB,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC;IACvB,IAAI,WAAW,YAAY,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,0BAA0B,IAAI,CAAC,IAAI,gBAAgB,WAAW,CAAC,OAAO,EAAE,CAAC,CAAC;IAC5H,IAAI,WAAW,KAAK,SAAS,IAAI,WAAW,KAAK,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,0BAA0B,IAAI,CAAC,IAAI,aAAa,CAAC,CAAC;IACzH,OAAO,WAAW,CAAC;AACpB,CAAC,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @param array
3
+ * @returns string containing ranges of numbers.
4
+ * @example
5
+ * const range = toRange([1, 2, 3, 12, 6, 7, 5, 27, 28, 29, 40, 41, 25, 42, 12])
6
+ * // range = "1-3 & 5-7 & 12 & 25 & 27-29 & 40-42"
7
+ */
8
+ export declare const toRange: (array: number[]) => string;
9
+ //# sourceMappingURL=toRange.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toRange.d.ts","sourceRoot":"","sources":["../../src/fn/toRange.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,eAAO,MAAM,OAAO,GAAI,OAAO,MAAM,EAAE,KAAG,MAezC,CAAC"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @param array
3
+ * @returns string containing ranges of numbers.
4
+ * @example
5
+ * const range = toRange([1, 2, 3, 12, 6, 7, 5, 27, 28, 29, 40, 41, 25, 42, 12])
6
+ * // range = "1-3 & 5-7 & 12 & 25 & 27-29 & 40-42"
7
+ */
8
+ export const toRange = (array) => {
9
+ array = array
10
+ .filter((a, pos) => array.indexOf(a) === pos)
11
+ .sort((a, b) => a - b)
12
+ .map((a) => +a);
13
+ let sum = `${array[0]}`;
14
+ let lastValue = array[0];
15
+ for (let i = 1; i <= array.length; i++) {
16
+ if (!(array[i] - 1 === array[i - 1])) {
17
+ if (array[i - 1] !== lastValue)
18
+ sum += `-${array[i - 1]}`;
19
+ if (array[i] !== undefined)
20
+ sum += ` & ${array[i]}`;
21
+ lastValue = array[i];
22
+ }
23
+ }
24
+ return sum;
25
+ };
26
+ //# sourceMappingURL=toRange.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toRange.js","sourceRoot":"","sources":["../../src/fn/toRange.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,KAAe,EAAU,EAAE;IAClD,KAAK,GAAG,KAAK;SACX,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC;SAC5C,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC;SACrB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IACjB,IAAI,GAAG,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;IACxB,IAAI,SAAS,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;IACzB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACxC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;YACtC,IAAI,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,SAAS;gBAAE,GAAG,IAAI,IAAI,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;YAC1D,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,SAAS;gBAAE,GAAG,IAAI,MAAM,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;YACpD,SAAS,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACtB,CAAC;IACF,CAAC;IACD,OAAO,GAAG,CAAC;AACZ,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const exists: (path: string) => Promise<boolean>;
2
+ //# sourceMappingURL=exists.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exists.d.ts","sourceRoot":"","sources":["../../src/fs/exists.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,MAAM,GAAU,MAAM,MAAM,KAAG,OAAO,CAAC,OAAO,CAO1D,CAAC"}