@koine/utils 2.0.0-beta.1 → 2.0.0-beta.11
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/Defer.mjs +6 -5
- package/Emitter.d.ts +3 -1
- package/Emitter.mjs +16 -17
- package/README.md +6 -1
- package/accentSets.d.ts +3 -2
- package/accentSets.mjs +116 -31
- package/addOrReplaceAtIdx.d.ts +4 -0
- package/addOrReplaceAtIdx.mjs +13 -6
- package/areEqual.d.ts +1 -1
- package/areEqual.mjs +17 -23
- package/arrayOfAll.d.ts +1 -2
- package/arrayOfAll.mjs +2 -8
- package/arraySum.d.ts +2 -1
- package/arraySum.mjs +3 -5
- package/arrayToLookup.mjs +2 -4
- package/buildUrlQueryString.mjs +11 -14
- package/capitalize.d.ts +2 -1
- package/capitalize.mjs +5 -6
- package/changeUrlPath.mjs +2 -3
- package/chunkByChunks.d.ts +1 -1
- package/chunkByChunks.mjs +18 -21
- package/chunkBySize.mjs +3 -4
- package/clamp.mjs +1 -2
- package/clsx.d.ts +6 -2
- package/clsx.mjs +14 -15
- package/convertRange.d.ts +3 -1
- package/convertRange.mjs +5 -4
- package/cookie.d.ts +13 -1
- package/cookie.mjs +8 -3
- package/createPalette.d.ts +3 -1
- package/createPalette.mjs +17 -7
- package/debounce.mjs +9 -17
- package/debouncePromise.d.ts +22 -4
- package/debouncePromise.mjs +73 -3
- package/debounceRaf.d.ts +1 -1
- package/debounceRaf.mjs +6 -11
- package/decode.mjs +2 -3
- package/encode.mjs +2 -3
- package/ensureInt.mjs +1 -4
- package/env.mjs +0 -1
- package/errorToString.d.ts +2 -1
- package/errorToString.mjs +3 -5
- package/findDuplicatedIndexes.mjs +4 -5
- package/forin.d.ts +2 -1
- package/forin.mjs +4 -4
- package/gbToBytes.mjs +1 -2
- package/getEmptyArray.d.ts +0 -1
- package/getEmptyArray.mjs +4 -4
- package/getKeys.d.ts +2 -1
- package/getKeys.mjs +3 -3
- package/getMediaQueryWidthResolvers.d.ts +6 -0
- package/getMediaQueryWidthResolvers.mjs +49 -50
- package/getMediaQueryWidthTailwindScreens.d.ts +4 -0
- package/getMediaQueryWidthTailwindScreens.mjs +22 -15
- package/getNonce.mjs +1 -2
- package/getParamAmong.d.ts +3 -2
- package/getParamAmong.mjs +5 -6
- package/getParamAsInt.d.ts +2 -2
- package/getParamAsInt.mjs +4 -6
- package/getParamAsString.d.ts +1 -1
- package/getParamAsString.mjs +2 -3
- package/getType.d.ts +0 -3
- package/getType.mjs +2 -7
- package/getUrlHashParams.mjs +2 -4
- package/getUrlHashPathname.mjs +1 -3
- package/getUrlPathnameParts.mjs +2 -7
- package/getUrlQueryParams.d.ts +3 -4
- package/getUrlQueryParams.mjs +10 -22
- package/imgEmptyPixel.mjs +1 -2
- package/index.d.ts +5 -2
- package/index.mjs +2 -2
- package/invariant.mjs +6 -8
- package/isAnyObject.mjs +1 -2
- package/isArray.mjs +1 -2
- package/isBlob.mjs +1 -2
- package/isBoolean.mjs +1 -2
- package/isBrowser.mjs +1 -2
- package/isBrowserNow.mjs +1 -2
- package/isDate.mjs +1 -2
- package/isEmptyArray.mjs +1 -2
- package/isEmptyObject.mjs +1 -2
- package/isEmptyString.mjs +1 -2
- package/isError.mjs +1 -2
- package/isExternalUrl.mjs +4 -6
- package/isFile.mjs +1 -2
- package/isFloat.mjs +1 -2
- package/isFormData.mjs +1 -2
- package/isFullArray.mjs +1 -2
- package/isFullObject.mjs +1 -2
- package/isFullString.mjs +1 -2
- package/isFunction.mjs +1 -2
- package/isInt.mjs +1 -2
- package/isMap.mjs +1 -2
- package/isNaNValue.mjs +1 -2
- package/isNegativeNumber.mjs +1 -2
- package/isNull.mjs +1 -2
- package/isNullOrUndefined.mjs +1 -2
- package/isNumber.mjs +1 -2
- package/isObject.mjs +1 -2
- package/isObjectLike.mjs +1 -2
- package/isOneOf.mjs +1 -7
- package/isPlainObject.mjs +3 -6
- package/isPositiveNumber.mjs +1 -2
- package/isPrimitive.mjs +5 -11
- package/isPromise.mjs +1 -2
- package/isRegExp.mjs +1 -2
- package/isServer.mjs +1 -2
- package/isServerNow.mjs +1 -2
- package/isSet.mjs +1 -2
- package/isString.mjs +1 -2
- package/isSymbol.mjs +1 -2
- package/isType.mjs +3 -5
- package/isUndefined.mjs +1 -2
- package/isWeakMap.mjs +1 -2
- package/isWeakSet.mjs +1 -2
- package/kbToBytes.mjs +1 -2
- package/location.mjs +3 -1
- package/lowercase.mjs +1 -4
- package/mapListBy.mjs +2 -5
- package/matchSorter.mjs +110 -128
- package/mbToBytes.mjs +1 -2
- package/mergeObjects.d.ts +2 -2
- package/mergeObjects.mjs +13 -16
- package/mergeUrlQueryParams.d.ts +0 -1
- package/mergeUrlQueryParams.mjs +4 -9
- package/moveSortableArrayItemByKey.d.ts +1 -1
- package/moveSortableArrayItemByKey.mjs +9 -9
- package/noop.mjs +1 -2
- package/normaliseUrl.mjs +1 -3
- package/normaliseUrlPathname.mjs +1 -3
- package/objectOmit.d.ts +1 -1
- package/objectOmit.mjs +4 -6
- package/objectPick.d.ts +1 -1
- package/objectPick.mjs +5 -6
- package/package.json +7 -11
- package/parseCookie.mjs +11 -15
- package/parseURL.mjs +5 -6
- package/quaranteneProps.d.ts +1 -1
- package/quaranteneProps.mjs +7 -9
- package/randomInt.mjs +1 -2
- package/randomKey.mjs +3 -4
- package/readCookie.d.ts +5 -0
- package/readCookie.mjs +7 -8
- package/removeAccents.mjs +5 -8
- package/removeCookie.d.ts +0 -4
- package/removeCookie.mjs +6 -9
- package/removeDuplicates.mjs +0 -1
- package/removeDuplicatesByKey.mjs +5 -7
- package/removeDuplicatesComparing.mjs +3 -4
- package/removeIndexesFromArray.mjs +3 -4
- package/removeTrailingSlash.mjs +1 -3
- package/removeUrlQueryParams.d.ts +0 -1
- package/removeUrlQueryParams.mjs +5 -8
- package/render.d.ts +2 -1
- package/render.mjs +45 -99
- package/roundTo.mjs +15 -17
- package/serializeCookie.d.ts +1 -5
- package/serializeCookie.mjs +10 -20
- package/setCookie.d.ts +0 -4
- package/setCookie.mjs +13 -20
- package/shuffle.d.ts +7 -6
- package/shuffle.mjs +17 -16
- package/slugify.d.ts +2 -1
- package/slugify.mjs +15 -12
- package/split.d.ts +4 -0
- package/split.mjs +4 -1
- package/swapMap.d.ts +1 -1
- package/swapMap.mjs +4 -6
- package/throttle.d.ts +2 -1
- package/throttle.mjs +6 -12
- package/titleCase.d.ts +4 -3
- package/titleCase.mjs +5 -9
- package/toNumber.mjs +1 -2
- package/toRgba.mjs +3 -5
- package/transformToUrlPathname.mjs +2 -5
- package/truncate.d.ts +1 -1
- package/truncate.mjs +2 -9
- package/tryUntil.d.ts +4 -1
- package/tryUntil.mjs +11 -11
- package/types.mjs +2 -1
- package/typings.d.ts +1 -6
- package/uid.mjs +3 -5
- package/updateLinkParams.mjs +2 -3
- package/updateUrlQueryParams.d.ts +0 -1
- package/updateUrlQueryParams.mjs +3 -8
- package/uppercase.d.ts +1 -0
- package/uppercase.mjs +2 -4
- package/uuid.mjs +2 -5
- package/uuidNumeric.mjs +1 -2
- package/wait.mjs +1 -4
- package/without.mjs +1 -3
- package/Defer.js +0 -30
- package/Emitter.js +0 -42
- package/accentSets.js +0 -41
- package/addOrReplaceAtIdx.js +0 -23
- package/areEqual.js +0 -81
- package/arrayOfAll.js +0 -36
- package/arraySum.js +0 -13
- package/arrayToLookup.js +0 -17
- package/buildUrlQueryString.js +0 -36
- package/capitalize.js +0 -16
- package/changeUrlPath.js +0 -23
- package/chunkByChunks.js +0 -41
- package/chunkBySize.js +0 -16
- package/clamp.js +0 -14
- package/clsx.js +0 -53
- package/convertRange.js +0 -20
- package/cookie.js +0 -13
- package/createPalette.js +0 -26
- package/debounce.js +0 -33
- package/debouncePromise.js +0 -12
- package/debounceRaf.js +0 -31
- package/decode.js +0 -14
- package/encode.js +0 -14
- package/ensureInt.js +0 -13
- package/env.js +0 -3
- package/errorToString.js +0 -15
- package/findDuplicatedIndexes.js +0 -18
- package/forin.js +0 -15
- package/gbToBytes.js +0 -11
- package/getEmptyArray.js +0 -20
- package/getKeys.js +0 -12
- package/getMediaQueryWidthResolvers.js +0 -72
- package/getMediaQueryWidthTailwindScreens.js +0 -33
- package/getNonce.js +0 -13
- package/getParamAmong.js +0 -22
- package/getParamAsInt.js +0 -25
- package/getParamAsString.js +0 -19
- package/getType.js +0 -23
- package/getUrlHashParams.js +0 -20
- package/getUrlHashPathname.js +0 -17
- package/getUrlPathnameParts.js +0 -25
- package/getUrlQueryParams.js +0 -43
- package/imgEmptyPixel.js +0 -10
- package/index.js +0 -267
- package/invariant.js +0 -38
- package/isAnyObject.js +0 -15
- package/isArray.js +0 -15
- package/isBlob.js +0 -15
- package/isBoolean.js +0 -15
- package/isBrowser.js +0 -9
- package/isBrowserNow.js +0 -12
- package/isDate.js +0 -15
- package/isEmptyArray.js +0 -15
- package/isEmptyObject.js +0 -15
- package/isEmptyString.js +0 -13
- package/isError.js +0 -15
- package/isExternalUrl.js +0 -26
- package/isFile.js +0 -15
- package/isFloat.js +0 -15
- package/isFormData.js +0 -15
- package/isFullArray.js +0 -15
- package/isFullObject.js +0 -15
- package/isFullString.js +0 -15
- package/isFunction.js +0 -13
- package/isInt.js +0 -15
- package/isMap.js +0 -15
- package/isNaNValue.js +0 -15
- package/isNegativeNumber.js +0 -15
- package/isNull.js +0 -15
- package/isNullOrUndefined.js +0 -14
- package/isNumber.js +0 -17
- package/isObject.js +0 -15
- package/isObjectLike.js +0 -17
- package/isOneOf.js +0 -14
- package/isPlainObject.js +0 -18
- package/isPositiveNumber.js +0 -15
- package/isPrimitive.js +0 -25
- package/isPromise.js +0 -15
- package/isRegExp.js +0 -15
- package/isServer.js +0 -12
- package/isServerNow.js +0 -12
- package/isSet.js +0 -15
- package/isString.js +0 -15
- package/isSymbol.js +0 -15
- package/isType.js +0 -27
- package/isUndefined.js +0 -15
- package/isWeakMap.js +0 -15
- package/isWeakSet.js +0 -15
- package/kbToBytes.js +0 -11
- package/location.js +0 -2
- package/lowercase.js +0 -13
- package/mapListBy.js +0 -18
- package/matchSorter.js +0 -374
- package/mbToBytes.js +0 -11
- package/mergeObjects.js +0 -41
- package/mergeUrlQueryParams.js +0 -27
- package/moveSortableArrayItemByKey.js +0 -21
- package/noop.js +0 -11
- package/normaliseUrl.js +0 -20
- package/normaliseUrlPathname.js +0 -19
- package/objectOmit.js +0 -23
- package/objectPick.js +0 -19
- package/parseCookie.js +0 -52
- package/parseURL.js +0 -24
- package/quaranteneProps.js +0 -37
- package/randomInt.js +0 -13
- package/randomKey.js +0 -15
- package/readCookie.js +0 -38
- package/removeAccents.js +0 -19
- package/removeCookie.js +0 -19
- package/removeDuplicates.js +0 -13
- package/removeDuplicatesByKey.js +0 -24
- package/removeDuplicatesComparing.js +0 -14
- package/removeIndexesFromArray.js +0 -18
- package/removeTrailingSlash.js +0 -14
- package/removeUrlQueryParams.js +0 -26
- package/render.js +0 -169
- package/roundTo.js +0 -38
- package/serializeCookie.js +0 -108
- package/setCookie.js +0 -62
- package/shuffle.js +0 -36
- package/slugify.js +0 -27
- package/split.js +0 -8
- package/swapMap.js +0 -18
- package/throttle.js +0 -30
- package/titleCase.js +0 -15
- package/toNumber.js +0 -12
- package/toRgba.js +0 -20
- package/transformToUrlPathname.js +0 -21
- package/truncate.js +0 -17
- package/tryUntil.js +0 -31
- package/types.js +0 -2
- package/uid.js +0 -16
- package/updateLinkParams.js +0 -19
- package/updateUrlQueryParams.js +0 -23
- package/uppercase.js +0 -13
- package/uuid.js +0 -17
- package/uuidNumeric.js +0 -10
- package/wait.js +0 -13
- package/without.js +0 -56
package/randomInt.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
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;
|
package/randomKey.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.randomKey = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Get random key from given object
|
|
6
|
-
*
|
|
7
|
-
* @category misc
|
|
8
|
-
* @see https://stackoverflow.com/a/15106541/1938970
|
|
9
|
-
*/
|
|
10
|
-
function randomKey(obj) {
|
|
11
|
-
var keys = Object.keys(obj);
|
|
12
|
-
return keys[(keys.length * Math.random()) << 0];
|
|
13
|
-
}
|
|
14
|
-
exports.randomKey = randomKey;
|
|
15
|
-
exports.default = randomKey;
|
package/readCookie.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
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: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:readCookie] failed to decode", value);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return name ? all[name] : all;
|
|
36
|
-
}
|
|
37
|
-
exports.readCookie = readCookie;
|
|
38
|
-
exports.default = readCookie;
|
package/removeAccents.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
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;
|
package/removeCookie.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
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;
|
package/removeDuplicates.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// /**
|
|
3
|
-
// * FIXME: Type 'Set<any>' can only be iterated through when using the
|
|
4
|
-
// * '--downlevelIteration' flag or with a '--target' of 'es2015' or higher.
|
|
5
|
-
// * I am not sure I want to use those ts options here. Let's keep it commented
|
|
6
|
-
// * for now
|
|
7
|
-
// *
|
|
8
|
-
// * @category array
|
|
9
|
-
// */
|
|
10
|
-
// export function removeDuplicates<T extends any[]>(arr: T) {
|
|
11
|
-
// return [...new Set(arr)];
|
|
12
|
-
// }
|
|
13
|
-
// export default removeDuplicates;
|
package/removeDuplicatesByKey.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
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
|
-
var keysMap = {};
|
|
13
|
-
var output = [];
|
|
14
|
-
for (var i = 0; i < array.length; i++) {
|
|
15
|
-
var item = array[i];
|
|
16
|
-
if (!keysMap[item[key]]) {
|
|
17
|
-
output.push(item);
|
|
18
|
-
keysMap[item[key]] = true;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return output;
|
|
22
|
-
}
|
|
23
|
-
exports.removeDuplicatesByKey = removeDuplicatesByKey;
|
|
24
|
-
exports.default = removeDuplicatesByKey;
|
|
@@ -1,14 +0,0 @@
|
|
|
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;
|
|
@@ -1,18 +0,0 @@
|
|
|
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;
|
package/removeTrailingSlash.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
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;
|
package/removeUrlQueryParams.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.removeUrlQueryParams = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
|
-
var buildUrlQueryString_1 = tslib_1.__importDefault(require("./buildUrlQueryString"));
|
|
6
|
-
var getUrlQueryParams_1 = tslib_1.__importDefault(require("./getUrlQueryParams"));
|
|
7
|
-
/**
|
|
8
|
-
* Remove the given keys from the given URL query parameters
|
|
9
|
-
*
|
|
10
|
-
* @category location
|
|
11
|
-
* @pure
|
|
12
|
-
*/
|
|
13
|
-
function removeUrlQueryParams(url, paramsToRemove) {
|
|
14
|
-
if (paramsToRemove === void 0) { paramsToRemove = []; }
|
|
15
|
-
var parts = url.split("?");
|
|
16
|
-
var allParams = (0, getUrlQueryParams_1.default)(url);
|
|
17
|
-
var params = {};
|
|
18
|
-
for (var key in allParams) {
|
|
19
|
-
if (!paramsToRemove.includes(key)) {
|
|
20
|
-
params[key] = allParams[key];
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return parts[0] + (0, buildUrlQueryString_1.default)(params);
|
|
24
|
-
}
|
|
25
|
-
exports.removeUrlQueryParams = removeUrlQueryParams;
|
|
26
|
-
exports.default = removeUrlQueryParams;
|
package/render.js
DELETED
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.render = void 0;
|
|
4
|
-
var varname = "data";
|
|
5
|
-
var evaluate = /<%([\s\S]+?(\}?)+)%>/g;
|
|
6
|
-
var interpolate = /<%=([\s\S]+?)%>/g;
|
|
7
|
-
var conditional = /<%\?(\?)?\s*([\s\S]*?)\s*%>/g;
|
|
8
|
-
var iterate = /<%~\s*(?:%>|([\s\S]+?)\s*:\s*([\w$]+)\s*(?::\s*([\w$]+))?\s*%>)/g;
|
|
9
|
-
// const encode = /<%!([\s\S]+?)%>/g;
|
|
10
|
-
var use = /<%#([\s\S]+?)%>/g;
|
|
11
|
-
var useParams = /(^|[^\w$])def(?:\.|\[['"])([\w$.]+)(?:['"]\])?\s*:\s*([\w$.]+|"[^"]+"|'[^']+'|\{[^}]+\})/g;
|
|
12
|
-
var define = /<%##\s*([\w.$]+)\s*(:|=)([\s\S]+?)#%>/g;
|
|
13
|
-
var defineParams = /^\s*([\w$]+):([\s\S]+)/;
|
|
14
|
-
var start = "'+(";
|
|
15
|
-
var end = ")+'";
|
|
16
|
-
// const startencode = "'+encodeHTML(";
|
|
17
|
-
var skip = /$^/;
|
|
18
|
-
var resolveDefs = function (block, def) {
|
|
19
|
-
return (typeof block === "string" ? block : block.toString())
|
|
20
|
-
.replace(define || skip, function (_, code, assign, value) {
|
|
21
|
-
if (code.indexOf("def.") === 0) {
|
|
22
|
-
code = code.substring(4);
|
|
23
|
-
}
|
|
24
|
-
if (!(code in def)) {
|
|
25
|
-
if (assign === ":") {
|
|
26
|
-
value.replace(defineParams,
|
|
27
|
-
// @ts-expect-error nevermind
|
|
28
|
-
function (_, param, v) {
|
|
29
|
-
def[code] = { arg: param, text: v };
|
|
30
|
-
});
|
|
31
|
-
// @ts-expect-error nevermind
|
|
32
|
-
if (!(code in def))
|
|
33
|
-
def[code] = value;
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
new Function("def", "def['" + code + "']=" + value)(def);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return "";
|
|
40
|
-
})
|
|
41
|
-
.replace(use || skip, function (_, code) {
|
|
42
|
-
code = code.replace(useParams, function (_, s, d, param) {
|
|
43
|
-
if (def[d] && def[d].arg && param) {
|
|
44
|
-
var rw = (d + ":" + param).replace(/'|\\/g, "_");
|
|
45
|
-
def.__exp = def.__exp || {};
|
|
46
|
-
def.__exp[rw] = def[d].text.replace(new RegExp("(^|[^\\w$])" + def[d].arg + "([^\\w$])", "g"), "$1" + param + "$2");
|
|
47
|
-
return s + "def.__exp['" + rw + "']";
|
|
48
|
-
}
|
|
49
|
-
return s;
|
|
50
|
-
});
|
|
51
|
-
var v = new Function("def", "return " + code)(def);
|
|
52
|
-
return v ? resolveDefs(v, def) : v;
|
|
53
|
-
});
|
|
54
|
-
};
|
|
55
|
-
var unescape = function (code) {
|
|
56
|
-
return code.replace(/\\('|\\)/g, "$1").replace(/[\r\t\n]/g, " ");
|
|
57
|
-
};
|
|
58
|
-
/**
|
|
59
|
-
* Render template (adapted from doT.js)
|
|
60
|
-
*
|
|
61
|
-
* The data made available to the template is always on the `data` key, e.g.:
|
|
62
|
-
* `renderer({ myVal: "xx" })`
|
|
63
|
-
* ... will be accessible on
|
|
64
|
-
* `<%= data.myVal %>`
|
|
65
|
-
*
|
|
66
|
-
* The default delimiters are customised to work without conflicts with Blade and Twig:
|
|
67
|
-
* ```
|
|
68
|
-
* <% %> for evaluation
|
|
69
|
-
* <%= %> for interpolation
|
|
70
|
-
* <%? %> for conditionals
|
|
71
|
-
* <%~ %> for array iteration
|
|
72
|
-
* <%# %> for compile-time evaluation/includes and partials
|
|
73
|
-
* <%## #%> for compile-time defines
|
|
74
|
-
*
|
|
75
|
-
* Unsupported:
|
|
76
|
-
* <%! %> for interpolation with encoding
|
|
77
|
-
* ```
|
|
78
|
-
*
|
|
79
|
-
* @example
|
|
80
|
-
*
|
|
81
|
-
* ```js
|
|
82
|
-
* import { render } from "...";
|
|
83
|
-
*
|
|
84
|
-
* const data = { name: "XYZ" };
|
|
85
|
-
* const tpl = `Hello <%= data.name %>`;
|
|
86
|
-
* const renderer = render(tpl);
|
|
87
|
-
*
|
|
88
|
-
* console.log(renderer(data)); // outputs 'Hello XYZ'
|
|
89
|
-
* ```
|
|
90
|
-
*
|
|
91
|
-
* @borrows [olado/doT by Laura Doktorova](https://github.com/olado/doT)
|
|
92
|
-
* @see https://olado.github.io/doT/index.html
|
|
93
|
-
*/
|
|
94
|
-
var render = function (tmpl, def) {
|
|
95
|
-
var sid = 0;
|
|
96
|
-
var indv;
|
|
97
|
-
var str = use || define ? resolveDefs(tmpl, def || {}) : tmpl;
|
|
98
|
-
str = ("var X='" +
|
|
99
|
-
str
|
|
100
|
-
.replace(/(^|\r|\n)\t* +| +\t*(\r|\n|$)/g, " ")
|
|
101
|
-
.replace(/\r|\n|\t|\/\*[\s\S]*?\*\//g, "")
|
|
102
|
-
.replace(/'|\\/g, "\\$&")
|
|
103
|
-
.replace(interpolate || skip, function (_, code) { return start + unescape(code) + end; })
|
|
104
|
-
// .replace(
|
|
105
|
-
// encode || skip,
|
|
106
|
-
// (_, code) => cse.startencode + unescape(code) + cse.end
|
|
107
|
-
// )
|
|
108
|
-
.replace(conditional || skip, function (_, elseCase, code) {
|
|
109
|
-
return elseCase
|
|
110
|
-
? code
|
|
111
|
-
? "';}else if(" + unescape(code) + "){X+='"
|
|
112
|
-
: "';}else{X+='"
|
|
113
|
-
: code
|
|
114
|
-
? "';if(" + unescape(code) + "){X+='"
|
|
115
|
-
: "';}X+='";
|
|
116
|
-
})
|
|
117
|
-
.replace(iterate || skip, function (_, arr, vName, iName) {
|
|
118
|
-
if (!arr)
|
|
119
|
-
return "';} } X+='";
|
|
120
|
-
sid++;
|
|
121
|
-
indv = iName || "i" + sid;
|
|
122
|
-
arr = unescape(arr);
|
|
123
|
-
return ("';var arr" +
|
|
124
|
-
sid +
|
|
125
|
-
"=" +
|
|
126
|
-
arr +
|
|
127
|
-
";if(arr" +
|
|
128
|
-
sid +
|
|
129
|
-
"){var " +
|
|
130
|
-
vName +
|
|
131
|
-
"," +
|
|
132
|
-
indv +
|
|
133
|
-
"=-1,l" +
|
|
134
|
-
sid +
|
|
135
|
-
"=arr" +
|
|
136
|
-
sid +
|
|
137
|
-
".length-1;while(" +
|
|
138
|
-
indv +
|
|
139
|
-
"<l" +
|
|
140
|
-
sid +
|
|
141
|
-
"){" +
|
|
142
|
-
vName +
|
|
143
|
-
"=arr" +
|
|
144
|
-
sid +
|
|
145
|
-
"[" +
|
|
146
|
-
indv +
|
|
147
|
-
"+=1];X+='");
|
|
148
|
-
})
|
|
149
|
-
.replace(evaluate || skip, function (_, code) { return "';" + unescape(code) + "X+='"; }) +
|
|
150
|
-
"';return X;")
|
|
151
|
-
.replace(/\n/g, "\\n")
|
|
152
|
-
.replace(/\t/g, "\\t")
|
|
153
|
-
.replace(/\r/g, "\\r")
|
|
154
|
-
.replace(/(\s|;|\}|^|\{)X\+='';/g, "$1")
|
|
155
|
-
.replace(/\+''/g, "");
|
|
156
|
-
//.replace(/(\s|;|\}|^|\{)X\+=''\+/g,'$1X+=');
|
|
157
|
-
try {
|
|
158
|
-
return new Function(varname, str);
|
|
159
|
-
}
|
|
160
|
-
catch (e) {
|
|
161
|
-
if (process.env["NODE_ENV"] !== "production") {
|
|
162
|
-
console.log("Could not create a template function: " + str);
|
|
163
|
-
throw e;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
return function () { return ""; };
|
|
167
|
-
};
|
|
168
|
-
exports.render = render;
|
|
169
|
-
exports.default = exports.render;
|
package/roundTo.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.roundTo = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Round to given number of the given number of decimals
|
|
6
|
-
*
|
|
7
|
-
* @category math
|
|
8
|
-
* @see https://stackoverflow.com/a/15762794/1938970
|
|
9
|
-
*/
|
|
10
|
-
function roundTo(num, decimals) {
|
|
11
|
-
if (decimals === void 0) { decimals = 2; }
|
|
12
|
-
if (isFinite(num) && !isNaN(num)) {
|
|
13
|
-
// method 1
|
|
14
|
-
// return Number(num).toFixed(decimals);
|
|
15
|
-
// method 2: @see https://stackoverflow.com/a/43532829/1938970
|
|
16
|
-
var multiplicator = Math.pow(10, decimals);
|
|
17
|
-
return Math.round(num * multiplicator) / multiplicator + "";
|
|
18
|
-
// method 3: @see https://stackoverflow.com/a/15762794/1938970
|
|
19
|
-
// let negative = false;
|
|
20
|
-
// if (num < 0) {
|
|
21
|
-
// negative = true;
|
|
22
|
-
// num = num * -1;
|
|
23
|
-
// }
|
|
24
|
-
// const multiplicator = Math.pow(10, decimals);
|
|
25
|
-
// const outputStr = parseFloat((num * multiplicator).toFixed(11));
|
|
26
|
-
// let outputNum = (Math.round(outputStr) / multiplicator).toFixed(decimals);
|
|
27
|
-
// if (negative) {
|
|
28
|
-
// return (Number(outputNum) * -1).toFixed(decimals);
|
|
29
|
-
// }
|
|
30
|
-
// return outputNum;
|
|
31
|
-
}
|
|
32
|
-
if (process.env["NODE_ENV"] !== "production") {
|
|
33
|
-
console.warn("[@koine/utils] math:roundTo -> given not a finite number as first arg");
|
|
34
|
-
}
|
|
35
|
-
return "";
|
|
36
|
-
}
|
|
37
|
-
exports.roundTo = roundTo;
|
|
38
|
-
exports.default = roundTo;
|
package/serializeCookie.js
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
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;
|
package/setCookie.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
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 = tslib_1.__importDefault(require("./isNumber"));
|
|
7
|
-
var isUndefined_1 = tslib_1.__importDefault(require("./isUndefined"));
|
|
8
|
-
function converterWrite(value) {
|
|
9
|
-
return encodeURIComponent(value).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g, decodeURIComponent);
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* @category cookie
|
|
13
|
-
*
|
|
14
|
-
* All cookie related code is inspired and adapted from:
|
|
15
|
-
* - [js-cookie](https://github.com/js-cookie/js-cookie)
|
|
16
|
-
* - [cookie](https://github.com/jshttp/cookie)
|
|
17
|
-
*/
|
|
18
|
-
function setCookie(name, value, attributes) {
|
|
19
|
-
if (attributes === void 0) { attributes = {}; }
|
|
20
|
-
// eslint-disable-next-line prefer-const
|
|
21
|
-
var expires = attributes.expires, restAttrs = tslib_1.__rest(attributes, ["expires"]);
|
|
22
|
-
var cleanedAttrs = tslib_1.__assign(tslib_1.__assign({ expires: "" }, cookie_1.defaultAttributesClient), restAttrs);
|
|
23
|
-
if ((0, isUndefined_1.default)(document)) {
|
|
24
|
-
if (process.env["NODE_ENV"] !== "production") {
|
|
25
|
-
console.warn("[@koine/utils:setCookie] document is undefined");
|
|
26
|
-
}
|
|
27
|
-
return undefined;
|
|
28
|
-
}
|
|
29
|
-
if ((0, isNumber_1.default)(expires)) {
|
|
30
|
-
expires = new Date(Date.now() + expires * 864e5);
|
|
31
|
-
}
|
|
32
|
-
if (expires) {
|
|
33
|
-
cleanedAttrs.expires = expires.toUTCString();
|
|
34
|
-
}
|
|
35
|
-
name = encodeURIComponent(name)
|
|
36
|
-
.replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent)
|
|
37
|
-
.replace(/[()]/g, escape);
|
|
38
|
-
var stringifiedAttributes = "";
|
|
39
|
-
for (var name_1 in attributes) {
|
|
40
|
-
var attrName = name_1;
|
|
41
|
-
if (!attributes[attrName]) {
|
|
42
|
-
continue;
|
|
43
|
-
}
|
|
44
|
-
stringifiedAttributes += "; " + attrName;
|
|
45
|
-
if (attributes[attrName] === true) {
|
|
46
|
-
continue;
|
|
47
|
-
}
|
|
48
|
-
// Considers RFC 6265 section 5.2:
|
|
49
|
-
// ...
|
|
50
|
-
// 3. If the remaining unparsed-attributes contains a %x3B (";")
|
|
51
|
-
// character:
|
|
52
|
-
// Consume the characters of the unparsed-attributes up to,
|
|
53
|
-
// not including, the first %x3B (";") character.
|
|
54
|
-
// ...
|
|
55
|
-
stringifiedAttributes +=
|
|
56
|
-
"=" + String(attributes[attrName]).split(";")[0];
|
|
57
|
-
}
|
|
58
|
-
return (document.cookie =
|
|
59
|
-
name + "=" + converterWrite(value) + stringifiedAttributes);
|
|
60
|
-
}
|
|
61
|
-
exports.setCookie = setCookie;
|
|
62
|
-
exports.default = setCookie;
|
package/shuffle.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
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/slugify.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
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;
|