@inrixia/helpers 2.0.2 → 2.0.4

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 (63) hide show
  1. package/README.md +1 -0
  2. package/package.json +42 -13
  3. package/{conv.js → src/conv.ts} +15 -13
  4. package/src/geo.ts +33 -0
  5. package/{index.js → src/index.ts} +8 -10
  6. package/src/logic.ts +52 -0
  7. package/{math.js → src/math.ts} +20 -19
  8. package/src/object.ts +349 -0
  9. package/src/react.ts +11 -0
  10. package/src/test.ts +86 -0
  11. package/src/ts/math.ts +62 -0
  12. package/src/ts/numRange.ts +15 -0
  13. package/src/ts.ts +54 -0
  14. package/tsconfig.json +22 -0
  15. package/conv.d.ts +0 -28
  16. package/conv.d.ts.map +0 -1
  17. package/conv.js.map +0 -1
  18. package/elastic.d.ts +0 -54
  19. package/elastic.d.ts.map +0 -1
  20. package/elastic.js +0 -150
  21. package/elastic.js.map +0 -1
  22. package/geo.d.ts +0 -19
  23. package/geo.d.ts.map +0 -1
  24. package/geo.js +0 -32
  25. package/geo.js.map +0 -1
  26. package/index.d.ts +0 -10
  27. package/index.d.ts.map +0 -1
  28. package/index.js.map +0 -1
  29. package/logic.d.ts +0 -23
  30. package/logic.d.ts.map +0 -1
  31. package/logic.js +0 -50
  32. package/logic.js.map +0 -1
  33. package/math.d.ts +0 -35
  34. package/math.d.ts.map +0 -1
  35. package/math.js.map +0 -1
  36. package/object.d.ts +0 -169
  37. package/object.d.ts.map +0 -1
  38. package/object.js +0 -349
  39. package/object.js.map +0 -1
  40. package/react.d.ts +0 -2
  41. package/react.d.ts.map +0 -1
  42. package/react.js +0 -14
  43. package/react.js.map +0 -1
  44. package/test/matchers.d.ts +0 -15
  45. package/test/matchers.d.ts.map +0 -1
  46. package/test/matchers.js +0 -69
  47. package/test/matchers.js.map +0 -1
  48. package/test.d.ts +0 -14
  49. package/test.d.ts.map +0 -1
  50. package/test.js +0 -2
  51. package/test.js.map +0 -1
  52. package/ts/math.d.ts +0 -12
  53. package/ts/math.d.ts.map +0 -1
  54. package/ts/math.js +0 -2
  55. package/ts/math.js.map +0 -1
  56. package/ts/numRange.d.ts +0 -12
  57. package/ts/numRange.d.ts.map +0 -1
  58. package/ts/numRange.js +0 -2
  59. package/ts/numRange.js.map +0 -1
  60. package/ts.d.ts +0 -29
  61. package/ts.d.ts.map +0 -1
  62. package/ts.js +0 -6
  63. package/ts.js.map +0 -1
package/logic.js DELETED
@@ -1,50 +0,0 @@
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
package/logic.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"logic.js","sourceRoot":"","sources":["../src/logic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AACjC,MAAM,C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,EAAE,CAAC;aAClB;YACD,MAAM,CAAC,CAAC;SACR;IACF,CAAC,CAAC;IACF,OAAO,QAAQ,CAAC;AACjB,CAAC,CAAC"}
package/math.d.ts DELETED
@@ -1,35 +0,0 @@
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
package/math.d.ts.map DELETED
@@ -1 +0,0 @@
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,CA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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"}
package/object.d.ts DELETED
@@ -1,169 +0,0 @@
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
- declare type ContentTemplate = {
121
- [key: string]: string | ContentTemplate;
122
- };
123
- /**
124
- * Replaces values in a given `templatestring` with contentKeys from a given `contentKeys` object.
125
- * @param contentKeys Object containing key value pairs of contentKeys to fill template string with
126
- * @param templatestring string containing templates to fill
127
- * @example
128
- * const contentKeys = {
129
- * "title": "This is a title",
130
- * "info": {
131
- * "desc": "This is some info!"
132
- * }
133
- * }
134
- * const template = "Wow! {title}... Here is some info: {info.desc}"
135
- *
136
- * fillTemplate(contentKeys, template) // => Wow! This is a title... Here is some info: This is some info!"
137
- */
138
- export declare const fillTemplate: (contentKeys: ContentTemplate, templatestring: string, parent?: string) => string;
139
- declare type EnvDict = {
140
- [key: string]: string | EnvDict;
141
- };
142
- /**
143
- * Converts process.env variables into a object
144
- * @example process.env["some_subproperty"] = "hello"
145
- * returns { some: { subProperty: "hello" } }
146
- */
147
- export declare const getEnv: () => EnvDict;
148
- declare type RecursiveUpdateOptions = {
149
- setUndefined?: boolean;
150
- setDefined?: boolean;
151
- };
152
- /**
153
- * Recursively update properties of a object with another.
154
- * @param targetObject Object to update.
155
- * @param newObject Object with new values to write to `targetObject`.
156
- * @param options.setUndefined Defaults to `true` Set properties that are undefined on `targetObject`.
157
- * @param options.setDefined Defaults to `false`. Overwrite properties that are not undefined on `targetObject`.
158
- */
159
- export declare const recursiveUpdate: (targetObject: UnknownRecord, newObject: UnknownRecord, options?: RecursiveUpdateOptions) => void;
160
- /**
161
- * 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.
162
- */
163
- export declare const rebuildTypes: (object: UnknownRecord, types: UnknownRecord) => void;
164
- /**
165
- * Fetch process.env[envName] or throw if its undefined
166
- */
167
- export declare const envOrThrow: (envName: string) => string;
168
- export {};
169
- //# sourceMappingURL=object.d.ts.map
package/object.d.ts.map DELETED
@@ -1 +0,0 @@
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,EAAE,MAAM,CAAA;CAAE,CAAC;AAEvG;;;;;GAKG;AACH,eAAO,MAAM,eAAe,WAAY,aAAa,SAAS,KAAK,wBAAwB,iBA0B1F,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,kBAAmB,MAAM,GAAG,MAAM,EAAE,iBAAiB,OAAO,YAAY,MAAM,KAAG,iBAOvG,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,IAAI,SAAU,OAAO,KAAG,MAKpC,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,sDAAuD,MAAM,QAMnF,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,SAAS,QAAS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C;AAEF;;GAEG;AACH,eAAO,MAAM,YAAY,WAAY,aAAa,SAAS,aAAa,KAAG,IAkB1E,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,UAAU,YAAa,MAAM,KAAG,MAI5C,CAAC"}
package/object.js DELETED
@@ -1,349 +0,0 @@
1
- import util from "util";
2
- /**
3
- * Checks if `key` has been seen before.
4
- */
5
- const hash = new Map();
6
- export const isDuplicate = (key) => {
7
- if (!hash.has(key))
8
- hash.set(key, true);
9
- else
10
- return true;
11
- return false;
12
- };
13
- /**
14
- * Simple object check.
15
- * @param item
16
- * @returns {boolean}
17
- */
18
- export const isObject = (item) => item !== undefined && typeof item === "object" && !Array.isArray(item);
19
- /**
20
- * Deep merge objects into target. Without modifying target.
21
- * @param target
22
- * @param source
23
- */
24
- export const deepMerge = (target, source) => {
25
- const output = Object.assign({}, target);
26
- if (isObject(target) && isObject(source)) {
27
- Object.keys(source).forEach((key) => {
28
- if (isObject(source[key])) {
29
- if (!(key in target))
30
- Object.assign(output, { [key]: source[key] });
31
- else
32
- output[key] = deepMerge(target[key], source[key]);
33
- }
34
- else
35
- Object.assign(output, { [key]: source[key] });
36
- });
37
- }
38
- return output;
39
- };
40
- /**
41
- * Take in a target `object` and a `types` object with identical keys but values as array of types those keys should be.
42
- * @param target Object
43
- * @param types Object identical to `target` but values are types
44
- * @returns `object` if the types dont match. `True` if they do.
45
- */
46
- export const deepTypeCompare = (target, types, location = "target") => {
47
- if (!(isObject(target) && isObject(types)))
48
- return { location, expectedType: "object", received: `${target}:${type(target)}` };
49
- for (const key in target) {
50
- const targetValue = target[key];
51
- if (isObject(targetValue)) {
52
- // If target.property is a object then check its child properties
53
- const same = deepTypeCompare(targetValue, types[key], `${location}.${key}`);
54
- if (same !== true)
55
- return same;
56
- }
57
- else {
58
- if (Array.isArray(targetValue) && Array.isArray(types[key])) {
59
- // target.property and types.property are arrays
60
- // Check each item in target.property against types.property[0]
61
- const childCheckType = types[key];
62
- for (const targetItem of targetValue) {
63
- const targetType = type(targetItem);
64
- // If the array entry is a object then check it
65
- if (targetType === "object")
66
- return deepTypeCompare(targetItem, childCheckType, `${location}.${key}`);
67
- else
68
- return compareTwo(childCheckType, targetItem, `${location}.${key}`);
69
- }
70
- }
71
- else {
72
- const same = compareTwo(types[key], target[key], `${location}.${key}`);
73
- if (same !== true)
74
- return same;
75
- }
76
- }
77
- }
78
- return true;
79
- };
80
- /**
81
- * Helper function for `deepTypeCompare` to compare a item to a type or set of types.
82
- * @param expectedTypes Expected type/types
83
- * @param receivedValue Object given
84
- * @param location Location of `got` given
85
- */
86
- export const compareTwo = (expectedTypes, receivedValue, location) => {
87
- if (!Array.isArray(expectedTypes))
88
- expectedTypes = [expectedTypes];
89
- const gotType = type(receivedValue);
90
- for (const expectedType of expectedTypes) {
91
- if (gotType !== expectedType)
92
- return { location, expectedType, received: `${receivedValue}:${gotType}` };
93
- }
94
- return true;
95
- };
96
- /**
97
- * Returns the type of `item` respecting `Array`, `null` and `undefined` unlike typeof.
98
- * @param item
99
- * @returns Type of item
100
- */
101
- export const type = (item) => {
102
- if (Array.isArray(item))
103
- return "array";
104
- if (item === null)
105
- return "null";
106
- if (item === undefined)
107
- return "undefined";
108
- return typeof item;
109
- };
110
- /**
111
- * Breaks `array` into smaller chunks based on `chunkSize`
112
- * @param array Array to break up.
113
- * @param chunkSize Maximum size of array chunks.
114
- *
115
- * @returns Array containing array chunks.
116
- */
117
- export const chunkArray = (array, chunkSize) => {
118
- if (array.length < chunkSize)
119
- return [array];
120
- let i, j;
121
- const returnArray = [];
122
- for (i = 0, j = array.length; i < j; i += chunkSize)
123
- returnArray.push(array.slice(i, i + chunkSize));
124
- return returnArray;
125
- };
126
- /**
127
- * stringifies and then parses a object to convert it to a JSON supported object.
128
- * @param obj Object to convert.
129
- * @example
130
- * const obj = {
131
- * a: 1,
132
- * b: [2, 7]
133
- * }
134
- * const a = objectify(obj)
135
- * const b = JSON.parse(JSON.stringify(obj))
136
- * console.log(a == b) -> true
137
- */
138
- export const objectify = (obj) => JSON.parse(JSON.stringify(obj));
139
- /**
140
- * Logs a inspected object to console
141
- * @param obj Object to inspect
142
- * @param options.showHidden Show hidden properties of object
143
- * @param options.depth Depth to inspect object
144
- * @param options.color Color resulting output
145
- */
146
- export const lObj = (obj, ...options) => console.log(iObj(obj, ...options));
147
- /**
148
- * Inspects a object
149
- * @param obj Object to inspect
150
- * @param options.showHidden Show hidden properties of object
151
- * @param options.depth Depth to inspect object
152
- * @param options.color Color resulting output
153
- */
154
- export const iObj = (obj, ...options) => {
155
- if (options[0] === undefined || options[0] === null)
156
- options[0] = false;
157
- if (options[1] === undefined || options[1] === null)
158
- options[1] = 5;
159
- if (options[2] === undefined || options[2] === null)
160
- options[2] = true;
161
- return util.inspect(obj, ...options);
162
- };
163
- /**
164
- * Single line inspect object.
165
- * @param obj Object to inspect
166
- * @param options.showHidden Show hidden properties of object
167
- * @param options.depth Depth to inspect object
168
- * @param options.color Color resulting output
169
- */
170
- export const sliObj = (obj, ...options) => iObj(obj, ...options)
171
- .replace(/\r?\n/g, " ")
172
- .replace(/ +/g, " ");
173
- /**
174
- * Recursively runs `func` and handles errors with `errorHandler` until `func` successfully finishes.
175
- * @param func Function to execute
176
- * @param errorHandler Function to execute when a error occours
177
- * @returns Return value of `func` on success
178
- */
179
- export const loopError = (func, errorHandler = (err) => new Promise((_res, r) => r(err))) => new Promise((resolve) => {
180
- func()
181
- .then(resolve)
182
- .catch(async (err) => {
183
- errorHandler(err).then(() => resolve(loopError(func, errorHandler)));
184
- });
185
- });
186
- /**
187
- * @param array
188
- * @returns string containing ranges of numbers.
189
- * @example
190
- * const range = toRange([1, 2, 3, 12, 6,7, 5, 27, 28, 29, 40, 41, 25, 42, 12])
191
- * // range = "1-3 & 5-7 & 12 & 25 & 27-29 & 40-42"
192
- */
193
- export const toRange = (array) => {
194
- array = array
195
- .filter((a, pos) => array.indexOf(a) === pos)
196
- .sort((a, b) => a - b)
197
- .map((a) => +a);
198
- let sum = `${array[0]}`;
199
- let lastValue = array[0];
200
- for (let i = 1; i <= array.length; i++) {
201
- if (!(array[i] - 1 === array[i - 1])) {
202
- if (array[i - 1] !== lastValue)
203
- sum += `-${array[i - 1]}`;
204
- if (array[i] !== undefined)
205
- sum += ` & ${array[i]}`;
206
- lastValue = array[i];
207
- }
208
- }
209
- return sum;
210
- };
211
- /**
212
- * Returns the `property` requested from `obj`
213
- * @param obj
214
- * @param property
215
- * @param delimiter
216
- * @example
217
- * const object = {
218
- * a: {
219
- * child: "Hello World"
220
- * }
221
- * }
222
- * const wantedProperty = "a.child"
223
- * console.log(deepGet(object, wantedProperty)) // -> "Hello World"
224
- */
225
- export const deepGet = (obj, property, delimiter = ".") => {
226
- const arr = property.split(delimiter);
227
- while (arr.length && (obj = obj[arr.shift()]))
228
- ;
229
- return obj;
230
- };
231
- /**
232
- * Replaces values in a given `templatestring` with contentKeys from a given `contentKeys` object.
233
- * @param contentKeys Object containing key value pairs of contentKeys to fill template string with
234
- * @param templatestring string containing templates to fill
235
- * @example
236
- * const contentKeys = {
237
- * "title": "This is a title",
238
- * "info": {
239
- * "desc": "This is some info!"
240
- * }
241
- * }
242
- * const template = "Wow! {title}... Here is some info: {info.desc}"
243
- *
244
- * fillTemplate(contentKeys, template) // => Wow! This is a title... Here is some info: This is some info!"
245
- */
246
- export const fillTemplate = (contentKeys, templatestring, parent = "") => {
247
- for (const key in contentKeys) {
248
- if (isObject(contentKeys[key]))
249
- templatestring = fillTemplate(contentKeys[key], templatestring, `${parent}${key}.`);
250
- else
251
- templatestring = templatestring.replace(new RegExp(`{${parent}${key}}`, "g"), contentKeys[key]);
252
- }
253
- return templatestring;
254
- };
255
- /**
256
- * Converts process.env variables into a object
257
- * @example process.env["some_subproperty"] = "hello"
258
- * returns { some: { subProperty: "hello" } }
259
- */
260
- export const getEnv = () => {
261
- // Define our return object env variables are applied to.
262
- const envObject = {};
263
- // Iterate over env keys
264
- for (const envKey in process.env) {
265
- // Set our reference object to be equal to the envObject to begin with.
266
- let objRef = envObject;
267
- // Reference to parent object to allow reassigning values that should be objects.
268
- let pObjRef = undefined;
269
- // Break apart the envKey into its keys. Ex some_subProperty = ["some", "subProperty"]
270
- // This regex handles cases where _ is in the key, it only matches the first _ per key allowing for keys with one or more _ in them
271
- const keys = envKey.split(/(?<=[^__])_/g);
272
- // For every key except the last...
273
- for (let i = 0; i < keys.length - 1; i++) {
274
- // Set the key on the objRef to a empty object if its undefined.
275
- if (!isObject(objRef)) {
276
- // If objRef is not a object. Use the parent object to set it to a object containing itself as _.
277
- if (pObjRef !== undefined)
278
- objRef = pObjRef[0][pObjRef[1]] = { _: objRef };
279
- pObjRef = [objRef, keys[i]];
280
- }
281
- else {
282
- pObjRef = [objRef, keys[i]];
283
- objRef = (objRef[keys[i]] ??= {});
284
- }
285
- }
286
- // Set the last key to equal the original value
287
- // If objRef is not a object. Use the parent object to set it to a object containing itself as _.
288
- if (!isObject(objRef) && pObjRef !== undefined)
289
- objRef = pObjRef[0][pObjRef[1]] = { _: objRef };
290
- const envValue = process.env[envKey];
291
- if (envValue !== undefined)
292
- objRef[keys[keys.length - 1]] = envValue;
293
- }
294
- return envObject;
295
- };
296
- /**
297
- * Recursively update properties of a object with another.
298
- * @param targetObject Object to update.
299
- * @param newObject Object with new values to write to `targetObject`.
300
- * @param options.setUndefined Defaults to `true` Set properties that are undefined on `targetObject`.
301
- * @param options.setDefined Defaults to `false`. Overwrite properties that are not undefined on `targetObject`.
302
- */
303
- export const recursiveUpdate = (targetObject, newObject, options = { setUndefined: true, setDefined: false }) => {
304
- if (!isObject(targetObject))
305
- throw new Error("targetObject is not an object!");
306
- if (!isObject(newObject))
307
- throw new Error("newObject is not an object!");
308
- for (const key in newObject) {
309
- if (isObject(targetObject[key]) && isObject(newObject[key]))
310
- recursiveUpdate(targetObject[key], newObject[key], options);
311
- else if (options.setUndefined && targetObject[key] === undefined)
312
- targetObject[key] = newObject[key];
313
- else if (options.setDefined && targetObject[key] !== undefined)
314
- targetObject[key] = newObject[key];
315
- }
316
- };
317
- /**
318
- * 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.
319
- */
320
- export const rebuildTypes = (object, types) => {
321
- for (const key in object) {
322
- if (types[key] === undefined)
323
- continue;
324
- switch (typeof types[key]) {
325
- case "number":
326
- object[key] = +object[key];
327
- break;
328
- case "string":
329
- object[key] = String(object[key]);
330
- break;
331
- case "boolean":
332
- object[key] = object[key] === true || object[key] === "true";
333
- break;
334
- default:
335
- rebuildTypes(object[key], types[key]);
336
- break;
337
- }
338
- }
339
- };
340
- /**
341
- * Fetch process.env[envName] or throw if its undefined
342
- */
343
- export const envOrThrow = (envName) => {
344
- const envValue = process.env[envName];
345
- if (envValue === undefined)
346
- throw new Error(`Enviroment variable "${envName}" is undefined!`);
347
- return envValue;
348
- };
349
- //# sourceMappingURL=object.js.map
package/object.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"object.js","sourceRoot":"","sources":["../src/object.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAGxB;;GAEG;AACH,MAAM,IAAI,GAAG,IAAI,GAAG,EAAE,CAAC;AACvB,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,GAAY,EAAW,EAAE;IACpD,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;QAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;;QACnC,OAAO,IAAI,CAAC;IACjB,OAAO,KAAK,CAAC;AACd,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,IAAa,EAAyB,EAAE,CAAC,IAAI,KAAK,SAAS,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAEzI;;;;GAIG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAoD,MAAS,EAAE,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H,MAAM,CAAC,GAAG,CAAE,GAAG,CAAO,MAAM,CAAC,GAAG,CAAE,CAAC;gBAC5C,MAAM;YACP,KAAK,QAAQ;gBACH,MAAM,CAAC,GAAG,CAAE,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;gBAC5C,MAAM;YACP,KAAK,SAAS;gBACH,MAAM,CAAC,GAAG,CAAE,GAAG,MAAM,CAAC,GAAG,CAAC,KAAK,IAAI,IAAI,MAAM,CAAC,GAAG,CAAC,KAAK,MAAM,CAAC;gBACxE,MAAM;YACP;gBACC,YAAY,CAAgB,MAAM,CAAC,GAAG,CAAC,EAAiB,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;gBACpE,MAAM;SACP;KACD;AACF,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,OAAe,EAAU,EAAE;IACrD,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACtC,IAAI,QAAQ,KAAK,SAAS;QAAE,MAAM,IAAI,KAAK,CAAC,wBAAwB,OAAO,iBAAiB,CAAC,CAAC;IAC9F,OAAO,QAAQ,CAAC;AACjB,CAAC,CAAC"}
package/react.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export declare const toBase64: (file: File) => Promise<string | ArrayBuffer>;
2
- //# sourceMappingURL=react.d.ts.map
package/react.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../src/react.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,QAAQ,SAAgB,IAAI,KAAG,QAAQ,MAAM,GAAG,WAAW,CAUvE,CAAC"}
package/react.js DELETED
@@ -1,14 +0,0 @@
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
package/react.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"react.js","sourceRoot":"","sources":["../src/react.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"}