@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/package.json
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koine/utils",
|
|
3
3
|
"sideEffects": false,
|
|
4
|
-
"dependencies": {
|
|
5
|
-
|
|
6
|
-
"ts-debounce": "^4.0.0",
|
|
7
|
-
"type-fest": "^3.11.1"
|
|
8
|
-
},
|
|
9
|
-
"peerDependencies": {
|
|
10
|
-
"tslib": "2.5.3"
|
|
11
|
-
},
|
|
4
|
+
"dependencies": {},
|
|
5
|
+
"module": "./index.mjs",
|
|
12
6
|
"main": "./index.js",
|
|
13
7
|
"types": "./index.d.ts",
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
}
|
|
8
|
+
"peerDependencies": {
|
|
9
|
+
"type-fest": "^4.1.0"
|
|
10
|
+
},
|
|
11
|
+
"version": "2.0.0-beta.11"
|
|
12
|
+
}
|
package/parseCookie.mjs
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Try decoding a string using a decoding function.
|
|
3
|
-
*/
|
|
4
|
-
function tryDecode(str, decode) {
|
|
3
|
+
*/ function tryDecode(str, decode) {
|
|
5
4
|
try {
|
|
6
5
|
return decode(str);
|
|
7
|
-
}
|
|
8
|
-
catch (e) {
|
|
6
|
+
} catch (e) {
|
|
9
7
|
return str;
|
|
10
8
|
}
|
|
11
9
|
}
|
|
@@ -16,26 +14,24 @@ function tryDecode(str, decode) {
|
|
|
16
14
|
* The object has the various cookies as keys(names) => values
|
|
17
15
|
*
|
|
18
16
|
* @category cookie
|
|
19
|
-
*/
|
|
20
|
-
export function parseCookie(str, attributes) {
|
|
21
|
-
if (attributes === void 0) { attributes = {}; }
|
|
17
|
+
*/ export function parseCookie(str, attributes = {}) {
|
|
22
18
|
if (typeof str !== "string") {
|
|
23
19
|
throw new TypeError("argument str must be a string");
|
|
24
20
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
for
|
|
29
|
-
|
|
30
|
-
|
|
21
|
+
const obj = {};
|
|
22
|
+
const pairs = str.split(";");
|
|
23
|
+
const { decode = decodeURIComponent } = attributes;
|
|
24
|
+
for(let i = 0; i < pairs.length; i++){
|
|
25
|
+
const pair = pairs[i];
|
|
26
|
+
const index = pair.indexOf("=");
|
|
31
27
|
// skip things that don't look like key=value
|
|
32
28
|
if (index < 0) {
|
|
33
29
|
continue;
|
|
34
30
|
}
|
|
35
|
-
|
|
31
|
+
const key = pair.substring(0, index).trim();
|
|
36
32
|
// only assign once
|
|
37
33
|
if (undefined == obj[key]) {
|
|
38
|
-
|
|
34
|
+
let val = pair.substring(index + 1, pair.length).trim();
|
|
39
35
|
// quoted values
|
|
40
36
|
if (val[0] === '"') {
|
|
41
37
|
val = val.slice(1, -1);
|
package/parseURL.mjs
CHANGED
|
@@ -3,10 +3,9 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @category location
|
|
5
5
|
* @see https://stackoverflow.com/a/21553982/1938970
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return (match && {
|
|
6
|
+
*/ export function parseURL(url) {
|
|
7
|
+
const match = url.match(/^(https?:)\/\/(([^:/?#]*)(?::([0-9]+))?)([/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/);
|
|
8
|
+
return match && {
|
|
10
9
|
href: url,
|
|
11
10
|
protocol: match[1],
|
|
12
11
|
host: match[2],
|
|
@@ -14,7 +13,7 @@ export function parseURL(url) {
|
|
|
14
13
|
port: match[4],
|
|
15
14
|
pathname: match[5],
|
|
16
15
|
search: match[6],
|
|
17
|
-
hash: match[7]
|
|
18
|
-
}
|
|
16
|
+
hash: match[7]
|
|
17
|
+
};
|
|
19
18
|
}
|
|
20
19
|
export default parseURL;
|
package/quaranteneProps.d.ts
CHANGED
package/quaranteneProps.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @category impl
|
|
3
|
-
* @
|
|
3
|
+
* @example
|
|
4
4
|
*
|
|
5
5
|
* ```ts
|
|
6
6
|
* const { _: { onKeyDown }, myOwnProp, ...rest } = quaranteneProps([
|
|
@@ -12,18 +12,16 @@
|
|
|
12
12
|
* "onKeyDown",
|
|
13
13
|
* ]);
|
|
14
14
|
* ```
|
|
15
|
-
*/
|
|
16
|
-
export function quaranteneProps(props, propsKeysToQuarantene) {
|
|
15
|
+
*/ export function quaranteneProps(props, propsKeysToQuarantene) {
|
|
17
16
|
// approach 1)
|
|
18
|
-
|
|
19
|
-
_: {}
|
|
17
|
+
const healthyProps = {
|
|
18
|
+
_: {}
|
|
20
19
|
};
|
|
21
|
-
for
|
|
22
|
-
|
|
20
|
+
for(const key in props){
|
|
21
|
+
const prop = props[key];
|
|
23
22
|
if (propsKeysToQuarantene.includes(key)) {
|
|
24
23
|
healthyProps._[key] = prop;
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
24
|
+
} else {
|
|
27
25
|
// @ts-expect-error nevermind
|
|
28
26
|
healthyProps[key] = prop;
|
|
29
27
|
}
|
package/randomInt.mjs
CHANGED
package/randomKey.mjs
CHANGED
|
@@ -3,9 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @category misc
|
|
5
5
|
* @see https://stackoverflow.com/a/15106541/1938970
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return keys[(keys.length * Math.random()) << 0];
|
|
6
|
+
*/ export function randomKey(obj) {
|
|
7
|
+
const keys = Object.keys(obj);
|
|
8
|
+
return keys[keys.length * Math.random() << 0];
|
|
10
9
|
}
|
|
11
10
|
export default randomKey;
|
package/readCookie.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read cookie
|
|
3
|
+
*
|
|
4
|
+
* @category cookie
|
|
5
|
+
*/
|
|
1
6
|
export declare function readCookie<T extends Record<string, unknown> = Record<string, string>>(name?: null): T;
|
|
2
7
|
export declare function readCookie<T extends Record<string, unknown> = Record<string, string>, N extends keyof T = keyof T>(name: N): T[N];
|
|
3
8
|
export default readCookie;
|
package/readCookie.mjs
CHANGED
|
@@ -11,19 +11,18 @@ export function readCookie(name) {
|
|
|
11
11
|
}
|
|
12
12
|
return name ? "" : {};
|
|
13
13
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
for
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
const cookies = document.cookie ? document.cookie.split("; ") : [];
|
|
15
|
+
const all = {};
|
|
16
|
+
for(let i = 0; i < cookies.length; i++){
|
|
17
|
+
const parts = cookies[i].split("=");
|
|
18
|
+
const value = parts.slice(1).join("=");
|
|
19
19
|
try {
|
|
20
|
-
|
|
20
|
+
const found = decodeURIComponent(parts[0]);
|
|
21
21
|
all[found] = converterRead(value);
|
|
22
22
|
if (name === found) {
|
|
23
23
|
break;
|
|
24
24
|
}
|
|
25
|
-
}
|
|
26
|
-
catch (e) {
|
|
25
|
+
} catch (e) {
|
|
27
26
|
if (process.env["NODE_ENV"] !== "production") {
|
|
28
27
|
console.warn("[@koine/utils:readCookie] failed to decode", value);
|
|
29
28
|
}
|
package/removeAccents.mjs
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import { accentsSets } from "./accentSets";
|
|
2
2
|
/**
|
|
3
3
|
* @category text
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
while (len--) {
|
|
10
|
-
var _a = sets[len], to = _a[0], from = _a[1];
|
|
11
|
-
text = text.replace(new RegExp("[".concat(from, "]"), "gi"), to);
|
|
4
|
+
*/ export function removeAccents(text = "", sets = accentsSets) {
|
|
5
|
+
let len = sets.length;
|
|
6
|
+
while(len--){
|
|
7
|
+
const [to, from] = sets[len];
|
|
8
|
+
text = text.replace(new RegExp(`[${from}]`, "gi"), to);
|
|
12
9
|
}
|
|
13
10
|
return text;
|
|
14
11
|
}
|
package/removeCookie.d.ts
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import { type CookieAttributesClient } from "./cookie";
|
|
2
2
|
/**
|
|
3
3
|
* @category cookie
|
|
4
|
-
*
|
|
5
|
-
* All cookie related code is inspired and adapted from:
|
|
6
|
-
* - [js-cookie](https://github.com/js-cookie/js-cookie)
|
|
7
|
-
* - [cookie](https://github.com/jshttp/cookie)
|
|
8
4
|
*/
|
|
9
5
|
export declare function removeCookie(name: string, attributes?: CookieAttributesClient): void;
|
|
10
6
|
export default removeCookie;
|
package/removeCookie.mjs
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
import { __assign } from "tslib";
|
|
2
1
|
import { defaultAttributesClient } from "./cookie";
|
|
3
2
|
import { setCookie } from "./setCookie";
|
|
4
3
|
/**
|
|
5
4
|
* @category cookie
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (attributes === void 0) { attributes = {}; }
|
|
13
|
-
setCookie(name, "", __assign(__assign(__assign({}, defaultAttributesClient), attributes), { expires: -1 }));
|
|
5
|
+
*/ export function removeCookie(name, attributes = {}) {
|
|
6
|
+
setCookie(name, "", {
|
|
7
|
+
...defaultAttributesClient,
|
|
8
|
+
...attributes,
|
|
9
|
+
expires: -1
|
|
10
|
+
});
|
|
14
11
|
}
|
|
15
12
|
export default removeCookie;
|
package/removeDuplicates.mjs
CHANGED
|
@@ -3,13 +3,11 @@
|
|
|
3
3
|
* comparison of each object's given key
|
|
4
4
|
*
|
|
5
5
|
* @category array
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
for (var i = 0; i < array.length; i++) {
|
|
12
|
-
var item = array[i];
|
|
6
|
+
*/ export function removeDuplicatesByKey(array = [], key) {
|
|
7
|
+
const keysMap = {};
|
|
8
|
+
const output = [];
|
|
9
|
+
for(let i = 0; i < array.length; i++){
|
|
10
|
+
const item = array[i];
|
|
13
11
|
if (!keysMap[item[key]]) {
|
|
14
12
|
output.push(item);
|
|
15
13
|
keysMap[item[key]] = true;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { removeIndexesFromArray } from "./removeIndexesFromArray";
|
|
2
1
|
import { findDuplicatedIndexes } from "./findDuplicatedIndexes";
|
|
2
|
+
import { removeIndexesFromArray } from "./removeIndexesFromArray";
|
|
3
3
|
/**
|
|
4
4
|
* @category array
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
var indexes = findDuplicatedIndexes(from);
|
|
5
|
+
*/ export function removeDuplicatesComparing(from, to) {
|
|
6
|
+
const indexes = findDuplicatedIndexes(from);
|
|
8
7
|
return removeIndexesFromArray(to, indexes);
|
|
9
8
|
}
|
|
10
9
|
export default removeDuplicatesComparing;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @category array
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
for (var i = 0; i < arr.length; i++) {
|
|
3
|
+
*/ export function removeIndexesFromArray(arr, indexes) {
|
|
4
|
+
const output = [];
|
|
5
|
+
for(let i = 0; i < arr.length; i++){
|
|
7
6
|
// eslint-disable-next-line no-prototype-builtins
|
|
8
7
|
if (!indexes.hasOwnProperty(i)) {
|
|
9
8
|
output.push(arr[i]);
|
package/removeTrailingSlash.mjs
CHANGED
|
@@ -2,9 +2,7 @@
|
|
|
2
2
|
* Strips out the trailing slash
|
|
3
3
|
*
|
|
4
4
|
* @category location
|
|
5
|
-
*/
|
|
6
|
-
export function removeTralingSlash(urlLike) {
|
|
7
|
-
if (urlLike === void 0) { urlLike = ""; }
|
|
5
|
+
*/ export function removeTralingSlash(urlLike = "") {
|
|
8
6
|
return urlLike.replace(/\/*$/, "");
|
|
9
7
|
}
|
|
10
8
|
export default removeTralingSlash;
|
package/removeUrlQueryParams.mjs
CHANGED
|
@@ -4,14 +4,11 @@ import getUrlQueryParams from "./getUrlQueryParams";
|
|
|
4
4
|
* Remove the given keys from the given URL query parameters
|
|
5
5
|
*
|
|
6
6
|
* @category location
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
var allParams = getUrlQueryParams(url);
|
|
13
|
-
var params = {};
|
|
14
|
-
for (var key in allParams) {
|
|
7
|
+
*/ export function removeUrlQueryParams(url, paramsToRemove = []) {
|
|
8
|
+
const parts = url.split("?");
|
|
9
|
+
const allParams = getUrlQueryParams(url);
|
|
10
|
+
const params = {};
|
|
11
|
+
for(const key in allParams){
|
|
15
12
|
if (!paramsToRemove.includes(key)) {
|
|
16
13
|
params[key] = allParams[key];
|
|
17
14
|
}
|
package/render.d.ts
CHANGED
package/render.mjs
CHANGED
|
@@ -1,57 +1,51 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
const varname = "data";
|
|
2
|
+
const evaluate = /<%([\s\S]+?(\}?)+)%>/g;
|
|
3
|
+
const interpolate = /<%=([\s\S]+?)%>/g;
|
|
4
|
+
const conditional = /<%\?(\?)?\s*([\s\S]*?)\s*%>/g;
|
|
5
|
+
const iterate = /<%~\s*(?:%>|([\s\S]+?)\s*:\s*([\w$]+)\s*(?::\s*([\w$]+))?\s*%>)/g;
|
|
6
6
|
// const encode = /<%!([\s\S]+?)%>/g;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
const use = /<%#([\s\S]+?)%>/g;
|
|
8
|
+
const useParams = /(^|[^\w$])def(?:\.|\[['"])([\w$.]+)(?:['"]\])?\s*:\s*([\w$.]+|"[^"]+"|'[^']+'|\{[^}]+\})/g;
|
|
9
|
+
const define = /<%##\s*([\w.$]+)\s*(:|=)([\s\S]+?)#%>/g;
|
|
10
|
+
const defineParams = /^\s*([\w$]+):([\s\S]+)/;
|
|
11
|
+
const start = "'+(";
|
|
12
|
+
const end = ")+'";
|
|
13
13
|
// const startencode = "'+encodeHTML(";
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return (typeof block === "string" ? block : block.toString())
|
|
17
|
-
.replace(define || skip, function (_, code, assign, value) {
|
|
14
|
+
const skip = /$^/;
|
|
15
|
+
const resolveDefs = (block, def)=>(typeof block === "string" ? block : block.toString()).replace(define || skip, (_, code, assign, value)=>{
|
|
18
16
|
if (code.indexOf("def.") === 0) {
|
|
19
17
|
code = code.substring(4);
|
|
20
18
|
}
|
|
21
19
|
if (!(code in def)) {
|
|
22
20
|
if (assign === ":") {
|
|
23
|
-
value.replace(defineParams,
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
value.replace(defineParams, // @ts-expect-error nevermind
|
|
22
|
+
(_, param, v)=>{
|
|
23
|
+
def[code] = {
|
|
24
|
+
arg: param,
|
|
25
|
+
text: v
|
|
26
|
+
};
|
|
27
27
|
});
|
|
28
28
|
// @ts-expect-error nevermind
|
|
29
|
-
if (!(code in def))
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
29
|
+
if (!(code in def)) def[code] = value;
|
|
30
|
+
} else {
|
|
33
31
|
new Function("def", "def['" + code + "']=" + value)(def);
|
|
34
32
|
}
|
|
35
33
|
}
|
|
36
34
|
return "";
|
|
37
|
-
})
|
|
38
|
-
.replace(
|
|
39
|
-
code = code.replace(useParams, function (_, s, d, param) {
|
|
35
|
+
}).replace(use || skip, (_, code)=>{
|
|
36
|
+
code = code.replace(useParams, (_, s, d, param)=>{
|
|
40
37
|
if (def[d] && def[d].arg && param) {
|
|
41
|
-
|
|
38
|
+
const rw = (d + ":" + param).replace(/'|\\/g, "_");
|
|
42
39
|
def.__exp = def.__exp || {};
|
|
43
40
|
def.__exp[rw] = def[d].text.replace(new RegExp("(^|[^\\w$])" + def[d].arg + "([^\\w$])", "g"), "$1" + param + "$2");
|
|
44
41
|
return s + "def.__exp['" + rw + "']";
|
|
45
42
|
}
|
|
46
43
|
return s;
|
|
47
44
|
});
|
|
48
|
-
|
|
45
|
+
const v = new Function("def", "return " + code)(def);
|
|
49
46
|
return v ? resolveDefs(v, def) : v;
|
|
50
47
|
});
|
|
51
|
-
|
|
52
|
-
var unescape = function (code) {
|
|
53
|
-
return code.replace(/\\('|\\)/g, "$1").replace(/[\r\t\n]/g, " ");
|
|
54
|
-
};
|
|
48
|
+
const unescape = (code)=>code.replace(/\\('|\\)/g, "$1").replace(/[\r\t\n]/g, " ");
|
|
55
49
|
/**
|
|
56
50
|
* Render template (adapted from doT.js)
|
|
57
51
|
*
|
|
@@ -73,9 +67,10 @@ var unescape = function (code) {
|
|
|
73
67
|
* <%! %> for interpolation with encoding
|
|
74
68
|
* ```
|
|
75
69
|
*
|
|
70
|
+
* @category impl
|
|
76
71
|
* @example
|
|
77
72
|
*
|
|
78
|
-
* ```
|
|
73
|
+
* ```ts
|
|
79
74
|
* import { render } from "...";
|
|
80
75
|
*
|
|
81
76
|
* const data = { name: "XYZ" };
|
|
@@ -87,79 +82,30 @@ var unescape = function (code) {
|
|
|
87
82
|
*
|
|
88
83
|
* @borrows [olado/doT by Laura Doktorova](https://github.com/olado/doT)
|
|
89
84
|
* @see https://olado.github.io/doT/index.html
|
|
90
|
-
*/
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
.replace(conditional || skip, function (_, elseCase, code) {
|
|
106
|
-
return elseCase
|
|
107
|
-
? code
|
|
108
|
-
? "';}else if(" + unescape(code) + "){X+='"
|
|
109
|
-
: "';}else{X+='"
|
|
110
|
-
: code
|
|
111
|
-
? "';if(" + unescape(code) + "){X+='"
|
|
112
|
-
: "';}X+='";
|
|
113
|
-
})
|
|
114
|
-
.replace(iterate || skip, function (_, arr, vName, iName) {
|
|
115
|
-
if (!arr)
|
|
116
|
-
return "';} } X+='";
|
|
117
|
-
sid++;
|
|
118
|
-
indv = iName || "i" + sid;
|
|
119
|
-
arr = unescape(arr);
|
|
120
|
-
return ("';var arr" +
|
|
121
|
-
sid +
|
|
122
|
-
"=" +
|
|
123
|
-
arr +
|
|
124
|
-
";if(arr" +
|
|
125
|
-
sid +
|
|
126
|
-
"){var " +
|
|
127
|
-
vName +
|
|
128
|
-
"," +
|
|
129
|
-
indv +
|
|
130
|
-
"=-1,l" +
|
|
131
|
-
sid +
|
|
132
|
-
"=arr" +
|
|
133
|
-
sid +
|
|
134
|
-
".length-1;while(" +
|
|
135
|
-
indv +
|
|
136
|
-
"<l" +
|
|
137
|
-
sid +
|
|
138
|
-
"){" +
|
|
139
|
-
vName +
|
|
140
|
-
"=arr" +
|
|
141
|
-
sid +
|
|
142
|
-
"[" +
|
|
143
|
-
indv +
|
|
144
|
-
"+=1];X+='");
|
|
145
|
-
})
|
|
146
|
-
.replace(evaluate || skip, function (_, code) { return "';" + unescape(code) + "X+='"; }) +
|
|
147
|
-
"';return X;")
|
|
148
|
-
.replace(/\n/g, "\\n")
|
|
149
|
-
.replace(/\t/g, "\\t")
|
|
150
|
-
.replace(/\r/g, "\\r")
|
|
151
|
-
.replace(/(\s|;|\}|^|\{)X\+='';/g, "$1")
|
|
152
|
-
.replace(/\+''/g, "");
|
|
85
|
+
*/ export const render = (tmpl, def)=>{
|
|
86
|
+
let sid = 0;
|
|
87
|
+
let indv;
|
|
88
|
+
let str = use || define ? resolveDefs(tmpl, def || {}) : tmpl;
|
|
89
|
+
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(
|
|
90
|
+
// encode || skip,
|
|
91
|
+
// (_, code) => cse.startencode + unescape(code) + cse.end
|
|
92
|
+
// )
|
|
93
|
+
.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)=>{
|
|
94
|
+
if (!arr) return "';} } X+='";
|
|
95
|
+
sid++;
|
|
96
|
+
indv = iName || "i" + sid;
|
|
97
|
+
arr = unescape(arr);
|
|
98
|
+
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+='";
|
|
99
|
+
}).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, "");
|
|
153
100
|
//.replace(/(\s|;|\}|^|\{)X\+=''\+/g,'$1X+=');
|
|
154
101
|
try {
|
|
155
102
|
return new Function(varname, str);
|
|
156
|
-
}
|
|
157
|
-
catch (e) {
|
|
103
|
+
} catch (e) {
|
|
158
104
|
if (process.env["NODE_ENV"] !== "production") {
|
|
159
105
|
console.log("Could not create a template function: " + str);
|
|
160
106
|
throw e;
|
|
161
107
|
}
|
|
162
108
|
}
|
|
163
|
-
return
|
|
109
|
+
return ()=>"";
|
|
164
110
|
};
|
|
165
111
|
export default render;
|
package/roundTo.mjs
CHANGED
|
@@ -3,28 +3,26 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @category math
|
|
5
5
|
* @see https://stackoverflow.com/a/15762794/1938970
|
|
6
|
-
*/
|
|
7
|
-
export function roundTo(num, decimals) {
|
|
8
|
-
if (decimals === void 0) { decimals = 2; }
|
|
6
|
+
*/ export function roundTo(num, decimals = 2) {
|
|
9
7
|
if (isFinite(num) && !isNaN(num)) {
|
|
10
8
|
// method 1
|
|
11
9
|
// return Number(num).toFixed(decimals);
|
|
12
10
|
// method 2: @see https://stackoverflow.com/a/43532829/1938970
|
|
13
|
-
|
|
11
|
+
const multiplicator = Math.pow(10, decimals);
|
|
14
12
|
return Math.round(num * multiplicator) / multiplicator + "";
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
13
|
+
// method 3: @see https://stackoverflow.com/a/15762794/1938970
|
|
14
|
+
// let negative = false;
|
|
15
|
+
// if (num < 0) {
|
|
16
|
+
// negative = true;
|
|
17
|
+
// num = num * -1;
|
|
18
|
+
// }
|
|
19
|
+
// const multiplicator = Math.pow(10, decimals);
|
|
20
|
+
// const outputStr = parseFloat((num * multiplicator).toFixed(11));
|
|
21
|
+
// let outputNum = (Math.round(outputStr) / multiplicator).toFixed(decimals);
|
|
22
|
+
// if (negative) {
|
|
23
|
+
// return (Number(outputNum) * -1).toFixed(decimals);
|
|
24
|
+
// }
|
|
25
|
+
// return outputNum;
|
|
28
26
|
}
|
|
29
27
|
if (process.env["NODE_ENV"] !== "production") {
|
|
30
28
|
console.warn("[@koine/utils] math:roundTo -> given not a finite number as first arg");
|
package/serializeCookie.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @
|
|
2
|
+
* @module
|
|
3
3
|
*
|
|
4
4
|
* @category cookie
|
|
5
5
|
*
|
|
@@ -18,10 +18,6 @@ import { type CookieAttributesServer } from "./cookie";
|
|
|
18
18
|
* => "foo=bar; httpOnly"
|
|
19
19
|
*
|
|
20
20
|
* @category cookie
|
|
21
|
-
*
|
|
22
|
-
* All cookie related code is inspired and adapted from:
|
|
23
|
-
* - [js-cookie](https://github.com/js-cookie/js-cookie)
|
|
24
|
-
* - [cookie](https://github.com/jshttp/cookie)
|
|
25
21
|
*/
|
|
26
22
|
export declare function serializeCookie(name: string, val: string, attributes?: CookieAttributesServer): string;
|
|
27
23
|
export default serializeCookie;
|