@koine/utils 2.0.0-beta.10 → 2.0.0-beta.12
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/Emitter.d.ts +3 -1
- package/Emitter.mjs +3 -1
- package/accentSets.d.ts +3 -2
- package/accentSets.mjs +3 -2
- package/addOrReplaceAtIdx.d.ts +4 -0
- package/addOrReplaceAtIdx.mjs +4 -0
- package/areEqual.d.ts +1 -1
- package/areEqual.mjs +1 -1
- package/arrayOfAll.d.ts +1 -2
- package/arrayOfAll.mjs +1 -2
- package/arraySum.d.ts +2 -1
- package/arraySum.mjs +2 -1
- package/capitalize.d.ts +2 -1
- package/capitalize.mjs +2 -1
- package/chunkByChunks.d.ts +1 -1
- package/chunkByChunks.mjs +1 -1
- package/clsx.d.ts +2 -1
- package/clsx.mjs +2 -1
- package/convertRange.d.ts +3 -1
- package/convertRange.mjs +3 -1
- package/cookie.d.ts +13 -1
- package/cookie.mjs +5 -1
- package/createPalette.d.ts +3 -1
- package/createPalette.mjs +3 -1
- package/debouncePromise.d.ts +10 -2
- package/debouncePromise.mjs +6 -2
- package/debounceRaf.d.ts +1 -1
- package/debounceRaf.mjs +1 -1
- package/errorToString.d.ts +2 -1
- package/errorToString.mjs +2 -1
- package/forin.d.ts +2 -1
- package/forin.mjs +2 -1
- package/getEmptyArray.d.ts +0 -1
- package/getEmptyArray.mjs +0 -1
- package/getKeys.d.ts +2 -1
- package/getKeys.mjs +2 -1
- package/getMediaQueryWidthResolvers.d.ts +6 -0
- package/getMediaQueryWidthResolvers.mjs +5 -1
- package/getMediaQueryWidthTailwindScreens.d.ts +4 -0
- package/getMediaQueryWidthTailwindScreens.mjs +4 -1
- package/getParamAmong.d.ts +3 -2
- package/getParamAmong.mjs +3 -2
- package/getParamAsInt.d.ts +2 -2
- package/getParamAsInt.mjs +2 -2
- package/getParamAsString.d.ts +1 -1
- package/getParamAsString.mjs +1 -1
- package/getType.d.ts +0 -3
- package/getType.mjs +0 -3
- package/getUrlQueryParams.d.ts +3 -4
- package/getUrlQueryParams.mjs +3 -4
- package/index.d.ts +4 -1
- package/matchSorter.mjs +2 -2
- package/mergeObjects.d.ts +1 -1
- package/mergeObjects.mjs +1 -1
- package/mergeUrlQueryParams.d.ts +0 -1
- package/mergeUrlQueryParams.mjs +0 -1
- package/moveSortableArrayItemByKey.d.ts +1 -1
- package/moveSortableArrayItemByKey.mjs +1 -1
- package/objectOmit.d.ts +1 -1
- package/objectOmit.mjs +1 -1
- package/objectPick.d.ts +1 -1
- package/objectPick.mjs +1 -1
- package/package.json +2 -2
- package/quaranteneProps.d.ts +1 -1
- package/quaranteneProps.mjs +1 -1
- package/readCookie.d.ts +5 -0
- package/removeCookie.d.ts +0 -4
- package/removeCookie.mjs +0 -4
- package/removeUrlQueryParams.d.ts +0 -1
- package/removeUrlQueryParams.mjs +0 -1
- package/render.d.ts +2 -1
- package/render.mjs +2 -1
- package/serializeCookie.d.ts +1 -5
- package/serializeCookie.mjs +1 -5
- package/setCookie.d.ts +0 -4
- package/setCookie.mjs +0 -4
- package/shuffle.d.ts +7 -6
- package/shuffle.mjs +7 -6
- package/slugify.d.ts +2 -1
- package/slugify.mjs +2 -1
- package/split.d.ts +4 -0
- package/split.mjs +4 -1
- package/swapMap.d.ts +1 -1
- package/swapMap.mjs +1 -1
- package/throttle.d.ts +1 -1
- package/throttle.mjs +1 -1
- package/titleCase.d.ts +4 -3
- package/titleCase.mjs +4 -3
- package/truncate.d.ts +1 -1
- package/truncate.mjs +1 -1
- package/tryUntil.d.ts +4 -1
- package/tryUntil.mjs +4 -1
- package/typings.d.ts +1 -6
- package/updateUrlQueryParams.d.ts +0 -1
- package/updateUrlQueryParams.mjs +0 -1
- package/uppercase.d.ts +1 -0
- package/uppercase.mjs +1 -0
- package/Defer.js +0 -35
- package/Emitter.js +0 -53
- package/accentSets.js +0 -133
- package/addOrReplaceAtIdx.js +0 -40
- package/areEqual.js +0 -75
- package/arrayOfAll.js +0 -45
- package/arraySum.js +0 -24
- package/arrayToLookup.js +0 -29
- package/buildUrlQueryString.js +0 -39
- package/capitalize.js +0 -28
- package/changeUrlPath.js +0 -29
- package/chunkByChunks.js +0 -52
- package/chunkBySize.js +0 -29
- package/clamp.js +0 -27
- package/clsx.js +0 -60
- package/convertRange.js +0 -33
- package/cookie.js +0 -21
- package/createPalette.js +0 -39
- package/debounce.js +0 -39
- package/debouncePromise.js +0 -87
- package/debounceRaf.js +0 -40
- package/decode.js +0 -27
- package/encode.js +0 -27
- package/ensureInt.js +0 -24
- package/env.js +0 -3
- package/errorToString.js +0 -22
- package/findDuplicatedIndexes.js +0 -31
- package/forin.js +0 -28
- package/gbToBytes.js +0 -24
- package/getEmptyArray.js +0 -29
- package/getKeys.js +0 -26
- package/getMediaQueryWidthResolvers.js +0 -81
- package/getMediaQueryWidthTailwindScreens.js +0 -51
- package/getNonce.js +0 -23
- package/getParamAmong.js +0 -25
- package/getParamAsInt.js +0 -28
- package/getParamAsString.js +0 -24
- package/getType.js +0 -30
- package/getUrlHashParams.js +0 -27
- package/getUrlHashPathname.js +0 -29
- package/getUrlPathnameParts.js +0 -25
- package/getUrlQueryParams.js +0 -36
- package/imgEmptyPixel.js +0 -24
- package/index.js +0 -532
- package/invariant.js +0 -50
- package/isAnyObject.js +0 -24
- package/isArray.js +0 -24
- package/isBlob.js +0 -24
- package/isBoolean.js +0 -24
- package/isBrowser.js +0 -23
- package/isBrowserNow.js +0 -22
- package/isDate.js +0 -24
- package/isEmptyArray.js +0 -24
- package/isEmptyObject.js +0 -24
- package/isEmptyString.js +0 -26
- package/isError.js +0 -24
- package/isExternalUrl.js +0 -32
- package/isFile.js +0 -24
- package/isFloat.js +0 -24
- package/isFormData.js +0 -24
- package/isFullArray.js +0 -24
- package/isFullObject.js +0 -24
- package/isFullString.js +0 -24
- package/isFunction.js +0 -22
- package/isInt.js +0 -24
- package/isMap.js +0 -24
- package/isNaNValue.js +0 -24
- package/isNegativeNumber.js +0 -24
- package/isNull.js +0 -24
- package/isNullOrUndefined.js +0 -24
- package/isNumber.js +0 -24
- package/isObject.js +0 -24
- package/isObjectLike.js +0 -24
- package/isOneOf.js +0 -22
- package/isPlainObject.js +0 -25
- package/isPositiveNumber.js +0 -24
- package/isPrimitive.js +0 -29
- package/isPromise.js +0 -24
- package/isRegExp.js +0 -24
- package/isServer.js +0 -23
- package/isServerNow.js +0 -22
- package/isSet.js +0 -24
- package/isString.js +0 -24
- package/isSymbol.js +0 -24
- package/isType.js +0 -32
- package/isUndefined.js +0 -24
- package/isWeakMap.js +0 -24
- package/isWeakSet.js +0 -24
- package/kbToBytes.js +0 -24
- package/location.js +0 -6
- package/lowercase.js +0 -24
- package/mapListBy.js +0 -29
- package/matchSorter.js +0 -373
- package/mbToBytes.js +0 -24
- package/mergeObjects.js +0 -39
- package/mergeUrlQueryParams.js +0 -32
- package/moveSortableArrayItemByKey.js +0 -35
- package/noop.js +0 -24
- package/normaliseUrl.js +0 -24
- package/normaliseUrlPathname.js +0 -24
- package/objectOmit.js +0 -35
- package/objectPick.js +0 -32
- package/parseCookie.js +0 -55
- package/parseURL.js +0 -37
- package/quaranteneProps.js +0 -49
- package/randomInt.js +0 -26
- package/randomKey.js +0 -28
- package/readCookie.js +0 -51
- package/removeAccents.js +0 -28
- package/removeCookie.js +0 -28
- package/removeDuplicates.js +0 -13
- package/removeDuplicatesByKey.js +0 -36
- package/removeDuplicatesComparing.js +0 -25
- package/removeIndexesFromArray.js +0 -31
- package/removeTrailingSlash.js +0 -26
- package/removeUrlQueryParams.js +0 -33
- package/render.js +0 -93
- package/roundTo.js +0 -50
- package/serializeCookie.js +0 -102
- package/setCookie.js +0 -68
- package/shuffle.js +0 -50
- package/slugify.js +0 -35
- package/split.js +0 -22
- package/swapMap.js +0 -30
- package/throttle.js +0 -38
- package/titleCase.js +0 -24
- package/toNumber.js +0 -23
- package/toRgba.js +0 -32
- package/transformToUrlPathname.js +0 -24
- package/truncate.js +0 -24
- package/tryUntil.js +0 -42
- package/types.js +0 -5
- package/uid.js +0 -24
- package/updateLinkParams.js +0 -26
- package/updateUrlQueryParams.js +0 -28
- package/uppercase.js +0 -24
- package/uuid.js +0 -28
- package/uuidNumeric.js +0 -23
- package/wait.js +0 -24
- package/without.js +0 -55
package/parseCookie.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
parseCookie: function() {
|
|
13
|
-
return parseCookie;
|
|
14
|
-
},
|
|
15
|
-
default: function() {
|
|
16
|
-
return _default;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
/**
|
|
20
|
-
* Try decoding a string using a decoding function.
|
|
21
|
-
*/ function tryDecode(str, decode) {
|
|
22
|
-
try {
|
|
23
|
-
return decode(str);
|
|
24
|
-
} catch (e) {
|
|
25
|
-
return str;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
function parseCookie(str, attributes = {}) {
|
|
29
|
-
if (typeof str !== "string") {
|
|
30
|
-
throw new TypeError("argument str must be a string");
|
|
31
|
-
}
|
|
32
|
-
const obj = {};
|
|
33
|
-
const pairs = str.split(";");
|
|
34
|
-
const { decode = decodeURIComponent } = attributes;
|
|
35
|
-
for(let i = 0; i < pairs.length; i++){
|
|
36
|
-
const pair = pairs[i];
|
|
37
|
-
const index = pair.indexOf("=");
|
|
38
|
-
// skip things that don't look like key=value
|
|
39
|
-
if (index < 0) {
|
|
40
|
-
continue;
|
|
41
|
-
}
|
|
42
|
-
const key = pair.substring(0, index).trim();
|
|
43
|
-
// only assign once
|
|
44
|
-
if (undefined == obj[key]) {
|
|
45
|
-
let val = pair.substring(index + 1, pair.length).trim();
|
|
46
|
-
// quoted values
|
|
47
|
-
if (val[0] === '"') {
|
|
48
|
-
val = val.slice(1, -1);
|
|
49
|
-
}
|
|
50
|
-
obj[key] = tryDecode(val, decode);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return obj;
|
|
54
|
-
}
|
|
55
|
-
const _default = parseCookie;
|
package/parseURL.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Solution without DOM or specific env native methods
|
|
3
|
-
*
|
|
4
|
-
* @category location
|
|
5
|
-
* @see https://stackoverflow.com/a/21553982/1938970
|
|
6
|
-
*/ "use strict";
|
|
7
|
-
Object.defineProperty(exports, "__esModule", {
|
|
8
|
-
value: true
|
|
9
|
-
});
|
|
10
|
-
function _export(target, all) {
|
|
11
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
12
|
-
enumerable: true,
|
|
13
|
-
get: all[name]
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
_export(exports, {
|
|
17
|
-
parseURL: function() {
|
|
18
|
-
return parseURL;
|
|
19
|
-
},
|
|
20
|
-
default: function() {
|
|
21
|
-
return _default;
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
function parseURL(url) {
|
|
25
|
-
const match = url.match(/^(https?:)\/\/(([^:/?#]*)(?::([0-9]+))?)([/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/);
|
|
26
|
-
return match && {
|
|
27
|
-
href: url,
|
|
28
|
-
protocol: match[1],
|
|
29
|
-
host: match[2],
|
|
30
|
-
hostname: match[3],
|
|
31
|
-
port: match[4],
|
|
32
|
-
pathname: match[5],
|
|
33
|
-
search: match[6],
|
|
34
|
-
hash: match[7]
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
const _default = parseURL;
|
package/quaranteneProps.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @category impl
|
|
3
|
-
* @usage
|
|
4
|
-
*
|
|
5
|
-
* ```ts
|
|
6
|
-
* const { _: { onKeyDown }, myOwnProp, ...rest } = quaranteneProps([
|
|
7
|
-
* "onPointerLeave",
|
|
8
|
-
* "onPointerMove",
|
|
9
|
-
* "onClick",
|
|
10
|
-
* "onPointerDown",
|
|
11
|
-
* "onPointerUp",
|
|
12
|
-
* "onKeyDown",
|
|
13
|
-
* ]);
|
|
14
|
-
* ```
|
|
15
|
-
*/ "use strict";
|
|
16
|
-
Object.defineProperty(exports, "__esModule", {
|
|
17
|
-
value: true
|
|
18
|
-
});
|
|
19
|
-
function _export(target, all) {
|
|
20
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
21
|
-
enumerable: true,
|
|
22
|
-
get: all[name]
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
_export(exports, {
|
|
26
|
-
quaranteneProps: function() {
|
|
27
|
-
return quaranteneProps;
|
|
28
|
-
},
|
|
29
|
-
default: function() {
|
|
30
|
-
return _default;
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
function quaranteneProps(props, propsKeysToQuarantene) {
|
|
34
|
-
// approach 1)
|
|
35
|
-
const healthyProps = {
|
|
36
|
-
_: {}
|
|
37
|
-
};
|
|
38
|
-
for(const key in props){
|
|
39
|
-
const prop = props[key];
|
|
40
|
-
if (propsKeysToQuarantene.includes(key)) {
|
|
41
|
-
healthyProps._[key] = prop;
|
|
42
|
-
} else {
|
|
43
|
-
// @ts-expect-error nevermind
|
|
44
|
-
healthyProps[key] = prop;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return healthyProps;
|
|
48
|
-
}
|
|
49
|
-
const _default = quaranteneProps;
|
package/randomInt.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get random int (min and max included)
|
|
3
|
-
*
|
|
4
|
-
* @category math
|
|
5
|
-
*/ "use strict";
|
|
6
|
-
Object.defineProperty(exports, "__esModule", {
|
|
7
|
-
value: true
|
|
8
|
-
});
|
|
9
|
-
function _export(target, all) {
|
|
10
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: all[name]
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
_export(exports, {
|
|
16
|
-
randomInt: function() {
|
|
17
|
-
return randomInt;
|
|
18
|
-
},
|
|
19
|
-
default: function() {
|
|
20
|
-
return _default;
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
function randomInt(min, max) {
|
|
24
|
-
return Math.floor(Math.random() * (max - min + 1) + min);
|
|
25
|
-
}
|
|
26
|
-
const _default = randomInt;
|
package/randomKey.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get random key from given object
|
|
3
|
-
*
|
|
4
|
-
* @category misc
|
|
5
|
-
* @see https://stackoverflow.com/a/15106541/1938970
|
|
6
|
-
*/ "use strict";
|
|
7
|
-
Object.defineProperty(exports, "__esModule", {
|
|
8
|
-
value: true
|
|
9
|
-
});
|
|
10
|
-
function _export(target, all) {
|
|
11
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
12
|
-
enumerable: true,
|
|
13
|
-
get: all[name]
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
_export(exports, {
|
|
17
|
-
randomKey: function() {
|
|
18
|
-
return randomKey;
|
|
19
|
-
},
|
|
20
|
-
default: function() {
|
|
21
|
-
return _default;
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
function randomKey(obj) {
|
|
25
|
-
const keys = Object.keys(obj);
|
|
26
|
-
return keys[keys.length * Math.random() << 0];
|
|
27
|
-
}
|
|
28
|
-
const _default = randomKey;
|
package/readCookie.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
readCookie: function() {
|
|
13
|
-
return readCookie;
|
|
14
|
-
},
|
|
15
|
-
default: function() {
|
|
16
|
-
return _default;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
function converterRead(value) {
|
|
20
|
-
if (value[0] === '"') {
|
|
21
|
-
value = value.slice(1, -1);
|
|
22
|
-
}
|
|
23
|
-
return value.replace(/(%[\dA-F]{2})+/gi, decodeURIComponent);
|
|
24
|
-
}
|
|
25
|
-
function readCookie(name) {
|
|
26
|
-
if (typeof document === "undefined") {
|
|
27
|
-
if (process.env["NODE_ENV"] !== "production") {
|
|
28
|
-
console.warn("[@koine/utils:readCookie] document is undefined");
|
|
29
|
-
}
|
|
30
|
-
return name ? "" : {};
|
|
31
|
-
}
|
|
32
|
-
const cookies = document.cookie ? document.cookie.split("; ") : [];
|
|
33
|
-
const all = {};
|
|
34
|
-
for(let i = 0; i < cookies.length; i++){
|
|
35
|
-
const parts = cookies[i].split("=");
|
|
36
|
-
const value = parts.slice(1).join("=");
|
|
37
|
-
try {
|
|
38
|
-
const found = decodeURIComponent(parts[0]);
|
|
39
|
-
all[found] = converterRead(value);
|
|
40
|
-
if (name === found) {
|
|
41
|
-
break;
|
|
42
|
-
}
|
|
43
|
-
} catch (e) {
|
|
44
|
-
if (process.env["NODE_ENV"] !== "production") {
|
|
45
|
-
console.warn("[@koine/utils:readCookie] failed to decode", value);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return name ? all[name] : all;
|
|
50
|
-
}
|
|
51
|
-
const _default = readCookie;
|
package/removeAccents.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
removeAccents: function() {
|
|
13
|
-
return removeAccents;
|
|
14
|
-
},
|
|
15
|
-
default: function() {
|
|
16
|
-
return _default;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
const _accentSets = require("./accentSets");
|
|
20
|
-
function removeAccents(text = "", sets = _accentSets.accentsSets) {
|
|
21
|
-
let len = sets.length;
|
|
22
|
-
while(len--){
|
|
23
|
-
const [to, from] = sets[len];
|
|
24
|
-
text = text.replace(new RegExp(`[${from}]`, "gi"), to);
|
|
25
|
-
}
|
|
26
|
-
return text;
|
|
27
|
-
}
|
|
28
|
-
const _default = removeAccents;
|
package/removeCookie.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
removeCookie: function() {
|
|
13
|
-
return removeCookie;
|
|
14
|
-
},
|
|
15
|
-
default: function() {
|
|
16
|
-
return _default;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
const _cookie = require("./cookie");
|
|
20
|
-
const _setCookie = require("./setCookie");
|
|
21
|
-
function removeCookie(name, attributes = {}) {
|
|
22
|
-
(0, _setCookie.setCookie)(name, "", {
|
|
23
|
-
..._cookie.defaultAttributesClient,
|
|
24
|
-
...attributes,
|
|
25
|
-
expires: -1
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
const _default = removeCookie;
|
package/removeDuplicates.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
// /**
|
|
2
|
-
// * FIXME: Type 'Set<any>' can only be iterated through when using the
|
|
3
|
-
// * '--downlevelIteration' flag or with a '--target' of 'es2015' or higher.
|
|
4
|
-
// * I am not sure I want to use those ts options here. Let's keep it commented
|
|
5
|
-
// * for now
|
|
6
|
-
// *
|
|
7
|
-
// * @category array
|
|
8
|
-
// */
|
|
9
|
-
// export function removeDuplicates<T extends any[]>(arr: T) {
|
|
10
|
-
// return [...new Set(arr)];
|
|
11
|
-
// }
|
|
12
|
-
// export default removeDuplicates;
|
|
13
|
-
"use strict";
|
package/removeDuplicatesByKey.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
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
|
-
*/ "use strict";
|
|
7
|
-
Object.defineProperty(exports, "__esModule", {
|
|
8
|
-
value: true
|
|
9
|
-
});
|
|
10
|
-
function _export(target, all) {
|
|
11
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
12
|
-
enumerable: true,
|
|
13
|
-
get: all[name]
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
_export(exports, {
|
|
17
|
-
removeDuplicatesByKey: function() {
|
|
18
|
-
return removeDuplicatesByKey;
|
|
19
|
-
},
|
|
20
|
-
default: function() {
|
|
21
|
-
return _default;
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
function removeDuplicatesByKey(array = [], key) {
|
|
25
|
-
const keysMap = {};
|
|
26
|
-
const output = [];
|
|
27
|
-
for(let i = 0; i < array.length; i++){
|
|
28
|
-
const item = array[i];
|
|
29
|
-
if (!keysMap[item[key]]) {
|
|
30
|
-
output.push(item);
|
|
31
|
-
keysMap[item[key]] = true;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return output;
|
|
35
|
-
}
|
|
36
|
-
const _default = removeDuplicatesByKey;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
removeDuplicatesComparing: function() {
|
|
13
|
-
return removeDuplicatesComparing;
|
|
14
|
-
},
|
|
15
|
-
default: function() {
|
|
16
|
-
return _default;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
const _findDuplicatedIndexes = require("./findDuplicatedIndexes");
|
|
20
|
-
const _removeIndexesFromArray = require("./removeIndexesFromArray");
|
|
21
|
-
function removeDuplicatesComparing(from, to) {
|
|
22
|
-
const indexes = (0, _findDuplicatedIndexes.findDuplicatedIndexes)(from);
|
|
23
|
-
return (0, _removeIndexesFromArray.removeIndexesFromArray)(to, indexes);
|
|
24
|
-
}
|
|
25
|
-
const _default = removeDuplicatesComparing;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @category array
|
|
3
|
-
*/ "use strict";
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
function _export(target, all) {
|
|
8
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
9
|
-
enumerable: true,
|
|
10
|
-
get: all[name]
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
_export(exports, {
|
|
14
|
-
removeIndexesFromArray: function() {
|
|
15
|
-
return removeIndexesFromArray;
|
|
16
|
-
},
|
|
17
|
-
default: function() {
|
|
18
|
-
return _default;
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
function removeIndexesFromArray(arr, indexes) {
|
|
22
|
-
const output = [];
|
|
23
|
-
for(let i = 0; i < arr.length; i++){
|
|
24
|
-
// eslint-disable-next-line no-prototype-builtins
|
|
25
|
-
if (!indexes.hasOwnProperty(i)) {
|
|
26
|
-
output.push(arr[i]);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
return output;
|
|
30
|
-
}
|
|
31
|
-
const _default = removeIndexesFromArray;
|
package/removeTrailingSlash.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Strips out the trailing slash
|
|
3
|
-
*
|
|
4
|
-
* @category location
|
|
5
|
-
*/ "use strict";
|
|
6
|
-
Object.defineProperty(exports, "__esModule", {
|
|
7
|
-
value: true
|
|
8
|
-
});
|
|
9
|
-
function _export(target, all) {
|
|
10
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: all[name]
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
_export(exports, {
|
|
16
|
-
removeTralingSlash: function() {
|
|
17
|
-
return removeTralingSlash;
|
|
18
|
-
},
|
|
19
|
-
default: function() {
|
|
20
|
-
return _default;
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
function removeTralingSlash(urlLike = "") {
|
|
24
|
-
return urlLike.replace(/\/*$/, "");
|
|
25
|
-
}
|
|
26
|
-
const _default = removeTralingSlash;
|
package/removeUrlQueryParams.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
removeUrlQueryParams: function() {
|
|
13
|
-
return removeUrlQueryParams;
|
|
14
|
-
},
|
|
15
|
-
default: function() {
|
|
16
|
-
return _default;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
|
20
|
-
const _buildUrlQueryString = /*#__PURE__*/ _interop_require_default._(require("./buildUrlQueryString"));
|
|
21
|
-
const _getUrlQueryParams = /*#__PURE__*/ _interop_require_default._(require("./getUrlQueryParams"));
|
|
22
|
-
function removeUrlQueryParams(url, paramsToRemove = []) {
|
|
23
|
-
const parts = url.split("?");
|
|
24
|
-
const allParams = (0, _getUrlQueryParams.default)(url);
|
|
25
|
-
const params = {};
|
|
26
|
-
for(const key in allParams){
|
|
27
|
-
if (!paramsToRemove.includes(key)) {
|
|
28
|
-
params[key] = allParams[key];
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return parts[0] + (0, _buildUrlQueryString.default)(params);
|
|
32
|
-
}
|
|
33
|
-
const _default = removeUrlQueryParams;
|
package/render.js
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
render: function() {
|
|
13
|
-
return render;
|
|
14
|
-
},
|
|
15
|
-
default: function() {
|
|
16
|
-
return _default;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
const varname = "data";
|
|
20
|
-
const evaluate = /<%([\s\S]+?(\}?)+)%>/g;
|
|
21
|
-
const interpolate = /<%=([\s\S]+?)%>/g;
|
|
22
|
-
const conditional = /<%\?(\?)?\s*([\s\S]*?)\s*%>/g;
|
|
23
|
-
const iterate = /<%~\s*(?:%>|([\s\S]+?)\s*:\s*([\w$]+)\s*(?::\s*([\w$]+))?\s*%>)/g;
|
|
24
|
-
// const encode = /<%!([\s\S]+?)%>/g;
|
|
25
|
-
const use = /<%#([\s\S]+?)%>/g;
|
|
26
|
-
const useParams = /(^|[^\w$])def(?:\.|\[['"])([\w$.]+)(?:['"]\])?\s*:\s*([\w$.]+|"[^"]+"|'[^']+'|\{[^}]+\})/g;
|
|
27
|
-
const define = /<%##\s*([\w.$]+)\s*(:|=)([\s\S]+?)#%>/g;
|
|
28
|
-
const defineParams = /^\s*([\w$]+):([\s\S]+)/;
|
|
29
|
-
const start = "'+(";
|
|
30
|
-
const end = ")+'";
|
|
31
|
-
// const startencode = "'+encodeHTML(";
|
|
32
|
-
const skip = /$^/;
|
|
33
|
-
const resolveDefs = (block, def)=>(typeof block === "string" ? block : block.toString()).replace(define || skip, (_, code, assign, value)=>{
|
|
34
|
-
if (code.indexOf("def.") === 0) {
|
|
35
|
-
code = code.substring(4);
|
|
36
|
-
}
|
|
37
|
-
if (!(code in def)) {
|
|
38
|
-
if (assign === ":") {
|
|
39
|
-
value.replace(defineParams, // @ts-expect-error nevermind
|
|
40
|
-
(_, param, v)=>{
|
|
41
|
-
def[code] = {
|
|
42
|
-
arg: param,
|
|
43
|
-
text: v
|
|
44
|
-
};
|
|
45
|
-
});
|
|
46
|
-
// @ts-expect-error nevermind
|
|
47
|
-
if (!(code in def)) def[code] = value;
|
|
48
|
-
} else {
|
|
49
|
-
new Function("def", "def['" + code + "']=" + value)(def);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return "";
|
|
53
|
-
}).replace(use || skip, (_, code)=>{
|
|
54
|
-
code = code.replace(useParams, (_, s, d, param)=>{
|
|
55
|
-
if (def[d] && def[d].arg && param) {
|
|
56
|
-
const rw = (d + ":" + param).replace(/'|\\/g, "_");
|
|
57
|
-
def.__exp = def.__exp || {};
|
|
58
|
-
def.__exp[rw] = def[d].text.replace(new RegExp("(^|[^\\w$])" + def[d].arg + "([^\\w$])", "g"), "$1" + param + "$2");
|
|
59
|
-
return s + "def.__exp['" + rw + "']";
|
|
60
|
-
}
|
|
61
|
-
return s;
|
|
62
|
-
});
|
|
63
|
-
const v = new Function("def", "return " + code)(def);
|
|
64
|
-
return v ? resolveDefs(v, def) : v;
|
|
65
|
-
});
|
|
66
|
-
const unescape = (code)=>code.replace(/\\('|\\)/g, "$1").replace(/[\r\t\n]/g, " ");
|
|
67
|
-
const render = (tmpl, def)=>{
|
|
68
|
-
let sid = 0;
|
|
69
|
-
let indv;
|
|
70
|
-
let str = use || define ? resolveDefs(tmpl, def || {}) : tmpl;
|
|
71
|
-
str = ("var X='" + str.replace(/(^|\r|\n)\t* +| +\t*(\r|\n|$)/g, " ").replace(/\r|\n|\t|\/\*[\s\S]*?\*\//g, "").replace(/'|\\/g, "\\$&").replace(interpolate || skip, (_, code)=>start + unescape(code) + end)// .replace(
|
|
72
|
-
// encode || skip,
|
|
73
|
-
// (_, code) => cse.startencode + unescape(code) + cse.end
|
|
74
|
-
// )
|
|
75
|
-
.replace(conditional || skip, (_, elseCase, code)=>elseCase ? code ? "';}else if(" + unescape(code) + "){X+='" : "';}else{X+='" : code ? "';if(" + unescape(code) + "){X+='" : "';}X+='").replace(iterate || skip, (_, arr, vName, iName)=>{
|
|
76
|
-
if (!arr) return "';} } X+='";
|
|
77
|
-
sid++;
|
|
78
|
-
indv = iName || "i" + sid;
|
|
79
|
-
arr = unescape(arr);
|
|
80
|
-
return "';var arr" + sid + "=" + arr + ";if(arr" + sid + "){var " + vName + "," + indv + "=-1,l" + sid + "=arr" + sid + ".length-1;while(" + indv + "<l" + sid + "){" + vName + "=arr" + sid + "[" + indv + "+=1];X+='";
|
|
81
|
-
}).replace(evaluate || skip, (_, code)=>"';" + unescape(code) + "X+='") + "';return X;").replace(/\n/g, "\\n").replace(/\t/g, "\\t").replace(/\r/g, "\\r").replace(/(\s|;|\}|^|\{)X\+='';/g, "$1").replace(/\+''/g, "");
|
|
82
|
-
//.replace(/(\s|;|\}|^|\{)X\+=''\+/g,'$1X+=');
|
|
83
|
-
try {
|
|
84
|
-
return new Function(varname, str);
|
|
85
|
-
} catch (e) {
|
|
86
|
-
if (process.env["NODE_ENV"] !== "production") {
|
|
87
|
-
console.log("Could not create a template function: " + str);
|
|
88
|
-
throw e;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
return ()=>"";
|
|
92
|
-
};
|
|
93
|
-
const _default = render;
|
package/roundTo.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Round to given number of the given number of decimals
|
|
3
|
-
*
|
|
4
|
-
* @category math
|
|
5
|
-
* @see https://stackoverflow.com/a/15762794/1938970
|
|
6
|
-
*/ "use strict";
|
|
7
|
-
Object.defineProperty(exports, "__esModule", {
|
|
8
|
-
value: true
|
|
9
|
-
});
|
|
10
|
-
function _export(target, all) {
|
|
11
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
12
|
-
enumerable: true,
|
|
13
|
-
get: all[name]
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
_export(exports, {
|
|
17
|
-
roundTo: function() {
|
|
18
|
-
return roundTo;
|
|
19
|
-
},
|
|
20
|
-
default: function() {
|
|
21
|
-
return _default;
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
function roundTo(num, decimals = 2) {
|
|
25
|
-
if (isFinite(num) && !isNaN(num)) {
|
|
26
|
-
// method 1
|
|
27
|
-
// return Number(num).toFixed(decimals);
|
|
28
|
-
// method 2: @see https://stackoverflow.com/a/43532829/1938970
|
|
29
|
-
const multiplicator = Math.pow(10, decimals);
|
|
30
|
-
return Math.round(num * multiplicator) / multiplicator + "";
|
|
31
|
-
// method 3: @see https://stackoverflow.com/a/15762794/1938970
|
|
32
|
-
// let negative = false;
|
|
33
|
-
// if (num < 0) {
|
|
34
|
-
// negative = true;
|
|
35
|
-
// num = num * -1;
|
|
36
|
-
// }
|
|
37
|
-
// const multiplicator = Math.pow(10, decimals);
|
|
38
|
-
// const outputStr = parseFloat((num * multiplicator).toFixed(11));
|
|
39
|
-
// let outputNum = (Math.round(outputStr) / multiplicator).toFixed(decimals);
|
|
40
|
-
// if (negative) {
|
|
41
|
-
// return (Number(outputNum) * -1).toFixed(decimals);
|
|
42
|
-
// }
|
|
43
|
-
// return outputNum;
|
|
44
|
-
}
|
|
45
|
-
if (process.env["NODE_ENV"] !== "production") {
|
|
46
|
-
console.warn("[@koine/utils] math:roundTo -> given not a finite number as first arg");
|
|
47
|
-
}
|
|
48
|
-
return "";
|
|
49
|
-
}
|
|
50
|
-
const _default = roundTo;
|