@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/serializeCookie.mjs
CHANGED
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @
|
|
2
|
+
* @module
|
|
3
3
|
*
|
|
4
4
|
* @category cookie
|
|
5
5
|
*
|
|
6
6
|
* All cookie related code is inspired and adapted from:
|
|
7
7
|
* - [js-cookie](https://github.com/js-cookie/js-cookie)
|
|
8
8
|
* - [cookie](https://github.com/jshttp/cookie)
|
|
9
|
-
*/
|
|
10
|
-
import { isNumber } from "./isNumber";
|
|
9
|
+
*/ import { isNumber } from "./isNumber";
|
|
11
10
|
/**
|
|
12
11
|
* RegExp to match field-content in RFC 7230 sec 3.2
|
|
13
12
|
*
|
|
14
13
|
* field-content = field-vchar [ 1*( SP / HTAB ) field-vchar ]
|
|
15
14
|
* field-vchar = VCHAR / obs-text
|
|
16
15
|
* obs-text = %x80-FF
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
var fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;
|
|
16
|
+
*/ // eslint-disable-next-line no-control-regex
|
|
17
|
+
const fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;
|
|
20
18
|
/**
|
|
21
19
|
* Serialize data into a cookie header.
|
|
22
20
|
*
|
|
@@ -27,16 +25,10 @@ var fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;
|
|
|
27
25
|
* => "foo=bar; httpOnly"
|
|
28
26
|
*
|
|
29
27
|
* @category cookie
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
*/
|
|
35
|
-
export function serializeCookie(name, val, attributes) {
|
|
36
|
-
if (attributes === void 0) { attributes = {}; }
|
|
37
|
-
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;
|
|
38
|
-
var maxAge = attributes.maxAge, expires = attributes.expires;
|
|
39
|
-
var value = encode(val);
|
|
28
|
+
*/ export function serializeCookie(name, val, attributes = {}) {
|
|
29
|
+
const { encode = encodeURIComponent, domain, path, httpOnly, secure, sameSite } = attributes;
|
|
30
|
+
let { maxAge, expires } = attributes;
|
|
31
|
+
const value = encode(val);
|
|
40
32
|
if (process.env["NODE_ENV"] !== "production") {
|
|
41
33
|
if (!fieldContentRegExp.test(name)) {
|
|
42
34
|
throw new TypeError("argument name is invalid");
|
|
@@ -48,7 +40,7 @@ export function serializeCookie(name, val, attributes) {
|
|
|
48
40
|
throw new TypeError("argument val is invalid");
|
|
49
41
|
}
|
|
50
42
|
}
|
|
51
|
-
|
|
43
|
+
let str = name + "=" + value;
|
|
52
44
|
if (null != maxAge) {
|
|
53
45
|
maxAge = maxAge - 0;
|
|
54
46
|
if (isNaN(maxAge) || !isFinite(maxAge)) {
|
|
@@ -85,7 +77,7 @@ export function serializeCookie(name, val, attributes) {
|
|
|
85
77
|
str += "; Secure";
|
|
86
78
|
}
|
|
87
79
|
if (sameSite) {
|
|
88
|
-
switch
|
|
80
|
+
switch(sameSite.toLowerCase()){
|
|
89
81
|
case "lax":
|
|
90
82
|
str += "; SameSite=Lax";
|
|
91
83
|
break;
|
|
@@ -95,8 +87,6 @@ export function serializeCookie(name, val, attributes) {
|
|
|
95
87
|
case "none":
|
|
96
88
|
str += "; SameSite=None";
|
|
97
89
|
break;
|
|
98
|
-
// default:
|
|
99
|
-
// throw new TypeError('option sameSite is invalid');
|
|
100
90
|
}
|
|
101
91
|
}
|
|
102
92
|
return str;
|
package/setCookie.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 setCookie<T extends string = string>(name: string, value: string | T, attributes?: CookieAttributesClient): string | undefined;
|
|
10
6
|
export default setCookie;
|
package/setCookie.mjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __assign, __rest } from "tslib";
|
|
2
1
|
import { defaultAttributesClient } from "./cookie";
|
|
3
2
|
import isNumber from "./isNumber";
|
|
4
3
|
import isUndefined from "./isUndefined";
|
|
@@ -7,16 +6,14 @@ function converterWrite(value) {
|
|
|
7
6
|
}
|
|
8
7
|
/**
|
|
9
8
|
* @category cookie
|
|
10
|
-
|
|
11
|
-
* All cookie related code is inspired and adapted from:
|
|
12
|
-
* - [js-cookie](https://github.com/js-cookie/js-cookie)
|
|
13
|
-
* - [cookie](https://github.com/jshttp/cookie)
|
|
14
|
-
*/
|
|
15
|
-
export function setCookie(name, value, attributes) {
|
|
16
|
-
if (attributes === void 0) { attributes = {}; }
|
|
9
|
+
*/ export function setCookie(name, value, attributes = {}) {
|
|
17
10
|
// eslint-disable-next-line prefer-const
|
|
18
|
-
|
|
19
|
-
|
|
11
|
+
let { expires, ...restAttrs } = attributes;
|
|
12
|
+
const cleanedAttrs = {
|
|
13
|
+
expires: "",
|
|
14
|
+
...defaultAttributesClient,
|
|
15
|
+
...restAttrs
|
|
16
|
+
};
|
|
20
17
|
if (isUndefined(document)) {
|
|
21
18
|
if (process.env["NODE_ENV"] !== "production") {
|
|
22
19
|
console.warn("[@koine/utils:setCookie] document is undefined");
|
|
@@ -29,12 +26,10 @@ export function setCookie(name, value, attributes) {
|
|
|
29
26
|
if (expires) {
|
|
30
27
|
cleanedAttrs.expires = expires.toUTCString();
|
|
31
28
|
}
|
|
32
|
-
name = encodeURIComponent(name)
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
for (var name_1 in attributes) {
|
|
37
|
-
var attrName = name_1;
|
|
29
|
+
name = encodeURIComponent(name).replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent).replace(/[()]/g, escape);
|
|
30
|
+
let stringifiedAttributes = "";
|
|
31
|
+
for(const name in attributes){
|
|
32
|
+
const attrName = name;
|
|
38
33
|
if (!attributes[attrName]) {
|
|
39
34
|
continue;
|
|
40
35
|
}
|
|
@@ -49,10 +44,8 @@ export function setCookie(name, value, attributes) {
|
|
|
49
44
|
// Consume the characters of the unparsed-attributes up to,
|
|
50
45
|
// not including, the first %x3B (";") character.
|
|
51
46
|
// ...
|
|
52
|
-
stringifiedAttributes +=
|
|
53
|
-
"=" + String(attributes[attrName]).split(";")[0];
|
|
47
|
+
stringifiedAttributes += "=" + String(attributes[attrName]).split(";")[0];
|
|
54
48
|
}
|
|
55
|
-
return
|
|
56
|
-
name + "=" + converterWrite(value) + stringifiedAttributes);
|
|
49
|
+
return document.cookie = name + "=" + converterWrite(value) + stringifiedAttributes;
|
|
57
50
|
}
|
|
58
51
|
export default setCookie;
|
package/shuffle.d.ts
CHANGED
|
@@ -2,15 +2,16 @@
|
|
|
2
2
|
* Creates an array of shuffled values, using a version of the
|
|
3
3
|
* [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
|
|
4
4
|
*
|
|
5
|
-
* @
|
|
6
|
-
* @
|
|
7
|
-
* @category arrays
|
|
8
|
-
* @param {Array} array The array to shuffle.
|
|
9
|
-
* @returns {Array} Returns the new shuffled array.
|
|
5
|
+
* @category array
|
|
6
|
+
* @borrows [lodash.shuffle](https://github.com/lodash/lodash/blob/master/shuffle.js)
|
|
10
7
|
* @example
|
|
11
|
-
*
|
|
8
|
+
* ```ts
|
|
12
9
|
* shuffle([1, 2, 3, 4])
|
|
13
10
|
* // => [4, 1, 3, 2]
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* @param array The array to shuffle.
|
|
14
|
+
* @returns The new shuffled array.
|
|
14
15
|
*/
|
|
15
16
|
export declare function shuffle<T>(array: T[]): T[];
|
|
16
17
|
export default shuffle;
|
package/shuffle.mjs
CHANGED
|
@@ -1,29 +1,30 @@
|
|
|
1
|
-
import { __spreadArray } from "tslib";
|
|
2
1
|
/**
|
|
3
2
|
* Creates an array of shuffled values, using a version of the
|
|
4
3
|
* [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
|
|
5
4
|
*
|
|
6
|
-
* @
|
|
7
|
-
* @
|
|
8
|
-
* @category arrays
|
|
9
|
-
* @param {Array} array The array to shuffle.
|
|
10
|
-
* @returns {Array} Returns the new shuffled array.
|
|
5
|
+
* @category array
|
|
6
|
+
* @borrows [lodash.shuffle](https://github.com/lodash/lodash/blob/master/shuffle.js)
|
|
11
7
|
* @example
|
|
12
|
-
*
|
|
8
|
+
* ```ts
|
|
13
9
|
* shuffle([1, 2, 3, 4])
|
|
14
10
|
* // => [4, 1, 3, 2]
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* @param array The array to shuffle.
|
|
14
|
+
* @returns The new shuffled array.
|
|
15
|
+
*/ export function shuffle(array) {
|
|
16
|
+
const length = array == null ? 0 : array.length;
|
|
18
17
|
if (!length) {
|
|
19
18
|
return [];
|
|
20
19
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
let index = -1;
|
|
21
|
+
const lastIndex = length - 1;
|
|
22
|
+
const result = [
|
|
23
|
+
...array
|
|
24
|
+
];
|
|
25
|
+
while(++index < length){
|
|
26
|
+
const rand = index + Math.floor(Math.random() * (lastIndex - index + 1));
|
|
27
|
+
const value = result[rand];
|
|
27
28
|
result[rand] = result[index];
|
|
28
29
|
result[index] = value;
|
|
29
30
|
}
|
package/slugify.d.ts
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
* - replaces the punctuation with dashes
|
|
6
6
|
*
|
|
7
7
|
* @category text
|
|
8
|
-
*
|
|
8
|
+
*
|
|
9
|
+
* @borrows [mathewbyrne's gist](https://gist.github.com/mathewbyrne/1280286#gistcomment-3498021)
|
|
9
10
|
*/
|
|
10
11
|
export declare function slugify(text: string, separator?: string): string;
|
|
11
12
|
export default slugify;
|
package/slugify.mjs
CHANGED
|
@@ -7,17 +7,20 @@ import { removeAccents } from "./removeAccents";
|
|
|
7
7
|
* - replaces the punctuation with dashes
|
|
8
8
|
*
|
|
9
9
|
* @category text
|
|
10
|
-
*
|
|
11
|
-
|
|
12
|
-
export function slugify(text, separator) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
10
|
+
*
|
|
11
|
+
* @borrows [mathewbyrne's gist](https://gist.github.com/mathewbyrne/1280286#gistcomment-3498021)
|
|
12
|
+
*/ export function slugify(text, separator = "-") {
|
|
13
|
+
return removeAccents(text.toString().toLowerCase().trim(), accentsSets.concat([
|
|
14
|
+
[
|
|
15
|
+
"-",
|
|
16
|
+
"[·/_,:;']"
|
|
17
|
+
]
|
|
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);
|
|
22
25
|
}
|
|
23
26
|
export default slugify;
|
package/split.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
export type Split<S extends string, D extends string> = string extends S ? string[] : S extends "" ? [] : S extends `${infer T}${D}${infer U}` ? [T, ...Split<U, D>] : [S];
|
|
2
|
+
/**
|
|
3
|
+
* @category native
|
|
4
|
+
* @category text
|
|
5
|
+
*/
|
|
2
6
|
export declare function split<T extends string, D extends string>(str: T, delimiter: D): Split<T, D>;
|
|
3
7
|
export default split;
|
package/split.mjs
CHANGED
package/swapMap.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Swap object map key/value
|
|
3
3
|
*
|
|
4
|
-
* @category
|
|
4
|
+
* @category object
|
|
5
5
|
*/
|
|
6
6
|
export declare function swapMap<T extends Record<string, string | number | symbol> = Record<string, string | number | symbol>>(map?: T): Record<T[keyof T], keyof T>;
|
|
7
7
|
export default swapMap;
|
package/swapMap.mjs
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Swap object map key/value
|
|
3
3
|
*
|
|
4
|
-
* @category
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var output = {};
|
|
9
|
-
for (var key in map) {
|
|
4
|
+
* @category object
|
|
5
|
+
*/ export function swapMap(map = {}) {
|
|
6
|
+
const output = {};
|
|
7
|
+
for(const key in map){
|
|
10
8
|
output[map[key]] = key;
|
|
11
9
|
}
|
|
12
10
|
return output;
|
package/throttle.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
/**
|
|
2
3
|
* Throttle function (e.g. for resize / scroll handlers)
|
|
3
4
|
*
|
|
4
5
|
* @category function
|
|
5
|
-
* @
|
|
6
|
+
* @borrows [Mobius1/Rangeable](https://github.com/Mobius1/Rangeable/)
|
|
6
7
|
*/
|
|
7
8
|
export declare function throttle<TFn extends Function, TContext>(fn: TFn, limit: number, context?: TContext): (this: TContext, ...args: any[]) => NodeJS.Timeout | undefined;
|
|
8
9
|
export default throttle;
|
package/throttle.mjs
CHANGED
|
@@ -1,22 +1,16 @@
|
|
|
1
|
-
import { __spreadArray } from "tslib";
|
|
2
1
|
/**
|
|
3
2
|
* Throttle function (e.g. for resize / scroll handlers)
|
|
4
3
|
*
|
|
5
4
|
* @category function
|
|
6
|
-
* @
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return function () {
|
|
11
|
-
var args = [];
|
|
12
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
13
|
-
args[_i] = arguments[_i];
|
|
14
|
-
}
|
|
5
|
+
* @borrows [Mobius1/Rangeable](https://github.com/Mobius1/Rangeable/)
|
|
6
|
+
*/ export function throttle(fn, limit, context) {
|
|
7
|
+
let wait;
|
|
8
|
+
return function(...args) {
|
|
15
9
|
context = context || this;
|
|
16
10
|
if (!wait) {
|
|
17
|
-
fn.apply
|
|
11
|
+
fn.apply(context, ...args);
|
|
18
12
|
wait = true;
|
|
19
|
-
return setTimeout(function
|
|
13
|
+
return setTimeout(function() {
|
|
20
14
|
wait = false;
|
|
21
15
|
}, limit);
|
|
22
16
|
}
|
package/titleCase.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @category
|
|
3
|
-
*
|
|
4
|
-
* @
|
|
2
|
+
* @category text
|
|
3
|
+
*
|
|
4
|
+
* @borrows [blakeembrey/change-case](https://github.com/blakeembrey/change-case/blob/master/packages/title-case/src/index.ts)
|
|
5
|
+
* @license Blake Embrey (hello@blakeembrey.com)
|
|
5
6
|
*/
|
|
6
7
|
export declare const titleCase: (input?: null | string) => string;
|
|
7
8
|
export default titleCase;
|
package/titleCase.mjs
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @category
|
|
3
|
-
*
|
|
4
|
-
* @
|
|
5
|
-
|
|
6
|
-
export
|
|
7
|
-
return input
|
|
8
|
-
? input.replace(/\w\S*/g, function (txt) { return txt.charAt(0).toUpperCase() + txt.substring(1).toLowerCase(); })
|
|
9
|
-
: "";
|
|
10
|
-
};
|
|
2
|
+
* @category text
|
|
3
|
+
*
|
|
4
|
+
* @borrows [blakeembrey/change-case](https://github.com/blakeembrey/change-case/blob/master/packages/title-case/src/index.ts)
|
|
5
|
+
* @license Blake Embrey (hello@blakeembrey.com)
|
|
6
|
+
*/ export const titleCase = (input)=>input ? input.replace(/\w\S*/g, (txt)=>txt.charAt(0).toUpperCase() + txt.substring(1).toLowerCase()) : "";
|
|
11
7
|
export default titleCase;
|
package/toNumber.mjs
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { isNumber } from "./isNumber";
|
|
2
2
|
/**
|
|
3
3
|
* @category cast
|
|
4
|
-
*/
|
|
5
|
-
export function toNumber(input, fallback) {
|
|
4
|
+
*/ export function toNumber(input, fallback) {
|
|
6
5
|
return isNumber(input) ? input : input ? parseFloat(input) : fallback || 0;
|
|
7
6
|
}
|
|
8
7
|
export default toNumber;
|
package/toRgba.mjs
CHANGED
|
@@ -4,12 +4,10 @@
|
|
|
4
4
|
// hexRgb(hexColor, { format: "css", alpha });
|
|
5
5
|
/**
|
|
6
6
|
* @category colors
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
if (alpha === void 0) { alpha = 1; }
|
|
10
|
-
var r = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
|
7
|
+
*/ export function toRgba(hex, alpha = 1) {
|
|
8
|
+
const r = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
|
11
9
|
if (r) {
|
|
12
|
-
return
|
|
10
|
+
return `rgba(${parseInt(r[1], 16)},${parseInt(r[2], 16)},${parseInt(r[3], 16)},${alpha})`;
|
|
13
11
|
}
|
|
14
12
|
return "";
|
|
15
13
|
}
|
|
@@ -7,10 +7,7 @@ import isString from "./isString";
|
|
|
7
7
|
* - replaces whitespaces with dashes
|
|
8
8
|
*
|
|
9
9
|
* @category location
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
return isString(toPathname)
|
|
13
|
-
? "/".concat(encodeURIComponent(toPathname.replace(/\s/g, "-").toLowerCase()))
|
|
14
|
-
: "";
|
|
10
|
+
*/ export function transformToUrlPathname(toPathname) {
|
|
11
|
+
return isString(toPathname) ? `/${encodeURIComponent(toPathname.replace(/\s/g, "-").toLowerCase())}` : "";
|
|
15
12
|
}
|
|
16
13
|
export default transformToUrlPathname;
|
package/truncate.d.ts
CHANGED
package/truncate.mjs
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Truncate string
|
|
3
3
|
*
|
|
4
|
-
* @category
|
|
5
|
-
*/
|
|
6
|
-
export var truncate = function (input, length) {
|
|
7
|
-
return input
|
|
8
|
-
? input.length > length
|
|
9
|
-
? input.substring(0, length) + "..."
|
|
10
|
-
: input
|
|
11
|
-
: "";
|
|
12
|
-
};
|
|
4
|
+
* @category text
|
|
5
|
+
*/ export const truncate = (input, length)=>input ? input.length > length ? input.substring(0, length) + "..." : input : "";
|
|
13
6
|
export default truncate;
|
package/tryUntil.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @
|
|
2
|
+
* @category function
|
|
3
|
+
* @category async
|
|
4
|
+
*
|
|
5
|
+
* @borrows [Javascript: Wait Until Something Happens or Timeout](https://levelup.gitconnected.com/javascript-wait-until-something-happens-or-timeout-82636839ea93)
|
|
3
6
|
*
|
|
4
7
|
* @param timeout in `ms`
|
|
5
8
|
* @param interval in `ms`
|
package/tryUntil.mjs
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @
|
|
2
|
+
* @category function
|
|
3
|
+
* @category async
|
|
4
|
+
*
|
|
5
|
+
* @borrows [Javascript: Wait Until Something Happens or Timeout](https://levelup.gitconnected.com/javascript-wait-until-something-happens-or-timeout-82636839ea93)
|
|
3
6
|
*
|
|
4
7
|
* @param timeout in `ms`
|
|
5
8
|
* @param interval in `ms`
|
|
6
|
-
*/
|
|
7
|
-
export var tryUntil = function (test, timeout, interval, resolve, reject) {
|
|
9
|
+
*/ export const tryUntil = (test, timeout, interval, resolve, reject)=>{
|
|
8
10
|
// return new Promise((resolve, reject) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
const timeWas = new Date();
|
|
12
|
+
const wait = setInterval(function() {
|
|
11
13
|
if (test()) {
|
|
12
14
|
// console.log("resolved after", new Date() - timeWas, "ms");
|
|
13
15
|
clearInterval(wait);
|
|
14
16
|
resolve();
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
else if (new Date() - timeWas > timeout) {
|
|
17
|
+
// @ts-expect-error ...
|
|
18
|
+
} else if (new Date() - timeWas > timeout) {
|
|
18
19
|
// Timeout
|
|
19
20
|
// console.log("rejected after", new Date() - timeWas, "ms");
|
|
20
21
|
clearInterval(wait);
|
|
21
|
-
if (reject)
|
|
22
|
-
reject();
|
|
22
|
+
if (reject) reject();
|
|
23
23
|
}
|
|
24
24
|
}, interval);
|
|
25
|
-
|
|
25
|
+
// });
|
|
26
26
|
};
|
|
27
27
|
export default tryUntil;
|
package/types.mjs
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
// import type { Replace } from "@koine/utils";
|
|
2
|
+
export { };
|
package/typings.d.ts
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* List here the global variables used by third party scripts supported within
|
|
3
|
-
* the `koine` ecosystem.
|
|
4
|
-
* variables.
|
|
3
|
+
* the `koine` ecosystem.
|
|
5
4
|
*/
|
|
6
|
-
|
|
7
|
-
// declare type NullableRecord<T> = {
|
|
8
|
-
// [K in keyof T]: T[K] | null;
|
|
9
|
-
// };
|
package/uid.mjs
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
let lastId = 0;
|
|
2
2
|
/**
|
|
3
3
|
* Super basic UID increment-based generator
|
|
4
4
|
*
|
|
5
5
|
* @category uid
|
|
6
|
-
*/
|
|
7
|
-
export var uid = function (prefix) {
|
|
8
|
-
if (prefix === void 0) { prefix = "id"; }
|
|
6
|
+
*/ export const uid = (prefix = "id")=>{
|
|
9
7
|
lastId++;
|
|
10
|
-
return
|
|
8
|
+
return `${prefix}-${lastId}`;
|
|
11
9
|
};
|
|
12
10
|
export default uid;
|
package/updateLinkParams.mjs
CHANGED
|
@@ -5,9 +5,8 @@ import updateUrlQueryParams from "./updateUrlQueryParams";
|
|
|
5
5
|
*
|
|
6
6
|
* @category location
|
|
7
7
|
* @pure
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
var href = updateUrlQueryParams($anchor.href, newParams);
|
|
8
|
+
*/ export function updateLinkParams($anchor, newParams) {
|
|
9
|
+
const href = updateUrlQueryParams($anchor.href, newParams);
|
|
11
10
|
$anchor.href = href;
|
|
12
11
|
return href;
|
|
13
12
|
}
|
|
@@ -3,7 +3,6 @@ import { type AnyQueryParams } from "./location";
|
|
|
3
3
|
* Update a URL string query parameters merging the given new query parameters
|
|
4
4
|
*
|
|
5
5
|
* @category location
|
|
6
|
-
* @pure
|
|
7
6
|
*/
|
|
8
7
|
export declare function updateUrlQueryParams(url: string, newParams?: NonNullable<AnyQueryParams>): string;
|
|
9
8
|
export default updateUrlQueryParams;
|
package/updateUrlQueryParams.mjs
CHANGED
|
@@ -5,14 +5,9 @@ import mergeUrlQueryParams from "./mergeUrlQueryParams";
|
|
|
5
5
|
* Update a URL string query parameters merging the given new query parameters
|
|
6
6
|
*
|
|
7
7
|
* @category location
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
if (newParams === void 0) { newParams = {}; }
|
|
12
|
-
var parts = url.split("?");
|
|
13
|
-
var allParams = parts[1]
|
|
14
|
-
? mergeUrlQueryParams(getUrlQueryParams(url), newParams)
|
|
15
|
-
: newParams;
|
|
8
|
+
*/ export function updateUrlQueryParams(url, newParams = {}) {
|
|
9
|
+
const parts = url.split("?");
|
|
10
|
+
const allParams = parts[1] ? mergeUrlQueryParams(getUrlQueryParams(url), newParams) : newParams;
|
|
16
11
|
return parts[0] + buildUrlQueryString(allParams);
|
|
17
12
|
}
|
|
18
13
|
export default updateUrlQueryParams;
|
package/uppercase.d.ts
CHANGED
package/uppercase.mjs
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
* Replacement for native `toUpperCase` tyescript ready (type narrowing ready)
|
|
3
3
|
*
|
|
4
4
|
* @category native
|
|
5
|
-
|
|
6
|
-
export
|
|
7
|
-
return (str || "").toUpperCase();
|
|
8
|
-
};
|
|
5
|
+
* @category text
|
|
6
|
+
*/ export const uppercase = (str)=>(str || "").toUpperCase();
|
|
9
7
|
export default uppercase;
|
package/uuid.mjs
CHANGED
|
@@ -3,11 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @category uid
|
|
5
5
|
* @see https://stackoverflow.com/a/2117523/1938970
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
|
|
9
|
-
var r = (Math.random() * 16) | 0, v = c == "x" ? r : (r & 0x3) | 0x8;
|
|
6
|
+
*/ export const uuid = ()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c)=>{
|
|
7
|
+
const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 0x3 | 0x8;
|
|
10
8
|
return v.toString(16);
|
|
11
9
|
});
|
|
12
|
-
};
|
|
13
10
|
export default uuid;
|
package/uuidNumeric.mjs
CHANGED
package/wait.mjs
CHANGED
|
@@ -2,8 +2,5 @@
|
|
|
2
2
|
* A promisified `setTimeout`
|
|
3
3
|
*
|
|
4
4
|
* @category async
|
|
5
|
-
*/
|
|
6
|
-
export var wait = function (milliseconds) {
|
|
7
|
-
return new Promise(function (resolve) { return setTimeout(resolve, milliseconds); });
|
|
8
|
-
};
|
|
5
|
+
*/ export const wait = (milliseconds)=>new Promise((resolve)=>setTimeout(resolve, milliseconds));
|
|
9
6
|
export default wait;
|
package/without.mjs
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
3
|
-
// TODO: finish this up, this is not exported yet
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */ // TODO: finish this up, this is not exported yet
|
|
4
2
|
// ready to copy-paste to https://www.typescriptlang.org/play
|
|
5
3
|
// type EmptyObject = Record<string, never>;
|
|
6
4
|
// type EmptyArray = never[];
|