@koine/utils 1.0.26 → 1.0.29
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/{async.d.ts → Defer.d.ts} +5 -5
- package/{async.js → Defer.js} +2 -7
- package/{emitter.d.ts → Emitter.d.ts} +1 -0
- package/{emitter.js → Emitter.js} +1 -0
- package/accentSets.d.ts +16 -0
- package/accentSets.js +38 -0
- package/addOrReplaceAtIdx.d.ts +5 -0
- package/addOrReplaceAtIdx.js +19 -0
- package/arrayToLookup.d.ts +7 -0
- package/arrayToLookup.js +13 -0
- package/buildUrlQueryString.d.ts +12 -0
- package/buildUrlQueryString.js +24 -0
- package/changeUrlPath.d.ts +10 -0
- package/changeUrlPath.js +18 -0
- package/chunkByChunks.d.ts +7 -0
- package/chunkByChunks.js +37 -0
- package/chunkBySize.d.ts +6 -0
- package/chunkBySize.js +12 -0
- package/clamp.d.ts +8 -0
- package/clamp.js +10 -0
- package/clsx.d.ts +9 -0
- package/clsx.js +49 -0
- package/convertRange.d.ts +14 -0
- package/convertRange.js +16 -0
- package/cookie.d.ts +7 -26
- package/cookie.js +3 -221
- package/decode.d.ts +6 -0
- package/decode.js +10 -0
- package/encode.d.ts +6 -0
- package/encode.js +10 -0
- package/{cast.d.ts → ensureInt.d.ts} +3 -1
- package/{cast.js → ensureInt.js} +3 -4
- package/findDuplicatedIndexes.d.ts +5 -0
- package/findDuplicatedIndexes.js +14 -0
- package/getKeys.d.ts +9 -0
- package/getKeys.js +9 -0
- package/getNonce.d.ts +6 -0
- package/getNonce.js +9 -0
- package/getType.d.ts +22 -0
- package/getType.js +19 -0
- package/getUrlHashParams.d.ts +9 -0
- package/getUrlHashParams.js +16 -0
- package/getUrlHashPathname.d.ts +9 -0
- package/getUrlHashPathname.js +13 -0
- package/getUrlPathnameParts.d.ts +12 -0
- package/getUrlPathnameParts.js +20 -0
- package/getUrlQueryParams.d.ts +14 -0
- package/getUrlQueryParams.js +38 -0
- package/index.d.ts +107 -15
- package/index.js +108 -16
- package/isAnyObject.d.ts +8 -0
- package/isAnyObject.js +10 -0
- package/isArray.d.ts +7 -0
- package/isArray.js +10 -0
- package/isBlob.d.ts +7 -0
- package/isBlob.js +10 -0
- package/isBoolean.d.ts +7 -0
- package/isBoolean.js +10 -0
- package/isBrowser.d.ts +6 -0
- package/{ssr.js → isBrowser.js} +5 -2
- package/isDate.d.ts +7 -0
- package/isDate.js +10 -0
- package/isEmptyArray.d.ts +7 -0
- package/isEmptyArray.js +10 -0
- package/isEmptyObject.d.ts +9 -0
- package/isEmptyObject.js +10 -0
- package/isEmptyString.d.ts +7 -0
- package/isEmptyString.js +9 -0
- package/isError.d.ts +7 -0
- package/isError.js +10 -0
- package/isExternalUrl.d.ts +9 -0
- package/isExternalUrl.js +21 -0
- package/isFile.d.ts +7 -0
- package/isFile.js +10 -0
- package/isFloat.d.ts +7 -0
- package/isFloat.js +10 -0
- package/isFormData.d.ts +7 -0
- package/isFormData.js +10 -0
- package/isFullArray.d.ts +7 -0
- package/isFullArray.js +10 -0
- package/isFullObject.d.ts +8 -0
- package/isFullObject.js +10 -0
- package/isFullString.d.ts +7 -0
- package/isFullString.js +10 -0
- package/isFunction.d.ts +8 -0
- package/isFunction.js +9 -0
- package/{detect.d.ts → isIE.d.ts} +3 -4
- package/isIE.js +18 -0
- package/isInt.d.ts +7 -0
- package/isInt.js +10 -0
- package/isMap.d.ts +7 -0
- package/isMap.js +10 -0
- package/isMobile.d.ts +7 -0
- package/{detect.js → isMobile.js} +4 -15
- package/isNaNValue.d.ts +7 -0
- package/isNaNValue.js +10 -0
- package/isNegativeNumber.d.ts +7 -0
- package/isNegativeNumber.js +10 -0
- package/isNull.d.ts +7 -0
- package/isNull.js +10 -0
- package/isNullOrUndefined.d.ts +7 -0
- package/isNullOrUndefined.js +10 -0
- package/isNumber.d.ts +9 -0
- package/isNumber.js +12 -0
- package/isObject.d.ts +8 -0
- package/isObject.js +10 -0
- package/isObjectLike.d.ts +10 -0
- package/isObjectLike.js +12 -0
- package/isOneOf.d.ts +9 -0
- package/isOneOf.js +10 -0
- package/isPlainObject.d.ts +8 -0
- package/isPlainObject.js +13 -0
- package/isPositiveNumber.d.ts +7 -0
- package/isPositiveNumber.js +10 -0
- package/isPrimitive.d.ts +7 -0
- package/isPrimitive.js +20 -0
- package/isPromise.d.ts +7 -0
- package/isPromise.js +10 -0
- package/isRegExp.d.ts +7 -0
- package/isRegExp.js +10 -0
- package/isServer.d.ts +6 -0
- package/isServer.js +8 -0
- package/isSet.d.ts +7 -0
- package/isSet.js +10 -0
- package/isString.d.ts +7 -0
- package/isString.js +10 -0
- package/isSymbol.d.ts +7 -0
- package/isSymbol.js +10 -0
- package/isType.d.ts +11 -0
- package/isType.js +22 -0
- package/isUndefined.d.ts +7 -0
- package/isUndefined.js +10 -0
- package/isWeakMap.d.ts +7 -0
- package/isWeakMap.js +10 -0
- package/isWeakSet.d.ts +7 -0
- package/isWeakSet.js +10 -0
- package/location.d.ts +2 -145
- package/location.js +1 -299
- package/mapListBy.d.ts +7 -0
- package/mapListBy.js +14 -0
- package/{match-sorter.d.ts → matchSorter.d.ts} +1 -0
- package/{match-sorter.js → matchSorter.js} +2 -1
- package/mergeObjects.d.ts +7 -0
- package/{objects.js → mergeObjects.js} +2 -31
- package/mergeUrlQueryParams.d.ts +9 -0
- package/mergeUrlQueryParams.js +22 -0
- package/navigateToHashParams.d.ts +9 -0
- package/navigateToHashParams.js +22 -0
- package/navigateToMergedHashParams.d.ts +8 -0
- package/navigateToMergedHashParams.js +14 -0
- package/navigateToMergedParams.d.ts +9 -0
- package/navigateToMergedParams.js +14 -0
- package/navigateToParams.d.ts +10 -0
- package/navigateToParams.js +18 -0
- package/navigateWithoutUrlParam.d.ts +8 -0
- package/navigateWithoutUrlParam.js +19 -0
- package/node/{async.js → Defer.js} +3 -9
- package/node/{emitter.js → Emitter.js} +1 -0
- package/node/accentSets.js +41 -0
- package/node/addOrReplaceAtIdx.js +23 -0
- package/node/arrayToLookup.js +17 -0
- package/node/buildUrlQueryString.js +28 -0
- package/node/changeUrlPath.js +22 -0
- package/node/chunkByChunks.js +41 -0
- package/node/chunkBySize.js +16 -0
- package/node/clamp.js +14 -0
- package/node/clsx.js +53 -0
- package/node/convertRange.js +20 -0
- package/node/cookie.js +4 -227
- package/node/decode.js +14 -0
- package/node/encode.js +14 -0
- package/node/{cast.js → ensureInt.js} +4 -6
- package/node/findDuplicatedIndexes.js +18 -0
- package/node/getKeys.js +12 -0
- package/node/getNonce.js +13 -0
- package/node/getType.js +23 -0
- package/node/getUrlHashParams.js +20 -0
- package/node/getUrlHashPathname.js +17 -0
- package/node/getUrlPathnameParts.js +24 -0
- package/node/getUrlQueryParams.js +42 -0
- package/node/index.js +108 -16
- package/node/isAnyObject.js +14 -0
- package/node/isArray.js +14 -0
- package/node/isBlob.js +14 -0
- package/node/isBoolean.js +14 -0
- package/node/{ssr.js → isBrowser.js} +6 -3
- package/node/isDate.js +14 -0
- package/node/isEmptyArray.js +14 -0
- package/node/isEmptyObject.js +14 -0
- package/node/isEmptyString.js +13 -0
- package/node/isError.js +14 -0
- package/node/isExternalUrl.js +25 -0
- package/node/isFile.js +14 -0
- package/node/isFloat.js +14 -0
- package/node/isFormData.js +14 -0
- package/node/isFullArray.js +14 -0
- package/node/isFullObject.js +14 -0
- package/node/isFullString.js +14 -0
- package/node/isFunction.js +13 -0
- package/node/isIE.js +22 -0
- package/node/isInt.js +14 -0
- package/node/isMap.js +14 -0
- package/node/{detect.js → isMobile.js} +6 -18
- package/node/isNaNValue.js +14 -0
- package/node/isNegativeNumber.js +14 -0
- package/node/isNull.js +14 -0
- package/node/isNullOrUndefined.js +13 -0
- package/node/isNumber.js +16 -0
- package/node/isObject.js +14 -0
- package/node/isObjectLike.js +16 -0
- package/node/isOneOf.js +14 -0
- package/node/isPlainObject.js +17 -0
- package/node/isPositiveNumber.js +14 -0
- package/node/isPrimitive.js +24 -0
- package/node/isPromise.js +14 -0
- package/node/isRegExp.js +14 -0
- package/node/isServer.js +11 -0
- package/node/isSet.js +14 -0
- package/node/isString.js +14 -0
- package/node/isSymbol.js +14 -0
- package/node/isType.js +26 -0
- package/node/isUndefined.js +14 -0
- package/node/isWeakMap.js +14 -0
- package/node/isWeakSet.js +14 -0
- package/node/location.js +0 -321
- package/node/mapListBy.js +18 -0
- package/node/{match-sorter.js → matchSorter.js} +3 -2
- package/node/{objects.js → mergeObjects.js} +5 -36
- package/node/mergeUrlQueryParams.js +26 -0
- package/node/navigateToHashParams.js +26 -0
- package/node/navigateToMergedHashParams.js +18 -0
- package/node/navigateToMergedParams.js +18 -0
- package/node/navigateToParams.js +22 -0
- package/node/navigateWithoutUrlParam.js +23 -0
- package/node/normaliseUrl.js +18 -0
- package/node/normaliseUrlPathname.js +18 -0
- package/node/{analytics-google.js → pageview.js} +12 -10
- package/node/parseCookie.js +52 -0
- package/node/parseURL.js +24 -0
- package/node/randomInt.js +13 -0
- package/node/{misc.js → randomKey.js} +2 -0
- package/node/readCookie.js +38 -0
- package/node/redirectTo.js +19 -0
- package/node/removeAccents.js +19 -0
- package/node/removeCookie.js +19 -0
- package/node/removeDuplicatesByKey.js +25 -0
- package/node/removeDuplicatesComparing.js +14 -0
- package/node/removeIndexesFromArray.js +18 -0
- package/node/removeTrailingSlash.js +14 -0
- package/node/{math.js → roundTo.js} +3 -32
- package/node/serializeCookie.js +108 -0
- package/node/setCookie.js +61 -0
- package/node/shuffle.js +36 -0
- package/node/slugify.js +27 -0
- package/node/swapMap.js +18 -0
- package/node/{typography.js → titleCase.js} +3 -12
- package/node/toNumber.js +12 -0
- package/node/{colors.js → toRgba.js} +4 -0
- package/node/transformToUrlPathname.js +20 -0
- package/node/truncate.js +17 -0
- package/node/uid.js +4 -13
- package/node/updateLinkParams.js +18 -0
- package/node/updateUrlQueryParams.js +22 -0
- package/node/uuid.js +17 -0
- package/node/wait.js +13 -0
- package/node/whitelistObject.js +19 -0
- package/normaliseUrl.d.ts +10 -0
- package/normaliseUrl.js +14 -0
- package/normaliseUrlPathname.d.ts +10 -0
- package/normaliseUrlPathname.js +14 -0
- package/package.json +1 -1
- package/{analytics-google.d.ts → pageview.d.ts} +3 -0
- package/{analytics-google.js → pageview.js} +12 -10
- package/parseCookie.d.ts +11 -0
- package/parseCookie.js +48 -0
- package/parseURL.d.ts +17 -0
- package/parseURL.js +20 -0
- package/randomInt.d.ts +7 -0
- package/randomInt.js +9 -0
- package/{misc.d.ts → randomKey.d.ts} +2 -0
- package/{misc.js → randomKey.js} +2 -0
- package/readCookie.d.ts +3 -0
- package/readCookie.js +34 -0
- package/redirectTo.d.ts +9 -0
- package/redirectTo.js +15 -0
- package/removeAccents.d.ts +6 -0
- package/removeAccents.js +15 -0
- package/removeCookie.d.ts +10 -0
- package/removeCookie.js +15 -0
- package/removeDuplicatesByKey.d.ts +8 -0
- package/removeDuplicatesByKey.js +21 -0
- package/removeDuplicatesComparing.d.ts +5 -0
- package/removeDuplicatesComparing.js +10 -0
- package/removeIndexesFromArray.d.ts +5 -0
- package/removeIndexesFromArray.js +14 -0
- package/removeTrailingSlash.d.ts +7 -0
- package/removeTrailingSlash.js +10 -0
- package/roundTo.d.ts +8 -0
- package/{math.js → roundTo.js} +2 -28
- package/serializeCookie.d.ts +27 -0
- package/serializeCookie.js +104 -0
- package/setCookie.d.ts +10 -0
- package/setCookie.js +57 -0
- package/shuffle.d.ts +16 -0
- package/shuffle.js +32 -0
- package/{text.d.ts → slugify.d.ts} +2 -5
- package/slugify.js +23 -0
- package/swapMap.d.ts +7 -0
- package/swapMap.js +14 -0
- package/{typography.d.ts → titleCase.d.ts} +2 -4
- package/{typography.js → titleCase.js} +2 -10
- package/toNumber.d.ts +5 -0
- package/toNumber.js +8 -0
- package/{colors.d.ts → toRgba.d.ts} +4 -0
- package/{colors.js → toRgba.js} +4 -0
- package/transformToUrlPathname.d.ts +11 -0
- package/transformToUrlPathname.js +16 -0
- package/truncate.d.ts +7 -0
- package/truncate.js +13 -0
- package/uid.d.ts +3 -6
- package/uid.js +3 -11
- package/updateLinkParams.d.ts +10 -0
- package/updateLinkParams.js +14 -0
- package/updateUrlQueryParams.d.ts +9 -0
- package/updateUrlQueryParams.js +18 -0
- package/uuid.d.ts +8 -0
- package/uuid.js +13 -0
- package/wait.d.ts +7 -0
- package/wait.js +9 -0
- package/whitelistObject.d.ts +8 -0
- package/whitelistObject.js +15 -0
- package/arrays.d.ts +0 -41
- package/arrays.js +0 -153
- package/is.d.ts +0 -288
- package/is.js +0 -376
- package/math.d.ts +0 -28
- package/node/arrays.js +0 -166
- package/node/is.js +0 -417
- package/node/security.js +0 -29
- package/node/text.js +0 -70
- package/objects.d.ts +0 -22
- package/security.d.ts +0 -12
- package/security.js +0 -23
- package/ssr.d.ts +0 -2
- package/text.js +0 -65
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import buildUrlQueryString from "./buildUrlQueryString";
|
|
2
|
+
import isBrowser from "./isBrowser";
|
|
3
|
+
/**
|
|
4
|
+
* Change current URL query parameters, it uses `history`.
|
|
5
|
+
*
|
|
6
|
+
* @category location
|
|
7
|
+
* @param replace Replace URL instead of pushing it in the history stack. By default it pushes it.
|
|
8
|
+
* @returns The query string with initial `?`
|
|
9
|
+
*/
|
|
10
|
+
export function navigateToParams(params, replace) {
|
|
11
|
+
if (params === void 0) { params = {}; }
|
|
12
|
+
var queryString = typeof params === "string" ? params : buildUrlQueryString(params);
|
|
13
|
+
if (isBrowser) {
|
|
14
|
+
history[replace ? "replaceState" : "pushState"](null, "", location.pathname + queryString);
|
|
15
|
+
}
|
|
16
|
+
return queryString;
|
|
17
|
+
}
|
|
18
|
+
export default navigateToParams;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Remove URL query parameter, it uses `history`
|
|
3
|
+
*
|
|
4
|
+
* @category location
|
|
5
|
+
* @param replace Replace URL instead of pushing it in the history stack. By default it pushes it.
|
|
6
|
+
*/
|
|
7
|
+
export declare function navigateWithoutUrlParam(paramName?: string, replace?: boolean): string;
|
|
8
|
+
export default navigateWithoutUrlParam;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import getUrlQueryParams from "./getUrlQueryParams";
|
|
2
|
+
import navigateToParams from "./navigateToParams";
|
|
3
|
+
/**
|
|
4
|
+
* Remove URL query parameter, it uses `history`
|
|
5
|
+
*
|
|
6
|
+
* @category location
|
|
7
|
+
* @param replace Replace URL instead of pushing it in the history stack. By default it pushes it.
|
|
8
|
+
*/
|
|
9
|
+
export function navigateWithoutUrlParam(paramName, replace) {
|
|
10
|
+
var params = {};
|
|
11
|
+
var currentParams = getUrlQueryParams();
|
|
12
|
+
for (var key in currentParams) {
|
|
13
|
+
if (key !== paramName) {
|
|
14
|
+
params[key] = currentParams[key];
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return navigateToParams(params, replace);
|
|
18
|
+
}
|
|
19
|
+
export default navigateWithoutUrlParam;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.Defer = void 0;
|
|
4
4
|
/**
|
|
5
|
+
* @category async
|
|
5
6
|
* @see https://stackoverflow.com/a/37673534/1938970
|
|
6
|
-
*
|
|
7
7
|
* @example
|
|
8
8
|
*
|
|
9
9
|
* ```ts
|
|
@@ -27,10 +27,4 @@ function Defer() {
|
|
|
27
27
|
return self;
|
|
28
28
|
}
|
|
29
29
|
exports.Defer = Defer;
|
|
30
|
-
|
|
31
|
-
* A promisified `setTimeout`
|
|
32
|
-
*/
|
|
33
|
-
var wait = function (milliseconds) {
|
|
34
|
-
return new Promise(function (resolve) { return setTimeout(resolve, milliseconds); });
|
|
35
|
-
};
|
|
36
|
-
exports.wait = wait;
|
|
30
|
+
exports.default = Defer;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.accentsSets = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Accent sets
|
|
6
|
+
*
|
|
7
|
+
* @category text
|
|
8
|
+
* @see https://gist.github.com/mathewbyrne/1280286#gistcomment-3498021
|
|
9
|
+
* @see https://gist.github.com/eek/9c4887e80b3ede05c0e39fee4dce3747 for usage
|
|
10
|
+
* of [normalize](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize)
|
|
11
|
+
*/
|
|
12
|
+
exports.accentsSets = [
|
|
13
|
+
["a", "ÀÁÂÃÅÆĀĂĄẠẢẤẦẨẪẬẮẰẲẴẶ"],
|
|
14
|
+
["ae", "Ä"],
|
|
15
|
+
["c", "ÇĆĈČ"],
|
|
16
|
+
["d", "ÐĎĐÞ"],
|
|
17
|
+
["e", "ÈÉÊËĒĔĖĘĚẸẺẼẾỀỂỄỆ"],
|
|
18
|
+
["g", "ĜĞĢǴ"],
|
|
19
|
+
["h", "ĤḦ"],
|
|
20
|
+
["i", "ÌÍÎÏĨĪĮİỈỊ"],
|
|
21
|
+
["j", "Ĵ"],
|
|
22
|
+
["ij", "IJ"],
|
|
23
|
+
["k", "Ķ"],
|
|
24
|
+
["l", "ĹĻĽŁ"],
|
|
25
|
+
["m", "Ḿ"],
|
|
26
|
+
["n", "ÑŃŅŇ"],
|
|
27
|
+
["o", "ÒÓÔÕØŌŎŐỌỎỐỒỔỖỘỚỜỞỠỢǪǬƠ"],
|
|
28
|
+
["oe", "΅"],
|
|
29
|
+
["p", "ṕ"],
|
|
30
|
+
["r", "ŔŖŘ"],
|
|
31
|
+
["s", "ŚŜŞŠ"],
|
|
32
|
+
["ss", "ß"],
|
|
33
|
+
["t", "ŢŤ"],
|
|
34
|
+
["u", "ÙÚÛŨŪŬŮŰŲỤỦỨỪỬỮỰƯ"],
|
|
35
|
+
["ue", "Ü"],
|
|
36
|
+
["w", "ẂŴẀẄ"],
|
|
37
|
+
["x", "ẍ"],
|
|
38
|
+
["y", "ÝŶŸỲỴỶỸ"],
|
|
39
|
+
["z", "ŹŻŽ"],
|
|
40
|
+
];
|
|
41
|
+
exports.default = exports.accentsSets;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addOrReplaceAtIdx = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
/**
|
|
6
|
+
* @category array
|
|
7
|
+
*/
|
|
8
|
+
function addOrReplaceAtIdx(list, newItem, newIdx) {
|
|
9
|
+
if (list.length === 0) {
|
|
10
|
+
return [newItem];
|
|
11
|
+
}
|
|
12
|
+
if (typeof newIdx === "undefined" || list.length - 1 < newIdx) {
|
|
13
|
+
return tslib_1.__spreadArray(tslib_1.__spreadArray([], list, true), [newItem], false);
|
|
14
|
+
}
|
|
15
|
+
return list.map(function (item, idx) {
|
|
16
|
+
if (idx === newIdx) {
|
|
17
|
+
return newItem;
|
|
18
|
+
}
|
|
19
|
+
return item;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
exports.addOrReplaceAtIdx = addOrReplaceAtIdx;
|
|
23
|
+
exports.default = addOrReplaceAtIdx;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.arrayToLookup = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Maps a simple flat array to a lookup dictionary object
|
|
6
|
+
*
|
|
7
|
+
* @category array
|
|
8
|
+
*/
|
|
9
|
+
function arrayToLookup(array) {
|
|
10
|
+
if (array === void 0) { array = []; }
|
|
11
|
+
return array.reduce(function (obj, item) {
|
|
12
|
+
obj[item] = 1;
|
|
13
|
+
return obj;
|
|
14
|
+
}, {});
|
|
15
|
+
}
|
|
16
|
+
exports.arrayToLookup = arrayToLookup;
|
|
17
|
+
exports.default = arrayToLookup;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildUrlQueryString = void 0;
|
|
4
|
+
var isNull_1 = require("./isNull");
|
|
5
|
+
var isUndefined_1 = require("./isUndefined");
|
|
6
|
+
/**
|
|
7
|
+
* Get clean query string for URL
|
|
8
|
+
*
|
|
9
|
+
* It returns the query string **with** the initial `?`
|
|
10
|
+
*
|
|
11
|
+
* TODO: at some point replace with `URLSearchParams`, @see [caniuse](https://caniuse.com/?search=URLSearchParams)
|
|
12
|
+
*
|
|
13
|
+
* @category location
|
|
14
|
+
*/
|
|
15
|
+
function buildUrlQueryString(params) {
|
|
16
|
+
if (params === void 0) { params = {}; }
|
|
17
|
+
var output = "";
|
|
18
|
+
for (var key in params) {
|
|
19
|
+
var value = params[key];
|
|
20
|
+
if (!(0, isNull_1.default)(value) && !(0, isUndefined_1.default)(value)) {
|
|
21
|
+
output += "".concat(key, "=").concat(encodeURIComponent(value + ""), "&");
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
// removes the last &
|
|
25
|
+
return output ? "?".concat(output.replace(/&+$/, "")) : "";
|
|
26
|
+
}
|
|
27
|
+
exports.buildUrlQueryString = buildUrlQueryString;
|
|
28
|
+
exports.default = buildUrlQueryString;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.changeUrlPath = void 0;
|
|
4
|
+
var isBrowser_1 = require("./isBrowser");
|
|
5
|
+
var normaliseUrlPathname_1 = require("./normaliseUrlPathname");
|
|
6
|
+
/**
|
|
7
|
+
* Change URL path, ensures initial and ending slashes and normalise eventual
|
|
8
|
+
* consecutive slashes, it uses `history`.
|
|
9
|
+
*
|
|
10
|
+
* @category location
|
|
11
|
+
* @param replace Replace URL instead of pushing it in the history stack. By default it pushes it.
|
|
12
|
+
* @returns {string} The new cleaned pathname
|
|
13
|
+
*/
|
|
14
|
+
function changeUrlPath(pathname, state, replace) {
|
|
15
|
+
var path = (0, normaliseUrlPathname_1.default)("/".concat(pathname, "/"));
|
|
16
|
+
if (isBrowser_1.default) {
|
|
17
|
+
history[replace ? "replaceState" : "pushState"](state, "", path);
|
|
18
|
+
}
|
|
19
|
+
return path;
|
|
20
|
+
}
|
|
21
|
+
exports.changeUrlPath = changeUrlPath;
|
|
22
|
+
exports.default = changeUrlPath;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.chunkByChunks = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* TODO: untested
|
|
6
|
+
* @category array
|
|
7
|
+
* @see https://stackoverflow.com/a/8189268/1938970
|
|
8
|
+
*/
|
|
9
|
+
function chunkByChunks(arr, nrOfChunks, balanced) {
|
|
10
|
+
if (nrOfChunks < 2)
|
|
11
|
+
return [arr];
|
|
12
|
+
var len = arr.length;
|
|
13
|
+
var output = [];
|
|
14
|
+
var i = 0;
|
|
15
|
+
var size;
|
|
16
|
+
if (len % nrOfChunks === 0) {
|
|
17
|
+
size = Math.floor(len / nrOfChunks);
|
|
18
|
+
while (i < len) {
|
|
19
|
+
output.push(arr.slice(i, (i += size)));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
else if (balanced) {
|
|
23
|
+
while (i < len) {
|
|
24
|
+
size = Math.ceil((len - i) / nrOfChunks--);
|
|
25
|
+
output.push(arr.slice(i, (i += size)));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
nrOfChunks--;
|
|
30
|
+
size = Math.floor(len / nrOfChunks);
|
|
31
|
+
if (len % size === 0)
|
|
32
|
+
size--;
|
|
33
|
+
while (i < size * nrOfChunks) {
|
|
34
|
+
output.push(arr.slice(i, (i += size)));
|
|
35
|
+
}
|
|
36
|
+
output.push(arr.slice(size * nrOfChunks));
|
|
37
|
+
}
|
|
38
|
+
return output;
|
|
39
|
+
}
|
|
40
|
+
exports.chunkByChunks = chunkByChunks;
|
|
41
|
+
exports.default = chunkByChunks;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.chunkBySize = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @category array
|
|
6
|
+
* @see https://stackoverflow.com/a/40682136/1938970
|
|
7
|
+
*/
|
|
8
|
+
function chunkBySize(arr, size) {
|
|
9
|
+
var output = [];
|
|
10
|
+
for (var i = 0; i < arr.length; i += size) {
|
|
11
|
+
output.push(arr.slice(i, i + size));
|
|
12
|
+
}
|
|
13
|
+
return output;
|
|
14
|
+
}
|
|
15
|
+
exports.chunkBySize = chunkBySize;
|
|
16
|
+
exports.default = chunkBySize;
|
package/node/clamp.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.clamp = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Returns a number whose value is limited to the given range.
|
|
6
|
+
*
|
|
7
|
+
* @category math
|
|
8
|
+
* @see https://stackoverflow.com/a/11409944/1938970
|
|
9
|
+
*/
|
|
10
|
+
function clamp(num, min, max) {
|
|
11
|
+
return Math.min(Math.max(num, min), max);
|
|
12
|
+
}
|
|
13
|
+
exports.clamp = clamp;
|
|
14
|
+
exports.default = clamp;
|
package/node/clsx.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.clsx = void 0;
|
|
4
|
+
// import _clsx from "clsx";
|
|
5
|
+
// export const clsx = _clsx;
|
|
6
|
+
function toVal(mix) {
|
|
7
|
+
var k, y, str = "";
|
|
8
|
+
if (typeof mix === "string" || typeof mix === "number") {
|
|
9
|
+
str += mix;
|
|
10
|
+
}
|
|
11
|
+
else if (typeof mix === "object") {
|
|
12
|
+
if (Array.isArray(mix)) {
|
|
13
|
+
for (k = 0; k < mix.length; k++) {
|
|
14
|
+
if (mix[k]) {
|
|
15
|
+
if ((y = toVal(mix[k]))) {
|
|
16
|
+
str && (str += " ");
|
|
17
|
+
str += y;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
for (k in mix) {
|
|
24
|
+
if (mix[k]) {
|
|
25
|
+
str && (str += " ");
|
|
26
|
+
str += k;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return str;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Class names utility, embedded from [clsx](https://github.com/lukeed/clsx)
|
|
35
|
+
*
|
|
36
|
+
* @see https://github.com/lukeed/clsx
|
|
37
|
+
* @license [MIT: Luke Edwards](https://github.com/lukeed/clsx/blob/master/license)
|
|
38
|
+
*/
|
|
39
|
+
var clsx = function () {
|
|
40
|
+
var i = 0, tmp, x, str = "";
|
|
41
|
+
while (i < arguments.length) {
|
|
42
|
+
// eslint-disable-next-line prefer-rest-params
|
|
43
|
+
if ((tmp = arguments[i++])) {
|
|
44
|
+
if ((x = toVal(tmp))) {
|
|
45
|
+
str && (str += " ");
|
|
46
|
+
str += x;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return str;
|
|
51
|
+
};
|
|
52
|
+
exports.clsx = clsx;
|
|
53
|
+
exports.default = exports.clsx;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertRange = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Convert range of a number
|
|
6
|
+
*
|
|
7
|
+
* e.g. converting number 5 in a scale/range from 0 10 to a scale/range from 50
|
|
8
|
+
* to 100 would return 75
|
|
9
|
+
* ```
|
|
10
|
+
* convertRange(5, [0, 10], [50, 100]);
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* @category math
|
|
14
|
+
* @see https://stackoverflow.com/a/14224813
|
|
15
|
+
*/
|
|
16
|
+
function convertRange(num, r1, r2) {
|
|
17
|
+
return ((num - r1[0]) * (r2[1] - r2[0])) / (r1[1] - r1[0]) + r2[0];
|
|
18
|
+
}
|
|
19
|
+
exports.convertRange = convertRange;
|
|
20
|
+
exports.default = convertRange;
|
package/node/cookie.js
CHANGED
|
@@ -2,235 +2,12 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* @file
|
|
4
4
|
*
|
|
5
|
-
*
|
|
5
|
+
* @category cookie
|
|
6
6
|
*
|
|
7
|
+
* All cookie related code is inspired and adapted from:
|
|
7
8
|
* - [js-cookie](https://github.com/js-cookie/js-cookie)
|
|
8
|
-
* @see https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/js-cookie/index.d.ts
|
|
9
9
|
* - [cookie](https://github.com/jshttp/cookie)
|
|
10
|
-
*
|
|
11
10
|
*/
|
|
12
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.
|
|
14
|
-
|
|
15
|
-
var is_1 = require("./is");
|
|
16
|
-
/**
|
|
17
|
-
* RegExp to match field-content in RFC 7230 sec 3.2
|
|
18
|
-
*
|
|
19
|
-
* field-content = field-vchar [ 1*( SP / HTAB ) field-vchar ]
|
|
20
|
-
* field-vchar = VCHAR / obs-text
|
|
21
|
-
* obs-text = %x80-FF
|
|
22
|
-
*/
|
|
23
|
-
// eslint-disable-next-line no-control-regex
|
|
24
|
-
var fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;
|
|
25
|
-
/**
|
|
26
|
-
* Parse a cookie header.
|
|
27
|
-
*
|
|
28
|
-
* Parse the given cookie header string into an object
|
|
29
|
-
* The object has the various cookies as keys(names) => values
|
|
30
|
-
*/
|
|
31
|
-
function parseCookie(str, attributes) {
|
|
32
|
-
if (attributes === void 0) { attributes = {}; }
|
|
33
|
-
if (typeof str !== "string") {
|
|
34
|
-
throw new TypeError("argument str must be a string");
|
|
35
|
-
}
|
|
36
|
-
var obj = {};
|
|
37
|
-
var pairs = str.split(";");
|
|
38
|
-
var _a = attributes.decode, decode = _a === void 0 ? decodeURIComponent : _a;
|
|
39
|
-
for (var i = 0; i < pairs.length; i++) {
|
|
40
|
-
var pair = pairs[i];
|
|
41
|
-
var index = pair.indexOf("=");
|
|
42
|
-
// skip things that don't look like key=value
|
|
43
|
-
if (index < 0) {
|
|
44
|
-
continue;
|
|
45
|
-
}
|
|
46
|
-
var key = pair.substring(0, index).trim();
|
|
47
|
-
// only assign once
|
|
48
|
-
if (undefined == obj[key]) {
|
|
49
|
-
var val = pair.substring(index + 1, pair.length).trim();
|
|
50
|
-
// quoted values
|
|
51
|
-
if (val[0] === '"') {
|
|
52
|
-
val = val.slice(1, -1);
|
|
53
|
-
}
|
|
54
|
-
obj[key] = tryDecode(val, decode);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return obj;
|
|
58
|
-
}
|
|
59
|
-
exports.parseCookie = parseCookie;
|
|
60
|
-
/**
|
|
61
|
-
* Serialize data into a cookie header.
|
|
62
|
-
*
|
|
63
|
-
* Serialize the a name value pair into a cookie string suitable for
|
|
64
|
-
* http headers. An optional attributes object specified cookie parameters.
|
|
65
|
-
*
|
|
66
|
-
* serialize('foo', 'bar', { httpOnly: true })
|
|
67
|
-
* => "foo=bar; httpOnly"
|
|
68
|
-
*/
|
|
69
|
-
function serializeCookie(name, val, attributes) {
|
|
70
|
-
if (attributes === void 0) { attributes = {}; }
|
|
71
|
-
var _a = attributes.encode, encode = _a === void 0 ? encodeURIComponent : _a, domain = attributes.domain, path = attributes.path, httpOnly = attributes.httpOnly, secure = attributes.secure, sameSite = attributes.sameSite;
|
|
72
|
-
var maxAge = attributes.maxAge, expires = attributes.expires;
|
|
73
|
-
var value = encode(val);
|
|
74
|
-
if (process.env["NODE_ENV"] !== "production") {
|
|
75
|
-
if (!fieldContentRegExp.test(name)) {
|
|
76
|
-
throw new TypeError("argument name is invalid");
|
|
77
|
-
}
|
|
78
|
-
if (typeof attributes.encode !== "function") {
|
|
79
|
-
throw new TypeError("option encode is invalid");
|
|
80
|
-
}
|
|
81
|
-
if (value && !fieldContentRegExp.test(value)) {
|
|
82
|
-
throw new TypeError("argument val is invalid");
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
var str = name + "=" + value;
|
|
86
|
-
if (null != maxAge) {
|
|
87
|
-
maxAge = maxAge - 0;
|
|
88
|
-
if (isNaN(maxAge) || !isFinite(maxAge)) {
|
|
89
|
-
throw new TypeError("option maxAge is invalid");
|
|
90
|
-
}
|
|
91
|
-
str += "; Max-Age=" + Math.floor(maxAge);
|
|
92
|
-
}
|
|
93
|
-
if (domain) {
|
|
94
|
-
if (process.env["NODE_ENV"] !== "production") {
|
|
95
|
-
if (!fieldContentRegExp.test(domain)) {
|
|
96
|
-
throw new TypeError("option domain is invalid");
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
str += "; Domain=" + domain;
|
|
100
|
-
}
|
|
101
|
-
if (path) {
|
|
102
|
-
if (process.env["NODE_ENV"] !== "production") {
|
|
103
|
-
if (!fieldContentRegExp.test(path)) {
|
|
104
|
-
throw new TypeError("option path is invalid");
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
str += "; Path=" + path;
|
|
108
|
-
}
|
|
109
|
-
if (expires) {
|
|
110
|
-
if ((0, is_1.isNumber)(expires)) {
|
|
111
|
-
expires = new Date(Date.now() + expires * 864e5);
|
|
112
|
-
}
|
|
113
|
-
str += "; Expires=" + expires.toUTCString();
|
|
114
|
-
}
|
|
115
|
-
if (httpOnly) {
|
|
116
|
-
str += "; HttpOnly";
|
|
117
|
-
}
|
|
118
|
-
if (secure) {
|
|
119
|
-
str += "; Secure";
|
|
120
|
-
}
|
|
121
|
-
if (sameSite) {
|
|
122
|
-
switch (sameSite.toLowerCase()) {
|
|
123
|
-
case "lax":
|
|
124
|
-
str += "; SameSite=Lax";
|
|
125
|
-
break;
|
|
126
|
-
case "strict":
|
|
127
|
-
str += "; SameSite=Strict";
|
|
128
|
-
break;
|
|
129
|
-
case "none":
|
|
130
|
-
str += "; SameSite=None";
|
|
131
|
-
break;
|
|
132
|
-
// default:
|
|
133
|
-
// throw new TypeError('option sameSite is invalid');
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
return str;
|
|
137
|
-
}
|
|
138
|
-
exports.serializeCookie = serializeCookie;
|
|
139
|
-
/**
|
|
140
|
-
* Try decoding a string using a decoding function.
|
|
141
|
-
*/
|
|
142
|
-
function tryDecode(str, decode) {
|
|
143
|
-
try {
|
|
144
|
-
return decode(str);
|
|
145
|
-
}
|
|
146
|
-
catch (e) {
|
|
147
|
-
return str;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
function converterRead(value) {
|
|
151
|
-
if (value[0] === '"') {
|
|
152
|
-
value = value.slice(1, -1);
|
|
153
|
-
}
|
|
154
|
-
return value.replace(/(%[\dA-F]{2})+/gi, decodeURIComponent);
|
|
155
|
-
}
|
|
156
|
-
function converterWrite(value) {
|
|
157
|
-
return encodeURIComponent(value).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g, decodeURIComponent);
|
|
158
|
-
}
|
|
159
|
-
function readCookie(name) {
|
|
160
|
-
if (typeof document === "undefined") {
|
|
161
|
-
if (process.env["NODE_ENV"] !== "production") {
|
|
162
|
-
console.warn("@koine/utils:cookie readCookie, document is undefined");
|
|
163
|
-
}
|
|
164
|
-
return name ? "" : {};
|
|
165
|
-
}
|
|
166
|
-
var cookies = document.cookie ? document.cookie.split("; ") : [];
|
|
167
|
-
var all = {};
|
|
168
|
-
for (var i = 0; i < cookies.length; i++) {
|
|
169
|
-
var parts = cookies[i].split("=");
|
|
170
|
-
var value = parts.slice(1).join("=");
|
|
171
|
-
try {
|
|
172
|
-
var found = decodeURIComponent(parts[0]);
|
|
173
|
-
all[found] = converterRead(value);
|
|
174
|
-
if (name === found) {
|
|
175
|
-
break;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
catch (e) {
|
|
179
|
-
if (process.env["NODE_ENV"] !== "production") {
|
|
180
|
-
console.warn("@koine/utils:cookie readCookie, failed to decode", value);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
return name ? all[name] : all;
|
|
185
|
-
}
|
|
186
|
-
exports.readCookie = readCookie;
|
|
187
|
-
var defaultAttributesClient = { path: "/" };
|
|
188
|
-
function setCookie(name, value, attributes) {
|
|
189
|
-
if (attributes === void 0) { attributes = {}; }
|
|
190
|
-
// eslint-disable-next-line prefer-const
|
|
191
|
-
var expires = attributes.expires, restAttrs = tslib_1.__rest(attributes, ["expires"]);
|
|
192
|
-
var cleanedAttrs = tslib_1.__assign(tslib_1.__assign({ expires: "" }, defaultAttributesClient), restAttrs);
|
|
193
|
-
if (typeof document === "undefined") {
|
|
194
|
-
if (process.env["NODE_ENV"] !== "production") {
|
|
195
|
-
console.warn("@koine/utils:cookie setCookie, document is undefined");
|
|
196
|
-
}
|
|
197
|
-
return;
|
|
198
|
-
}
|
|
199
|
-
if ((0, is_1.isNumber)(expires)) {
|
|
200
|
-
expires = new Date(Date.now() + expires * 864e5);
|
|
201
|
-
}
|
|
202
|
-
if (expires) {
|
|
203
|
-
cleanedAttrs.expires = expires.toUTCString();
|
|
204
|
-
}
|
|
205
|
-
name = encodeURIComponent(name)
|
|
206
|
-
.replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent)
|
|
207
|
-
.replace(/[()]/g, escape);
|
|
208
|
-
var stringifiedAttributes = "";
|
|
209
|
-
for (var name_1 in attributes) {
|
|
210
|
-
var attrName = name_1;
|
|
211
|
-
if (!attributes[attrName]) {
|
|
212
|
-
continue;
|
|
213
|
-
}
|
|
214
|
-
stringifiedAttributes += "; " + attrName;
|
|
215
|
-
if (attributes[attrName] === true) {
|
|
216
|
-
continue;
|
|
217
|
-
}
|
|
218
|
-
// Considers RFC 6265 section 5.2:
|
|
219
|
-
// ...
|
|
220
|
-
// 3. If the remaining unparsed-attributes contains a %x3B (";")
|
|
221
|
-
// character:
|
|
222
|
-
// Consume the characters of the unparsed-attributes up to,
|
|
223
|
-
// not including, the first %x3B (";") character.
|
|
224
|
-
// ...
|
|
225
|
-
stringifiedAttributes +=
|
|
226
|
-
"=" + String(attributes[attrName]).split(";")[0];
|
|
227
|
-
}
|
|
228
|
-
return (document.cookie =
|
|
229
|
-
name + "=" + converterWrite(value) + stringifiedAttributes);
|
|
230
|
-
}
|
|
231
|
-
exports.setCookie = setCookie;
|
|
232
|
-
function removeCookie(name, attributes) {
|
|
233
|
-
if (attributes === void 0) { attributes = {}; }
|
|
234
|
-
setCookie(name, "", tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, defaultAttributesClient), attributes), { expires: -1 }));
|
|
235
|
-
}
|
|
236
|
-
exports.removeCookie = removeCookie;
|
|
12
|
+
exports.defaultAttributesClient = void 0;
|
|
13
|
+
exports.defaultAttributesClient = { path: "/" };
|
package/node/decode.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decode = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @category security
|
|
6
|
+
* @see https://stackoverflow.com/a/22405578/9122820
|
|
7
|
+
*/
|
|
8
|
+
function decode(str) {
|
|
9
|
+
return str.replace(/.{3}/g, function (c) {
|
|
10
|
+
return String.fromCharCode(parseInt(c, 10));
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
exports.decode = decode;
|
|
14
|
+
exports.default = decode;
|
package/node/encode.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.encode = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @category security
|
|
6
|
+
* @see https://stackoverflow.com/a/22405578/9122820
|
|
7
|
+
*/
|
|
8
|
+
function encode(str) {
|
|
9
|
+
return str.replace(/./g, function (c) {
|
|
10
|
+
return ("00" + c.charCodeAt(0)).slice(-3);
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
exports.encode = encode;
|
|
14
|
+
exports.default = encode;
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ensureInt =
|
|
4
|
-
var is_1 = require("./is");
|
|
5
|
-
function toNumber(input, fallback) {
|
|
6
|
-
return (0, is_1.isNumber)(input) ? input : input ? parseFloat(input) : fallback || 0;
|
|
7
|
-
}
|
|
8
|
-
exports.toNumber = toNumber;
|
|
3
|
+
exports.ensureInt = void 0;
|
|
9
4
|
/**
|
|
10
5
|
* Ensure input to be an integer
|
|
6
|
+
*
|
|
7
|
+
* @category cast
|
|
11
8
|
*/
|
|
12
9
|
var ensureInt = function (input) {
|
|
13
10
|
return typeof input === "string" ? parseInt(input, 10) : Math.round(input);
|
|
14
11
|
};
|
|
15
12
|
exports.ensureInt = ensureInt;
|
|
13
|
+
exports.default = exports.ensureInt;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findDuplicatedIndexes = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @category array
|
|
6
|
+
*/
|
|
7
|
+
function findDuplicatedIndexes(arr) {
|
|
8
|
+
var indexes = {};
|
|
9
|
+
for (var i = 0; i < arr.length; i++) {
|
|
10
|
+
var idxInArray = arr.indexOf(arr[i]);
|
|
11
|
+
if (idxInArray !== i && idxInArray !== -1) {
|
|
12
|
+
indexes[i] = true;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return indexes;
|
|
16
|
+
}
|
|
17
|
+
exports.findDuplicatedIndexes = findDuplicatedIndexes;
|
|
18
|
+
exports.default = findDuplicatedIndexes;
|