@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,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseCookie = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Try decoding a string using a decoding function.
|
|
6
|
+
*/
|
|
7
|
+
function tryDecode(str, decode) {
|
|
8
|
+
try {
|
|
9
|
+
return decode(str);
|
|
10
|
+
}
|
|
11
|
+
catch (e) {
|
|
12
|
+
return str;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Parse a cookie header.
|
|
17
|
+
*
|
|
18
|
+
* Parse the given cookie header string into an object
|
|
19
|
+
* The object has the various cookies as keys(names) => values
|
|
20
|
+
*
|
|
21
|
+
* @category cookie
|
|
22
|
+
*/
|
|
23
|
+
function parseCookie(str, attributes) {
|
|
24
|
+
if (attributes === void 0) { attributes = {}; }
|
|
25
|
+
if (typeof str !== "string") {
|
|
26
|
+
throw new TypeError("argument str must be a string");
|
|
27
|
+
}
|
|
28
|
+
var obj = {};
|
|
29
|
+
var pairs = str.split(";");
|
|
30
|
+
var _a = attributes.decode, decode = _a === void 0 ? decodeURIComponent : _a;
|
|
31
|
+
for (var i = 0; i < pairs.length; i++) {
|
|
32
|
+
var pair = pairs[i];
|
|
33
|
+
var index = pair.indexOf("=");
|
|
34
|
+
// skip things that don't look like key=value
|
|
35
|
+
if (index < 0) {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
var key = pair.substring(0, index).trim();
|
|
39
|
+
// only assign once
|
|
40
|
+
if (undefined == obj[key]) {
|
|
41
|
+
var val = pair.substring(index + 1, pair.length).trim();
|
|
42
|
+
// quoted values
|
|
43
|
+
if (val[0] === '"') {
|
|
44
|
+
val = val.slice(1, -1);
|
|
45
|
+
}
|
|
46
|
+
obj[key] = tryDecode(val, decode);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return obj;
|
|
50
|
+
}
|
|
51
|
+
exports.parseCookie = parseCookie;
|
|
52
|
+
exports.default = parseCookie;
|
package/node/parseURL.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseURL = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Solution without DOM or specific env native methods
|
|
6
|
+
*
|
|
7
|
+
* @category location
|
|
8
|
+
* @see https://stackoverflow.com/a/21553982/1938970
|
|
9
|
+
*/
|
|
10
|
+
function parseURL(url) {
|
|
11
|
+
var match = url.match(/^(https?:)\/\/(([^:/?#]*)(?::([0-9]+))?)([/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/);
|
|
12
|
+
return (match && {
|
|
13
|
+
href: url,
|
|
14
|
+
protocol: match[1],
|
|
15
|
+
host: match[2],
|
|
16
|
+
hostname: match[3],
|
|
17
|
+
port: match[4],
|
|
18
|
+
pathname: match[5],
|
|
19
|
+
search: match[6],
|
|
20
|
+
hash: match[7],
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
exports.parseURL = parseURL;
|
|
24
|
+
exports.default = parseURL;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.randomInt = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Get random int (min and max included)
|
|
6
|
+
*
|
|
7
|
+
* @category math
|
|
8
|
+
*/
|
|
9
|
+
function randomInt(min, max) {
|
|
10
|
+
return Math.floor(Math.random() * (max - min + 1) + min);
|
|
11
|
+
}
|
|
12
|
+
exports.randomInt = randomInt;
|
|
13
|
+
exports.default = randomInt;
|
|
@@ -4,6 +4,7 @@ exports.randomKey = void 0;
|
|
|
4
4
|
/**
|
|
5
5
|
* Get random key from given object
|
|
6
6
|
*
|
|
7
|
+
* @category misc
|
|
7
8
|
* @see https://stackoverflow.com/a/15106541/1938970
|
|
8
9
|
*/
|
|
9
10
|
function randomKey(obj) {
|
|
@@ -11,3 +12,4 @@ function randomKey(obj) {
|
|
|
11
12
|
return keys[(keys.length * Math.random()) << 0];
|
|
12
13
|
}
|
|
13
14
|
exports.randomKey = randomKey;
|
|
15
|
+
exports.default = randomKey;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readCookie = void 0;
|
|
4
|
+
function converterRead(value) {
|
|
5
|
+
if (value[0] === '"') {
|
|
6
|
+
value = value.slice(1, -1);
|
|
7
|
+
}
|
|
8
|
+
return value.replace(/(%[\dA-F]{2})+/gi, decodeURIComponent);
|
|
9
|
+
}
|
|
10
|
+
function readCookie(name) {
|
|
11
|
+
if (typeof document === "undefined") {
|
|
12
|
+
if (process.env["NODE_ENV"] !== "production") {
|
|
13
|
+
console.warn("@koine/utils:cookie readCookie, document is undefined");
|
|
14
|
+
}
|
|
15
|
+
return name ? "" : {};
|
|
16
|
+
}
|
|
17
|
+
var cookies = document.cookie ? document.cookie.split("; ") : [];
|
|
18
|
+
var all = {};
|
|
19
|
+
for (var i = 0; i < cookies.length; i++) {
|
|
20
|
+
var parts = cookies[i].split("=");
|
|
21
|
+
var value = parts.slice(1).join("=");
|
|
22
|
+
try {
|
|
23
|
+
var found = decodeURIComponent(parts[0]);
|
|
24
|
+
all[found] = converterRead(value);
|
|
25
|
+
if (name === found) {
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
catch (e) {
|
|
30
|
+
if (process.env["NODE_ENV"] !== "production") {
|
|
31
|
+
console.warn("@koine/utils:cookie readCookie, failed to decode", value);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return name ? all[name] : all;
|
|
36
|
+
}
|
|
37
|
+
exports.readCookie = readCookie;
|
|
38
|
+
exports.default = readCookie;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.redirectTo = void 0;
|
|
4
|
+
var buildUrlQueryString_1 = require("./buildUrlQueryString");
|
|
5
|
+
var isBrowser_1 = require("./isBrowser");
|
|
6
|
+
/**
|
|
7
|
+
* Redirect to url with params {optionally}, removes eventual trailing question
|
|
8
|
+
* marks from the given URL, it uses `location`
|
|
9
|
+
*
|
|
10
|
+
* @category location
|
|
11
|
+
*/
|
|
12
|
+
function redirectTo(url, params) {
|
|
13
|
+
if (isBrowser_1.default) {
|
|
14
|
+
var queryString = (0, buildUrlQueryString_1.default)(params);
|
|
15
|
+
location.href = url.replace(/\?+$/g, "") + queryString;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.redirectTo = redirectTo;
|
|
19
|
+
exports.default = redirectTo;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.removeAccents = void 0;
|
|
4
|
+
var accentSets_1 = require("./accentSets");
|
|
5
|
+
/**
|
|
6
|
+
* @category text
|
|
7
|
+
*/
|
|
8
|
+
function removeAccents(text, sets) {
|
|
9
|
+
if (text === void 0) { text = ""; }
|
|
10
|
+
if (sets === void 0) { sets = accentSets_1.accentsSets; }
|
|
11
|
+
var len = sets.length;
|
|
12
|
+
while (len--) {
|
|
13
|
+
var _a = sets[len], to = _a[0], from = _a[1];
|
|
14
|
+
text = text.replace(new RegExp("[".concat(from, "]"), "gi"), to);
|
|
15
|
+
}
|
|
16
|
+
return text;
|
|
17
|
+
}
|
|
18
|
+
exports.removeAccents = removeAccents;
|
|
19
|
+
exports.default = removeAccents;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.removeCookie = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var cookie_1 = require("./cookie");
|
|
6
|
+
var setCookie_1 = require("./setCookie");
|
|
7
|
+
/**
|
|
8
|
+
* @category cookie
|
|
9
|
+
*
|
|
10
|
+
* All cookie related code is inspired and adapted from:
|
|
11
|
+
* - [js-cookie](https://github.com/js-cookie/js-cookie)
|
|
12
|
+
* - [cookie](https://github.com/jshttp/cookie)
|
|
13
|
+
*/
|
|
14
|
+
function removeCookie(name, attributes) {
|
|
15
|
+
if (attributes === void 0) { attributes = {}; }
|
|
16
|
+
(0, setCookie_1.setCookie)(name, "", tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, cookie_1.defaultAttributesClient), attributes), { expires: -1 }));
|
|
17
|
+
}
|
|
18
|
+
exports.removeCookie = removeCookie;
|
|
19
|
+
exports.default = removeCookie;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.removeDuplicatesByKey = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Remove duplicated array objects, equality is determined by a strict (`===`)
|
|
6
|
+
* comparison of each object's given key
|
|
7
|
+
*
|
|
8
|
+
* @category array
|
|
9
|
+
*/
|
|
10
|
+
function removeDuplicatesByKey(array, key) {
|
|
11
|
+
if (array === void 0) { array = []; }
|
|
12
|
+
if (key === void 0) { key = ""; }
|
|
13
|
+
var keysMap = {};
|
|
14
|
+
var output = [];
|
|
15
|
+
for (var i = 0; i < array.length; i++) {
|
|
16
|
+
var item = array[i];
|
|
17
|
+
if (!keysMap[item[key]]) {
|
|
18
|
+
output.push(item);
|
|
19
|
+
keysMap[item[key]] = true;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return output;
|
|
23
|
+
}
|
|
24
|
+
exports.removeDuplicatesByKey = removeDuplicatesByKey;
|
|
25
|
+
exports.default = removeDuplicatesByKey;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.removeDuplicatesComparing = void 0;
|
|
4
|
+
var removeIndexesFromArray_1 = require("./removeIndexesFromArray");
|
|
5
|
+
var findDuplicatedIndexes_1 = require("./findDuplicatedIndexes");
|
|
6
|
+
/**
|
|
7
|
+
* @category array
|
|
8
|
+
*/
|
|
9
|
+
function removeDuplicatesComparing(from, to) {
|
|
10
|
+
var indexes = (0, findDuplicatedIndexes_1.findDuplicatedIndexes)(from);
|
|
11
|
+
return (0, removeIndexesFromArray_1.removeIndexesFromArray)(to, indexes);
|
|
12
|
+
}
|
|
13
|
+
exports.removeDuplicatesComparing = removeDuplicatesComparing;
|
|
14
|
+
exports.default = removeDuplicatesComparing;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.removeIndexesFromArray = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @category array
|
|
6
|
+
*/
|
|
7
|
+
function removeIndexesFromArray(arr, indexes) {
|
|
8
|
+
var output = [];
|
|
9
|
+
for (var i = 0; i < arr.length; i++) {
|
|
10
|
+
// eslint-disable-next-line no-prototype-builtins
|
|
11
|
+
if (!indexes.hasOwnProperty(i)) {
|
|
12
|
+
output.push(arr[i]);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return output;
|
|
16
|
+
}
|
|
17
|
+
exports.removeIndexesFromArray = removeIndexesFromArray;
|
|
18
|
+
exports.default = removeIndexesFromArray;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.removeTralingSlash = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Strips out the trailing slash
|
|
6
|
+
*
|
|
7
|
+
* @category location
|
|
8
|
+
*/
|
|
9
|
+
function removeTralingSlash(urlLike) {
|
|
10
|
+
if (urlLike === void 0) { urlLike = ""; }
|
|
11
|
+
return urlLike.replace(/\/*$/, "");
|
|
12
|
+
}
|
|
13
|
+
exports.removeTralingSlash = removeTralingSlash;
|
|
14
|
+
exports.default = removeTralingSlash;
|
|
@@ -1,25 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
/**
|
|
5
|
-
* Get random int (min and max included)
|
|
6
|
-
*/
|
|
7
|
-
function randomInt(min, max) {
|
|
8
|
-
return Math.floor(Math.random() * (max - min + 1) + min);
|
|
9
|
-
}
|
|
10
|
-
exports.randomInt = randomInt;
|
|
11
|
-
/**
|
|
12
|
-
* Returns a number whose value is limited to the given range.
|
|
13
|
-
*
|
|
14
|
-
* @see https://stackoverflow.com/a/11409944/1938970
|
|
15
|
-
*/
|
|
16
|
-
function clamp(num, min, max) {
|
|
17
|
-
return Math.min(Math.max(num, min), max);
|
|
18
|
-
}
|
|
19
|
-
exports.clamp = clamp;
|
|
3
|
+
exports.roundTo = void 0;
|
|
20
4
|
/**
|
|
21
5
|
* Round to given number of the given number of decimals
|
|
22
6
|
*
|
|
7
|
+
* @category math
|
|
23
8
|
* @see https://stackoverflow.com/a/15762794/1938970
|
|
24
9
|
*/
|
|
25
10
|
function roundTo(num, decimals) {
|
|
@@ -50,18 +35,4 @@ function roundTo(num, decimals) {
|
|
|
50
35
|
return "";
|
|
51
36
|
}
|
|
52
37
|
exports.roundTo = roundTo;
|
|
53
|
-
|
|
54
|
-
* Convert range of a number
|
|
55
|
-
*
|
|
56
|
-
* e.g. converting number 5 in a scale/range from 0 10 to a scale/range from 50
|
|
57
|
-
* to 100 would return 75
|
|
58
|
-
* ```
|
|
59
|
-
* convertRange(5, [0, 10], [50, 100]);
|
|
60
|
-
* ```
|
|
61
|
-
*
|
|
62
|
-
* @see https://stackoverflow.com/a/14224813
|
|
63
|
-
*/
|
|
64
|
-
function convertRange(num, r1, r2) {
|
|
65
|
-
return ((num - r1[0]) * (r2[1] - r2[0])) / (r1[1] - r1[0]) + r2[0];
|
|
66
|
-
}
|
|
67
|
-
exports.convertRange = convertRange;
|
|
38
|
+
exports.default = roundTo;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.serializeCookie = void 0;
|
|
13
|
+
var isNumber_1 = require("./isNumber");
|
|
14
|
+
/**
|
|
15
|
+
* RegExp to match field-content in RFC 7230 sec 3.2
|
|
16
|
+
*
|
|
17
|
+
* field-content = field-vchar [ 1*( SP / HTAB ) field-vchar ]
|
|
18
|
+
* field-vchar = VCHAR / obs-text
|
|
19
|
+
* obs-text = %x80-FF
|
|
20
|
+
*/
|
|
21
|
+
// eslint-disable-next-line no-control-regex
|
|
22
|
+
var fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;
|
|
23
|
+
/**
|
|
24
|
+
* Serialize data into a cookie header.
|
|
25
|
+
*
|
|
26
|
+
* Serialize the a name value pair into a cookie string suitable for
|
|
27
|
+
* http headers. An optional attributes object specified cookie parameters.
|
|
28
|
+
*
|
|
29
|
+
* serialize('foo', 'bar', { httpOnly: true })
|
|
30
|
+
* => "foo=bar; httpOnly"
|
|
31
|
+
*
|
|
32
|
+
* @category cookie
|
|
33
|
+
*
|
|
34
|
+
* All cookie related code is inspired and adapted from:
|
|
35
|
+
* - [js-cookie](https://github.com/js-cookie/js-cookie)
|
|
36
|
+
* - [cookie](https://github.com/jshttp/cookie)
|
|
37
|
+
*/
|
|
38
|
+
function serializeCookie(name, val, attributes) {
|
|
39
|
+
if (attributes === void 0) { attributes = {}; }
|
|
40
|
+
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;
|
|
41
|
+
var maxAge = attributes.maxAge, expires = attributes.expires;
|
|
42
|
+
var value = encode(val);
|
|
43
|
+
if (process.env["NODE_ENV"] !== "production") {
|
|
44
|
+
if (!fieldContentRegExp.test(name)) {
|
|
45
|
+
throw new TypeError("argument name is invalid");
|
|
46
|
+
}
|
|
47
|
+
if (typeof attributes.encode !== "function") {
|
|
48
|
+
throw new TypeError("option encode is invalid");
|
|
49
|
+
}
|
|
50
|
+
if (value && !fieldContentRegExp.test(value)) {
|
|
51
|
+
throw new TypeError("argument val is invalid");
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
var str = name + "=" + value;
|
|
55
|
+
if (null != maxAge) {
|
|
56
|
+
maxAge = maxAge - 0;
|
|
57
|
+
if (isNaN(maxAge) || !isFinite(maxAge)) {
|
|
58
|
+
throw new TypeError("option maxAge is invalid");
|
|
59
|
+
}
|
|
60
|
+
str += "; Max-Age=" + Math.floor(maxAge);
|
|
61
|
+
}
|
|
62
|
+
if (domain) {
|
|
63
|
+
if (process.env["NODE_ENV"] !== "production") {
|
|
64
|
+
if (!fieldContentRegExp.test(domain)) {
|
|
65
|
+
throw new TypeError("option domain is invalid");
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
str += "; Domain=" + domain;
|
|
69
|
+
}
|
|
70
|
+
if (path) {
|
|
71
|
+
if (process.env["NODE_ENV"] !== "production") {
|
|
72
|
+
if (!fieldContentRegExp.test(path)) {
|
|
73
|
+
throw new TypeError("option path is invalid");
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
str += "; Path=" + path;
|
|
77
|
+
}
|
|
78
|
+
if (expires) {
|
|
79
|
+
if ((0, isNumber_1.isNumber)(expires)) {
|
|
80
|
+
expires = new Date(Date.now() + expires * 864e5);
|
|
81
|
+
}
|
|
82
|
+
str += "; Expires=" + expires.toUTCString();
|
|
83
|
+
}
|
|
84
|
+
if (httpOnly) {
|
|
85
|
+
str += "; HttpOnly";
|
|
86
|
+
}
|
|
87
|
+
if (secure) {
|
|
88
|
+
str += "; Secure";
|
|
89
|
+
}
|
|
90
|
+
if (sameSite) {
|
|
91
|
+
switch (sameSite.toLowerCase()) {
|
|
92
|
+
case "lax":
|
|
93
|
+
str += "; SameSite=Lax";
|
|
94
|
+
break;
|
|
95
|
+
case "strict":
|
|
96
|
+
str += "; SameSite=Strict";
|
|
97
|
+
break;
|
|
98
|
+
case "none":
|
|
99
|
+
str += "; SameSite=None";
|
|
100
|
+
break;
|
|
101
|
+
// default:
|
|
102
|
+
// throw new TypeError('option sameSite is invalid');
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return str;
|
|
106
|
+
}
|
|
107
|
+
exports.serializeCookie = serializeCookie;
|
|
108
|
+
exports.default = serializeCookie;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setCookie = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var cookie_1 = require("./cookie");
|
|
6
|
+
var isNumber_1 = require("./isNumber");
|
|
7
|
+
function converterWrite(value) {
|
|
8
|
+
return encodeURIComponent(value).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g, decodeURIComponent);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* @category cookie
|
|
12
|
+
*
|
|
13
|
+
* All cookie related code is inspired and adapted from:
|
|
14
|
+
* - [js-cookie](https://github.com/js-cookie/js-cookie)
|
|
15
|
+
* - [cookie](https://github.com/jshttp/cookie)
|
|
16
|
+
*/
|
|
17
|
+
function setCookie(name, value, attributes) {
|
|
18
|
+
if (attributes === void 0) { attributes = {}; }
|
|
19
|
+
// eslint-disable-next-line prefer-const
|
|
20
|
+
var expires = attributes.expires, restAttrs = tslib_1.__rest(attributes, ["expires"]);
|
|
21
|
+
var cleanedAttrs = tslib_1.__assign(tslib_1.__assign({ expires: "" }, cookie_1.defaultAttributesClient), restAttrs);
|
|
22
|
+
if (typeof document === "undefined") {
|
|
23
|
+
if (process.env["NODE_ENV"] !== "production") {
|
|
24
|
+
console.warn("@koine/utils:cookie setCookie, document is undefined");
|
|
25
|
+
}
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if ((0, isNumber_1.default)(expires)) {
|
|
29
|
+
expires = new Date(Date.now() + expires * 864e5);
|
|
30
|
+
}
|
|
31
|
+
if (expires) {
|
|
32
|
+
cleanedAttrs.expires = expires.toUTCString();
|
|
33
|
+
}
|
|
34
|
+
name = encodeURIComponent(name)
|
|
35
|
+
.replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent)
|
|
36
|
+
.replace(/[()]/g, escape);
|
|
37
|
+
var stringifiedAttributes = "";
|
|
38
|
+
for (var name_1 in attributes) {
|
|
39
|
+
var attrName = name_1;
|
|
40
|
+
if (!attributes[attrName]) {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
stringifiedAttributes += "; " + attrName;
|
|
44
|
+
if (attributes[attrName] === true) {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
// Considers RFC 6265 section 5.2:
|
|
48
|
+
// ...
|
|
49
|
+
// 3. If the remaining unparsed-attributes contains a %x3B (";")
|
|
50
|
+
// character:
|
|
51
|
+
// Consume the characters of the unparsed-attributes up to,
|
|
52
|
+
// not including, the first %x3B (";") character.
|
|
53
|
+
// ...
|
|
54
|
+
stringifiedAttributes +=
|
|
55
|
+
"=" + String(attributes[attrName]).split(";")[0];
|
|
56
|
+
}
|
|
57
|
+
return (document.cookie =
|
|
58
|
+
name + "=" + converterWrite(value) + stringifiedAttributes);
|
|
59
|
+
}
|
|
60
|
+
exports.setCookie = setCookie;
|
|
61
|
+
exports.default = setCookie;
|
package/node/shuffle.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.shuffle = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
/**
|
|
6
|
+
* Creates an array of shuffled values, using a version of the
|
|
7
|
+
* [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
|
|
8
|
+
*
|
|
9
|
+
* @see lodash.shuffle
|
|
10
|
+
* @since 0.1.0
|
|
11
|
+
* @category arrays
|
|
12
|
+
* @param {Array} array The array to shuffle.
|
|
13
|
+
* @returns {Array} Returns the new shuffled array.
|
|
14
|
+
* @example
|
|
15
|
+
*
|
|
16
|
+
* shuffle([1, 2, 3, 4])
|
|
17
|
+
* // => [4, 1, 3, 2]
|
|
18
|
+
*/
|
|
19
|
+
function shuffle(array) {
|
|
20
|
+
var length = array == null ? 0 : array.length;
|
|
21
|
+
if (!length) {
|
|
22
|
+
return [];
|
|
23
|
+
}
|
|
24
|
+
var index = -1;
|
|
25
|
+
var lastIndex = length - 1;
|
|
26
|
+
var result = tslib_1.__spreadArray([], array, true);
|
|
27
|
+
while (++index < length) {
|
|
28
|
+
var rand = index + Math.floor(Math.random() * (lastIndex - index + 1));
|
|
29
|
+
var value = result[rand];
|
|
30
|
+
result[rand] = result[index];
|
|
31
|
+
result[index] = value;
|
|
32
|
+
}
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
exports.shuffle = shuffle;
|
|
36
|
+
exports.default = shuffle;
|
package/node/slugify.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.slugify = void 0;
|
|
4
|
+
var accentSets_1 = require("./accentSets");
|
|
5
|
+
var removeAccents_1 = require("./removeAccents");
|
|
6
|
+
/**
|
|
7
|
+
* Slugify a text
|
|
8
|
+
*
|
|
9
|
+
* - replaces the accented letters
|
|
10
|
+
* - replaces the punctuation with dashes
|
|
11
|
+
*
|
|
12
|
+
* @category text
|
|
13
|
+
* @see https://gist.github.com/mathewbyrne/1280286#gistcomment-3498021
|
|
14
|
+
*/
|
|
15
|
+
function slugify(text, separator) {
|
|
16
|
+
if (separator === void 0) { separator = "-"; }
|
|
17
|
+
return (0, removeAccents_1.removeAccents)(text.toString().toLowerCase().trim(), accentSets_1.accentsSets.concat([["-", "[·/_,:;']"]]))
|
|
18
|
+
.replace(/\s+/g, "-") // replace spaces with -
|
|
19
|
+
.replace(/&/g, "-and-") // replace & with 'and'
|
|
20
|
+
.replace(/[^\w-]+/g, "") // remove all non-word chars
|
|
21
|
+
.replace(/--+/g, "-") // replace multiple - with single -
|
|
22
|
+
.replace(/^-+/, "") // trim - from start of text
|
|
23
|
+
.replace(/-+$/, "") // trim - from end of text
|
|
24
|
+
.replace(/-/g, separator);
|
|
25
|
+
}
|
|
26
|
+
exports.slugify = slugify;
|
|
27
|
+
exports.default = slugify;
|
package/node/swapMap.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.swapMap = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Swap object map key/value
|
|
6
|
+
*
|
|
7
|
+
* @category objects
|
|
8
|
+
*/
|
|
9
|
+
function swapMap(map) {
|
|
10
|
+
if (map === void 0) { map = {}; }
|
|
11
|
+
var output = {};
|
|
12
|
+
for (var key in map) {
|
|
13
|
+
output[map[key]] = key;
|
|
14
|
+
}
|
|
15
|
+
return output;
|
|
16
|
+
}
|
|
17
|
+
exports.swapMap = swapMap;
|
|
18
|
+
exports.default = swapMap;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.titleCase = void 0;
|
|
4
4
|
/**
|
|
5
|
+
* @category typography
|
|
5
6
|
* @see https://github.com/blakeembrey/change-case/blob/master/packages/title-case/src/index.ts
|
|
6
7
|
* @author Blake Embrey (hello@blakeembrey.com)
|
|
7
8
|
*/
|
|
@@ -11,14 +12,4 @@ var titleCase = function (input) {
|
|
|
11
12
|
: "";
|
|
12
13
|
};
|
|
13
14
|
exports.titleCase = titleCase;
|
|
14
|
-
|
|
15
|
-
* Truncate string
|
|
16
|
-
*/
|
|
17
|
-
var truncate = function (input, length) {
|
|
18
|
-
return input
|
|
19
|
-
? input.length > length
|
|
20
|
-
? input.substring(0, length) + "..."
|
|
21
|
-
: input
|
|
22
|
-
: "";
|
|
23
|
-
};
|
|
24
|
-
exports.truncate = truncate;
|
|
15
|
+
exports.default = exports.titleCase;
|
package/node/toNumber.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toNumber = void 0;
|
|
4
|
+
var isNumber_1 = require("./isNumber");
|
|
5
|
+
/**
|
|
6
|
+
* @category cast
|
|
7
|
+
*/
|
|
8
|
+
function toNumber(input, fallback) {
|
|
9
|
+
return (0, isNumber_1.isNumber)(input) ? input : input ? parseFloat(input) : fallback || 0;
|
|
10
|
+
}
|
|
11
|
+
exports.toNumber = toNumber;
|
|
12
|
+
exports.default = toNumber;
|
|
@@ -5,6 +5,9 @@ exports.toRgba = void 0;
|
|
|
5
5
|
// export const toRgb = (hexColor: string) => hexRgb(hexColor, { format: "css" });
|
|
6
6
|
// export const toRgba = (hexColor: string, alpha: number) =>
|
|
7
7
|
// hexRgb(hexColor, { format: "css", alpha });
|
|
8
|
+
/**
|
|
9
|
+
* @category colors
|
|
10
|
+
*/
|
|
8
11
|
function toRgba(hex, alpha) {
|
|
9
12
|
if (alpha === void 0) { alpha = 1; }
|
|
10
13
|
var r = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
|
@@ -14,3 +17,4 @@ function toRgba(hex, alpha) {
|
|
|
14
17
|
return "";
|
|
15
18
|
}
|
|
16
19
|
exports.toRgba = toRgba;
|
|
20
|
+
exports.default = toRgba;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformToUrlPathname = void 0;
|
|
4
|
+
var isString_1 = require("./isString");
|
|
5
|
+
/**
|
|
6
|
+
* Transform string in a URL pathname (relative URL)
|
|
7
|
+
*
|
|
8
|
+
* - adds an initial slash
|
|
9
|
+
* - encode the string
|
|
10
|
+
* - replaces whitespaces with dashes
|
|
11
|
+
*
|
|
12
|
+
* @category location
|
|
13
|
+
*/
|
|
14
|
+
function transformToUrlPathname(toPathname) {
|
|
15
|
+
return (0, isString_1.default)(toPathname)
|
|
16
|
+
? "/".concat(encodeURIComponent(toPathname.replace(/\s/g, "-").toLowerCase()))
|
|
17
|
+
: "";
|
|
18
|
+
}
|
|
19
|
+
exports.transformToUrlPathname = transformToUrlPathname;
|
|
20
|
+
exports.default = transformToUrlPathname;
|
package/node/truncate.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.truncate = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Truncate string
|
|
6
|
+
*
|
|
7
|
+
* @category typography
|
|
8
|
+
*/
|
|
9
|
+
var truncate = function (input, length) {
|
|
10
|
+
return input
|
|
11
|
+
? input.length > length
|
|
12
|
+
? input.substring(0, length) + "..."
|
|
13
|
+
: input
|
|
14
|
+
: "";
|
|
15
|
+
};
|
|
16
|
+
exports.truncate = truncate;
|
|
17
|
+
exports.default = exports.truncate;
|