@sparted/shared-library 0.0.13 → 0.0.15
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 +6 -50
- package/_virtual/_tslib.js.map +1 -1
- package/array/array-to-map.js +10 -9
- package/array/array-to-map.js.map +1 -1
- package/array/get-values-from-keys.js +7 -3
- package/array/get-values-from-keys.js.map +1 -1
- package/array/index.js +11 -2
- package/array/index.js.map +1 -1
- package/date/constants.js +12 -5
- package/date/constants.js.map +1 -1
- package/date/convert.js +9 -4
- package/date/convert.js.map +1 -1
- package/date/format-minutes.js +11 -7
- package/date/format-minutes.js.map +1 -1
- package/date/get-time-diff-as-string.js +41 -39
- package/date/get-time-diff-as-string.js.map +1 -1
- package/date/index.js +16 -3
- package/date/index.js.map +1 -1
- package/formatting/format-number.js +12 -8
- package/formatting/format-number.js.map +1 -1
- package/formatting/index.js +9 -1
- package/formatting/index.js.map +1 -1
- package/fp/index.js +9 -1
- package/fp/index.js.map +1 -1
- package/fp/run-while.js +10 -7
- package/fp/run-while.js.map +1 -1
- package/http/encode-search-object.js +15 -14
- package/http/encode-search-object.js.map +1 -1
- package/http/fetch-with-timeout.js +11 -7
- package/http/fetch-with-timeout.js.map +1 -1
- package/http/index.js +12 -2
- package/http/index.js.map +1 -1
- package/index.js +67 -27
- package/index.js.map +1 -1
- package/linked-list/apply-diff-linked-list.js +7 -3
- package/linked-list/apply-diff-linked-list.js.map +1 -1
- package/linked-list/create-linked-list.js +38 -34
- package/linked-list/create-linked-list.js.map +1 -1
- package/linked-list/find-linked-list.js +8 -5
- package/linked-list/find-linked-list.js.map +1 -1
- package/linked-list/get-linked-list.js +6 -2
- package/linked-list/get-linked-list.js.map +1 -1
- package/linked-list/index.js +9 -1
- package/linked-list/index.js.map +1 -1
- package/linked-list/insert-linked-list.js +22 -20
- package/linked-list/insert-linked-list.js.map +1 -1
- package/linked-list/linked-list-utils.js +36 -29
- package/linked-list/linked-list-utils.js.map +1 -1
- package/linked-list/reduce-linked-list.js +11 -7
- package/linked-list/reduce-linked-list.js.map +1 -1
- package/linked-list/remove-linked-list.js +19 -16
- package/linked-list/remove-linked-list.js.map +1 -1
- package/linked-list/update-linked-list.js +13 -10
- package/linked-list/update-linked-list.js.map +1 -1
- package/linked-list/while-linked-list.js +10 -7
- package/linked-list/while-linked-list.js.map +1 -1
- package/math/clamp-number.js +8 -5
- package/math/clamp-number.js.map +1 -1
- package/math/index.js +16 -4
- package/math/index.js.map +1 -1
- package/math/interpolate.js +11 -7
- package/math/interpolate.js.map +1 -1
- package/math/number-range.js +9 -5
- package/math/number-range.js.map +1 -1
- package/math/random-number.js +8 -5
- package/math/random-number.js.map +1 -1
- package/object/index.js +9 -1
- package/object/index.js.map +1 -1
- package/object/merge-deep.js +10 -9
- package/object/merge-deep.js.map +1 -1
- package/package.json +1 -1
- package/parsing/index.js +13 -3
- package/parsing/index.js.map +1 -1
- package/parsing/parse-boolean.js +6 -2
- package/parsing/parse-boolean.js.map +1 -1
- package/parsing/parse-enum.js +8 -4
- package/parsing/parse-enum.js.map +1 -1
- package/parsing/parse-number.js +7 -3
- package/parsing/parse-number.js.map +1 -1
- package/predicates/index.js +18 -5
- package/predicates/index.js.map +1 -1
- package/predicates/is-function.js +6 -2
- package/predicates/is-function.js.map +1 -1
- package/predicates/is-null.js +6 -2
- package/predicates/is-null.js.map +1 -1
- package/predicates/is-object.js +6 -2
- package/predicates/is-object.js.map +1 -1
- package/predicates/is-primitive.js +10 -5
- package/predicates/is-primitive.js.map +1 -1
- package/predicates/is-undefined.js +6 -2
- package/predicates/is-undefined.js.map +1 -1
- package/promise/delay.js +7 -3
- package/promise/delay.js.map +1 -1
- package/promise/execute-or-resolve-default.js +7 -3
- package/promise/execute-or-resolve-default.js.map +1 -1
- package/promise/execute-with-delay.js +11 -13
- package/promise/execute-with-delay.js.map +1 -1
- package/promise/index.js +13 -3
- package/promise/index.js.map +1 -1
- package/string/index.js +9 -1
- package/string/index.js.map +1 -1
- package/string/replace-in-template.js +15 -13
- package/string/replace-in-template.js.map +1 -1
- package/types/index.js +1 -0
- package/types/index.js.map +1 -1
package/_virtual/_tslib.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
1
5
|
/******************************************************************************
|
|
2
6
|
Copyright (c) Microsoft Corporation.
|
|
3
7
|
|
|
@@ -13,17 +17,6 @@ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
13
17
|
PERFORMANCE OF THIS SOFTWARE.
|
|
14
18
|
***************************************************************************** */
|
|
15
19
|
|
|
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
20
|
function __rest(s, e) {
|
|
28
21
|
var t = {};
|
|
29
22
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
@@ -44,45 +37,8 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
44
37
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
45
38
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
46
39
|
});
|
|
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
40
|
}
|
|
86
41
|
|
|
87
|
-
|
|
42
|
+
exports.__awaiter = __awaiter;
|
|
43
|
+
exports.__rest = __rest;
|
|
88
44
|
//# 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,19 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* Transform an array to a map.
|
|
5
7
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
return array.reduce(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var value = options.dataModifier
|
|
8
|
+
const arrayToMap = (array, options) => {
|
|
9
|
+
const { selectKey } = options;
|
|
10
|
+
return array.reduce((acc, current) => {
|
|
11
|
+
const key = selectKey(current);
|
|
12
|
+
const value = options.dataModifier
|
|
12
13
|
? options.dataModifier(current)
|
|
13
14
|
: current;
|
|
14
|
-
return
|
|
15
|
+
return Object.assign(Object.assign({}, acc), { [key]: value });
|
|
15
16
|
}, {});
|
|
16
17
|
};
|
|
17
18
|
|
|
18
|
-
|
|
19
|
+
exports.arrayToMap = arrayToMap;
|
|
19
20
|
//# sourceMappingURL=array-to-map.js.map
|
|
@@ -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,6 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const valuesFromKeys = (keys, map) => {
|
|
6
|
+
return keys.map((key) => map[key]);
|
|
3
7
|
};
|
|
4
8
|
|
|
5
|
-
|
|
9
|
+
exports.valuesFromKeys = valuesFromKeys;
|
|
6
10
|
//# sourceMappingURL=get-values-from-keys.js.map
|
|
@@ -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;;;;"}
|
package/array/index.js
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var arrayToMap = require('./array-to-map.js');
|
|
6
|
+
var getValuesFromKeys = require('./get-values-from-keys.js');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
exports.arrayToMap = arrayToMap.arrayToMap;
|
|
11
|
+
exports.valuesFromKeys = getValuesFromKeys.valuesFromKeys;
|
|
3
12
|
//# sourceMappingURL=index.js.map
|
package/array/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":";;;;;;;;;;"}
|
package/date/constants.js
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
var MS_MINUTE = MS_SECOND * 60;
|
|
3
|
-
var MS_HOUR = MS_MINUTE * 60;
|
|
4
|
-
var MS_DAY = MS_HOUR * 24;
|
|
1
|
+
'use strict';
|
|
5
2
|
|
|
6
|
-
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const MS_SECOND = 1000;
|
|
6
|
+
const MS_MINUTE = MS_SECOND * 60;
|
|
7
|
+
const MS_HOUR = MS_MINUTE * 60;
|
|
8
|
+
const MS_DAY = MS_HOUR * 24;
|
|
9
|
+
|
|
10
|
+
exports.MS_DAY = MS_DAY;
|
|
11
|
+
exports.MS_HOUR = MS_HOUR;
|
|
12
|
+
exports.MS_MINUTE = MS_MINUTE;
|
|
13
|
+
exports.MS_SECOND = MS_SECOND;
|
|
7
14
|
//# sourceMappingURL=constants.js.map
|
package/date/constants.js.map
CHANGED
|
@@ -1 +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,
|
|
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
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
var msToHour = function (ms) { return Math.floor(ms / MS_HOUR); };
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
var constants = require('./constants.js');
|
|
6
|
+
|
|
7
|
+
const msToMinute = (ms) => Math.floor(ms / constants.MS_MINUTE);
|
|
8
|
+
const msToHour = (ms) => Math.floor(ms / constants.MS_HOUR);
|
|
9
|
+
|
|
10
|
+
exports.msToHour = msToHour;
|
|
11
|
+
exports.msToMinute = msToMinute;
|
|
7
12
|
//# sourceMappingURL=convert.js.map
|
package/date/convert.js.map
CHANGED
|
@@ -1 +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":"
|
|
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":["MS_MINUTE","MS_HOUR"],"mappings":";;;;;;AAEa,MAAA,UAAU,GAAG,CAAC,EAAU,KAAK,IAAI,CAAC,KAAK,CAAC,EAAE,GAAGA,mBAAS,EAAE;AAExD,MAAA,QAAQ,GAAG,CAAC,EAAU,KAAK,IAAI,CAAC,KAAK,CAAC,EAAE,GAAGC,iBAAO;;;;;"}
|
package/date/format-minutes.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const formatMinutes = (timeInMin) => {
|
|
6
|
+
const hours = Math.floor(timeInMin / 60);
|
|
7
|
+
const mins = Math.round(timeInMin % 60);
|
|
4
8
|
if (hours === 0)
|
|
5
|
-
return
|
|
9
|
+
return `${mins}min`;
|
|
6
10
|
if (mins === 0)
|
|
7
|
-
return
|
|
8
|
-
return
|
|
11
|
+
return `${hours}h`;
|
|
12
|
+
return `${hours}h${mins}min`;
|
|
9
13
|
};
|
|
10
14
|
|
|
11
|
-
|
|
15
|
+
exports.formatMinutes = formatMinutes;
|
|
12
16
|
//# sourceMappingURL=format-minutes.js.map
|
|
@@ -1 +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":"
|
|
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;;;;"}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
import { MS_HOUR, MS_DAY } from './constants.js';
|
|
3
|
-
import { msToMinute, msToHour } from './convert.js';
|
|
1
|
+
'use strict';
|
|
4
2
|
|
|
5
|
-
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var replaceInTemplate = require('../string/replace-in-template.js');
|
|
6
|
+
var constants = require('./constants.js');
|
|
7
|
+
var convert = require('./convert.js');
|
|
8
|
+
|
|
9
|
+
const defaultLocaleLabels = [
|
|
6
10
|
'January',
|
|
7
11
|
'February',
|
|
8
12
|
'March',
|
|
@@ -16,7 +20,7 @@ var defaultLocaleLabels = [
|
|
|
16
20
|
'November',
|
|
17
21
|
'December',
|
|
18
22
|
];
|
|
19
|
-
|
|
23
|
+
const defaultEnglishTemplate = {
|
|
20
24
|
timeTemplate: '%time% %timeLabel% ago',
|
|
21
25
|
fullDateTemplate: 'on %date%',
|
|
22
26
|
monthLocaleLabels: defaultLocaleLabels,
|
|
@@ -31,32 +35,32 @@ var defaultEnglishTemplate = {
|
|
|
31
35
|
},
|
|
32
36
|
},
|
|
33
37
|
};
|
|
34
|
-
|
|
38
|
+
const TEMPLATE_CONFIG = {
|
|
35
39
|
delimiter: {
|
|
36
40
|
left: '%',
|
|
37
41
|
right: '%',
|
|
38
42
|
},
|
|
39
43
|
};
|
|
40
|
-
|
|
41
|
-
|
|
44
|
+
const formatMinuteString = (minute) => {
|
|
45
|
+
const str = minute.toString();
|
|
42
46
|
return {
|
|
43
|
-
time: str.length === 2 ? str :
|
|
47
|
+
time: str.length === 2 ? str : `0${str}`,
|
|
44
48
|
};
|
|
45
49
|
};
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
50
|
+
const formatHourString = (hour) => {
|
|
51
|
+
const period = hour < 12 ? 'am' : 'pm';
|
|
52
|
+
const twelveHourTime = hour > 12 ? hour - 12 : hour;
|
|
49
53
|
return {
|
|
50
54
|
time: twelveHourTime === 0 ? '12' : twelveHourTime.toString(),
|
|
51
|
-
period
|
|
55
|
+
period,
|
|
52
56
|
};
|
|
53
57
|
};
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if (msDiff < MS_HOUR) {
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
const getTemplatingParameters = (msDiff, config) => {
|
|
59
|
+
const { dates, templateConfig } = config;
|
|
60
|
+
const { timeLabel, monthLocaleLabels, timeTemplate, fullDateTemplate } = templateConfig;
|
|
61
|
+
if (msDiff < constants.MS_HOUR) {
|
|
62
|
+
const minuteDiff = convert.msToMinute(msDiff);
|
|
63
|
+
const minuteUnit = minuteDiff > 1
|
|
60
64
|
? timeLabel.minute.plural
|
|
61
65
|
: timeLabel.minute.singular;
|
|
62
66
|
return {
|
|
@@ -67,9 +71,9 @@ var getTemplatingParameters = function (msDiff, config) {
|
|
|
67
71
|
},
|
|
68
72
|
};
|
|
69
73
|
}
|
|
70
|
-
if (msDiff < MS_DAY) {
|
|
71
|
-
|
|
72
|
-
|
|
74
|
+
if (msDiff < constants.MS_DAY) {
|
|
75
|
+
const hourDiff = convert.msToHour(msDiff);
|
|
76
|
+
const hourUnit = hourDiff > 1
|
|
73
77
|
? timeLabel.hour.plural
|
|
74
78
|
: timeLabel.hour.singular;
|
|
75
79
|
return {
|
|
@@ -80,15 +84,15 @@ var getTemplatingParameters = function (msDiff, config) {
|
|
|
80
84
|
},
|
|
81
85
|
};
|
|
82
86
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
87
|
+
const monthLabel = monthLocaleLabels[dates.old.getMonth()];
|
|
88
|
+
const minute = formatMinuteString(dates.old.getMinutes());
|
|
89
|
+
const hour = formatHourString(dates.old.getHours());
|
|
90
|
+
const dayFormat = `${monthLabel} ${dates.old.getDate()}`;
|
|
91
|
+
const timeFormat = `${hour.time}:${minute.time} ${hour.period}`;
|
|
88
92
|
return {
|
|
89
93
|
template: fullDateTemplate,
|
|
90
94
|
params: {
|
|
91
|
-
date:
|
|
95
|
+
date: `${dayFormat}, ${timeFormat}`,
|
|
92
96
|
},
|
|
93
97
|
};
|
|
94
98
|
};
|
|
@@ -103,24 +107,22 @@ var getTemplatingParameters = function (msDiff, config) {
|
|
|
103
107
|
* @param template - DiffTemplate
|
|
104
108
|
* @returns a preformated string to be inserted in a phrase.
|
|
105
109
|
*/
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
var oldDateTime = olderDate.getTime();
|
|
110
|
-
var recentDateTime = recentDate.getTime();
|
|
110
|
+
const getTimeDiffAsString = (olderDate, recentDate = new Date(), templateConfig = defaultEnglishTemplate) => {
|
|
111
|
+
const oldDateTime = olderDate.getTime();
|
|
112
|
+
const recentDateTime = recentDate.getTime();
|
|
111
113
|
if (oldDateTime > recentDateTime) {
|
|
112
114
|
return '';
|
|
113
115
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
+
const msDiff = recentDateTime - oldDateTime;
|
|
117
|
+
const { template, params } = getTemplatingParameters(msDiff, {
|
|
116
118
|
dates: {
|
|
117
119
|
old: olderDate,
|
|
118
120
|
recent: recentDate,
|
|
119
121
|
},
|
|
120
|
-
templateConfig
|
|
121
|
-
})
|
|
122
|
-
return replaceInTemplate(template, params, TEMPLATE_CONFIG);
|
|
122
|
+
templateConfig,
|
|
123
|
+
});
|
|
124
|
+
return replaceInTemplate.replaceInTemplate(template, params, TEMPLATE_CONFIG);
|
|
123
125
|
};
|
|
124
126
|
|
|
125
|
-
|
|
127
|
+
exports.getTimeDiffAsString = getTimeDiffAsString;
|
|
126
128
|
//# sourceMappingURL=get-time-diff-as-string.js.map
|
|
@@ -1 +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":"
|
|
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":["MS_HOUR","msToMinute","MS_DAY","msToHour","replaceInTemplate"],"mappings":"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"}
|
package/date/index.js
CHANGED
|
@@ -1,4 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var constants = require('./constants.js');
|
|
6
|
+
var formatMinutes = require('./format-minutes.js');
|
|
7
|
+
var getTimeDiffAsString = require('./get-time-diff-as-string.js');
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
exports.MS_DAY = constants.MS_DAY;
|
|
12
|
+
exports.MS_HOUR = constants.MS_HOUR;
|
|
13
|
+
exports.MS_MINUTE = constants.MS_MINUTE;
|
|
14
|
+
exports.MS_SECOND = constants.MS_SECOND;
|
|
15
|
+
exports.formatMinutes = formatMinutes.formatMinutes;
|
|
16
|
+
exports.getTimeDiffAsString = getTimeDiffAsString.getTimeDiffAsString;
|
|
4
17
|
//# sourceMappingURL=index.js.map
|
package/date/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,14 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const DECIMAL_SEPARATOR = '.';
|
|
6
|
+
const THOUSAND_UNIT = 'k';
|
|
7
|
+
const formatNumber = (n) => {
|
|
8
|
+
const numString = String(n);
|
|
5
9
|
if (n < 1000) {
|
|
6
10
|
return numString;
|
|
7
11
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return
|
|
12
|
+
const decimalsMinusLast = numString.slice(0, numString.length - 3);
|
|
13
|
+
const lastDecimal = numString.slice(numString.length - 3, numString.length - 2);
|
|
14
|
+
return `${decimalsMinusLast}${DECIMAL_SEPARATOR}${lastDecimal}${THOUSAND_UNIT}`;
|
|
11
15
|
};
|
|
12
16
|
|
|
13
|
-
|
|
17
|
+
exports.formatNumber = formatNumber;
|
|
14
18
|
//# sourceMappingURL=format-number.js.map
|
|
@@ -1 +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,
|
|
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;;;;"}
|
package/formatting/index.js
CHANGED
|
@@ -1,2 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var formatNumber = require('./format-number.js');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
exports.formatNumber = formatNumber.formatNumber;
|
|
2
10
|
//# sourceMappingURL=index.js.map
|
package/formatting/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":";;;;;;;;"}
|
package/fp/index.js
CHANGED
package/fp/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":";;;;;;;;"}
|
package/fp/run-while.js
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
1
5
|
/**
|
|
2
6
|
* Run the callback while the predicate return true. Throws an
|
|
3
7
|
* error if the iteration count exceeds the iteration limit.
|
|
4
8
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var shouldRun = predicate(currentValue);
|
|
9
|
+
const runWhile = ({ predicate, callback, initialValue, iterationLimit = Infinity }) => {
|
|
10
|
+
let counter = 0;
|
|
11
|
+
let currentValue = initialValue;
|
|
12
|
+
let shouldRun = predicate(currentValue);
|
|
10
13
|
while (shouldRun) {
|
|
11
14
|
if (counter >= iterationLimit) {
|
|
12
15
|
break;
|
|
13
16
|
}
|
|
14
|
-
|
|
17
|
+
const nextValue = callback(currentValue, counter);
|
|
15
18
|
counter += 1;
|
|
16
19
|
shouldRun = predicate(nextValue);
|
|
17
20
|
currentValue = nextValue;
|
|
@@ -22,5 +25,5 @@ var runWhile = function (_a) {
|
|
|
22
25
|
};
|
|
23
26
|
};
|
|
24
27
|
|
|
25
|
-
|
|
28
|
+
exports.runWhile = runWhile;
|
|
26
29
|
//# sourceMappingURL=run-while.js.map
|
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 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;
|
|
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;;;;"}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const defaultEncodingConfig = {
|
|
2
6
|
keyValueDelimiter: ':',
|
|
3
7
|
pairDelimiter: '+',
|
|
4
8
|
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var pairDelimiter = config.pairDelimiter, keyValueDelimiter = config.keyValueDelimiter;
|
|
9
|
+
const encodeSearchValue = (searchValue, config = defaultEncodingConfig) => {
|
|
10
|
+
const { pairDelimiter, keyValueDelimiter } = config;
|
|
8
11
|
return Object.entries(searchValue)
|
|
9
|
-
.map(
|
|
10
|
-
var key = _a[0], value = _a[1];
|
|
11
|
-
return "".concat(key).concat(keyValueDelimiter).concat(encodeURI(value));
|
|
12
|
-
})
|
|
12
|
+
.map(([key, value]) => `${key}${keyValueDelimiter}${encodeURI(value)}`)
|
|
13
13
|
.join(pairDelimiter);
|
|
14
14
|
};
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
const encodeSearchObject = (searchObject) => {
|
|
16
|
+
const { sort, query, offset, limit } = searchObject;
|
|
17
|
+
const sortEncoded = sort ? encodeSearchValue(sort) : null;
|
|
18
|
+
const queryEncoded = query ? encodeSearchValue(query) : null;
|
|
19
|
+
const urlParams = new URLSearchParams({
|
|
20
20
|
offset: offset.toString(),
|
|
21
21
|
limit: limit.toString(),
|
|
22
22
|
});
|
|
@@ -27,5 +27,6 @@ var encodeSearchObject = function (searchObject) {
|
|
|
27
27
|
return urlParams.toString();
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
exports.encodeSearchObject = encodeSearchObject;
|
|
31
|
+
exports.encodeSearchValue = encodeSearchValue;
|
|
31
32
|
//# sourceMappingURL=encode-search-object.js.map
|