@sparted/shared-library 0.0.11 → 0.0.12

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 (71) hide show
  1. package/_virtual/_tslib.js +66 -0
  2. package/_virtual/_tslib.js.map +1 -0
  3. package/array/array-to-map.d.ts +14 -0
  4. package/array/array-to-map.js +19 -0
  5. package/array/array-to-map.js.map +1 -0
  6. package/array/get-values-from-keys.d.ts +1 -0
  7. package/array/get-values-from-keys.js +6 -0
  8. package/array/get-values-from-keys.js.map +1 -0
  9. package/array/index.d.ts +2 -0
  10. package/array/index.js +3 -0
  11. package/array/index.js.map +1 -0
  12. package/fp/index.d.ts +1 -0
  13. package/fp/index.js +2 -0
  14. package/fp/index.js.map +1 -0
  15. package/fp/run-while.d.ts +31 -0
  16. package/fp/run-while.js +26 -0
  17. package/fp/run-while.js.map +1 -0
  18. package/index.d.ts +7 -0
  19. package/index.js.map +1 -0
  20. package/package.json +3 -2
  21. package/parsing/index.d.ts +3 -0
  22. package/parsing/index.js +4 -0
  23. package/parsing/index.js.map +1 -0
  24. package/parsing/parse-boolean.d.ts +4 -0
  25. package/parsing/parse-boolean.js +12 -0
  26. package/parsing/parse-boolean.js.map +1 -0
  27. package/parsing/parse-enum.d.ts +5 -0
  28. package/parsing/parse-enum.js +13 -0
  29. package/parsing/parse-enum.js.map +1 -0
  30. package/parsing/parse-number.d.ts +4 -0
  31. package/parsing/parse-number.js +13 -0
  32. package/parsing/parse-number.js.map +1 -0
  33. package/predicates/index.d.ts +5 -0
  34. package/predicates/index.js +6 -0
  35. package/predicates/index.js.map +1 -0
  36. package/predicates/is-function.d.ts +1 -0
  37. package/predicates/is-function.js +6 -0
  38. package/predicates/is-function.js.map +1 -0
  39. package/predicates/is-null.d.ts +1 -0
  40. package/predicates/is-null.js +6 -0
  41. package/predicates/is-null.js.map +1 -0
  42. package/predicates/is-object.d.ts +1 -0
  43. package/predicates/is-object.js +6 -0
  44. package/predicates/is-object.js.map +1 -0
  45. package/predicates/is-primitive.d.ts +3 -0
  46. package/predicates/is-primitive.js +17 -0
  47. package/predicates/is-primitive.js.map +1 -0
  48. package/predicates/is-undefined.d.ts +1 -0
  49. package/predicates/is-undefined.js +6 -0
  50. package/predicates/is-undefined.js.map +1 -0
  51. package/promise/execute-or-resolve-default.d.ts +5 -0
  52. package/promise/execute-or-resolve-default.js +10 -0
  53. package/promise/execute-or-resolve-default.js.map +1 -0
  54. package/promise/execute-with-delay.d.ts +1 -0
  55. package/promise/execute-with-delay.js +17 -0
  56. package/promise/execute-with-delay.js.map +1 -0
  57. package/promise/index.d.ts +2 -0
  58. package/promise/index.js +3 -0
  59. package/promise/index.js.map +1 -0
  60. package/string/index.d.ts +1 -0
  61. package/string/index.js +2 -0
  62. package/string/index.js.map +1 -0
  63. package/string/replace-in-template.d.ts +14 -0
  64. package/string/replace-in-template.js +35 -0
  65. package/string/replace-in-template.js.map +1 -0
  66. package/types/function.d.ts +1 -0
  67. package/types/general.d.ts +2 -0
  68. package/types/index.d.ts +3 -0
  69. package/types/index.js +2 -0
  70. package/types/index.js.map +1 -0
  71. package/types/object.d.ts +22 -0
@@ -0,0 +1,66 @@
1
+ /******************************************************************************
2
+ Copyright (c) Microsoft Corporation.
3
+
4
+ Permission to use, copy, modify, and/or distribute this software for any
5
+ purpose with or without fee is hereby granted.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
9
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
11
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
12
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13
+ PERFORMANCE OF THIS SOFTWARE.
14
+ ***************************************************************************** */
15
+
16
+ var __assign = function() {
17
+ __assign = Object.assign || function __assign(t) {
18
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
19
+ s = arguments[i];
20
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
21
+ }
22
+ return t;
23
+ };
24
+ return __assign.apply(this, arguments);
25
+ };
26
+
27
+ function __awaiter(thisArg, _arguments, P, generator) {
28
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
29
+ return new (P || (P = Promise))(function (resolve, reject) {
30
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
31
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
32
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
33
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
34
+ });
35
+ }
36
+
37
+ function __generator(thisArg, body) {
38
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
39
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
40
+ function verb(n) { return function (v) { return step([n, v]); }; }
41
+ function step(op) {
42
+ if (f) throw new TypeError("Generator is already executing.");
43
+ while (_) try {
44
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
45
+ if (y = 0, t) op = [op[0] & 2, t.value];
46
+ switch (op[0]) {
47
+ case 0: case 1: t = op; break;
48
+ case 4: _.label++; return { value: op[1], done: false };
49
+ case 5: _.label++; y = op[1]; op = [0]; continue;
50
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
51
+ default:
52
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
53
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
54
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
55
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
56
+ if (t[2]) _.ops.pop();
57
+ _.trys.pop(); continue;
58
+ }
59
+ op = body.call(thisArg, _);
60
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
61
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
62
+ }
63
+ }
64
+
65
+ export { __assign, __awaiter, __generator };
66
+ //# sourceMappingURL=_tslib.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_tslib.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,14 @@
1
+ export declare type ArrayToMapOptions<InitialValue, ModifiedValue = InitialValue> = {
2
+ /**
3
+ * Function to return the key used in the map.
4
+ */
5
+ selectKey: (value: InitialValue) => string;
6
+ /**
7
+ * Transform the initial data into another value
8
+ */
9
+ dataModifier?: (value: InitialValue) => ModifiedValue;
10
+ };
11
+ /**
12
+ * Transform an array to a map.
13
+ */
14
+ export declare const arrayToMap: <InitialValue, ModifiedValue = InitialValue>(array: readonly InitialValue[], options: ArrayToMapOptions<InitialValue, ModifiedValue>) => Record<string, ModifiedValue>;
@@ -0,0 +1,19 @@
1
+ import { __assign } from '../_virtual/_tslib.js';
2
+
3
+ /**
4
+ * Transform an array to a map.
5
+ */
6
+ var arrayToMap = function (array, options) {
7
+ var selectKey = options.selectKey;
8
+ return array.reduce(function (acc, current) {
9
+ var _a;
10
+ var key = selectKey(current);
11
+ var value = options.dataModifier
12
+ ? options.dataModifier(current)
13
+ : current;
14
+ return __assign(__assign({}, acc), (_a = {}, _a[key] = value, _a));
15
+ }, {});
16
+ };
17
+
18
+ export { arrayToMap };
19
+ //# sourceMappingURL=array-to-map.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array-to-map.js","sources":["../../src/array/array-to-map.ts"],"sourcesContent":["export type ArrayToMapOptions<InitialValue, ModifiedValue = InitialValue> = {\n /**\n * Function to return the key used in the map.\n */\n selectKey: (value: InitialValue) => string,\n /**\n * Transform the initial data into another value\n */\n dataModifier?: (value: InitialValue) => ModifiedValue;\n};\n\n/**\n * Transform an array to a map.\n */\nexport const arrayToMap = <InitialValue, ModifiedValue = InitialValue>(\n array: ReadonlyArray<InitialValue>,\n options: ArrayToMapOptions<InitialValue, ModifiedValue>,\n) => {\n const { selectKey } = options;\n\n return array.reduce<Record<string, ModifiedValue>>((acc, current) => {\n const key = selectKey(current);\n const value = options.dataModifier\n ? options.dataModifier(current)\n : current;\n\n return {\n ...acc,\n [key]: value as ModifiedValue,\n };\n }, {});\n};\n"],"names":[],"mappings":";;AAWA;;AAEG;AACU,IAAA,UAAU,GAAG,UACxB,KAAkC,EAClC,OAAuD,EAAA;AAE/C,IAAA,IAAA,SAAS,GAAK,OAAO,CAAA,SAAZ,CAAa;AAE9B,IAAA,OAAO,KAAK,CAAC,MAAM,CAAgC,UAAC,GAAG,EAAE,OAAO,EAAA;;AAC9D,QAAA,IAAM,GAAG,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC;AAC/B,QAAA,IAAM,KAAK,GAAG,OAAO,CAAC,YAAY;AAChC,cAAE,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC;cAC7B,OAAO,CAAC;AAEZ,QAAA,OAAA,QAAA,CAAA,QAAA,CAAA,EAAA,EACK,GAAG,CAAA,GAAA,EAAA,GAAA,EAAA,EAAA,EAAA,CACL,GAAG,CAAA,GAAG,KAAsB,EAC7B,EAAA,EAAA,CAAA;KACH,EAAE,EAAE,CAAC,CAAC;AACT;;;;"}
@@ -0,0 +1 @@
1
+ export declare const valuesFromKeys: <T>(keys: string[], map: Record<string, T>) => T[];
@@ -0,0 +1,6 @@
1
+ var valuesFromKeys = function (keys, map) {
2
+ return keys.map(function (key) { return map[key]; });
3
+ };
4
+
5
+ export { valuesFromKeys };
6
+ //# sourceMappingURL=get-values-from-keys.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-values-from-keys.js","sources":["../../src/array/get-values-from-keys.ts"],"sourcesContent":["export const valuesFromKeys = <T>(keys: string[], map: Record<string, T>) => {\n return keys.map((key) => map[key]);\n};\n"],"names":[],"mappings":"AAAa,IAAA,cAAc,GAAG,UAAI,IAAc,EAAE,GAAsB,EAAA;AACtE,IAAA,OAAO,IAAI,CAAC,GAAG,CAAC,UAAC,GAAG,EAAA,EAAK,OAAA,GAAG,CAAC,GAAG,CAAC,CAAR,EAAQ,CAAC,CAAC;AACrC;;;;"}
@@ -0,0 +1,2 @@
1
+ export * from './array-to-map';
2
+ export * from './get-values-from-keys';
package/array/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { arrayToMap } from './array-to-map.js';
2
+ export { valuesFromKeys } from './get-values-from-keys.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
package/fp/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './run-while';
package/fp/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { runWhile } from './run-while.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,31 @@
1
+ export declare type RunWhileConfig<T> = {
2
+ /**
3
+ * Return a boolean to keep running the callback or not.
4
+ */
5
+ predicate: (current: T) => boolean;
6
+ /**
7
+ * The function to run while `predicate` returns `true`
8
+ */
9
+ callback: (current: T, iteractionCount: number) => T;
10
+ /**
11
+ * `callback` will not be run again if `iterationCount` exceeds this value.
12
+ * Default to `Infinity`
13
+ */
14
+ iterationLimit?: number;
15
+ /**
16
+ * The first value passed to the callback.
17
+ */
18
+ initialValue: T;
19
+ };
20
+ export declare type RunWhileFn = <T>(config: RunWhileConfig<T>) => {
21
+ /**
22
+ * The callback last result.
23
+ */
24
+ result: T;
25
+ iterationCount: number;
26
+ };
27
+ /**
28
+ * Run the callback while the predicate return true. Throws an
29
+ * error if the iteration count exceeds the iteration limit.
30
+ */
31
+ export declare const runWhile: RunWhileFn;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Run the callback while the predicate return true. Throws an
3
+ * error if the iteration count exceeds the iteration limit.
4
+ */
5
+ var runWhile = function (_a) {
6
+ var predicate = _a.predicate, callback = _a.callback, initialValue = _a.initialValue, _b = _a.iterationLimit, iterationLimit = _b === void 0 ? Infinity : _b;
7
+ var counter = 0;
8
+ var currentValue = initialValue;
9
+ var shouldRun = predicate(currentValue);
10
+ while (shouldRun) {
11
+ if (counter >= iterationLimit) {
12
+ throw new Error('Iteration limit reached');
13
+ }
14
+ var nextValue = callback(currentValue, counter);
15
+ counter += 1;
16
+ shouldRun = predicate(nextValue);
17
+ currentValue = nextValue;
18
+ }
19
+ return {
20
+ result: currentValue,
21
+ iterationCount: counter,
22
+ };
23
+ };
24
+
25
+ export { runWhile };
26
+ //# sourceMappingURL=run-while.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-while.js","sources":["../../src/fp/run-while.ts"],"sourcesContent":["export type RunWhileConfig<T> = {\n /**\n * Return a boolean to keep running the callback or not.\n */\n predicate: (current: T) => boolean,\n /**\n * The function to run while `predicate` returns `true`\n */\n callback: (current: T, iteractionCount: number) => T,\n /**\n * `callback` will not be run again if `iterationCount` exceeds this value.\n * Default to `Infinity`\n */\n iterationLimit?: number,\n /**\n * The first value passed to the callback.\n */\n initialValue: T,\n};\n\nexport type RunWhileFn = <T>(config: RunWhileConfig<T>) => {\n /**\n * The callback last result.\n */\n result: T,\n iterationCount: number,\n};\n\n/**\n * Run the callback while the predicate return true. Throws an\n * error if the iteration count exceeds the iteration limit.\n */\nexport const runWhile: RunWhileFn = ({ predicate, callback, initialValue, iterationLimit = Infinity }) => {\n let counter = 0;\n let currentValue = initialValue;\n let shouldRun = predicate(currentValue);\n\n while (shouldRun) {\n if (counter >= iterationLimit) {\n throw new Error('Iteration limit reached');\n }\n\n const nextValue = callback(currentValue, counter);\n\n counter += 1;\n shouldRun = predicate(nextValue);\n currentValue = nextValue;\n }\n\n return {\n result: currentValue,\n iterationCount: counter,\n };\n};\n"],"names":[],"mappings":"AA4BA;;;AAGG;AACI,IAAM,QAAQ,GAAe,UAAC,EAAgE,EAAA;AAA9D,IAAA,IAAA,SAAS,GAAA,EAAA,CAAA,SAAA,EAAE,QAAQ,GAAA,EAAA,CAAA,QAAA,EAAE,YAAY,GAAA,EAAA,CAAA,YAAA,EAAE,EAAyB,GAAA,EAAA,CAAA,cAAA,EAAzB,cAAc,GAAA,EAAA,KAAA,KAAA,CAAA,GAAG,QAAQ,GAAA,EAAA,CAAA;IACjG,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,IAAI,YAAY,GAAG,YAAY,CAAC;AAChC,IAAA,IAAI,SAAS,GAAG,SAAS,CAAC,YAAY,CAAC,CAAC;AAExC,IAAA,OAAO,SAAS,EAAE;QAChB,IAAI,OAAO,IAAI,cAAc,EAAE;AAC7B,YAAA,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;AAC5C,SAAA;QAED,IAAM,SAAS,GAAG,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;QAElD,OAAO,IAAI,CAAC,CAAC;AACb,QAAA,SAAS,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC;QACjC,YAAY,GAAG,SAAS,CAAC;AAC1B,KAAA;IAED,OAAO;AACL,QAAA,MAAM,EAAE,YAAY;AACpB,QAAA,cAAc,EAAE,OAAO;KACxB,CAAC;AACJ;;;;"}
package/index.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ export * from './array';
2
+ export * from './fp';
3
+ export * from './parsing';
4
+ export * from './predicates';
5
+ export * from './promise';
6
+ export * from './string';
7
+ export * from './types';
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sparted/shared-library",
3
- "version": "0.0.11",
3
+ "version": "0.0.12",
4
4
  "repository": "git@github.com:Sparted/shared-library.git",
5
5
  "author": "Thomas <duprethomasfr@gmail.com>",
6
6
  "license": "MIT",
@@ -8,7 +8,8 @@
8
8
  "main": "index.js",
9
9
  "module": "index.js",
10
10
  "files": [
11
- "."
11
+ "**/*",
12
+ "**/**"
12
13
  ],
13
14
  "scripts": {
14
15
  "test": "jest",
@@ -0,0 +1,3 @@
1
+ export * from './parse-boolean';
2
+ export * from './parse-enum';
3
+ export * from './parse-number';
@@ -0,0 +1,4 @@
1
+ export { parseBoolean } from './parse-boolean.js';
2
+ export { createEnumParser } from './parse-enum.js';
3
+ export { parseNumber } from './parse-number.js';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Parse a string to a boolean. Throw error if string is neither "true" nor "false"
3
+ */
4
+ export declare const parseBoolean: (value: string) => boolean;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Parse a string to a boolean. Throw error if string is neither "true" nor "false"
3
+ */
4
+ var parseBoolean = function (value) {
5
+ if (value !== 'true' && value !== 'false') {
6
+ throw new Error('Cannot parse value');
7
+ }
8
+ return value === 'true';
9
+ };
10
+
11
+ export { parseBoolean };
12
+ //# sourceMappingURL=parse-boolean.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-boolean.js","sources":["../../src/parsing/parse-boolean.ts"],"sourcesContent":["/**\n * Parse a string to a boolean. Throw error if string is neither \"true\" nor \"false\"\n */\n export const parseBoolean = (value: string): boolean => {\n if (value !== 'true' && value !== 'false') {\n throw new Error('Cannot parse value');\n }\n\n return value === 'true';\n};\n"],"names":[],"mappings":"AAAA;;AAEG;AACK,IAAM,YAAY,GAAG,UAAC,KAAa,EAAA;AACzC,IAAA,IAAI,KAAK,KAAK,MAAM,IAAI,KAAK,KAAK,OAAO,EAAE;AACzC,QAAA,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;AACvC,KAAA;IAED,OAAO,KAAK,KAAK,MAAM,CAAC;AAC1B;;;;"}
@@ -0,0 +1,5 @@
1
+ import type { Primitive } from '../types';
2
+ /**
3
+ * Factory to build enum to parse a string to an enum. Throw error if string is not an enum value
4
+ */
5
+ export declare const createEnumParser: <E extends Record<string, Primitive>>(enumType: E) => (value: string) => E;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Factory to build enum to parse a string to an enum. Throw error if string is not an enum value
3
+ */
4
+ var createEnumParser = function (enumType) { return (function (value) {
5
+ var enumValues = Object.values(enumType);
6
+ if (!enumValues.includes(value)) {
7
+ throw new Error('Can\'t parse this value');
8
+ }
9
+ return value;
10
+ }); };
11
+
12
+ export { createEnumParser };
13
+ //# sourceMappingURL=parse-enum.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-enum.js","sources":["../../src/parsing/parse-enum.ts"],"sourcesContent":["import type { Primitive } from '../types';\n\n/**\n * Factory to build enum to parse a string to an enum. Throw error if string is not an enum value\n */\n export const createEnumParser = <E extends Record<string, Primitive>>(enumType: E) => (\n (value: string) => {\n const enumValues = Object.values(enumType);\n\n if (!enumValues.includes(value as any)) {\n throw new Error('Can\\'t parse this value');\n }\n\n return value as unknown as E;\n }\n);"],"names":[],"mappings":"AAEA;;AAEG;AACW,IAAA,gBAAgB,GAAG,UAAsC,QAAW,EAAK,EAAA,QACrF,UAAC,KAAa,EAAA;IACZ,IAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AAE3C,IAAA,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,KAAY,CAAC,EAAE;AACtC,QAAA,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;AAC5C,KAAA;AAED,IAAA,OAAO,KAAqB,CAAC;AAC/B,CAAC,EAToF;;;;"}
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Parse a string to a number. Throw error if string is NaN
3
+ */
4
+ export declare const parseNumber: (value: string) => number;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Parse a string to a number. Throw error if string is NaN
3
+ */
4
+ var parseNumber = function (value) {
5
+ var number = parseInt(value, 10);
6
+ if (Number.isNaN(number)) {
7
+ throw new Error('Cannot parse value');
8
+ }
9
+ return number;
10
+ };
11
+
12
+ export { parseNumber };
13
+ //# sourceMappingURL=parse-number.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-number.js","sources":["../../src/parsing/parse-number.ts"],"sourcesContent":["/**\n * Parse a string to a number. Throw error if string is NaN\n */\n export const parseNumber = (value: string): number => {\n const number = parseInt(value, 10);\n\n if (Number.isNaN(number)) {\n throw new Error('Cannot parse value');\n }\n\n return number;\n};"],"names":[],"mappings":"AAAA;;AAEG;AACK,IAAM,WAAW,GAAG,UAAC,KAAa,EAAA;IACxC,IAAM,MAAM,GAAG,QAAQ,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AAEnC,IAAA,IAAI,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE;AACxB,QAAA,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;AACvC,KAAA;AAED,IAAA,OAAO,MAAM,CAAC;AAChB;;;;"}
@@ -0,0 +1,5 @@
1
+ export * from './is-function';
2
+ export * from './is-null';
3
+ export * from './is-object';
4
+ export * from './is-primitive';
5
+ export * from './is-undefined';
@@ -0,0 +1,6 @@
1
+ export { isFunction } from './is-function.js';
2
+ export { isNull } from './is-null.js';
3
+ export { isObject } from './is-object.js';
4
+ export { isArrayOfPrimitive, isPrimitive } from './is-primitive.js';
5
+ export { isUndefined } from './is-undefined.js';
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
@@ -0,0 +1 @@
1
+ export declare const isFunction: (value: any) => value is Function;
@@ -0,0 +1,6 @@
1
+ var isFunction = function (value) {
2
+ return typeof value === 'function';
3
+ };
4
+
5
+ export { isFunction };
6
+ //# sourceMappingURL=is-function.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-function.js","sources":["../../src/predicates/is-function.ts"],"sourcesContent":["export const isFunction = (value: any): value is Function => {\n return typeof value === 'function';\n};\n"],"names":[],"mappings":"AAAO,IAAM,UAAU,GAAG,UAAC,KAAU,EAAA;AACnC,IAAA,OAAO,OAAO,KAAK,KAAK,UAAU,CAAC;AACrC;;;;"}
@@ -0,0 +1 @@
1
+ export declare const isNull: (value: any) => value is null;
@@ -0,0 +1,6 @@
1
+ var isNull = function (value) {
2
+ return value === null;
3
+ };
4
+
5
+ export { isNull };
6
+ //# sourceMappingURL=is-null.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-null.js","sources":["../../src/predicates/is-null.ts"],"sourcesContent":["export const isNull = (value: any): value is null => {\n return value === null;\n};\n"],"names":[],"mappings":"AAAO,IAAM,MAAM,GAAG,UAAC,KAAU,EAAA;IAC/B,OAAO,KAAK,KAAK,IAAI,CAAC;AACxB;;;;"}
@@ -0,0 +1 @@
1
+ export declare const isObject: (value: any) => value is Object;
@@ -0,0 +1,6 @@
1
+ var isObject = function (value) {
2
+ return typeof value === 'object';
3
+ };
4
+
5
+ export { isObject };
6
+ //# sourceMappingURL=is-object.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-object.js","sources":["../../src/predicates/is-object.ts"],"sourcesContent":["export const isObject = (value: any): value is Object => {\n return typeof value === 'object';\n};\n"],"names":[],"mappings":"AAAO,IAAM,QAAQ,GAAG,UAAC,KAAU,EAAA;AACjC,IAAA,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC;AACnC;;;;"}
@@ -0,0 +1,3 @@
1
+ import { Primitive } from '../types/general';
2
+ export declare const isPrimitive: (value: any) => value is Primitive;
3
+ export declare const isArrayOfPrimitive: (value: any) => value is Primitive[];
@@ -0,0 +1,17 @@
1
+ var PRIMITIVE_TYPES = [
2
+ 'string',
3
+ 'boolean',
4
+ 'number',
5
+ ];
6
+ var isPrimitive = function (value) {
7
+ return PRIMITIVE_TYPES.includes(typeof value);
8
+ };
9
+ var isArrayOfPrimitive = function (value) {
10
+ if (!Array.isArray(value)) {
11
+ return false;
12
+ }
13
+ return value.every(function (arrayValue) { return isPrimitive(arrayValue); });
14
+ };
15
+
16
+ export { isArrayOfPrimitive, isPrimitive };
17
+ //# sourceMappingURL=is-primitive.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-primitive.js","sources":["../../src/predicates/is-primitive.ts"],"sourcesContent":["import { Primitive } from '../types/general';\n\nconst PRIMITIVE_TYPES = [\n 'string',\n 'boolean',\n 'number',\n];\n\nexport const isPrimitive = (value: any): value is Primitive => {\n return PRIMITIVE_TYPES.includes(typeof value);\n};\n\nexport const isArrayOfPrimitive = (value: any): value is Array<Primitive> => {\n if (!Array.isArray(value)) {\n return false;\n }\n\n return value.every((arrayValue) => isPrimitive(arrayValue));\n};\n"],"names":[],"mappings":"AAEA,IAAM,eAAe,GAAG;IACtB,QAAQ;IACR,SAAS;IACT,QAAQ;CACT,CAAC;AAEK,IAAM,WAAW,GAAG,UAAC,KAAU,EAAA;AACpC,IAAA,OAAO,eAAe,CAAC,QAAQ,CAAC,OAAO,KAAK,CAAC,CAAC;AAChD,EAAE;AAEK,IAAM,kBAAkB,GAAG,UAAC,KAAU,EAAA;AAC3C,IAAA,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;AACzB,QAAA,OAAO,KAAK,CAAC;AACd,KAAA;AAED,IAAA,OAAO,KAAK,CAAC,KAAK,CAAC,UAAC,UAAU,EAAA,EAAK,OAAA,WAAW,CAAC,UAAU,CAAC,CAAvB,EAAuB,CAAC,CAAC;AAC9D;;;;"}
@@ -0,0 +1 @@
1
+ export declare const isUndefined: (value: any) => value is undefined;
@@ -0,0 +1,6 @@
1
+ var isUndefined = function (value) {
2
+ return value === undefined;
3
+ };
4
+
5
+ export { isUndefined };
6
+ //# sourceMappingURL=is-undefined.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-undefined.js","sources":["../../src/predicates/is-undefined.ts"],"sourcesContent":["export const isUndefined = (value: any): value is undefined => {\n return value === undefined;\n};\n"],"names":[],"mappings":"AAAO,IAAM,WAAW,GAAG,UAAC,KAAU,EAAA;IACpC,OAAO,KAAK,KAAK,SAAS,CAAC;AAC7B;;;;"}
@@ -0,0 +1,5 @@
1
+ export declare type ExecutionConfig<Default> = {
2
+ execute: boolean;
3
+ defaultValue: Default;
4
+ };
5
+ export declare const executeOrResolveDefault: <T, Default>(callback: () => Promise<T>, config: ExecutionConfig<Default>) => Promise<T | Default>;
@@ -0,0 +1,10 @@
1
+ var executeOrResolveDefault = function (callback, config) {
2
+ var execute = config.execute, defaultValue = config.defaultValue;
3
+ if (execute) {
4
+ return callback();
5
+ }
6
+ return Promise.resolve(defaultValue);
7
+ };
8
+
9
+ export { executeOrResolveDefault };
10
+ //# sourceMappingURL=execute-or-resolve-default.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execute-or-resolve-default.js","sources":["../../src/promise/execute-or-resolve-default.ts"],"sourcesContent":["export type ExecutionConfig<Default> = {\n execute: boolean,\n defaultValue: Default,\n};\n\nexport const executeOrResolveDefault = <T, Default>(callback: () => Promise<T>, config: ExecutionConfig<Default>): Promise<T | Default> => {\n const { execute, defaultValue } = config;\n\n if (execute) {\n return callback();\n }\n\n return Promise.resolve(defaultValue);\n};\n"],"names":[],"mappings":"AAKa,IAAA,uBAAuB,GAAG,UAAa,QAA0B,EAAE,MAAgC,EAAA;IACtG,IAAA,OAAO,GAAmB,MAAM,CAAA,OAAzB,EAAE,YAAY,GAAK,MAAM,CAAA,YAAX,CAAY;AAEzC,IAAA,IAAI,OAAO,EAAE;QACX,OAAO,QAAQ,EAAE,CAAC;AACnB,KAAA;AAED,IAAA,OAAO,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;AACvC;;;;"}
@@ -0,0 +1 @@
1
+ export declare const executeWithDelay: <T>(callback: () => T, delay: number) => Promise<T>;
@@ -0,0 +1,17 @@
1
+ import { __awaiter, __generator } from '../_virtual/_tslib.js';
2
+
3
+ var executeWithDelay = function (callback, delay) { return __awaiter(void 0, void 0, void 0, function () {
4
+ return __generator(this, function (_a) {
5
+ switch (_a.label) {
6
+ case 0: return [4 /*yield*/, new Promise(function (resolve) {
7
+ setTimeout(resolve, delay);
8
+ })];
9
+ case 1:
10
+ _a.sent();
11
+ return [2 /*return*/, callback()];
12
+ }
13
+ });
14
+ }); };
15
+
16
+ export { executeWithDelay };
17
+ //# sourceMappingURL=execute-with-delay.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execute-with-delay.js","sources":["../../src/promise/execute-with-delay.ts"],"sourcesContent":["export const executeWithDelay = async <T>(callback: () => T, delay: number): Promise<T> => {\n await new Promise((resolve) => {\n setTimeout(resolve, delay);\n });\n\n return callback();\n};\n"],"names":[],"mappings":";;AAAa,IAAA,gBAAgB,GAAG,UAAU,QAAiB,EAAE,KAAa,EAAA,EAAA,OAAA,SAAA,CAAA,KAAA,CAAA,EAAA,KAAA,CAAA,EAAA,KAAA,CAAA,EAAA,YAAA;;;AACxE,YAAA,KAAA,CAAA,EAAA,OAAA,CAAA,CAAA,YAAM,IAAI,OAAO,CAAC,UAAC,OAAO,EAAA;AACxB,oBAAA,UAAU,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;AAC7B,iBAAC,CAAC,CAAA,CAAA;;AAFF,gBAAA,EAAA,CAAA,IAAA,EAEE,CAAC;gBAEH,OAAO,CAAA,CAAA,aAAA,QAAQ,EAAE,CAAC,CAAA;;;;;;;"}
@@ -0,0 +1,2 @@
1
+ export * from './execute-or-resolve-default';
2
+ export * from './execute-with-delay';
@@ -0,0 +1,3 @@
1
+ export { executeOrResolveDefault } from './execute-or-resolve-default.js';
2
+ export { executeWithDelay } from './execute-with-delay.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
@@ -0,0 +1 @@
1
+ export * from './replace-in-template';
@@ -0,0 +1,2 @@
1
+ export { replaceInTemplate } from './replace-in-template.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,14 @@
1
+ export declare type ReplaceConfig = {
2
+ delimiter: string | {
3
+ left: string;
4
+ right: string;
5
+ };
6
+ };
7
+ /**
8
+ * Replace string inside a template. For now, only works with
9
+ * an object containing promirives or array of primitives. If
10
+ * it contains other objects, they will be ignored.
11
+ *
12
+ * Uses the mustache syntax by default.
13
+ */
14
+ export declare const replaceInTemplate: (template: string, params: Record<string, any>, config?: ReplaceConfig) => string;
@@ -0,0 +1,35 @@
1
+ import { isPrimitive, isArrayOfPrimitive } from '../predicates/is-primitive.js';
2
+
3
+ var defaultConfig = {
4
+ delimiter: {
5
+ left: '{{',
6
+ right: '}}',
7
+ },
8
+ };
9
+ /**
10
+ * Replace string inside a template. For now, only works with
11
+ * an object containing promirives or array of primitives. If
12
+ * it contains other objects, they will be ignored.
13
+ *
14
+ * Uses the mustache syntax by default.
15
+ */
16
+ var replaceInTemplate = function (template, params, config) {
17
+ if (config === void 0) { config = defaultConfig; }
18
+ var delimiter = config.delimiter;
19
+ var leftDelimiter = typeof delimiter === 'string' ? delimiter : delimiter.left;
20
+ var rightDelimiter = typeof delimiter === 'string' ? delimiter : delimiter.right;
21
+ return Object
22
+ .entries(params)
23
+ .reduce(function (acc, _a) {
24
+ var key = _a[0], value = _a[1];
25
+ if (!isPrimitive(value) && !isArrayOfPrimitive(value)) {
26
+ return acc;
27
+ }
28
+ var searchValue = "".concat(leftDelimiter).concat(key).concat(rightDelimiter);
29
+ var replaceBy = Array.isArray(value) ? value.join(', ') : String(value);
30
+ return acc.replace(searchValue, replaceBy);
31
+ }, template);
32
+ };
33
+
34
+ export { replaceInTemplate };
35
+ //# sourceMappingURL=replace-in-template.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"replace-in-template.js","sources":["../../src/string/replace-in-template.ts"],"sourcesContent":["import { isArrayOfPrimitive, isPrimitive } from '../predicates';\n\nexport type ReplaceConfig = {\n delimiter: string | {\n left: string,\n right: string,\n },\n};\n\nconst defaultConfig: ReplaceConfig = {\n delimiter: {\n left: '{{',\n right: '}}',\n },\n};\n\n/**\n * Replace string inside a template. For now, only works with\n * an object containing promirives or array of primitives. If\n * it contains other objects, they will be ignored.\n *\n * Uses the mustache syntax by default.\n */\nexport const replaceInTemplate = (\n template: string,\n params: Record<string, any>,\n config: ReplaceConfig = defaultConfig,\n) => {\n const { delimiter } = config;\n const leftDelimiter = typeof delimiter === 'string' ? delimiter : delimiter.left;\n const rightDelimiter = typeof delimiter === 'string' ? delimiter : delimiter.right;\n\n return Object\n .entries(params)\n .reduce((acc, [key, value]) => {\n if (!isPrimitive(value) && !isArrayOfPrimitive(value)) {\n return acc;\n }\n\n const searchValue = `${leftDelimiter}${key}${rightDelimiter}`;\n const replaceBy = Array.isArray(value) ? value.join(', ') : String(value);\n\n return acc.replace(searchValue, replaceBy);\n }, template);\n};\n"],"names":[],"mappings":";;AASA,IAAM,aAAa,GAAkB;AACnC,IAAA,SAAS,EAAE;AACT,QAAA,IAAI,EAAE,IAAI;AACV,QAAA,KAAK,EAAE,IAAI;AACZ,KAAA;CACF,CAAC;AAEF;;;;;;AAMG;IACU,iBAAiB,GAAG,UAC/B,QAAgB,EAChB,MAA2B,EAC3B,MAAqC,EAAA;AAArC,IAAA,IAAA,MAAA,KAAA,KAAA,CAAA,EAAA,EAAA,MAAqC,GAAA,aAAA,CAAA,EAAA;AAE7B,IAAA,IAAA,SAAS,GAAK,MAAM,CAAA,SAAX,CAAY;AAC7B,IAAA,IAAM,aAAa,GAAG,OAAO,SAAS,KAAK,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC,IAAI,CAAC;AACjF,IAAA,IAAM,cAAc,GAAG,OAAO,SAAS,KAAK,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC,KAAK,CAAC;AAEnF,IAAA,OAAO,MAAM;SACV,OAAO,CAAC,MAAM,CAAC;AACf,SAAA,MAAM,CAAC,UAAC,GAAG,EAAE,EAAY,EAAA;YAAX,GAAG,GAAA,EAAA,CAAA,CAAA,CAAA,EAAE,KAAK,GAAA,EAAA,CAAA,CAAA,CAAA,CAAA;QACvB,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,EAAE;AACrD,YAAA,OAAO,GAAG,CAAC;AACZ,SAAA;QAED,IAAM,WAAW,GAAG,EAAG,CAAA,MAAA,CAAA,aAAa,SAAG,GAAG,CAAA,CAAA,MAAA,CAAG,cAAc,CAAE,CAAC;QAC9D,IAAM,SAAS,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;QAE1E,OAAO,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;KAC5C,EAAE,QAAQ,CAAC,CAAC;AACjB;;;;"}
@@ -0,0 +1 @@
1
+ export declare type GenericFunction<TS extends any[], R> = (...args: TS) => R;
@@ -0,0 +1,2 @@
1
+ export declare type Primitive = string | number | boolean;
2
+ export declare type Nullable<T> = T | null;
@@ -0,0 +1,3 @@
1
+ export * from './function';
2
+ export * from './general';
3
+ export * from './object';
package/types/index.js ADDED
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,22 @@
1
+ export declare type NonMethodKeys<T> = {
2
+ [P in keyof T]: T[P] extends Function ? never : P;
3
+ }[keyof T];
4
+ export declare type Attributes<T> = {
5
+ [K in NonMethodKeys<T>]: T[K];
6
+ };
7
+ export declare type PartialAttributes<T> = {
8
+ [K in NonMethodKeys<T>]?: T[K];
9
+ };
10
+ export declare type MethodKeys<T> = {
11
+ [P in keyof T]: T[P] extends Function ? P : never;
12
+ }[keyof T];
13
+ export declare type Methods<T> = {
14
+ [K in MethodKeys<T>]: T[K];
15
+ };
16
+ export declare type PartialMethods<T> = {
17
+ [K in MethodKeys<T>]?: T[K];
18
+ };
19
+ export declare type ClassType<T> = {
20
+ new (...args: any[]): T;
21
+ };
22
+ export declare type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;