@sparted/shared-library 0.0.12 → 0.0.14
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.
- package/_virtual/_tslib.js +11 -38
- package/_virtual/_tslib.js.map +1 -1
- package/array/array-to-map.js +6 -9
- package/array/array-to-map.js.map +1 -1
- package/array/get-values-from-keys.js +2 -2
- package/array/get-values-from-keys.js.map +1 -1
- package/date/constants.d.ts +4 -0
- package/date/constants.js +7 -0
- package/date/constants.js.map +1 -0
- package/date/convert.d.ts +2 -0
- package/date/convert.js +7 -0
- package/date/convert.js.map +1 -0
- package/date/format-minutes.d.ts +1 -0
- package/date/format-minutes.js +12 -0
- package/date/format-minutes.js.map +1 -0
- package/date/get-time-diff-as-string.d.ts +47 -0
- package/date/get-time-diff-as-string.js +124 -0
- package/date/get-time-diff-as-string.js.map +1 -0
- package/date/index.d.ts +4 -0
- package/date/index.js +4 -0
- package/date/index.js.map +1 -0
- package/formatting/format-number.d.ts +1 -0
- package/formatting/format-number.js +14 -0
- package/formatting/format-number.js.map +1 -0
- package/formatting/index.d.ts +1 -0
- package/formatting/index.js +2 -0
- package/formatting/index.js.map +1 -0
- package/fp/run-while.js +6 -7
- package/fp/run-while.js.map +1 -1
- package/http/encode-search-object.d.ts +7 -0
- package/http/encode-search-object.js +27 -0
- package/http/encode-search-object.js.map +1 -0
- package/http/fetch-with-timeout.d.ts +8 -0
- package/http/fetch-with-timeout.js +18 -0
- package/http/fetch-with-timeout.js.map +1 -0
- package/http/index.d.ts +2 -0
- package/http/index.js +3 -0
- package/http/index.js.map +1 -0
- package/index.d.ts +6 -0
- package/index.js +13 -0
- package/index.js.map +1 -1
- package/linked-list/apply-diff-linked-list.d.ts +2 -0
- package/linked-list/apply-diff-linked-list.js +27 -0
- package/linked-list/apply-diff-linked-list.js.map +1 -0
- package/linked-list/create-linked-list.d.ts +2 -0
- package/linked-list/create-linked-list.js +66 -0
- package/linked-list/create-linked-list.js.map +1 -0
- package/linked-list/find-linked-list.d.ts +2 -0
- package/linked-list/find-linked-list.js +24 -0
- package/linked-list/find-linked-list.js.map +1 -0
- package/linked-list/get-linked-list.d.ts +2 -0
- package/linked-list/get-linked-list.js +9 -0
- package/linked-list/get-linked-list.js.map +1 -0
- package/linked-list/index.d.ts +2 -0
- package/linked-list/index.js +2 -0
- package/linked-list/index.js.map +1 -0
- package/linked-list/insert-linked-list.d.ts +2 -0
- package/linked-list/insert-linked-list.js +28 -0
- package/linked-list/insert-linked-list.js.map +1 -0
- package/linked-list/linked-list-utils.d.ts +23 -0
- package/linked-list/linked-list-utils.js +96 -0
- package/linked-list/linked-list-utils.js.map +1 -0
- package/linked-list/reduce-linked-list.d.ts +2 -0
- package/linked-list/reduce-linked-list.js +17 -0
- package/linked-list/reduce-linked-list.js.map +1 -0
- package/linked-list/remove-linked-list.d.ts +2 -0
- package/linked-list/remove-linked-list.js +24 -0
- package/linked-list/remove-linked-list.js.map +1 -0
- package/linked-list/type.d.ts +34 -0
- package/linked-list/update-linked-list.d.ts +2 -0
- package/linked-list/update-linked-list.js +20 -0
- package/linked-list/update-linked-list.js.map +1 -0
- package/linked-list/walk-list-item-record.d.ts +15 -0
- package/linked-list/while-linked-list.d.ts +2 -0
- package/linked-list/while-linked-list.js +28 -0
- package/linked-list/while-linked-list.js.map +1 -0
- package/math/clamp-number.d.ts +2 -0
- package/math/clamp-number.js +9 -0
- package/math/clamp-number.js.map +1 -0
- package/math/index.d.ts +4 -0
- package/math/index.js +5 -0
- package/math/index.js.map +1 -0
- package/math/interpolate.d.ts +2 -0
- package/math/interpolate.js +16 -0
- package/math/interpolate.js.map +1 -0
- package/math/number-range.d.ts +6 -0
- package/math/number-range.js +12 -0
- package/math/number-range.js.map +1 -0
- package/math/random-number.d.ts +2 -0
- package/math/random-number.js +9 -0
- package/math/random-number.js.map +1 -0
- package/object/index.d.ts +1 -0
- package/object/index.js +2 -0
- package/object/index.js.map +1 -0
- package/object/merge-deep.d.ts +2 -0
- package/object/merge-deep.js +21 -0
- package/object/merge-deep.js.map +1 -0
- package/package.json +2 -1
- package/parsing/parse-boolean.js +1 -1
- package/parsing/parse-boolean.js.map +1 -1
- package/parsing/parse-enum.js +3 -3
- package/parsing/parse-enum.js.map +1 -1
- package/parsing/parse-number.js +2 -2
- package/parsing/parse-number.js.map +1 -1
- package/predicates/is-function.js +1 -1
- package/predicates/is-function.js.map +1 -1
- package/predicates/is-null.js +1 -1
- package/predicates/is-null.js.map +1 -1
- package/predicates/is-object.js +1 -1
- package/predicates/is-object.js.map +1 -1
- package/predicates/is-primitive.js +4 -4
- package/predicates/is-primitive.js.map +1 -1
- package/predicates/is-undefined.js +1 -1
- package/predicates/is-undefined.js.map +1 -1
- package/predicates/is-uuid.d.ts +1 -0
- package/promise/delay.d.ts +1 -0
- package/promise/delay.js +6 -0
- package/promise/delay.js.map +1 -0
- package/promise/execute-or-resolve-default.js +2 -2
- package/promise/execute-or-resolve-default.js.map +1 -1
- package/promise/execute-with-delay.d.ts +1 -1
- package/promise/execute-with-delay.js +6 -13
- package/promise/execute-with-delay.js.map +1 -1
- package/promise/index.d.ts +1 -0
- package/promise/index.js +1 -0
- package/promise/index.js.map +1 -1
- package/string/replace-in-template.js +8 -10
- package/string/replace-in-template.js.map +1 -1
- package/types/general.d.ts +1 -0
- package/types/index.d.ts +1 -0
- package/types/object.d.ts +13 -0
- package/types/search.d.ts +24 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { assertNumberRange } from './number-range.js';
|
|
2
|
+
|
|
3
|
+
const randomNumber = ({ min, max }) => {
|
|
4
|
+
assertNumberRange({ min, max });
|
|
5
|
+
return Math.floor(Math.random() * (max - min) + min);
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export { randomNumber };
|
|
9
|
+
//# sourceMappingURL=random-number.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"random-number.js","sources":["../../src/math/random-number.ts"],"sourcesContent":["import { assertNumberRange } from './number-range';\nimport type { NumberRange } from './number-range';\n\nexport const randomNumber = ({ min, max }: NumberRange) => {\n assertNumberRange({ min, max });\n\n return Math.floor(\n Math.random() * (max - min) + min,\n );\n};\n"],"names":[],"mappings":";;AAGa,MAAA,YAAY,GAAG,CAAC,EAAE,GAAG,EAAE,GAAG,EAAe,KAAI;AACxD,IAAA,iBAAiB,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC;AAEhC,IAAA,OAAO,IAAI,CAAC,KAAK,CACf,IAAI,CAAC,MAAM,EAAE,IAAI,GAAG,GAAG,GAAG,CAAC,GAAG,GAAG,CAClC,CAAC;AACJ;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './merge-deep';
|
package/object/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// https://stackoverflow.com/questions/8511281/check-if-a-value-is-an-object-in-javascript/8511350#8511350
|
|
2
|
+
const isObject = (a) => typeof a === 'object' && a !== null;
|
|
3
|
+
const isValueType = (a) => (!isObject(a) || Array.isArray(a));
|
|
4
|
+
const mergeDeep = (a, b) => {
|
|
5
|
+
if (isValueType(a) || isValueType(b)) {
|
|
6
|
+
return b;
|
|
7
|
+
}
|
|
8
|
+
return Object.keys(b).reduce((acc, key) => {
|
|
9
|
+
if (!(key in a)) {
|
|
10
|
+
return acc;
|
|
11
|
+
}
|
|
12
|
+
if (b[key] === a[key]) {
|
|
13
|
+
return acc;
|
|
14
|
+
}
|
|
15
|
+
const merged = mergeDeep(a[key], b[key]);
|
|
16
|
+
return Object.assign(Object.assign({}, acc), { [key]: merged });
|
|
17
|
+
}, a);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export { mergeDeep };
|
|
21
|
+
//# sourceMappingURL=merge-deep.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge-deep.js","sources":["../../src/object/merge-deep.ts"],"sourcesContent":["import type { DeepPartial, ValueType } from '../types';\n\n// https://stackoverflow.com/questions/8511281/check-if-a-value-is-an-object-in-javascript/8511350#8511350\nconst isObject = (a: any) => typeof a === 'object' && a !== null;\nconst isValueType = (a: any): a is ValueType => (\n !isObject(a) || Array.isArray(a)\n);\n\nexport const mergeDeep = <T>(a: T, b: DeepPartial<T>): T => {\n if (isValueType(a) || isValueType(b)) {\n return b as T;\n }\n\n return (Object.keys(b) as (keyof T)[]).reduce((acc, key) => {\n if (!(key in a)) {\n return acc;\n }\n\n if (b[key] === a[key]) {\n return acc;\n }\n\n const merged = mergeDeep(a[key], (b[key] as DeepPartial<T[keyof T]>));\n\n return { ...acc, [key]: merged };\n }, a);\n};\n"],"names":[],"mappings":"AAEA;AACA,MAAM,QAAQ,GAAG,CAAC,CAAM,KAAK,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,CAAC;AACjE,MAAM,WAAW,GAAG,CAAC,CAAM,MACzB,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CACjC,CAAC;MAEW,SAAS,GAAG,CAAI,CAAI,EAAE,CAAiB,KAAO;IACzD,IAAI,WAAW,CAAC,CAAC,CAAC,IAAI,WAAW,CAAC,CAAC,CAAC,EAAE;AACpC,QAAA,OAAO,CAAM,CAAC;AACf,KAAA;AAED,IAAA,OAAQ,MAAM,CAAC,IAAI,CAAC,CAAC,CAAiB,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,KAAI;AACzD,QAAA,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC,EAAE;AACf,YAAA,OAAO,GAAG,CAAC;AACZ,SAAA;QAED,IAAI,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,EAAE;AACrB,YAAA,OAAO,GAAG,CAAC;AACZ,SAAA;AAED,QAAA,MAAM,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,EAAG,CAAC,CAAC,GAAG,CAA6B,CAAC,CAAC;AAEtE,QAAA,OAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,EAAA,EAAY,GAAG,CAAE,EAAA,EAAA,CAAC,GAAG,GAAG,MAAM,EAAG,CAAA,CAAA;KAClC,EAAE,CAAC,CAAC,CAAC;AACR;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sparted/shared-library",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.14",
|
|
4
4
|
"repository": "git@github.com:Sparted/shared-library.git",
|
|
5
5
|
"author": "Thomas <duprethomasfr@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"jest": "^29.0.3",
|
|
25
25
|
"jest-environment-jsdom": "^29.0.3",
|
|
26
26
|
"jest-extended": "^3.1.0",
|
|
27
|
+
"jest-fetch-mock": "^3.0.3",
|
|
27
28
|
"rollup": "^2.79.1",
|
|
28
29
|
"rollup-plugin-typescript2": "^0.34.0",
|
|
29
30
|
"ts-jest": "^29.0.2",
|
package/parsing/parse-boolean.js
CHANGED
|
@@ -1 +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;
|
|
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;AACW,MAAA,YAAY,GAAG,CAAC,KAAa,KAAa;AACtD,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;;;;"}
|
package/parsing/parse-enum.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Factory to build enum to parse a string to an enum. Throw error if string is not an enum value
|
|
3
3
|
*/
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const createEnumParser = (enumType) => ((value) => {
|
|
5
|
+
const enumValues = Object.values(enumType);
|
|
6
6
|
if (!enumValues.includes(value)) {
|
|
7
7
|
throw new Error('Can\'t parse this value');
|
|
8
8
|
}
|
|
9
9
|
return value;
|
|
10
|
-
});
|
|
10
|
+
});
|
|
11
11
|
|
|
12
12
|
export { createEnumParser };
|
|
13
13
|
//# sourceMappingURL=parse-enum.js.map
|
|
@@ -1 +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;
|
|
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;AACK,MAAM,gBAAgB,GAAG,CAAsC,QAAW,MAChF,CAAC,KAAa,KAAI;IAChB,MAAM,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;;;;"}
|
package/parsing/parse-number.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Parse a string to a number. Throw error if string is NaN
|
|
3
3
|
*/
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const parseNumber = (value) => {
|
|
5
|
+
const number = parseInt(value, 10);
|
|
6
6
|
if (Number.isNaN(number)) {
|
|
7
7
|
throw new Error('Cannot parse value');
|
|
8
8
|
}
|
|
@@ -1 +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;
|
|
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;AACW,MAAA,WAAW,GAAG,CAAC,KAAa,KAAY;IACpD,MAAM,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;;;;"}
|
|
@@ -1 +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":"
|
|
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":"AAAa,MAAA,UAAU,GAAG,CAAC,KAAU,KAAuB;AAC1D,IAAA,OAAO,OAAO,KAAK,KAAK,UAAU,CAAC;AACrC;;;;"}
|
package/predicates/is-null.js
CHANGED
|
@@ -1 +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":"
|
|
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":"AAAa,MAAA,MAAM,GAAG,CAAC,KAAU,KAAmB;IAClD,OAAO,KAAK,KAAK,IAAI,CAAC;AACxB;;;;"}
|
package/predicates/is-object.js
CHANGED
|
@@ -1 +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":"
|
|
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":"AAAa,MAAA,QAAQ,GAAG,CAAC,KAAU,KAAqB;AACtD,IAAA,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC;AACnC;;;;"}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
const PRIMITIVE_TYPES = [
|
|
2
2
|
'string',
|
|
3
3
|
'boolean',
|
|
4
4
|
'number',
|
|
5
5
|
];
|
|
6
|
-
|
|
6
|
+
const isPrimitive = (value) => {
|
|
7
7
|
return PRIMITIVE_TYPES.includes(typeof value);
|
|
8
8
|
};
|
|
9
|
-
|
|
9
|
+
const isArrayOfPrimitive = (value) => {
|
|
10
10
|
if (!Array.isArray(value)) {
|
|
11
11
|
return false;
|
|
12
12
|
}
|
|
13
|
-
return value.every(
|
|
13
|
+
return value.every((arrayValue) => isPrimitive(arrayValue));
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
export { isArrayOfPrimitive, isPrimitive };
|
|
@@ -1 +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,
|
|
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,MAAM,eAAe,GAAG;IACtB,QAAQ;IACR,SAAS;IACT,QAAQ;CACT,CAAC;AAEW,MAAA,WAAW,GAAG,CAAC,KAAU,KAAwB;AAC5D,IAAA,OAAO,eAAe,CAAC,QAAQ,CAAC,OAAO,KAAK,CAAC,CAAC;AAChD,EAAE;AAEW,MAAA,kBAAkB,GAAG,CAAC,KAAU,KAA+B;AAC1E,IAAA,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;AACzB,QAAA,OAAO,KAAK,CAAC;AACd,KAAA;AAED,IAAA,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,UAAU,KAAK,WAAW,CAAC,UAAU,CAAC,CAAC,CAAC;AAC9D;;;;"}
|
|
@@ -1 +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":"
|
|
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":"AAAa,MAAA,WAAW,GAAG,CAAC,KAAU,KAAwB;IAC5D,OAAO,KAAK,KAAK,SAAS,CAAC;AAC7B;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isUuidV4: (arg: any) => arg is string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const delay: (time: number) => Promise<unknown>;
|
package/promise/delay.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delay.js","sources":["../../src/promise/delay.ts"],"sourcesContent":["export const delay = (time: number) => new Promise((resolve) => {\n setTimeout(resolve, time);\n});\n"],"names":[],"mappings":"AAAO,MAAM,KAAK,GAAG,CAAC,IAAY,KAAK,IAAI,OAAO,CAAC,CAAC,OAAO,KAAI;AAC7D,IAAA,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;AAC5B,CAAC;;;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
const executeOrResolveDefault = (callback, config) => {
|
|
2
|
+
const { execute, defaultValue } = config;
|
|
3
3
|
if (execute) {
|
|
4
4
|
return callback();
|
|
5
5
|
}
|
|
@@ -1 +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":"
|
|
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":"MAKa,uBAAuB,GAAG,CAAa,QAA0B,EAAE,MAAgC,KAA0B;AACxI,IAAA,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,GAAG,MAAM,CAAC;AAEzC,IAAA,IAAI,OAAO,EAAE;QACX,OAAO,QAAQ,EAAE,CAAC;AACnB,KAAA;AAED,IAAA,OAAO,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;AACvC;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const executeWithDelay: <T>(callback: () => T,
|
|
1
|
+
export declare const executeWithDelay: <T>(callback: () => T, time: number) => Promise<T>;
|
|
@@ -1,17 +1,10 @@
|
|
|
1
|
-
import { __awaiter
|
|
1
|
+
import { __awaiter } from '../_virtual/_tslib.js';
|
|
2
|
+
import { delay } from './delay.js';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
setTimeout(resolve, delay);
|
|
8
|
-
})];
|
|
9
|
-
case 1:
|
|
10
|
-
_a.sent();
|
|
11
|
-
return [2 /*return*/, callback()];
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
}); };
|
|
4
|
+
const executeWithDelay = (callback, time) => __awaiter(void 0, void 0, void 0, function* () {
|
|
5
|
+
yield delay(time);
|
|
6
|
+
return callback();
|
|
7
|
+
});
|
|
15
8
|
|
|
16
9
|
export { executeWithDelay };
|
|
17
10
|
//# sourceMappingURL=execute-with-delay.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execute-with-delay.js","sources":["../../src/promise/execute-with-delay.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"execute-with-delay.js","sources":["../../src/promise/execute-with-delay.ts"],"sourcesContent":["import { delay } from './delay';\n\nexport const executeWithDelay = async <T>(callback: () => T, time: number): Promise<T> => {\n await delay(time);\n return callback();\n};\n"],"names":[],"mappings":";;;MAEa,gBAAgB,GAAG,CAAU,QAAiB,EAAE,IAAY,KAAgB,SAAA,CAAA,KAAA,CAAA,EAAA,KAAA,CAAA,EAAA,KAAA,CAAA,EAAA,aAAA;AACvF,IAAA,MAAM,KAAK,CAAC,IAAI,CAAC,CAAC;IAClB,OAAO,QAAQ,EAAE,CAAC;AACpB,CAAC;;;;"}
|
package/promise/index.d.ts
CHANGED
package/promise/index.js
CHANGED
package/promise/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isPrimitive, isArrayOfPrimitive } from '../predicates/is-primitive.js';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const defaultConfig = {
|
|
4
4
|
delimiter: {
|
|
5
5
|
left: '{{',
|
|
6
6
|
right: '}}',
|
|
@@ -13,20 +13,18 @@ var defaultConfig = {
|
|
|
13
13
|
*
|
|
14
14
|
* Uses the mustache syntax by default.
|
|
15
15
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
var rightDelimiter = typeof delimiter === 'string' ? delimiter : delimiter.right;
|
|
16
|
+
const replaceInTemplate = (template, params, config = defaultConfig) => {
|
|
17
|
+
const { delimiter } = config;
|
|
18
|
+
const leftDelimiter = typeof delimiter === 'string' ? delimiter : delimiter.left;
|
|
19
|
+
const rightDelimiter = typeof delimiter === 'string' ? delimiter : delimiter.right;
|
|
21
20
|
return Object
|
|
22
21
|
.entries(params)
|
|
23
|
-
.reduce(
|
|
24
|
-
var key = _a[0], value = _a[1];
|
|
22
|
+
.reduce((acc, [key, value]) => {
|
|
25
23
|
if (!isPrimitive(value) && !isArrayOfPrimitive(value)) {
|
|
26
24
|
return acc;
|
|
27
25
|
}
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
const searchValue = `${leftDelimiter}${key}${rightDelimiter}`;
|
|
27
|
+
const replaceBy = Array.isArray(value) ? value.join(', ') : String(value);
|
|
30
28
|
return acc.replace(searchValue, replaceBy);
|
|
31
29
|
}, template);
|
|
32
30
|
};
|
|
@@ -1 +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,
|
|
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,MAAM,aAAa,GAAkB;AACnC,IAAA,SAAS,EAAE;AACT,QAAA,IAAI,EAAE,IAAI;AACV,QAAA,KAAK,EAAE,IAAI;AACZ,KAAA;CACF,CAAC;AAEF;;;;;;AAMG;AACI,MAAM,iBAAiB,GAAG,CAC/B,QAAgB,EAChB,MAA2B,EAC3B,MAAA,GAAwB,aAAa,KACnC;AACF,IAAA,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC;AAC7B,IAAA,MAAM,aAAa,GAAG,OAAO,SAAS,KAAK,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC,IAAI,CAAC;AACjF,IAAA,MAAM,cAAc,GAAG,OAAO,SAAS,KAAK,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC,KAAK,CAAC;AAEnF,IAAA,OAAO,MAAM;SACV,OAAO,CAAC,MAAM,CAAC;SACf,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,KAAI;QAC5B,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,EAAE;AACrD,YAAA,OAAO,GAAG,CAAC;AACZ,SAAA;QAED,MAAM,WAAW,GAAG,CAAG,EAAA,aAAa,GAAG,GAAG,CAAA,EAAG,cAAc,CAAA,CAAE,CAAC;QAC9D,MAAM,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;;;;"}
|
package/types/general.d.ts
CHANGED
package/types/index.d.ts
CHANGED
package/types/object.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ValueType } from './general';
|
|
1
2
|
export declare type NonMethodKeys<T> = {
|
|
2
3
|
[P in keyof T]: T[P] extends Function ? never : P;
|
|
3
4
|
}[keyof T];
|
|
@@ -20,3 +21,15 @@ export declare type ClassType<T> = {
|
|
|
20
21
|
new (...args: any[]): T;
|
|
21
22
|
};
|
|
22
23
|
export declare type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
24
|
+
export declare type DeepPartial<T> = T extends ValueType ? T : {
|
|
25
|
+
[P in keyof T]?: DeepPartial<T[P]>;
|
|
26
|
+
};
|
|
27
|
+
export declare type Intersection<A, B> = {
|
|
28
|
+
[P in keyof A & keyof B]: A[P] | B[P];
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Helper type. Passes T out again, but boxes it in a way that it cannot
|
|
32
|
+
* "widen" the type by accident if it is a generic that should be inferred
|
|
33
|
+
* from elsewhere.
|
|
34
|
+
*/
|
|
35
|
+
export declare type NoInfer<T> = [T][T extends any ? 0 : never];
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare type SearchSortBy = string;
|
|
2
|
+
export declare type SearchSortOrder = 'asc' | 'desc';
|
|
3
|
+
export declare type SearchSort = {
|
|
4
|
+
[by: SearchSortBy]: SearchSortOrder;
|
|
5
|
+
};
|
|
6
|
+
export declare type SearchQueryProperty = string;
|
|
7
|
+
export declare type SearchQueryValue = string;
|
|
8
|
+
export declare type SearchQuery = {
|
|
9
|
+
[property: SearchQueryProperty]: SearchQueryValue;
|
|
10
|
+
};
|
|
11
|
+
export declare type SearchObject = {
|
|
12
|
+
offset: number;
|
|
13
|
+
limit: number;
|
|
14
|
+
sort?: Record<string, SearchSortOrder>;
|
|
15
|
+
query?: SearchQuery;
|
|
16
|
+
};
|
|
17
|
+
export declare type SearchResponse<T> = {
|
|
18
|
+
items: ReadonlyArray<T>;
|
|
19
|
+
offset: number;
|
|
20
|
+
limit: number;
|
|
21
|
+
total: number;
|
|
22
|
+
next: string | null;
|
|
23
|
+
previous: string | null;
|
|
24
|
+
};
|