@sparted/shared-library 0.0.11 → 0.0.13
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 +88 -0
- package/_virtual/_tslib.js.map +1 -0
- package/array/array-to-map.d.ts +14 -0
- package/array/array-to-map.js +19 -0
- package/array/array-to-map.js.map +1 -0
- package/array/get-values-from-keys.d.ts +1 -0
- package/array/get-values-from-keys.js +6 -0
- package/array/get-values-from-keys.js.map +1 -0
- package/array/index.d.ts +2 -0
- package/array/index.js +3 -0
- package/array/index.js.map +1 -0
- 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 +126 -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/index.d.ts +1 -0
- package/fp/index.js +2 -0
- package/fp/index.js.map +1 -0
- package/fp/run-while.d.ts +31 -0
- package/fp/run-while.js +26 -0
- package/fp/run-while.js.map +1 -0
- package/http/encode-search-object.d.ts +7 -0
- package/http/encode-search-object.js +31 -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 +13 -0
- package/index.js +13 -0
- package/index.js.map +1 -0
- 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 +25 -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 +30 -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 +97 -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 +25 -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 +21 -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 +29 -0
- package/linked-list/while-linked-list.js.map +1 -0
- package/math/clamp-number.d.ts +2 -0
- package/math/clamp-number.js +10 -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 +13 -0
- package/math/number-range.js.map +1 -0
- package/math/random-number.d.ts +2 -0
- package/math/random-number.js +10 -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 +24 -0
- package/object/merge-deep.js.map +1 -0
- package/package.json +4 -2
- package/parsing/index.d.ts +3 -0
- package/parsing/index.js +4 -0
- package/parsing/index.js.map +1 -0
- package/parsing/parse-boolean.d.ts +4 -0
- package/parsing/parse-boolean.js +12 -0
- package/parsing/parse-boolean.js.map +1 -0
- package/parsing/parse-enum.d.ts +5 -0
- package/parsing/parse-enum.js +13 -0
- package/parsing/parse-enum.js.map +1 -0
- package/parsing/parse-number.d.ts +4 -0
- package/parsing/parse-number.js +13 -0
- package/parsing/parse-number.js.map +1 -0
- package/predicates/index.d.ts +5 -0
- package/predicates/index.js +6 -0
- package/predicates/index.js.map +1 -0
- package/predicates/is-function.d.ts +1 -0
- package/predicates/is-function.js +6 -0
- package/predicates/is-function.js.map +1 -0
- package/predicates/is-null.d.ts +1 -0
- package/predicates/is-null.js +6 -0
- package/predicates/is-null.js.map +1 -0
- package/predicates/is-object.d.ts +1 -0
- package/predicates/is-object.js +6 -0
- package/predicates/is-object.js.map +1 -0
- package/predicates/is-primitive.d.ts +3 -0
- package/predicates/is-primitive.js +17 -0
- package/predicates/is-primitive.js.map +1 -0
- package/predicates/is-undefined.d.ts +1 -0
- package/predicates/is-undefined.js +6 -0
- package/predicates/is-undefined.js.map +1 -0
- 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.d.ts +5 -0
- package/promise/execute-or-resolve-default.js +10 -0
- package/promise/execute-or-resolve-default.js.map +1 -0
- package/promise/execute-with-delay.d.ts +1 -0
- package/promise/execute-with-delay.js +16 -0
- package/promise/execute-with-delay.js.map +1 -0
- package/promise/index.d.ts +3 -0
- package/promise/index.js +4 -0
- package/promise/index.js.map +1 -0
- package/string/index.d.ts +1 -0
- package/string/index.js +2 -0
- package/string/index.js.map +1 -0
- package/string/replace-in-template.d.ts +14 -0
- package/string/replace-in-template.js +35 -0
- package/string/replace-in-template.js.map +1 -0
- package/types/function.d.ts +1 -0
- package/types/general.d.ts +3 -0
- package/types/index.d.ts +4 -0
- package/types/index.js +2 -0
- package/types/index.js.map +1 -0
- package/types/object.d.ts +35 -0
- package/types/search.d.ts +24 -0
|
@@ -0,0 +1,88 @@
|
|
|
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 __rest(s, e) {
|
|
28
|
+
var t = {};
|
|
29
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
30
|
+
t[p] = s[p];
|
|
31
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
32
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
33
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
34
|
+
t[p[i]] = s[p[i]];
|
|
35
|
+
}
|
|
36
|
+
return t;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
40
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
41
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
42
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
43
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
44
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
45
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function __generator(thisArg, body) {
|
|
50
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
51
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
52
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
53
|
+
function step(op) {
|
|
54
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
55
|
+
while (_) try {
|
|
56
|
+
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;
|
|
57
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
58
|
+
switch (op[0]) {
|
|
59
|
+
case 0: case 1: t = op; break;
|
|
60
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
61
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
62
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
63
|
+
default:
|
|
64
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
65
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
66
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
67
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
68
|
+
if (t[2]) _.ops.pop();
|
|
69
|
+
_.trys.pop(); continue;
|
|
70
|
+
}
|
|
71
|
+
op = body.call(thisArg, _);
|
|
72
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
73
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function __spreadArray(to, from, pack) {
|
|
78
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
79
|
+
if (ar || !(i in from)) {
|
|
80
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
81
|
+
ar[i] = from[i];
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export { __assign, __awaiter, __generator, __rest, __spreadArray };
|
|
88
|
+
//# 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 @@
|
|
|
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;;;;"}
|
package/array/index.d.ts
ADDED
package/array/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -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,IAAM,SAAS,GAAG,KAAK;AACjB,IAAA,SAAS,GAAG,SAAS,GAAG,GAAG;AAC3B,IAAA,OAAO,GAAG,SAAS,GAAG,GAAG;AACzB,IAAA,MAAM,GAAG,OAAO,GAAG;;;;"}
|
package/date/convert.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { MS_MINUTE, MS_HOUR } from './constants.js';
|
|
2
|
+
|
|
3
|
+
var msToMinute = function (ms) { return Math.floor(ms / MS_MINUTE); };
|
|
4
|
+
var msToHour = function (ms) { return Math.floor(ms / MS_HOUR); };
|
|
5
|
+
|
|
6
|
+
export { msToHour, msToMinute };
|
|
7
|
+
//# sourceMappingURL=convert.js.map
|
|
@@ -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,IAAA,UAAU,GAAG,UAAC,EAAU,IAAK,OAAA,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,SAAS,CAAC,CAAA,GAAC;AAExD,IAAA,QAAQ,GAAG,UAAC,EAAU,IAAK,OAAA,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,OAAO,CAAC,CAAA;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const formatMinutes: (timeInMin: number) => string;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
var formatMinutes = function (timeInMin) {
|
|
2
|
+
var hours = Math.floor(timeInMin / 60);
|
|
3
|
+
var mins = Math.round(timeInMin % 60);
|
|
4
|
+
if (hours === 0)
|
|
5
|
+
return "".concat(mins, "min");
|
|
6
|
+
if (mins === 0)
|
|
7
|
+
return "".concat(hours, "h");
|
|
8
|
+
return "".concat(hours, "h").concat(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":"AAAO,IAAM,aAAa,GAAG,UAAC,SAAiB,EAAA;IAC7C,IAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,GAAG,EAAE,CAAC,CAAC;IACzC,IAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,GAAG,EAAE,CAAC,CAAC;IAExC,IAAI,KAAK,KAAK,CAAC;QAAE,OAAO,EAAA,CAAA,MAAA,CAAG,IAAI,EAAA,KAAA,CAAK,CAAC;IACrC,IAAI,IAAI,KAAK,CAAC;QAAE,OAAO,EAAA,CAAA,MAAA,CAAG,KAAK,EAAA,GAAA,CAAG,CAAC;AAEnC,IAAA,OAAO,EAAG,CAAA,MAAA,CAAA,KAAK,EAAI,GAAA,CAAA,CAAA,MAAA,CAAA,IAAI,QAAK,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,126 @@
|
|
|
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
|
+
var 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
|
+
var 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
|
+
var TEMPLATE_CONFIG = {
|
|
35
|
+
delimiter: {
|
|
36
|
+
left: '%',
|
|
37
|
+
right: '%',
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
var formatMinuteString = function (minute) {
|
|
41
|
+
var str = minute.toString();
|
|
42
|
+
return {
|
|
43
|
+
time: str.length === 2 ? str : "0".concat(str),
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
var formatHourString = function (hour) {
|
|
47
|
+
var period = hour < 12 ? 'am' : 'pm';
|
|
48
|
+
var twelveHourTime = hour > 12 ? hour - 12 : hour;
|
|
49
|
+
return {
|
|
50
|
+
time: twelveHourTime === 0 ? '12' : twelveHourTime.toString(),
|
|
51
|
+
period: period,
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
var getTemplatingParameters = function (msDiff, config) {
|
|
55
|
+
var dates = config.dates, templateConfig = config.templateConfig;
|
|
56
|
+
var timeLabel = templateConfig.timeLabel, monthLocaleLabels = templateConfig.monthLocaleLabels, timeTemplate = templateConfig.timeTemplate, fullDateTemplate = templateConfig.fullDateTemplate;
|
|
57
|
+
if (msDiff < MS_HOUR) {
|
|
58
|
+
var minuteDiff = msToMinute(msDiff);
|
|
59
|
+
var 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
|
+
var hourDiff = msToHour(msDiff);
|
|
72
|
+
var 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
|
+
var monthLabel = monthLocaleLabels[dates.old.getMonth()];
|
|
84
|
+
var minute = formatMinuteString(dates.old.getMinutes());
|
|
85
|
+
var hour = formatHourString(dates.old.getHours());
|
|
86
|
+
var dayFormat = "".concat(monthLabel, " ").concat(dates.old.getDate());
|
|
87
|
+
var timeFormat = "".concat(hour.time, ":").concat(minute.time, " ").concat(hour.period);
|
|
88
|
+
return {
|
|
89
|
+
template: fullDateTemplate,
|
|
90
|
+
params: {
|
|
91
|
+
date: "".concat(dayFormat, ", ").concat(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
|
+
var getTimeDiffAsString = function (olderDate, recentDate, templateConfig) {
|
|
107
|
+
if (recentDate === void 0) { recentDate = new Date(); }
|
|
108
|
+
if (templateConfig === void 0) { templateConfig = defaultEnglishTemplate; }
|
|
109
|
+
var oldDateTime = olderDate.getTime();
|
|
110
|
+
var recentDateTime = recentDate.getTime();
|
|
111
|
+
if (oldDateTime > recentDateTime) {
|
|
112
|
+
return '';
|
|
113
|
+
}
|
|
114
|
+
var msDiff = recentDateTime - oldDateTime;
|
|
115
|
+
var _a = getTemplatingParameters(msDiff, {
|
|
116
|
+
dates: {
|
|
117
|
+
old: olderDate,
|
|
118
|
+
recent: recentDate,
|
|
119
|
+
},
|
|
120
|
+
templateConfig: templateConfig,
|
|
121
|
+
}), template = _a.template, params = _a.params;
|
|
122
|
+
return replaceInTemplate(template, params, TEMPLATE_CONFIG);
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
export { getTimeDiffAsString };
|
|
126
|
+
//# 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_CONFIG);\n};\n"],"names":[],"mappings":";;;;AAyCA,IAAM,mBAAmB,GAAsB;IAC7C,SAAS;IACT,UAAU;IACV,OAAO;IACP,OAAO;IACP,KAAK;IACL,MAAM;IACN,MAAM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AA,EAAuB,GAAA,uBAAuB,CAAC,MAAM,EAAE;AAC3D,QAAA,KAAK,EAAE;AACL,YAAA,GAAG,EAAE,SAAS;AACd,YAAA,MAAM,EAAE,UAAU;AACnB,SAAA;AACD,QAAA,cAAc,EAAA,cAAA;AACf,KAAA,CAAC,EANM,QAAQ,GAAA,EAAA,CAAA,QAAA,EAAE,MAAM,YAMtB,CAAC;IAEH,OAAO,iBAAiB,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
|
+
var DECIMAL_SEPARATOR = '.';
|
|
2
|
+
var THOUSAND_UNIT = 'k';
|
|
3
|
+
var formatNumber = function (n) {
|
|
4
|
+
var numString = String(n);
|
|
5
|
+
if (n < 1000) {
|
|
6
|
+
return numString;
|
|
7
|
+
}
|
|
8
|
+
var decimalsMinusLast = numString.slice(0, numString.length - 3);
|
|
9
|
+
var lastDecimal = numString.slice(numString.length - 3, numString.length - 2);
|
|
10
|
+
return "".concat(decimalsMinusLast).concat(DECIMAL_SEPARATOR).concat(lastDecimal).concat(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,IAAM,iBAAiB,GAAG,GAAG,CAAC;AAC9B,IAAM,aAAa,GAAG,GAAG,CAAC;AAEnB,IAAM,YAAY,GAAG,UAAC,CAAS,EAAA;AACpC,IAAA,IAAM,SAAS,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IAC5B,IAAI,CAAC,GAAG,IAAI,EAAE;AACZ,QAAA,OAAO,SAAS,CAAC;AAClB,KAAA;AAED,IAAA,IAAM,iBAAiB,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AACnE,IAAA,IAAM,WAAW,GAAG,SAAS,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAEhF,OAAO,EAAA,CAAA,MAAA,CAAG,iBAAiB,CAAG,CAAA,MAAA,CAAA,iBAAiB,SAAG,WAAW,CAAA,CAAA,MAAA,CAAG,aAAa,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/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './run-while';
|
package/fp/index.js
ADDED
package/fp/index.js.map
ADDED
|
@@ -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;
|
package/fp/run-while.js
ADDED
|
@@ -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
|
+
break;
|
|
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 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;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;YAC7B,MAAM;AACP,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;;;;"}
|
|
@@ -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,31 @@
|
|
|
1
|
+
var defaultEncodingConfig = {
|
|
2
|
+
keyValueDelimiter: ':',
|
|
3
|
+
pairDelimiter: '+',
|
|
4
|
+
};
|
|
5
|
+
var encodeSearchValue = function (searchValue, config) {
|
|
6
|
+
if (config === void 0) { config = defaultEncodingConfig; }
|
|
7
|
+
var pairDelimiter = config.pairDelimiter, keyValueDelimiter = config.keyValueDelimiter;
|
|
8
|
+
return Object.entries(searchValue)
|
|
9
|
+
.map(function (_a) {
|
|
10
|
+
var key = _a[0], value = _a[1];
|
|
11
|
+
return "".concat(key).concat(keyValueDelimiter).concat(encodeURI(value));
|
|
12
|
+
})
|
|
13
|
+
.join(pairDelimiter);
|
|
14
|
+
};
|
|
15
|
+
var encodeSearchObject = function (searchObject) {
|
|
16
|
+
var sort = searchObject.sort, query = searchObject.query, offset = searchObject.offset, limit = searchObject.limit;
|
|
17
|
+
var sortEncoded = sort ? encodeSearchValue(sort) : null;
|
|
18
|
+
var queryEncoded = query ? encodeSearchValue(query) : null;
|
|
19
|
+
var urlParams = new URLSearchParams({
|
|
20
|
+
offset: offset.toString(),
|
|
21
|
+
limit: limit.toString(),
|
|
22
|
+
});
|
|
23
|
+
if (sortEncoded)
|
|
24
|
+
urlParams.append('sort', sortEncoded);
|
|
25
|
+
if (queryEncoded)
|
|
26
|
+
urlParams.append('query', queryEncoded);
|
|
27
|
+
return urlParams.toString();
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export { encodeSearchObject, encodeSearchValue };
|
|
31
|
+
//# 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('query', queryEncoded);\n\n return urlParams.toString();\n};\n"],"names":[],"mappings":"AAOA,IAAM,qBAAqB,GAAmB;AAC5C,IAAA,iBAAiB,EAAE,GAAG;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AA,SAAS,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;AACvD,IAAA,IAAI,YAAY;AAAE,QAAA,SAAS,CAAC,MAAM,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;AAE1D,IAAA,OAAO,SAAS,CAAC,QAAQ,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, __assign } 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
|
+
var fetchWithTimeout = function (input, init) {
|
|
8
|
+
var abortController = new AbortController();
|
|
9
|
+
var _a = init || {}, timeout = _a.timeout, rest = __rest(_a, ["timeout"]);
|
|
10
|
+
var params = __assign(__assign({}, rest), { signal: abortController.signal });
|
|
11
|
+
if (timeout !== undefined) {
|
|
12
|
+
setTimeout(function () { return 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;AACU,IAAA,gBAAgB,GAAG,UAAC,KAAkB,EAAE,IAAyD,EAAA;AAC5G,IAAA,IAAM,eAAe,GAAG,IAAI,eAAe,EAAE,CAAC;AAE9C,IAAA,IAAM,EAAuB,GAAA,IAAI,IAAI,EAAE,EAA/B,OAAO,GAAA,EAAA,CAAA,OAAA,EAAK,IAAI,GAAA,MAAA,CAAA,EAAA,EAAlB,CAAoB,SAAA,CAAA,CAAa,CAAC;IAExC,IAAM,MAAM,GACP,QAAA,CAAA,QAAA,CAAA,EAAA,EAAA,IAAI,CACP,EAAA,EAAA,MAAM,EAAE,eAAe,CAAC,MAAM,EAAA,CAC/B,CAAC;IAEF,IAAI,OAAO,KAAK,SAAS,EAAE;AACzB,QAAA,UAAU,CAAC,YAAA,EAAM,OAAA,eAAe,CAAC,KAAK,EAAE,CAAA,EAAA,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":";"}
|