@inrixia/helpers 2.0.5 → 2.0.7

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 (54) hide show
  1. package/dist/conv.d.ts +28 -0
  2. package/dist/conv.d.ts.map +1 -0
  3. package/{src/conv.ts → dist/conv.js} +13 -15
  4. package/dist/conv.js.map +1 -0
  5. package/dist/geo.d.ts +19 -0
  6. package/dist/geo.d.ts.map +1 -0
  7. package/dist/geo.js +32 -0
  8. package/dist/geo.js.map +1 -0
  9. package/dist/index.d.ts +9 -0
  10. package/dist/index.d.ts.map +1 -0
  11. package/{src/index.ts → dist/index.js} +9 -8
  12. package/dist/index.js.map +1 -0
  13. package/dist/logic.d.ts +23 -0
  14. package/dist/logic.d.ts.map +1 -0
  15. package/dist/logic.js +50 -0
  16. package/dist/logic.js.map +1 -0
  17. package/dist/math.d.ts +35 -0
  18. package/dist/math.d.ts.map +1 -0
  19. package/{src/math.ts → dist/math.js} +19 -20
  20. package/dist/math.js.map +1 -0
  21. package/dist/object.d.ts +166 -0
  22. package/dist/object.d.ts.map +1 -0
  23. package/dist/object.js +350 -0
  24. package/dist/object.js.map +1 -0
  25. package/dist/react.d.ts +2 -0
  26. package/dist/react.d.ts.map +1 -0
  27. package/dist/react.js +14 -0
  28. package/dist/react.js.map +1 -0
  29. package/dist/test.d.ts +27 -0
  30. package/dist/test.d.ts.map +1 -0
  31. package/dist/test.js +69 -0
  32. package/dist/test.js.map +1 -0
  33. package/dist/ts/math.d.ts +12 -0
  34. package/dist/ts/math.d.ts.map +1 -0
  35. package/dist/ts/math.js +2 -0
  36. package/dist/ts/math.js.map +1 -0
  37. package/dist/ts/numRange.d.ts +12 -0
  38. package/dist/ts/numRange.d.ts.map +1 -0
  39. package/dist/ts/numRange.js +2 -0
  40. package/dist/ts/numRange.js.map +1 -0
  41. package/dist/ts.d.ts +29 -0
  42. package/dist/ts.d.ts.map +1 -0
  43. package/dist/ts.js +6 -0
  44. package/dist/ts.js.map +1 -0
  45. package/package.json +1 -1
  46. package/src/geo.ts +0 -33
  47. package/src/logic.ts +0 -52
  48. package/src/object.ts +0 -349
  49. package/src/react.ts +0 -11
  50. package/src/test.ts +0 -86
  51. package/src/ts/math.ts +0 -62
  52. package/src/ts/numRange.ts +0 -15
  53. package/src/ts.ts +0 -54
  54. package/tsconfig.json +0 -22
package/dist/conv.d.ts ADDED
@@ -0,0 +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;
28
+ //# sourceMappingURL=conv.d.ts.map
@@ -0,0 +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,6 +1,5 @@
1
1
  const a = 17.625;
2
2
  const b = 243.04;
3
-
4
3
  /**
5
4
  * Get `dryBulbTemp` from `dewBulbTemp` and `relativeHumidity`
6
5
  * @param dewPointTemp Dew point temperature in degrees celsius
@@ -9,12 +8,11 @@ const b = 243.04;
9
8
  *
10
9
  * @url https://bmcnoldy.rsmas.miami.edu/humidity_conversions.pdf
11
10
  */
12
- export const dryBulbTemp = (dewPointTemp: number, relativeHumidity: number): number => {
13
- const lnRH = Math.log(relativeHumidity / 100);
14
- const aTdbTd = (a * dewPointTemp) / (b + dewPointTemp);
15
- return (b * (aTdbTd - lnRH)) / (a + lnRH - aTdbTd);
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);
16
15
  };
17
-
18
16
  /**
19
17
  * Get `dewPointTemp` from `dryBulbTemp` and `relativeHumidity`
20
18
  * @param dryBulbTemp Dry bulb temperature in degrees celsius
@@ -23,12 +21,11 @@ export const dryBulbTemp = (dewPointTemp: number, relativeHumidity: number): num
23
21
  *
24
22
  * @url https://bmcnoldy.rsmas.miami.edu/humidity_conversions.pdf
25
23
  */
26
- export const dewPointTemp = (dryBulbTemp: number, relativeHumidity: number): number => {
27
- const lnRH = Math.log(relativeHumidity / 100);
28
- const aTbT = (a * dryBulbTemp) / (b + dryBulbTemp);
29
- return (b * (lnRH + aTbT)) / (a - lnRH - aTbT);
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);
30
28
  };
31
-
32
29
  /**
33
30
  * Get `relativeHumidity` from `dryBulbTemp` and `dewPointTemp`
34
31
  * @param dryBulbTemp Dry bulb temperature in degrees celsius
@@ -37,8 +34,9 @@ export const dewPointTemp = (dryBulbTemp: number, relativeHumidity: number): num
37
34
  *
38
35
  * @url https://bmcnoldy.rsmas.miami.edu/humidity_conversions.pdf
39
36
  */
40
- export const relativeHumidity = (dryBulbTemp: number, dewPointTemp: number): number => {
41
- const aTdbTd = (a * dewPointTemp) / (b + dewPointTemp);
42
- const aTbT = (a * dryBulbTemp) / (b + dryBulbTemp);
43
- return 100 * (Math.exp(aTdbTd) / Math.exp(aTbT));
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));
44
41
  };
42
+ //# sourceMappingURL=conv.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conv.js","sourceRoot":"","sources":["../src/conv.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,GAAG,MAAM,CAAC;AACjB,MAAM,CAAC,GAAG,MAAM,CAAC;AAEjB;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,YAAoB,EAAE,gBAAwB,EAAU,EAAE;IACrF,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,gBAAgB,GAAG,GAAG,CAAC,CAAC;IAC9C,MAAM,MAAM,GAAG,CAAC,CAAC,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC;IACvD,OAAO,CAAC,CAAC,GAAG,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,GAAG,MAAM,CAAC,CAAC;AACpD,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,WAAmB,EAAE,gBAAwB,EAAU,EAAE;IACrF,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,gBAAgB,GAAG,GAAG,CAAC,CAAC;IAC9C,MAAM,IAAI,GAAG,CAAC,CAAC,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC;IACnD,OAAO,CAAC,CAAC,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC;AAChD,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,WAAmB,EAAE,YAAoB,EAAU,EAAE;IACrF,MAAM,MAAM,GAAG,CAAC,CAAC,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC;IACvD,MAAM,IAAI,GAAG,CAAC,CAAC,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC;IACnD,OAAO,GAAG,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;AAClD,CAAC,CAAC"}
package/dist/geo.d.ts ADDED
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Converts latitude or longitude to degrees, minutes & seconds.
3
+ * @param coord Latitude or longitude coordinate
4
+ *
5
+ * @returns Coordinate in degrees, minutes & seconds
6
+ */
7
+ export declare const toDMS: (coord: number) => {
8
+ degrees: number;
9
+ minutes: number;
10
+ seconds: number;
11
+ };
12
+ export declare const toRad: (val: number) => number;
13
+ /**
14
+ * Returns the distance between two LatLong's in kilometers
15
+ * @param pos1 [lat, long] coordinates
16
+ * @param pos2 [lat, long] coordinates
17
+ */
18
+ export declare const getDistance: (pos1: [number, number], pos2: [number, number]) => number;
19
+ //# sourceMappingURL=geo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"geo.d.ts","sourceRoot":"","sources":["../src/geo.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,KAAK,UAAW,MAAM;aAAc,MAAM;aAAW,MAAM;aAAW,MAAM;CAOxF,CAAC;AAGF,eAAO,MAAM,KAAK,QAAS,MAAM,KAAG,MAA+B,CAAC;AAEpE;;;;GAIG;AACH,eAAO,MAAM,WAAW,SAAU,CAAC,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,KAAG,MAS5E,CAAC"}
package/dist/geo.js ADDED
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Converts latitude or longitude to degrees, minutes & seconds.
3
+ * @param coord Latitude or longitude coordinate
4
+ *
5
+ * @returns Coordinate in degrees, minutes & seconds
6
+ */
7
+ export const toDMS = (coord) => {
8
+ const absolute = Math.abs(coord);
9
+ const degrees = Math.floor(absolute);
10
+ const minutesNotTruncated = (absolute - degrees) * 60;
11
+ const minutes = Math.floor(minutesNotTruncated);
12
+ const seconds = Math.floor((minutesNotTruncated - minutes) * 60);
13
+ return { degrees, minutes, seconds };
14
+ };
15
+ // Converts numeric degrees to radians
16
+ export const toRad = (val) => (val * Math.PI) / 180;
17
+ /**
18
+ * Returns the distance between two LatLong's in kilometers
19
+ * @param pos1 [lat, long] coordinates
20
+ * @param pos2 [lat, long] coordinates
21
+ */
22
+ export const getDistance = (pos1, pos2) => {
23
+ const [lat1, lon1] = pos1;
24
+ const [lat2, lon2] = pos2;
25
+ const R = 6371; // km
26
+ const dLat = toRad(lat2 - lat1);
27
+ const dLon = toRad(lon2 - lon1);
28
+ const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(toRad(lat1)) * Math.cos(toRad(lat2));
29
+ const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
30
+ return R * c;
31
+ };
32
+ //# sourceMappingURL=geo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"geo.js","sourceRoot":"","sources":["../src/geo.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,KAAa,EAAyD,EAAE;IAC7F,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACjC,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IACrC,MAAM,mBAAmB,GAAG,CAAC,QAAQ,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IACtD,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC;IAChD,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,mBAAmB,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IACjE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;AACtC,CAAC,CAAC;AAEF,sCAAsC;AACtC,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,GAAW,EAAU,EAAE,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC;AAEpE;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,IAAsB,EAAE,IAAsB,EAAU,EAAE;IACrF,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,IAAI,CAAC;IAC1B,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,IAAI,CAAC;IAC1B,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,KAAK;IACrB,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC;IAChC,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC;IAChC,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;IAC5I,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACzD,OAAO,CAAC,GAAG,CAAC,CAAC;AACd,CAAC,CAAC"}
@@ -0,0 +1,9 @@
1
+ export * from "./conv.js";
2
+ export * from "./geo.js";
3
+ export * from "./logic.js";
4
+ export * from "./math.js";
5
+ export * from "./object.js";
6
+ export * from "./react.js";
7
+ export * from "./test.js";
8
+ export * from "./ts.js";
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC"}
@@ -1,8 +1,9 @@
1
- export * from "./conv.js";
2
- export * from "./geo.js";
3
- export * from "./logic.js";
4
- export * from "./math.js";
5
- export * from "./object.js";
6
- export * from "./react.js";
7
- export * from "./test.js";
8
- export * from "./ts.js";
1
+ export * from "./conv.js";
2
+ export * from "./geo.js";
3
+ export * from "./logic.js";
4
+ export * from "./math.js";
5
+ export * from "./object.js";
6
+ export * from "./react.js";
7
+ export * from "./test.js";
8
+ export * from "./ts.js";
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC"}
@@ -0,0 +1,23 @@
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logic.d.ts","sourceRoot":"","sources":["../src/logic.ts"],"names":[],"mappings":";AACA,eAAO,MAAM,KAAK,6CAAwB,CAAC;AAE3C,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;AAED,eAAO,MAAM,KAAK;qBAEW,OAAO,cAAc,MAAM,KAAK,IAAI;;;kCAoBhE,CAAC"}
package/dist/logic.js ADDED
@@ -0,0 +1,50 @@
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
@@ -0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,CAAC;gBACb,IAAI,iBAAiB,GAAG,CAAC;oBAAE,MAAM,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,iBAAiB,CAAC,CAAC;gBAC1E,OAAO,QAAQ,EAAE,CAAC;aAClB;YACD,MAAM,CAAC,CAAC;SACR;IACF,CAAC,CAAC;IACF,OAAO,QAAQ,CAAC;AACjB,CAAC,CAAC"}
package/dist/math.d.ts ADDED
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Calculates the difference between two angles (0°-360°), `angle1` & `angle2` returned result is in decimal degrees and is signed.
3
+ * @param angle1 First angle to compare
4
+ * @param angle2 Second angle to compare
5
+ * @param signed If the result is signed or absolute
6
+ * @returns The difference in degrees
7
+ */
8
+ export declare const angleDifference: (angle1: number, angle2: number, signed?: boolean) => number;
9
+ /**
10
+ * Converts `angle` to 0°-360°
11
+ * @param angle
12
+ * @returns `angle` in 0-360°
13
+ */
14
+ export declare const to360: (angle: number) => number;
15
+ /**
16
+ * Rounds a number to `digits` decimal places.
17
+ * @param num Number to round
18
+ * @param digits Decimal places to round to
19
+ * @returns Rounded number
20
+ */
21
+ export declare const qRnd: (num: number, digits?: number) => number;
22
+ /**
23
+ * Pad a number with 0's
24
+ * @param num Number to pad.
25
+ * @param zeros Number of digits returned number should have.
26
+ *
27
+ * @returns Padded number
28
+ * @example
29
+ * let paddedNumber = nPad(5)
30
+ * // paddedNumber = "05"
31
+ * let triplePaddedNumber = nPad(6, 3)
32
+ * // triplePaddedNumber = "006"
33
+ */
34
+ export declare const nPad: (num: number | string, zeros?: number) => string;
35
+ //# sourceMappingURL=math.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"math.d.ts","sourceRoot":"","sources":["../src/math.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,WAAY,MAAM,UAAU,MAAM,uBAAkB,MAO/E,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,KAAK,UAAW,MAAM,KAAG,MAGrC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,IAAI,QAAS,MAAM,sBAAe,MAG9C,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,IAAI,QAAS,MAAM,GAAG,MAAM,qBAAc,MAItD,CAAC"}
@@ -5,36 +5,33 @@
5
5
  * @param signed If the result is signed or absolute
6
6
  * @returns The difference in degrees
7
7
  */
8
- export const angleDifference = (angle1: number, angle2: number, signed = true): number => {
9
- let difference = Math.abs(angle1 - angle2) % 360;
10
- difference = difference > 180 ? 360 - difference : difference;
11
-
12
- // Calculate sign
13
- if (signed) return (angle1 - angle2 >= 0 && angle1 - angle2 <= 180) || (angle1 - angle2 <= -180 && angle1 - angle2 >= -360) ? difference : difference * -1;
14
- return difference;
8
+ export const angleDifference = (angle1, angle2, signed = true) => {
9
+ let difference = Math.abs(angle1 - angle2) % 360;
10
+ difference = difference > 180 ? 360 - difference : difference;
11
+ // Calculate sign
12
+ if (signed)
13
+ return (angle1 - angle2 >= 0 && angle1 - angle2 <= 180) || (angle1 - angle2 <= -180 && angle1 - angle2 >= -360) ? difference : difference * -1;
14
+ return difference;
15
15
  };
16
-
17
16
  /**
18
17
  * Converts `angle` to 0°-360°
19
18
  * @param angle
20
19
  * @returns `angle` in 0-360°
21
20
  */
22
- export const to360 = (angle: number): number => {
23
- angle = angle % 360;
24
- return angle < 0 ? angle + 360 : angle;
21
+ export const to360 = (angle) => {
22
+ angle = angle % 360;
23
+ return angle < 0 ? angle + 360 : angle;
25
24
  };
26
-
27
25
  /**
28
26
  * Rounds a number to `digits` decimal places.
29
27
  * @param num Number to round
30
28
  * @param digits Decimal places to round to
31
29
  * @returns Rounded number
32
30
  */
33
- export const qRnd = (num: number, digits = 0): number => {
34
- digits = 10 ** digits;
35
- return ~~(num * digits) / digits;
31
+ export const qRnd = (num, digits = 0) => {
32
+ digits = 10 ** digits;
33
+ return ~~(num * digits) / digits;
36
34
  };
37
-
38
35
  /**
39
36
  * Pad a number with 0's
40
37
  * @param num Number to pad.
@@ -47,8 +44,10 @@ export const qRnd = (num: number, digits = 0): number => {
47
44
  * let triplePaddedNumber = nPad(6, 3)
48
45
  * // triplePaddedNumber = "006"
49
46
  */
50
- export const nPad = (num: number | string, zeros = 2): string => {
51
- num = num.toString();
52
- while (num.length < zeros) num = "0" + num;
53
- return num;
47
+ export const nPad = (num, zeros = 2) => {
48
+ num = num.toString();
49
+ while (num.length < zeros)
50
+ num = "0" + num;
51
+ return num;
54
52
  };
53
+ //# sourceMappingURL=math.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"math.js","sourceRoot":"","sources":["../src/math.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,MAAc,EAAE,MAAc,EAAE,MAAM,GAAG,IAAI,EAAU,EAAE;IACxF,IAAI,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,GAAG,GAAG,CAAC;IACjD,UAAU,GAAG,UAAU,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC;IAE9D,iBAAiB;IACjB,IAAI,MAAM;QAAE,OAAO,CAAC,MAAM,GAAG,MAAM,IAAI,CAAC,IAAI,MAAM,GAAG,MAAM,IAAI,GAAG,CAAC,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,CAAC,GAAG,IAAI,MAAM,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC;IAC3J,OAAO,UAAU,CAAC;AACnB,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,KAAa,EAAU,EAAE;IAC9C,KAAK,GAAG,KAAK,GAAG,GAAG,CAAC;IACpB,OAAO,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC;AACxC,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,GAAW,EAAE,MAAM,GAAG,CAAC,EAAU,EAAE;IACvD,MAAM,GAAG,EAAE,IAAI,MAAM,CAAC;IACtB,OAAO,CAAC,CAAC,CAAC,GAAG,GAAG,MAAM,CAAC,GAAG,MAAM,CAAC;AAClC,CAAC,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,GAAoB,EAAE,KAAK,GAAG,CAAC,EAAU,EAAE;IAC/D,GAAG,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAC;IACrB,OAAO,GAAG,CAAC,MAAM,GAAG,KAAK;QAAE,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;IAC3C,OAAO,GAAG,CAAC;AACZ,CAAC,CAAC"}
@@ -0,0 +1,166 @@
1
+ import { UnknownRecord } from "./ts.js";
2
+ export declare const isDuplicate: (key: unknown) => boolean;
3
+ /**
4
+ * Simple object check.
5
+ * @param item
6
+ * @returns {boolean}
7
+ */
8
+ export declare const isObject: (item: unknown) => item is UnknownRecord;
9
+ /**
10
+ * Deep merge objects into target. Without modifying target.
11
+ * @param target
12
+ * @param source
13
+ */
14
+ export declare const deepMerge: <T extends S, S extends UnknownRecord = Partial<T>>(target: T, source: S) => T & S;
15
+ export declare type Types = {
16
+ [key: string]: string | string[] | Types | Types[];
17
+ };
18
+ export declare type TypeCompareResult = boolean | {
19
+ expectedType: string;
20
+ received: string;
21
+ location: string;
22
+ };
23
+ /**
24
+ * Take in a target `object` and a `types` object with identical keys but values as array of types those keys should be.
25
+ * @param target Object
26
+ * @param types Object identical to `target` but values are types
27
+ * @returns `object` if the types dont match. `True` if they do.
28
+ */
29
+ export declare const deepTypeCompare: (target: UnknownRecord, types: Types, location?: string) => TypeCompareResult;
30
+ /**
31
+ * Helper function for `deepTypeCompare` to compare a item to a type or set of types.
32
+ * @param expectedTypes Expected type/types
33
+ * @param receivedValue Object given
34
+ * @param location Location of `got` given
35
+ */
36
+ export declare const compareTwo: (expectedTypes: string | string[], receivedValue: unknown, location: string) => TypeCompareResult;
37
+ /**
38
+ * Returns the type of `item` respecting `Array`, `null` and `undefined` unlike typeof.
39
+ * @param item
40
+ * @returns Type of item
41
+ */
42
+ export declare const type: (item: unknown) => string;
43
+ /**
44
+ * Breaks `array` into smaller chunks based on `chunkSize`
45
+ * @param array Array to break up.
46
+ * @param chunkSize Maximum size of array chunks.
47
+ *
48
+ * @returns Array containing array chunks.
49
+ */
50
+ export declare const chunkArray: <T extends string | unknown[]>(array: T, chunkSize: number) => T[];
51
+ /**
52
+ * stringifies and then parses a object to convert it to a JSON supported object.
53
+ * @param obj Object to convert.
54
+ * @example
55
+ * const obj = {
56
+ * a: 1,
57
+ * b: [2, 7]
58
+ * }
59
+ * const a = objectify(obj)
60
+ * const b = JSON.parse(JSON.stringify(obj))
61
+ * console.log(a == b) -> true
62
+ */
63
+ export declare const objectify: (obj: UnknownRecord) => UnknownRecord;
64
+ /**
65
+ * Logs a inspected object to console
66
+ * @param obj Object to inspect
67
+ * @param options.showHidden Show hidden properties of object
68
+ * @param options.depth Depth to inspect object
69
+ * @param options.color Color resulting output
70
+ */
71
+ export declare const lObj: (obj: unknown, showHidden?: boolean | undefined, depth?: number | undefined, color?: boolean | undefined) => void;
72
+ /**
73
+ * Inspects a object
74
+ * @param obj Object to inspect
75
+ * @param options.showHidden Show hidden properties of object
76
+ * @param options.depth Depth to inspect object
77
+ * @param options.color Color resulting output
78
+ */
79
+ export declare const iObj: (obj: unknown, showHidden?: boolean | undefined, depth?: number | undefined, color?: boolean | undefined) => string;
80
+ /**
81
+ * Single line inspect object.
82
+ * @param obj Object to inspect
83
+ * @param options.showHidden Show hidden properties of object
84
+ * @param options.depth Depth to inspect object
85
+ * @param options.color Color resulting output
86
+ */
87
+ export declare const sliObj: (obj: unknown, showHidden?: boolean | undefined, depth?: number | undefined, color?: boolean | undefined) => string;
88
+ declare type AsyncFunction = (...args: unknown[]) => Promise<unknown>;
89
+ declare type ErrorHandler = (err: Error) => Promise<void>;
90
+ /**
91
+ * Recursively runs `func` and handles errors with `errorHandler` until `func` successfully finishes.
92
+ * @param func Function to execute
93
+ * @param errorHandler Function to execute when a error occours
94
+ * @returns Return value of `func` on success
95
+ */
96
+ export declare const loopError: <F extends AsyncFunction>(func: F, errorHandler?: ErrorHandler) => ReturnType<F>;
97
+ /**
98
+ * @param array
99
+ * @returns string containing ranges of numbers.
100
+ * @example
101
+ * const range = toRange([1, 2, 3, 12, 6,7, 5, 27, 28, 29, 40, 41, 25, 42, 12])
102
+ * // range = "1-3 & 5-7 & 12 & 25 & 27-29 & 40-42"
103
+ */
104
+ export declare const toRange: (array: number[]) => string;
105
+ /**
106
+ * Returns the `property` requested from `obj`
107
+ * @param obj
108
+ * @param property
109
+ * @param delimiter
110
+ * @example
111
+ * const object = {
112
+ * a: {
113
+ * child: "Hello World"
114
+ * }
115
+ * }
116
+ * const wantedProperty = "a.child"
117
+ * console.log(deepGet(object, wantedProperty)) // -> "Hello World"
118
+ */
119
+ export declare const deepGet: <T = unknown>(obj: UnknownRecord, property: string, delimiter?: string) => T | undefined;
120
+ /**
121
+ * Replaces values in a given `templatestring` with contentKeys from a given `contentKeys` object.
122
+ * @param contentKeys Object containing key value pairs of contentKeys to fill template string with
123
+ * @param templatestring string containing templates to fill
124
+ * @example
125
+ * const contentKeys = {
126
+ * "title": "This is a title",
127
+ * "info": {
128
+ * "desc": "This is some info!"
129
+ * }
130
+ * }
131
+ * const template = "Wow! {title}... Here is some info: {info.desc}"
132
+ *
133
+ * fillTemplate(contentKeys, template) // => Wow! This is a title... Here is some info: This is some info!"
134
+ */
135
+ export declare const fillTemplate: (contentKeys: UnknownRecord, templatestring: string, parent?: string) => string;
136
+ declare type EnvDict = {
137
+ [key: string]: string | EnvDict;
138
+ };
139
+ /**
140
+ * Converts process.env variables into a object
141
+ * @example process.env["some_subproperty"] = "hello"
142
+ * returns { some: { subProperty: "hello" } }
143
+ */
144
+ export declare const getEnv: () => EnvDict;
145
+ declare type RecursiveUpdateOptions = {
146
+ setUndefined?: boolean;
147
+ setDefined?: boolean;
148
+ };
149
+ /**
150
+ * Recursively update properties of a object with another.
151
+ * @param targetObject Object to update.
152
+ * @param newObject Object with new values to write to `targetObject`.
153
+ * @param options.setUndefined Defaults to `true` Set properties that are undefined on `targetObject`.
154
+ * @param options.setDefined Defaults to `false`. Overwrite properties that are not undefined on `targetObject`.
155
+ */
156
+ export declare const recursiveUpdate: (targetObject: UnknownRecord, newObject: UnknownRecord, options?: RecursiveUpdateOptions) => void;
157
+ /**
158
+ * Set the types of a given `object` based on the types of an identical `types` object. Usful in conjunction with `getEnv` to convert a object only containing strings/objects to actual types.
159
+ */
160
+ export declare const rebuildTypes: (object: UnknownRecord, types: UnknownRecord) => void;
161
+ /**
162
+ * Fetch process.env[envName] or throw if its undefined
163
+ */
164
+ export declare const envOrThrow: (envName: string) => string;
165
+ export {};
166
+ //# sourceMappingURL=object.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../src/object.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAMxC,eAAO,MAAM,WAAW,QAAS,OAAO,KAAG,OAI1C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,QAAQ,SAAU,OAAO,0BAAkG,CAAC;AAEzI;;;;GAIG;AACH,eAAO,MAAM,SAAS,oFAWrB,CAAC;AAEF,oBAAY,KAAK,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,KAAK,GAAG,KAAK,EAAE,CAAA;CAAE,CAAC;AAC3E,oBAAY,iBAAiB,GAAG,OAAO,GAAG;IAAE,YAAY,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,EA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