@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
package/node/uid.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.uid = void 0;
|
|
4
4
|
var lastId = 0;
|
|
5
5
|
/**
|
|
6
6
|
* Super basic UID increment-based generator
|
|
7
|
+
*
|
|
8
|
+
* @category uid
|
|
7
9
|
*/
|
|
8
10
|
var uid = function (prefix) {
|
|
9
11
|
if (prefix === void 0) { prefix = "id"; }
|
|
@@ -11,15 +13,4 @@ var uid = function (prefix) {
|
|
|
11
13
|
return "".concat(prefix, "-").concat(lastId);
|
|
12
14
|
};
|
|
13
15
|
exports.uid = uid;
|
|
14
|
-
|
|
15
|
-
* Uuid, tiny custom helper instead of node's uuid/v4
|
|
16
|
-
*
|
|
17
|
-
* @see https://stackoverflow.com/a/2117523/1938970
|
|
18
|
-
*/
|
|
19
|
-
var uuid = function () {
|
|
20
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
|
|
21
|
-
var r = (Math.random() * 16) | 0, v = c == "x" ? r : (r & 0x3) | 0x8;
|
|
22
|
-
return v.toString(16);
|
|
23
|
-
});
|
|
24
|
-
};
|
|
25
|
-
exports.uuid = uuid;
|
|
16
|
+
exports.default = exports.uid;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updateLinkParams = void 0;
|
|
4
|
+
var updateUrlQueryParams_1 = require("./updateUrlQueryParams");
|
|
5
|
+
/**
|
|
6
|
+
* Update link `<a href="">` merging the given new query parameters.
|
|
7
|
+
* it returns the newly created `href` URL value
|
|
8
|
+
*
|
|
9
|
+
* @category location
|
|
10
|
+
* @pure
|
|
11
|
+
*/
|
|
12
|
+
function updateLinkParams($anchor, newParams) {
|
|
13
|
+
var href = (0, updateUrlQueryParams_1.default)($anchor.href, newParams);
|
|
14
|
+
$anchor.href = href;
|
|
15
|
+
return href;
|
|
16
|
+
}
|
|
17
|
+
exports.updateLinkParams = updateLinkParams;
|
|
18
|
+
exports.default = updateLinkParams;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updateUrlQueryParams = void 0;
|
|
4
|
+
var buildUrlQueryString_1 = require("./buildUrlQueryString");
|
|
5
|
+
var getUrlQueryParams_1 = require("./getUrlQueryParams");
|
|
6
|
+
var mergeUrlQueryParams_1 = require("./mergeUrlQueryParams");
|
|
7
|
+
/**
|
|
8
|
+
* Update a URL string query parameters merging the given new query parameters
|
|
9
|
+
*
|
|
10
|
+
* @category location
|
|
11
|
+
* @pure
|
|
12
|
+
*/
|
|
13
|
+
function updateUrlQueryParams(url, newParams) {
|
|
14
|
+
if (newParams === void 0) { newParams = {}; }
|
|
15
|
+
var parts = url.split("?");
|
|
16
|
+
var allParams = parts[1]
|
|
17
|
+
? (0, mergeUrlQueryParams_1.default)((0, getUrlQueryParams_1.default)(url), newParams)
|
|
18
|
+
: newParams;
|
|
19
|
+
return parts[0] + (0, buildUrlQueryString_1.default)(allParams);
|
|
20
|
+
}
|
|
21
|
+
exports.updateUrlQueryParams = updateUrlQueryParams;
|
|
22
|
+
exports.default = updateUrlQueryParams;
|
package/node/uuid.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.uuid = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Uuid, tiny custom helper instead of node's uuid/v4
|
|
6
|
+
*
|
|
7
|
+
* @category uid
|
|
8
|
+
* @see https://stackoverflow.com/a/2117523/1938970
|
|
9
|
+
*/
|
|
10
|
+
var uuid = function () {
|
|
11
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
|
|
12
|
+
var r = (Math.random() * 16) | 0, v = c == "x" ? r : (r & 0x3) | 0x8;
|
|
13
|
+
return v.toString(16);
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
exports.uuid = uuid;
|
|
17
|
+
exports.default = exports.uuid;
|
package/node/wait.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.wait = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* A promisified `setTimeout`
|
|
6
|
+
*
|
|
7
|
+
* @category async
|
|
8
|
+
*/
|
|
9
|
+
var wait = function (milliseconds) {
|
|
10
|
+
return new Promise(function (resolve) { return setTimeout(resolve, milliseconds); });
|
|
11
|
+
};
|
|
12
|
+
exports.wait = wait;
|
|
13
|
+
exports.default = exports.wait;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.whitelistObject = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Whitelist an object properties by selecting only the given keys, it returns a
|
|
6
|
+
* new object.
|
|
7
|
+
*
|
|
8
|
+
* @category objects
|
|
9
|
+
*/
|
|
10
|
+
function whitelistObject(object, keys) {
|
|
11
|
+
var output = {};
|
|
12
|
+
var len = keys.length;
|
|
13
|
+
while (len--) {
|
|
14
|
+
output[keys[len]] = object[keys[len]];
|
|
15
|
+
}
|
|
16
|
+
return output;
|
|
17
|
+
}
|
|
18
|
+
exports.whitelistObject = whitelistObject;
|
|
19
|
+
exports.default = whitelistObject;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalise URL (absolute URL)
|
|
3
|
+
*
|
|
4
|
+
* - replaces too many consecutive slashes (except `http{s}://`)
|
|
5
|
+
* - removes the trailing slash
|
|
6
|
+
*
|
|
7
|
+
* @category location
|
|
8
|
+
*/
|
|
9
|
+
export declare function normaliseUrl(absoluteUrl?: string): string;
|
|
10
|
+
export default normaliseUrl;
|
package/normaliseUrl.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import removeTralingSlash from "./removeTrailingSlash";
|
|
2
|
+
/**
|
|
3
|
+
* Normalise URL (absolute URL)
|
|
4
|
+
*
|
|
5
|
+
* - replaces too many consecutive slashes (except `http{s}://`)
|
|
6
|
+
* - removes the trailing slash
|
|
7
|
+
*
|
|
8
|
+
* @category location
|
|
9
|
+
*/
|
|
10
|
+
export function normaliseUrl(absoluteUrl) {
|
|
11
|
+
if (absoluteUrl === void 0) { absoluteUrl = ""; }
|
|
12
|
+
return removeTralingSlash(absoluteUrl.replace(/([^:]\/)\/+/g, "$1"));
|
|
13
|
+
}
|
|
14
|
+
export default normaliseUrl;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalise URL pathname (relative URL)
|
|
3
|
+
*
|
|
4
|
+
* - replaces too many consecutive slashes
|
|
5
|
+
* - removes the trailing slash
|
|
6
|
+
*
|
|
7
|
+
* @category location
|
|
8
|
+
*/
|
|
9
|
+
export declare function normaliseUrlPathname(pathname?: string): string;
|
|
10
|
+
export default normaliseUrlPathname;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import removeTralingSlash from "./removeTrailingSlash";
|
|
2
|
+
/**
|
|
3
|
+
* Normalise URL pathname (relative URL)
|
|
4
|
+
*
|
|
5
|
+
* - replaces too many consecutive slashes
|
|
6
|
+
* - removes the trailing slash
|
|
7
|
+
*
|
|
8
|
+
* @category location
|
|
9
|
+
*/
|
|
10
|
+
export function normaliseUrlPathname(pathname) {
|
|
11
|
+
if (pathname === void 0) { pathname = ""; }
|
|
12
|
+
return removeTralingSlash(pathname.replace(/\/+/g, "/"));
|
|
13
|
+
}
|
|
14
|
+
export default normaliseUrlPathname;
|
package/package.json
CHANGED
|
@@ -3,4 +3,7 @@ export declare type GtmPageviewArgs = [
|
|
|
3
3
|
page_title?: string,
|
|
4
4
|
page_location?: string
|
|
5
5
|
];
|
|
6
|
+
/**
|
|
7
|
+
* @category analytics-google
|
|
8
|
+
*/
|
|
6
9
|
export declare const pageview: (page_path?: string | undefined, page_title?: string | undefined, page_location?: string | undefined) => void;
|
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
import isUndefined from "./isUndefined";
|
|
2
|
+
/**
|
|
3
|
+
* @category analytics-google
|
|
4
|
+
*/
|
|
2
5
|
export var pageview = function () {
|
|
3
6
|
var args = [];
|
|
4
7
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
5
8
|
args[_i] = arguments[_i];
|
|
6
9
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
// }
|
|
10
|
+
if (!isUndefined(window) && !isUndefined(window.gtag)) {
|
|
11
|
+
window.gtag("event", "page_view", {
|
|
12
|
+
page_path: args[0] || location.pathname,
|
|
13
|
+
page_title: args[1] || document.title,
|
|
14
|
+
page_location: args[2] || location.href,
|
|
15
|
+
// send_to: '<GA_MEASUREMENT_ID>'
|
|
16
|
+
});
|
|
17
|
+
}
|
|
16
18
|
};
|
|
17
19
|
// export type GtmEventArgs = [
|
|
18
20
|
// eventCategory?: string,
|
package/parseCookie.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type CookieAttributesServer } from "./cookie";
|
|
2
|
+
/**
|
|
3
|
+
* Parse a cookie header.
|
|
4
|
+
*
|
|
5
|
+
* Parse the given cookie header string into an object
|
|
6
|
+
* The object has the various cookies as keys(names) => values
|
|
7
|
+
*
|
|
8
|
+
* @category cookie
|
|
9
|
+
*/
|
|
10
|
+
export declare function parseCookie<T extends Record<string, unknown> = Record<string, string>>(str: string, attributes?: CookieAttributesServer): T;
|
|
11
|
+
export default parseCookie;
|
package/parseCookie.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Try decoding a string using a decoding function.
|
|
3
|
+
*/
|
|
4
|
+
function tryDecode(str, decode) {
|
|
5
|
+
try {
|
|
6
|
+
return decode(str);
|
|
7
|
+
}
|
|
8
|
+
catch (e) {
|
|
9
|
+
return str;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Parse a cookie header.
|
|
14
|
+
*
|
|
15
|
+
* Parse the given cookie header string into an object
|
|
16
|
+
* The object has the various cookies as keys(names) => values
|
|
17
|
+
*
|
|
18
|
+
* @category cookie
|
|
19
|
+
*/
|
|
20
|
+
export function parseCookie(str, attributes) {
|
|
21
|
+
if (attributes === void 0) { attributes = {}; }
|
|
22
|
+
if (typeof str !== "string") {
|
|
23
|
+
throw new TypeError("argument str must be a string");
|
|
24
|
+
}
|
|
25
|
+
var obj = {};
|
|
26
|
+
var pairs = str.split(";");
|
|
27
|
+
var _a = attributes.decode, decode = _a === void 0 ? decodeURIComponent : _a;
|
|
28
|
+
for (var i = 0; i < pairs.length; i++) {
|
|
29
|
+
var pair = pairs[i];
|
|
30
|
+
var index = pair.indexOf("=");
|
|
31
|
+
// skip things that don't look like key=value
|
|
32
|
+
if (index < 0) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
var key = pair.substring(0, index).trim();
|
|
36
|
+
// only assign once
|
|
37
|
+
if (undefined == obj[key]) {
|
|
38
|
+
var val = pair.substring(index + 1, pair.length).trim();
|
|
39
|
+
// quoted values
|
|
40
|
+
if (val[0] === '"') {
|
|
41
|
+
val = val.slice(1, -1);
|
|
42
|
+
}
|
|
43
|
+
obj[key] = tryDecode(val, decode);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return obj;
|
|
47
|
+
}
|
|
48
|
+
export default parseCookie;
|
package/parseURL.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Solution without DOM or specific env native methods
|
|
3
|
+
*
|
|
4
|
+
* @category location
|
|
5
|
+
* @see https://stackoverflow.com/a/21553982/1938970
|
|
6
|
+
*/
|
|
7
|
+
export declare function parseURL(url: string): {
|
|
8
|
+
href: string;
|
|
9
|
+
protocol: string;
|
|
10
|
+
host: string;
|
|
11
|
+
hostname: string;
|
|
12
|
+
port: string;
|
|
13
|
+
pathname: string;
|
|
14
|
+
search: string;
|
|
15
|
+
hash: string;
|
|
16
|
+
} | null;
|
|
17
|
+
export default parseURL;
|
package/parseURL.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Solution without DOM or specific env native methods
|
|
3
|
+
*
|
|
4
|
+
* @category location
|
|
5
|
+
* @see https://stackoverflow.com/a/21553982/1938970
|
|
6
|
+
*/
|
|
7
|
+
export function parseURL(url) {
|
|
8
|
+
var match = url.match(/^(https?:)\/\/(([^:/?#]*)(?::([0-9]+))?)([/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/);
|
|
9
|
+
return (match && {
|
|
10
|
+
href: url,
|
|
11
|
+
protocol: match[1],
|
|
12
|
+
host: match[2],
|
|
13
|
+
hostname: match[3],
|
|
14
|
+
port: match[4],
|
|
15
|
+
pathname: match[5],
|
|
16
|
+
search: match[6],
|
|
17
|
+
hash: match[7],
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
export default parseURL;
|
package/randomInt.d.ts
ADDED
package/randomInt.js
ADDED
package/{misc.js → randomKey.js}
RENAMED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Get random key from given object
|
|
3
3
|
*
|
|
4
|
+
* @category misc
|
|
4
5
|
* @see https://stackoverflow.com/a/15106541/1938970
|
|
5
6
|
*/
|
|
6
7
|
export function randomKey(obj) {
|
|
7
8
|
var keys = Object.keys(obj);
|
|
8
9
|
return keys[(keys.length * Math.random()) << 0];
|
|
9
10
|
}
|
|
11
|
+
export default randomKey;
|
package/readCookie.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare function readCookie<T extends Record<string, unknown> = Record<string, string>>(name?: null): T;
|
|
2
|
+
export declare function readCookie<T extends Record<string, unknown> = Record<string, string>, N extends keyof T = keyof T>(name: N): T[N];
|
|
3
|
+
export default readCookie;
|
package/readCookie.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
function converterRead(value) {
|
|
2
|
+
if (value[0] === '"') {
|
|
3
|
+
value = value.slice(1, -1);
|
|
4
|
+
}
|
|
5
|
+
return value.replace(/(%[\dA-F]{2})+/gi, decodeURIComponent);
|
|
6
|
+
}
|
|
7
|
+
export function readCookie(name) {
|
|
8
|
+
if (typeof document === "undefined") {
|
|
9
|
+
if (process.env["NODE_ENV"] !== "production") {
|
|
10
|
+
console.warn("@koine/utils:cookie readCookie, document is undefined");
|
|
11
|
+
}
|
|
12
|
+
return name ? "" : {};
|
|
13
|
+
}
|
|
14
|
+
var cookies = document.cookie ? document.cookie.split("; ") : [];
|
|
15
|
+
var all = {};
|
|
16
|
+
for (var i = 0; i < cookies.length; i++) {
|
|
17
|
+
var parts = cookies[i].split("=");
|
|
18
|
+
var value = parts.slice(1).join("=");
|
|
19
|
+
try {
|
|
20
|
+
var found = decodeURIComponent(parts[0]);
|
|
21
|
+
all[found] = converterRead(value);
|
|
22
|
+
if (name === found) {
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
if (process.env["NODE_ENV"] !== "production") {
|
|
28
|
+
console.warn("@koine/utils:cookie readCookie, failed to decode", value);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return name ? all[name] : all;
|
|
33
|
+
}
|
|
34
|
+
export default readCookie;
|
package/redirectTo.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type AnyQueryParams } from "./location";
|
|
2
|
+
/**
|
|
3
|
+
* Redirect to url with params {optionally}, removes eventual trailing question
|
|
4
|
+
* marks from the given URL, it uses `location`
|
|
5
|
+
*
|
|
6
|
+
* @category location
|
|
7
|
+
*/
|
|
8
|
+
export declare function redirectTo(url: string, params?: AnyQueryParams): void;
|
|
9
|
+
export default redirectTo;
|
package/redirectTo.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import buildUrlQueryString from "./buildUrlQueryString";
|
|
2
|
+
import isBrowser from "./isBrowser";
|
|
3
|
+
/**
|
|
4
|
+
* Redirect to url with params {optionally}, removes eventual trailing question
|
|
5
|
+
* marks from the given URL, it uses `location`
|
|
6
|
+
*
|
|
7
|
+
* @category location
|
|
8
|
+
*/
|
|
9
|
+
export function redirectTo(url, params) {
|
|
10
|
+
if (isBrowser) {
|
|
11
|
+
var queryString = buildUrlQueryString(params);
|
|
12
|
+
location.href = url.replace(/\?+$/g, "") + queryString;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export default redirectTo;
|
package/removeAccents.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { accentsSets } from "./accentSets";
|
|
2
|
+
/**
|
|
3
|
+
* @category text
|
|
4
|
+
*/
|
|
5
|
+
export function removeAccents(text, sets) {
|
|
6
|
+
if (text === void 0) { text = ""; }
|
|
7
|
+
if (sets === void 0) { sets = accentsSets; }
|
|
8
|
+
var len = sets.length;
|
|
9
|
+
while (len--) {
|
|
10
|
+
var _a = sets[len], to = _a[0], from = _a[1];
|
|
11
|
+
text = text.replace(new RegExp("[".concat(from, "]"), "gi"), to);
|
|
12
|
+
}
|
|
13
|
+
return text;
|
|
14
|
+
}
|
|
15
|
+
export default removeAccents;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type CookieAttributesClient } from "./cookie";
|
|
2
|
+
/**
|
|
3
|
+
* @category cookie
|
|
4
|
+
*
|
|
5
|
+
* All cookie related code is inspired and adapted from:
|
|
6
|
+
* - [js-cookie](https://github.com/js-cookie/js-cookie)
|
|
7
|
+
* - [cookie](https://github.com/jshttp/cookie)
|
|
8
|
+
*/
|
|
9
|
+
export declare function removeCookie(name: string, attributes?: CookieAttributesClient): void;
|
|
10
|
+
export default removeCookie;
|
package/removeCookie.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { __assign } from "tslib";
|
|
2
|
+
import { defaultAttributesClient } from "./cookie";
|
|
3
|
+
import { setCookie } from "./setCookie";
|
|
4
|
+
/**
|
|
5
|
+
* @category cookie
|
|
6
|
+
*
|
|
7
|
+
* All cookie related code is inspired and adapted from:
|
|
8
|
+
* - [js-cookie](https://github.com/js-cookie/js-cookie)
|
|
9
|
+
* - [cookie](https://github.com/jshttp/cookie)
|
|
10
|
+
*/
|
|
11
|
+
export function removeCookie(name, attributes) {
|
|
12
|
+
if (attributes === void 0) { attributes = {}; }
|
|
13
|
+
setCookie(name, "", __assign(__assign(__assign({}, defaultAttributesClient), attributes), { expires: -1 }));
|
|
14
|
+
}
|
|
15
|
+
export default removeCookie;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Remove duplicated array objects, equality is determined by a strict (`===`)
|
|
3
|
+
* comparison of each object's given key
|
|
4
|
+
*
|
|
5
|
+
* @category array
|
|
6
|
+
*/
|
|
7
|
+
export declare function removeDuplicatesByKey<T extends Record<string | number | symbol, any>>(array?: T[], key?: keyof T): T[];
|
|
8
|
+
export default removeDuplicatesByKey;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Remove duplicated array objects, equality is determined by a strict (`===`)
|
|
3
|
+
* comparison of each object's given key
|
|
4
|
+
*
|
|
5
|
+
* @category array
|
|
6
|
+
*/
|
|
7
|
+
export function removeDuplicatesByKey(array, key) {
|
|
8
|
+
if (array === void 0) { array = []; }
|
|
9
|
+
if (key === void 0) { key = ""; }
|
|
10
|
+
var keysMap = {};
|
|
11
|
+
var output = [];
|
|
12
|
+
for (var i = 0; i < array.length; i++) {
|
|
13
|
+
var item = array[i];
|
|
14
|
+
if (!keysMap[item[key]]) {
|
|
15
|
+
output.push(item);
|
|
16
|
+
keysMap[item[key]] = true;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return output;
|
|
20
|
+
}
|
|
21
|
+
export default removeDuplicatesByKey;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { removeIndexesFromArray } from "./removeIndexesFromArray";
|
|
2
|
+
import { findDuplicatedIndexes } from "./findDuplicatedIndexes";
|
|
3
|
+
/**
|
|
4
|
+
* @category array
|
|
5
|
+
*/
|
|
6
|
+
export function removeDuplicatesComparing(from, to) {
|
|
7
|
+
var indexes = findDuplicatedIndexes(from);
|
|
8
|
+
return removeIndexesFromArray(to, indexes);
|
|
9
|
+
}
|
|
10
|
+
export default removeDuplicatesComparing;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @category array
|
|
3
|
+
*/
|
|
4
|
+
export function removeIndexesFromArray(arr, indexes) {
|
|
5
|
+
var output = [];
|
|
6
|
+
for (var i = 0; i < arr.length; i++) {
|
|
7
|
+
// eslint-disable-next-line no-prototype-builtins
|
|
8
|
+
if (!indexes.hasOwnProperty(i)) {
|
|
9
|
+
output.push(arr[i]);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return output;
|
|
13
|
+
}
|
|
14
|
+
export default removeIndexesFromArray;
|
package/roundTo.d.ts
ADDED
package/{math.js → roundTo.js}
RENAMED
|
@@ -1,20 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get random int (min and max included)
|
|
3
|
-
*/
|
|
4
|
-
export function randomInt(min, max) {
|
|
5
|
-
return Math.floor(Math.random() * (max - min + 1) + min);
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* Returns a number whose value is limited to the given range.
|
|
9
|
-
*
|
|
10
|
-
* @see https://stackoverflow.com/a/11409944/1938970
|
|
11
|
-
*/
|
|
12
|
-
export function clamp(num, min, max) {
|
|
13
|
-
return Math.min(Math.max(num, min), max);
|
|
14
|
-
}
|
|
15
1
|
/**
|
|
16
2
|
* Round to given number of the given number of decimals
|
|
17
3
|
*
|
|
4
|
+
* @category math
|
|
18
5
|
* @see https://stackoverflow.com/a/15762794/1938970
|
|
19
6
|
*/
|
|
20
7
|
export function roundTo(num, decimals) {
|
|
@@ -44,17 +31,4 @@ export function roundTo(num, decimals) {
|
|
|
44
31
|
}
|
|
45
32
|
return "";
|
|
46
33
|
}
|
|
47
|
-
|
|
48
|
-
* Convert range of a number
|
|
49
|
-
*
|
|
50
|
-
* e.g. converting number 5 in a scale/range from 0 10 to a scale/range from 50
|
|
51
|
-
* to 100 would return 75
|
|
52
|
-
* ```
|
|
53
|
-
* convertRange(5, [0, 10], [50, 100]);
|
|
54
|
-
* ```
|
|
55
|
-
*
|
|
56
|
-
* @see https://stackoverflow.com/a/14224813
|
|
57
|
-
*/
|
|
58
|
-
export function convertRange(num, r1, r2) {
|
|
59
|
-
return ((num - r1[0]) * (r2[1] - r2[0])) / (r1[1] - r1[0]) + r2[0];
|
|
60
|
-
}
|
|
34
|
+
export default roundTo;
|