@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
package/_virtual/_tslib.js
CHANGED
|
@@ -13,16 +13,17 @@ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
13
13
|
PERFORMANCE OF THIS SOFTWARE.
|
|
14
14
|
***************************************************************************** */
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
function __rest(s, e) {
|
|
17
|
+
var t = {};
|
|
18
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
19
|
+
t[p] = s[p];
|
|
20
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
21
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
22
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
23
|
+
t[p[i]] = s[p[i]];
|
|
21
24
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return __assign.apply(this, arguments);
|
|
25
|
-
};
|
|
25
|
+
return t;
|
|
26
|
+
}
|
|
26
27
|
|
|
27
28
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
28
29
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
@@ -32,35 +33,7 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
32
33
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
33
34
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
34
35
|
});
|
|
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
36
|
}
|
|
64
37
|
|
|
65
|
-
export {
|
|
38
|
+
export { __awaiter, __rest };
|
|
66
39
|
//# sourceMappingURL=_tslib.js.map
|
package/_virtual/_tslib.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_tslib.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"_tslib.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/array/array-to-map.js
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
import { __assign } from '../_virtual/_tslib.js';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* Transform an array to a map.
|
|
5
3
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
return array.reduce(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var value = options.dataModifier
|
|
4
|
+
const arrayToMap = (array, options) => {
|
|
5
|
+
const { selectKey } = options;
|
|
6
|
+
return array.reduce((acc, current) => {
|
|
7
|
+
const key = selectKey(current);
|
|
8
|
+
const value = options.dataModifier
|
|
12
9
|
? options.dataModifier(current)
|
|
13
10
|
: current;
|
|
14
|
-
return
|
|
11
|
+
return Object.assign(Object.assign({}, acc), { [key]: value });
|
|
15
12
|
}, {});
|
|
16
13
|
};
|
|
17
14
|
|
|
@@ -1 +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":"
|
|
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;MACU,UAAU,GAAG,CACxB,KAAkC,EAClC,OAAuD,KACrD;AACF,IAAA,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IAE9B,OAAO,KAAK,CAAC,MAAM,CAAgC,CAAC,GAAG,EAAE,OAAO,KAAI;AAClE,QAAA,MAAM,GAAG,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC;AAC/B,QAAA,MAAM,KAAK,GAAG,OAAO,CAAC,YAAY;AAChC,cAAE,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC;cAC7B,OAAO,CAAC;AAEZ,QAAA,OAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,EAAA,EACK,GAAG,CACN,EAAA,EAAA,CAAC,GAAG,GAAG,KAAsB,EAC7B,CAAA,CAAA;KACH,EAAE,EAAE,CAAC,CAAC;AACT;;;;"}
|
|
@@ -1 +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":"
|
|
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":"MAAa,cAAc,GAAG,CAAI,IAAc,EAAE,GAAsB,KAAI;AAC1E,IAAA,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;AACrC;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sources":["../../src/date/constants.ts"],"sourcesContent":["export const MS_SECOND = 1000;\nexport const MS_MINUTE = MS_SECOND * 60;\nexport const MS_HOUR = MS_MINUTE * 60;\nexport const MS_DAY = MS_HOUR * 24;"],"names":[],"mappings":"AAAO,MAAM,SAAS,GAAG,KAAK;AACjB,MAAA,SAAS,GAAG,SAAS,GAAG,GAAG;AAC3B,MAAA,OAAO,GAAG,SAAS,GAAG,GAAG;AACzB,MAAA,MAAM,GAAG,OAAO,GAAG;;;;"}
|
package/date/convert.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert.js","sources":["../../src/date/convert.ts"],"sourcesContent":["import { MS_MINUTE, MS_HOUR } from './constants';\n\nexport const msToMinute = (ms: number) => Math.floor(ms / MS_MINUTE);\n\nexport const msToHour = (ms: number) => Math.floor(ms / MS_HOUR);"],"names":[],"mappings":";;AAEa,MAAA,UAAU,GAAG,CAAC,EAAU,KAAK,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,SAAS,EAAE;AAExD,MAAA,QAAQ,GAAG,CAAC,EAAU,KAAK,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,OAAO;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const formatMinutes: (timeInMin: number) => string;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const formatMinutes = (timeInMin) => {
|
|
2
|
+
const hours = Math.floor(timeInMin / 60);
|
|
3
|
+
const mins = Math.round(timeInMin % 60);
|
|
4
|
+
if (hours === 0)
|
|
5
|
+
return `${mins}min`;
|
|
6
|
+
if (mins === 0)
|
|
7
|
+
return `${hours}h`;
|
|
8
|
+
return `${hours}h${mins}min`;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export { formatMinutes };
|
|
12
|
+
//# sourceMappingURL=format-minutes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format-minutes.js","sources":["../../src/date/format-minutes.ts"],"sourcesContent":["export const formatMinutes = (timeInMin: number): string => {\n const hours = Math.floor(timeInMin / 60);\n const mins = Math.round(timeInMin % 60);\n\n if (hours === 0) return `${mins}min`;\n if (mins === 0) return `${hours}h`;\n\n return `${hours}h${mins}min`;\n};\n"],"names":[],"mappings":"AAAa,MAAA,aAAa,GAAG,CAAC,SAAiB,KAAY;IACzD,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,GAAG,EAAE,CAAC,CAAC;IACzC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,GAAG,EAAE,CAAC,CAAC;IAExC,IAAI,KAAK,KAAK,CAAC;QAAE,OAAO,CAAA,EAAG,IAAI,CAAA,GAAA,CAAK,CAAC;IACrC,IAAI,IAAI,KAAK,CAAC;QAAE,OAAO,CAAA,EAAG,KAAK,CAAA,CAAA,CAAG,CAAC;AAEnC,IAAA,OAAO,CAAG,EAAA,KAAK,CAAI,CAAA,EAAA,IAAI,KAAK,CAAC;AAC/B;;;;"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export declare type MonthLocaleLabels = [
|
|
2
|
+
string,
|
|
3
|
+
string,
|
|
4
|
+
string,
|
|
5
|
+
string,
|
|
6
|
+
string,
|
|
7
|
+
string,
|
|
8
|
+
string,
|
|
9
|
+
string,
|
|
10
|
+
string,
|
|
11
|
+
string,
|
|
12
|
+
string,
|
|
13
|
+
string
|
|
14
|
+
];
|
|
15
|
+
export declare type DiffTemplate = {
|
|
16
|
+
/**
|
|
17
|
+
* e.g.: ("%time% %timelabel% blabla")
|
|
18
|
+
*/
|
|
19
|
+
timeTemplate: string;
|
|
20
|
+
/**
|
|
21
|
+
* e.g.: "%date% blabla"
|
|
22
|
+
*/
|
|
23
|
+
monthLocaleLabels: MonthLocaleLabels;
|
|
24
|
+
fullDateTemplate: string;
|
|
25
|
+
timeLabel: {
|
|
26
|
+
minute: {
|
|
27
|
+
singular: string;
|
|
28
|
+
plural: string;
|
|
29
|
+
};
|
|
30
|
+
hour: {
|
|
31
|
+
singular: string;
|
|
32
|
+
plural: string;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* The returned string follows the following rules:
|
|
38
|
+
* - If diff < 60 minutes: '29 min ago'
|
|
39
|
+
* - If diff >= 60 minutes & < 24 hours: '12 hours ago' | '1 hour ago'
|
|
40
|
+
* - If diff > 24 hours: 'on March 15, 14:45 pm'
|
|
41
|
+
*
|
|
42
|
+
* @param olderDate - Date
|
|
43
|
+
* @param recentDate - Date
|
|
44
|
+
* @param template - DiffTemplate
|
|
45
|
+
* @returns a preformated string to be inserted in a phrase.
|
|
46
|
+
*/
|
|
47
|
+
export declare const getTimeDiffAsString: (olderDate: Date, recentDate?: Date, templateConfig?: DiffTemplate) => string;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { replaceInTemplate } from '../string/replace-in-template.js';
|
|
2
|
+
import { MS_HOUR, MS_DAY } from './constants.js';
|
|
3
|
+
import { msToMinute, msToHour } from './convert.js';
|
|
4
|
+
|
|
5
|
+
const defaultLocaleLabels = [
|
|
6
|
+
'January',
|
|
7
|
+
'February',
|
|
8
|
+
'March',
|
|
9
|
+
'April',
|
|
10
|
+
'May',
|
|
11
|
+
'June',
|
|
12
|
+
'July',
|
|
13
|
+
'August',
|
|
14
|
+
'September',
|
|
15
|
+
'October',
|
|
16
|
+
'November',
|
|
17
|
+
'December',
|
|
18
|
+
];
|
|
19
|
+
const defaultEnglishTemplate = {
|
|
20
|
+
timeTemplate: '%time% %timeLabel% ago',
|
|
21
|
+
fullDateTemplate: 'on %date%',
|
|
22
|
+
monthLocaleLabels: defaultLocaleLabels,
|
|
23
|
+
timeLabel: {
|
|
24
|
+
minute: {
|
|
25
|
+
singular: 'min',
|
|
26
|
+
plural: 'min',
|
|
27
|
+
},
|
|
28
|
+
hour: {
|
|
29
|
+
singular: 'hour',
|
|
30
|
+
plural: 'hours',
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
const TEMPLATE_CONFIG = {
|
|
35
|
+
delimiter: {
|
|
36
|
+
left: '%',
|
|
37
|
+
right: '%',
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
const formatMinuteString = (minute) => {
|
|
41
|
+
const str = minute.toString();
|
|
42
|
+
return {
|
|
43
|
+
time: str.length === 2 ? str : `0${str}`,
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
const formatHourString = (hour) => {
|
|
47
|
+
const period = hour < 12 ? 'am' : 'pm';
|
|
48
|
+
const twelveHourTime = hour > 12 ? hour - 12 : hour;
|
|
49
|
+
return {
|
|
50
|
+
time: twelveHourTime === 0 ? '12' : twelveHourTime.toString(),
|
|
51
|
+
period,
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
const getTemplatingParameters = (msDiff, config) => {
|
|
55
|
+
const { dates, templateConfig } = config;
|
|
56
|
+
const { timeLabel, monthLocaleLabels, timeTemplate, fullDateTemplate } = templateConfig;
|
|
57
|
+
if (msDiff < MS_HOUR) {
|
|
58
|
+
const minuteDiff = msToMinute(msDiff);
|
|
59
|
+
const minuteUnit = minuteDiff > 1
|
|
60
|
+
? timeLabel.minute.plural
|
|
61
|
+
: timeLabel.minute.singular;
|
|
62
|
+
return {
|
|
63
|
+
template: timeTemplate,
|
|
64
|
+
params: {
|
|
65
|
+
time: String(minuteDiff || 1),
|
|
66
|
+
timeLabel: minuteUnit,
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
if (msDiff < MS_DAY) {
|
|
71
|
+
const hourDiff = msToHour(msDiff);
|
|
72
|
+
const hourUnit = hourDiff > 1
|
|
73
|
+
? timeLabel.hour.plural
|
|
74
|
+
: timeLabel.hour.singular;
|
|
75
|
+
return {
|
|
76
|
+
template: timeTemplate,
|
|
77
|
+
params: {
|
|
78
|
+
time: String(hourDiff),
|
|
79
|
+
timeLabel: hourUnit,
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
const monthLabel = monthLocaleLabels[dates.old.getMonth()];
|
|
84
|
+
const minute = formatMinuteString(dates.old.getMinutes());
|
|
85
|
+
const hour = formatHourString(dates.old.getHours());
|
|
86
|
+
const dayFormat = `${monthLabel} ${dates.old.getDate()}`;
|
|
87
|
+
const timeFormat = `${hour.time}:${minute.time} ${hour.period}`;
|
|
88
|
+
return {
|
|
89
|
+
template: fullDateTemplate,
|
|
90
|
+
params: {
|
|
91
|
+
date: `${dayFormat}, ${timeFormat}`,
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* The returned string follows the following rules:
|
|
97
|
+
* - If diff < 60 minutes: '29 min ago'
|
|
98
|
+
* - If diff >= 60 minutes & < 24 hours: '12 hours ago' | '1 hour ago'
|
|
99
|
+
* - If diff > 24 hours: 'on March 15, 14:45 pm'
|
|
100
|
+
*
|
|
101
|
+
* @param olderDate - Date
|
|
102
|
+
* @param recentDate - Date
|
|
103
|
+
* @param template - DiffTemplate
|
|
104
|
+
* @returns a preformated string to be inserted in a phrase.
|
|
105
|
+
*/
|
|
106
|
+
const getTimeDiffAsString = (olderDate, recentDate = new Date(), templateConfig = defaultEnglishTemplate) => {
|
|
107
|
+
const oldDateTime = olderDate.getTime();
|
|
108
|
+
const recentDateTime = recentDate.getTime();
|
|
109
|
+
if (oldDateTime > recentDateTime) {
|
|
110
|
+
return '';
|
|
111
|
+
}
|
|
112
|
+
const msDiff = recentDateTime - oldDateTime;
|
|
113
|
+
const { template, params } = getTemplatingParameters(msDiff, {
|
|
114
|
+
dates: {
|
|
115
|
+
old: olderDate,
|
|
116
|
+
recent: recentDate,
|
|
117
|
+
},
|
|
118
|
+
templateConfig,
|
|
119
|
+
});
|
|
120
|
+
return replaceInTemplate(template, params, TEMPLATE_CONFIG);
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
export { getTimeDiffAsString };
|
|
124
|
+
//# sourceMappingURL=get-time-diff-as-string.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-time-diff-as-string.js","sources":["../../src/date/get-time-diff-as-string.ts"],"sourcesContent":["import { ReplaceConfig, replaceInTemplate } from '../string';\nimport { MS_HOUR, MS_DAY } from './constants';\nimport { msToMinute, msToHour } from './convert';\n\nexport type MonthLocaleLabels = [\n string,\n string,\n string,\n string,\n string,\n string,\n string,\n string,\n string,\n string,\n string,\n string,\n];\n\nexport type DiffTemplate = {\n /**\n * e.g.: (\"%time% %timelabel% blabla\")\n */\n timeTemplate: string,\n /**\n * e.g.: \"%date% blabla\"\n */\n monthLocaleLabels: MonthLocaleLabels,\n fullDateTemplate: string,\n timeLabel: {\n minute: {\n singular: string,\n plural: string,\n },\n hour: {\n singular: string,\n plural: string,\n },\n }\n};\n\nconst defaultLocaleLabels: MonthLocaleLabels = [\n 'January',\n 'February',\n 'March',\n 'April',\n 'May',\n 'June',\n 'July',\n 'August',\n 'September',\n 'October',\n 'November',\n 'December',\n];\n\nconst defaultEnglishTemplate: DiffTemplate = {\n timeTemplate: '%time% %timeLabel% ago',\n fullDateTemplate: 'on %date%',\n monthLocaleLabels: defaultLocaleLabels,\n timeLabel: {\n minute: {\n singular: 'min',\n plural: 'min',\n },\n hour: {\n singular: 'hour',\n plural: 'hours',\n },\n },\n};\n\nconst TEMPLATE_CONFIG: ReplaceConfig = {\n delimiter: {\n left: '%',\n right: '%',\n },\n};\n\ntype HourFormat = {\n time: string,\n period: 'am' | 'pm';\n}\n\ntype MinuteFormat = {\n time: string,\n};\n\ntype DateForTemplate = {\n old: Date,\n recent: Date,\n};\n\ntype ParamForTemplateConfig = {\n templateConfig: DiffTemplate,\n dates: DateForTemplate,\n}\n\nconst formatMinuteString = (minute: number): MinuteFormat => {\n const str = minute.toString();\n\n return {\n time: str.length === 2 ? str : `0${str}`,\n };\n}\n\nconst formatHourString = (hour: number): HourFormat => {\n const period = hour < 12 ? 'am' : 'pm';\n const twelveHourTime = hour > 12 ? hour - 12 : hour;\n\n return {\n time: twelveHourTime === 0 ? '12' : twelveHourTime.toString(),\n period,\n }\n};\n\nconst getTemplatingParameters = (msDiff: number, config: ParamForTemplateConfig) => {\n const { dates, templateConfig } = config;\n const { timeLabel, monthLocaleLabels, timeTemplate, fullDateTemplate } = templateConfig;\n\n if (msDiff < MS_HOUR) {\n const minuteDiff = msToMinute(msDiff);\n const minuteUnit = minuteDiff > 1\n ? timeLabel.minute.plural\n : timeLabel.minute.singular;\n\n return {\n template: timeTemplate,\n params: {\n time: String(minuteDiff || 1),\n timeLabel: minuteUnit,\n },\n };\n }\n\n if (msDiff < MS_DAY) {\n const hourDiff = msToHour(msDiff);\n const hourUnit = hourDiff > 1\n ? timeLabel.hour.plural\n : timeLabel.hour.singular;\n\n return {\n template: timeTemplate,\n params: {\n time: String(hourDiff),\n timeLabel: hourUnit,\n },\n };\n }\n\n const monthLabel = monthLocaleLabels[dates.old.getMonth()];\n\n const minute = formatMinuteString(dates.old.getMinutes());\n const hour = formatHourString(dates.old.getHours());\n\n const dayFormat = `${monthLabel} ${dates.old.getDate()}`;\n const timeFormat = `${hour.time}:${minute.time} ${hour.period}`;\n\n return {\n template: fullDateTemplate,\n params: {\n date: `${dayFormat}, ${timeFormat}`,\n },\n };\n}\n\n/**\n * The returned string follows the following rules:\n * - If diff < 60 minutes: '29 min ago'\n * - If diff >= 60 minutes & < 24 hours: '12 hours ago' | '1 hour ago'\n * - If diff > 24 hours: 'on March 15, 14:45 pm'\n *\n * @param olderDate - Date\n * @param recentDate - Date\n * @param template - DiffTemplate\n * @returns a preformated string to be inserted in a phrase.\n */\nexport const getTimeDiffAsString = (olderDate: Date, recentDate = new Date(), templateConfig = defaultEnglishTemplate): string => {\n const oldDateTime = olderDate.getTime();\n const recentDateTime = recentDate.getTime();\n\n if (oldDateTime > recentDateTime) {\n return '';\n }\n\n const msDiff = recentDateTime - oldDateTime;\n const { template, params } = getTemplatingParameters(msDiff, {\n dates: {\n old: olderDate,\n recent: recentDate,\n },\n templateConfig,\n });\n\n return replaceInTemplate(template, params, TEMPLATE_C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AiB,CAAC,QAAQ,EAAE,MAAM,EAAE,eAAe,CAAC,CAAC;AAC9D;;;;"}
|
package/date/index.d.ts
ADDED
package/date/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const formatNumber: (n: number) => string;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const DECIMAL_SEPARATOR = '.';
|
|
2
|
+
const THOUSAND_UNIT = 'k';
|
|
3
|
+
const formatNumber = (n) => {
|
|
4
|
+
const numString = String(n);
|
|
5
|
+
if (n < 1000) {
|
|
6
|
+
return numString;
|
|
7
|
+
}
|
|
8
|
+
const decimalsMinusLast = numString.slice(0, numString.length - 3);
|
|
9
|
+
const lastDecimal = numString.slice(numString.length - 3, numString.length - 2);
|
|
10
|
+
return `${decimalsMinusLast}${DECIMAL_SEPARATOR}${lastDecimal}${THOUSAND_UNIT}`;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export { formatNumber };
|
|
14
|
+
//# sourceMappingURL=format-number.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format-number.js","sources":["../../src/formatting/format-number.ts"],"sourcesContent":["const DECIMAL_SEPARATOR = '.';\nconst THOUSAND_UNIT = 'k';\n\nexport const formatNumber = (n: number): string => {\n const numString = String(n);\n if (n < 1000) {\n return numString;\n }\n\n const decimalsMinusLast = numString.slice(0, numString.length - 3);\n const lastDecimal = numString.slice(numString.length - 3, numString.length - 2);\n\n return `${decimalsMinusLast}${DECIMAL_SEPARATOR}${lastDecimal}${THOUSAND_UNIT}`;\n};\n"],"names":[],"mappings":"AAAA,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAC9B,MAAM,aAAa,GAAG,GAAG,CAAC;AAEb,MAAA,YAAY,GAAG,CAAC,CAAS,KAAY;AAChD,IAAA,MAAM,SAAS,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IAC5B,IAAI,CAAC,GAAG,IAAI,EAAE;AACZ,QAAA,OAAO,SAAS,CAAC;AAClB,KAAA;AAED,IAAA,MAAM,iBAAiB,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AACnE,IAAA,MAAM,WAAW,GAAG,SAAS,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAEhF,OAAO,CAAA,EAAG,iBAAiB,CAAG,EAAA,iBAAiB,GAAG,WAAW,CAAA,EAAG,aAAa,CAAA,CAAE,CAAC;AAClF;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './format-number';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/fp/run-while.js
CHANGED
|
@@ -2,16 +2,15 @@
|
|
|
2
2
|
* Run the callback while the predicate return true. Throws an
|
|
3
3
|
* error if the iteration count exceeds the iteration limit.
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var shouldRun = predicate(currentValue);
|
|
5
|
+
const runWhile = ({ predicate, callback, initialValue, iterationLimit = Infinity }) => {
|
|
6
|
+
let counter = 0;
|
|
7
|
+
let currentValue = initialValue;
|
|
8
|
+
let shouldRun = predicate(currentValue);
|
|
10
9
|
while (shouldRun) {
|
|
11
10
|
if (counter >= iterationLimit) {
|
|
12
|
-
|
|
11
|
+
break;
|
|
13
12
|
}
|
|
14
|
-
|
|
13
|
+
const nextValue = callback(currentValue, counter);
|
|
15
14
|
counter += 1;
|
|
16
15
|
shouldRun = predicate(nextValue);
|
|
17
16
|
currentValue = nextValue;
|
package/fp/run-while.js.map
CHANGED
|
@@ -1 +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
|
|
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 break;\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;AACU,MAAA,QAAQ,GAAe,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,YAAY,EAAE,cAAc,GAAG,QAAQ,EAAE,KAAI;IACvG,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;YAC7B,MAAM;AACP,SAAA;QAED,MAAM,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;;;;"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { SearchObject } from '../types';
|
|
2
|
+
export declare type EncodingConfig = {
|
|
3
|
+
keyValueDelimiter: string;
|
|
4
|
+
pairDelimiter: string;
|
|
5
|
+
};
|
|
6
|
+
export declare const encodeSearchValue: <T extends Record<string, string>>(searchValue: T, config?: EncodingConfig) => string;
|
|
7
|
+
export declare const encodeSearchObject: (searchObject: SearchObject) => string;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const defaultEncodingConfig = {
|
|
2
|
+
keyValueDelimiter: ':',
|
|
3
|
+
pairDelimiter: '+',
|
|
4
|
+
};
|
|
5
|
+
const encodeSearchValue = (searchValue, config = defaultEncodingConfig) => {
|
|
6
|
+
const { pairDelimiter, keyValueDelimiter } = config;
|
|
7
|
+
return Object.entries(searchValue)
|
|
8
|
+
.map(([key, value]) => `${key}${keyValueDelimiter}${encodeURI(value)}`)
|
|
9
|
+
.join(pairDelimiter);
|
|
10
|
+
};
|
|
11
|
+
const encodeSearchObject = (searchObject) => {
|
|
12
|
+
const { sort, query, offset, limit } = searchObject;
|
|
13
|
+
const sortEncoded = sort ? encodeSearchValue(sort) : null;
|
|
14
|
+
const queryEncoded = query ? encodeSearchValue(query) : null;
|
|
15
|
+
const urlParams = new URLSearchParams({
|
|
16
|
+
offset: offset.toString(),
|
|
17
|
+
limit: limit.toString(),
|
|
18
|
+
});
|
|
19
|
+
if (sortEncoded)
|
|
20
|
+
urlParams.append('sort', sortEncoded);
|
|
21
|
+
if (queryEncoded)
|
|
22
|
+
urlParams.append('query', queryEncoded);
|
|
23
|
+
return urlParams.toString();
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export { encodeSearchObject, encodeSearchValue };
|
|
27
|
+
//# sourceMappingURL=encode-search-object.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encode-search-object.js","sources":["../../src/http/encode-search-object.ts"],"sourcesContent":["import { SearchObject } from '../types';\n\nexport type EncodingConfig = {\n keyValueDelimiter: string,\n pairDelimiter: string,\n};\n\nconst defaultEncodingConfig: EncodingConfig = {\n keyValueDelimiter: ':',\n pairDelimiter: '+',\n};\n\nexport const encodeSearchValue = <T extends Record<string, string>>(\n searchValue: T,\n config: EncodingConfig = defaultEncodingConfig,\n) => {\n const { pairDelimiter, keyValueDelimiter } = config;\n\n return Object.entries(searchValue)\n .map(([key, value]) => `${key}${keyValueDelimiter}${encodeURI(value)}`)\n .join(pairDelimiter);\n};\n\nexport const encodeSearchObject = (searchObject: SearchObject): string => {\n const { sort, query, offset, limit } = searchObject;\n\n const sortEncoded = sort ? encodeSearchValue(sort) : null;\n const queryEncoded = query ? encodeSearchValue(query) : null;\n\n const urlParams = new URLSearchParams({\n offset: offset.toString(),\n limit: limit.toString(),\n });\n\n if (sortEncoded) urlParams.append('sort', sortEncoded);\n if (queryEncoded) urlParams.append('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,EAAE,CAAC;AAC9B;;;;"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare type RequestInitWithTimeout = RequestInit & {
|
|
2
|
+
timeout?: number;
|
|
3
|
+
};
|
|
4
|
+
/**
|
|
5
|
+
* Use fetch to perform an HTTP request
|
|
6
|
+
* Add an optional timeout, that will abort the request if it has not returned before
|
|
7
|
+
*/
|
|
8
|
+
export declare const fetchWithTimeout: (input: RequestInfo, init?: Omit<RequestInitWithTimeout, 'signal'> | undefined) => Promise<Response>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { __rest } from '../_virtual/_tslib.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Use fetch to perform an HTTP request
|
|
5
|
+
* Add an optional timeout, that will abort the request if it has not returned before
|
|
6
|
+
*/
|
|
7
|
+
const fetchWithTimeout = (input, init) => {
|
|
8
|
+
const abortController = new AbortController();
|
|
9
|
+
const _a = init || {}, { timeout } = _a, rest = __rest(_a, ["timeout"]);
|
|
10
|
+
const params = Object.assign(Object.assign({}, rest), { signal: abortController.signal });
|
|
11
|
+
if (timeout !== undefined) {
|
|
12
|
+
setTimeout(() => abortController.abort(), timeout);
|
|
13
|
+
}
|
|
14
|
+
return fetch(input, params);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export { fetchWithTimeout };
|
|
18
|
+
//# sourceMappingURL=fetch-with-timeout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch-with-timeout.js","sources":["../../src/http/fetch-with-timeout.ts"],"sourcesContent":["export type RequestInitWithTimeout = RequestInit & {\n timeout?: number\n};\n\n/**\n * Use fetch to perform an HTTP request\n * Add an optional timeout, that will abort the request if it has not returned before\n */\nexport const fetchWithTimeout = (input: RequestInfo, init?: Omit<RequestInitWithTimeout, 'signal'> | undefined): Promise<Response> => {\n const abortController = new AbortController();\n\n const { timeout, ...rest } = init || {};\n\n const params = {\n ...rest,\n signal: abortController.signal,\n };\n\n if (timeout !== undefined) {\n setTimeout(() => abortController.abort(), timeout);\n }\n\n return fetch(input, params);\n};\n"],"names":[],"mappings":";;AAIA;;;AAGG;MACU,gBAAgB,GAAG,CAAC,KAAkB,EAAE,IAAyD,KAAuB;AACnI,IAAA,MAAM,eAAe,GAAG,IAAI,eAAe,EAAE,CAAC;AAE9C,IAAA,MAAM,EAAuB,GAAA,IAAI,IAAI,EAAE,EAAjC,EAAE,OAAO,EAAA,GAAA,EAAwB,EAAnB,IAAI,GAAlB,MAAA,CAAA,EAAA,EAAA,CAAA,SAAA,CAAoB,CAAa,CAAC;IAExC,MAAM,MAAM,GACP,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,EAAA,EAAA,IAAI,CACP,EAAA,EAAA,MAAM,EAAE,eAAe,CAAC,MAAM,EAAA,CAC/B,CAAC;IAEF,IAAI,OAAO,KAAK,SAAS,EAAE;QACzB,UAAU,CAAC,MAAM,eAAe,CAAC,KAAK,EAAE,EAAE,OAAO,CAAC,CAAC;AACpD,KAAA;AAED,IAAA,OAAO,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;AAC9B;;;;"}
|
package/http/index.d.ts
ADDED
package/http/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
export * from './array';
|
|
2
|
+
export * from './date';
|
|
3
|
+
export * from './formatting';
|
|
2
4
|
export * from './fp';
|
|
5
|
+
export * from './http';
|
|
6
|
+
export * from './linked-list';
|
|
7
|
+
export * from './math';
|
|
8
|
+
export * from './object';
|
|
3
9
|
export * from './parsing';
|
|
4
10
|
export * from './predicates';
|
|
5
11
|
export * from './promise';
|
package/index.js
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
export { arrayToMap } from './array/array-to-map.js';
|
|
2
2
|
export { valuesFromKeys } from './array/get-values-from-keys.js';
|
|
3
|
+
export { MS_DAY, MS_HOUR, MS_MINUTE, MS_SECOND } from './date/constants.js';
|
|
4
|
+
export { formatMinutes } from './date/format-minutes.js';
|
|
5
|
+
export { getTimeDiffAsString } from './date/get-time-diff-as-string.js';
|
|
6
|
+
export { formatNumber } from './formatting/format-number.js';
|
|
3
7
|
export { runWhile } from './fp/run-while.js';
|
|
8
|
+
export { encodeSearchObject, encodeSearchValue } from './http/encode-search-object.js';
|
|
9
|
+
export { fetchWithTimeout } from './http/fetch-with-timeout.js';
|
|
10
|
+
export { createLinkedList } from './linked-list/create-linked-list.js';
|
|
11
|
+
export { clampNumber } from './math/clamp-number.js';
|
|
12
|
+
export { interpolate } from './math/interpolate.js';
|
|
13
|
+
export { assertNumberRange, isNumberInRange } from './math/number-range.js';
|
|
14
|
+
export { randomNumber } from './math/random-number.js';
|
|
15
|
+
export { mergeDeep } from './object/merge-deep.js';
|
|
4
16
|
export { parseBoolean } from './parsing/parse-boolean.js';
|
|
5
17
|
export { createEnumParser } from './parsing/parse-enum.js';
|
|
6
18
|
export { parseNumber } from './parsing/parse-number.js';
|
|
@@ -11,5 +23,6 @@ export { isArrayOfPrimitive, isPrimitive } from './predicates/is-primitive.js';
|
|
|
11
23
|
export { isUndefined } from './predicates/is-undefined.js';
|
|
12
24
|
export { executeOrResolveDefault } from './promise/execute-or-resolve-default.js';
|
|
13
25
|
export { executeWithDelay } from './promise/execute-with-delay.js';
|
|
26
|
+
export { delay } from './promise/delay.js';
|
|
14
27
|
export { replaceInTemplate } from './string/replace-in-template.js';
|
|
15
28
|
//# sourceMappingURL=index.js.map
|
package/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":";;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const applyDiffLinkedList = (before, after, list) => {
|
|
2
|
+
// Delete
|
|
3
|
+
if (!after && before) {
|
|
4
|
+
return list.remove(before.id);
|
|
5
|
+
}
|
|
6
|
+
// Insert
|
|
7
|
+
if (!before && after) {
|
|
8
|
+
return list.insert(after);
|
|
9
|
+
}
|
|
10
|
+
// For the following commands, none of the 2 items can be null
|
|
11
|
+
// We dont use && because checks are already done above, but ts cannot infer that they cannot be null afterwards
|
|
12
|
+
if (!before || !after) {
|
|
13
|
+
throw new Error('Cannot have both before & after as null');
|
|
14
|
+
}
|
|
15
|
+
if (before.id !== after.id) {
|
|
16
|
+
throw new Error('Cannot change id of a ListNode');
|
|
17
|
+
}
|
|
18
|
+
const listWithPotentialReorder = before.nextId === after.nextId
|
|
19
|
+
? list
|
|
20
|
+
: list
|
|
21
|
+
.remove(before.id)
|
|
22
|
+
.insert(after);
|
|
23
|
+
return listWithPotentialReorder.update(after);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export { applyDiffLinkedList };
|
|
27
|
+
//# sourceMappingURL=apply-diff-linked-list.js.map
|