@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/clsx.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
type ClassValue = ClassArray | ClassDictionary | string | number | null | boolean | undefined;
|
|
2
|
+
type ClassDictionary = Record<string, any>;
|
|
3
|
+
type ClassArray = ClassValue[];
|
|
4
|
+
export type ClsxClassValue = ClassValue;
|
|
2
5
|
/**
|
|
3
6
|
* Class names utility
|
|
4
7
|
*
|
|
8
|
+
* @category impl
|
|
5
9
|
* @borrows [lukeed/clsx](https://github.com/lukeed/clsx)
|
|
6
|
-
* @license
|
|
10
|
+
* @license MIT Luke Edwards https://github.com/lukeed/clsx/blob/master/license
|
|
7
11
|
*/
|
|
8
12
|
export declare const clsx: (...args: ClassValue[]) => string;
|
|
9
13
|
export default clsx;
|
package/clsx.mjs
CHANGED
|
@@ -1,23 +1,22 @@
|
|
|
1
|
+
// import type { ClassValue } from "clsx";
|
|
1
2
|
// import _clsx from "clsx";
|
|
2
3
|
// export const clsx = _clsx;
|
|
3
4
|
function toVal(mix) {
|
|
4
|
-
|
|
5
|
+
let k, y, str = "";
|
|
5
6
|
if (typeof mix === "string" || typeof mix === "number") {
|
|
6
7
|
str += mix;
|
|
7
|
-
}
|
|
8
|
-
else if (typeof mix === "object") {
|
|
8
|
+
} else if (typeof mix === "object") {
|
|
9
9
|
if (Array.isArray(mix)) {
|
|
10
|
-
for
|
|
10
|
+
for(k = 0; k < mix.length; k++){
|
|
11
11
|
if (mix[k]) {
|
|
12
|
-
if (
|
|
12
|
+
if (y = toVal(mix[k])) {
|
|
13
13
|
str && (str += " ");
|
|
14
14
|
str += y;
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
for (k in mix) {
|
|
18
|
+
} else {
|
|
19
|
+
for(k in mix){
|
|
21
20
|
if (mix[k]) {
|
|
22
21
|
str && (str += " ");
|
|
23
22
|
str += k;
|
|
@@ -30,15 +29,15 @@ function toVal(mix) {
|
|
|
30
29
|
/**
|
|
31
30
|
* Class names utility
|
|
32
31
|
*
|
|
32
|
+
* @category impl
|
|
33
33
|
* @borrows [lukeed/clsx](https://github.com/lukeed/clsx)
|
|
34
|
-
* @license
|
|
35
|
-
*/
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
while (i < arguments.length) {
|
|
34
|
+
* @license MIT Luke Edwards https://github.com/lukeed/clsx/blob/master/license
|
|
35
|
+
*/ export const clsx = function() {
|
|
36
|
+
let i = 0, tmp, x, str = "";
|
|
37
|
+
while(i < arguments.length){
|
|
39
38
|
// eslint-disable-next-line prefer-rest-params
|
|
40
|
-
if (
|
|
41
|
-
if (
|
|
39
|
+
if (tmp = arguments[i++]) {
|
|
40
|
+
if (x = toVal(tmp)) {
|
|
42
41
|
str && (str += " ");
|
|
43
42
|
str += x;
|
|
44
43
|
}
|
package/convertRange.d.ts
CHANGED
package/convertRange.mjs
CHANGED
|
@@ -3,14 +3,15 @@
|
|
|
3
3
|
*
|
|
4
4
|
* e.g. converting number 5 in a scale/range from 0 10 to a scale/range from 50
|
|
5
5
|
* to 100 would return 75
|
|
6
|
-
*
|
|
6
|
+
* @example
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
7
9
|
* convertRange(5, [0, 10], [50, 100]);
|
|
8
10
|
* ```
|
|
9
11
|
*
|
|
10
12
|
* @category math
|
|
11
13
|
* @see https://stackoverflow.com/a/14224813
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
return ((num - r1[0]) * (r2[1] - r2[0])) / (r1[1] - r1[0]) + r2[0];
|
|
14
|
+
*/ export function convertRange(num, r1, r2) {
|
|
15
|
+
return (num - r1[0]) * (r2[1] - r2[0]) / (r1[1] - r1[0]) + r2[0];
|
|
15
16
|
}
|
|
16
17
|
export default convertRange;
|
package/cookie.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @
|
|
2
|
+
* @module
|
|
3
3
|
*
|
|
4
4
|
* @category cookie
|
|
5
5
|
*
|
|
@@ -7,6 +7,9 @@
|
|
|
7
7
|
* - [js-cookie](https://github.com/js-cookie/js-cookie)
|
|
8
8
|
* - [cookie](https://github.com/jshttp/cookie)
|
|
9
9
|
*/
|
|
10
|
+
/**
|
|
11
|
+
* @category cookie
|
|
12
|
+
*/
|
|
10
13
|
type CookieAttributes = {
|
|
11
14
|
/**
|
|
12
15
|
* Define when the cookie will be removed. Value can be a Number
|
|
@@ -41,13 +44,22 @@ type CookieAttributes = {
|
|
|
41
44
|
*/
|
|
42
45
|
sameSite?: "strict" | "Strict" | "lax" | "Lax" | "none" | "None" | undefined;
|
|
43
46
|
};
|
|
47
|
+
/**
|
|
48
|
+
* @category cookie
|
|
49
|
+
*/
|
|
44
50
|
export type CookieAttributesServer = CookieAttributes & {
|
|
45
51
|
maxAge?: number;
|
|
46
52
|
httpOnly?: boolean;
|
|
47
53
|
encode?: (input: string) => string;
|
|
48
54
|
decode?: (input: string) => string;
|
|
49
55
|
};
|
|
56
|
+
/**
|
|
57
|
+
* @category cookie
|
|
58
|
+
*/
|
|
50
59
|
export type CookieAttributesClient = CookieAttributes;
|
|
60
|
+
/**
|
|
61
|
+
* @category cookie
|
|
62
|
+
*/
|
|
51
63
|
export declare const defaultAttributesClient: {
|
|
52
64
|
path: string;
|
|
53
65
|
};
|
package/cookie.mjs
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
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
|
-
|
|
9
|
+
*/ /**
|
|
10
|
+
* @category cookie
|
|
11
|
+
*/ /**
|
|
12
|
+
* @category cookie
|
|
13
|
+
*/ export const defaultAttributesClient = {
|
|
14
|
+
path: "/"
|
|
15
|
+
};
|
package/createPalette.d.ts
CHANGED
|
@@ -10,7 +10,9 @@ type PaletteMap<T extends PaletteShades> = {
|
|
|
10
10
|
* Create palette, this is primarily thought to improve the reuse of a palette
|
|
11
11
|
* definition between TailwindCSS and straight ES imports
|
|
12
12
|
*
|
|
13
|
-
* @category
|
|
13
|
+
* @category colors
|
|
14
|
+
* @category tailwind
|
|
15
|
+
* @category responsive
|
|
14
16
|
*
|
|
15
17
|
* @returns An array with: 1) A flat palette map 2) A TailwindCSS ready palette
|
|
16
18
|
* object 3) A flat array of colors (no special sorting, same order as the `shades`
|
package/createPalette.mjs
CHANGED
|
@@ -2,21 +2,31 @@
|
|
|
2
2
|
* Create palette, this is primarily thought to improve the reuse of a palette
|
|
3
3
|
* definition between TailwindCSS and straight ES imports
|
|
4
4
|
*
|
|
5
|
-
* @category
|
|
5
|
+
* @category colors
|
|
6
|
+
* @category tailwind
|
|
7
|
+
* @category responsive
|
|
6
8
|
*
|
|
7
9
|
* @returns An array with: 1) A flat palette map 2) A TailwindCSS ready palette
|
|
8
10
|
* object 3) A flat array of colors (no special sorting, same order as the `shades`
|
|
9
11
|
* given as argument)
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
var map = shades.reduce(function (map, def) {
|
|
12
|
+
*/ export const createPalette = (name, shades)=>{
|
|
13
|
+
const map = shades.reduce((map, def)=>{
|
|
13
14
|
map[def[0]] = def[1];
|
|
14
15
|
return map;
|
|
15
16
|
}, {});
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
// NOTE: the following breaks typedoc, with `any` it compiles
|
|
18
|
+
// const map = shades.reduce((map, def) => {
|
|
19
|
+
// map[def[0]] = def[1] as TColor;
|
|
20
|
+
// return map;
|
|
21
|
+
// }, {} as { [s: string]: TColor });
|
|
22
|
+
const tailwindPalette = shades.reduce((map, def)=>{
|
|
23
|
+
map[`${name}-${def[0]}`] = def[1];
|
|
18
24
|
return map;
|
|
19
25
|
}, {});
|
|
20
|
-
return [
|
|
26
|
+
return [
|
|
27
|
+
map,
|
|
28
|
+
tailwindPalette,
|
|
29
|
+
Object.values(map)
|
|
30
|
+
];
|
|
21
31
|
};
|
|
22
32
|
export default createPalette;
|
package/debounce.mjs
CHANGED
|
@@ -3,27 +3,19 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @category function
|
|
5
5
|
* @borrows [davidwalsh/debounce](https://davidwalsh.name/javascript-debounce-function)
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return function () {
|
|
10
|
-
var args = [];
|
|
11
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
12
|
-
args[_i] = arguments[_i];
|
|
13
|
-
}
|
|
6
|
+
*/ export function debounce(fn, wait, immediate) {
|
|
7
|
+
let timeout;
|
|
8
|
+
return function(...args) {
|
|
14
9
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
const context = this;
|
|
11
|
+
const later = function() {
|
|
17
12
|
timeout = null;
|
|
18
|
-
if (!immediate)
|
|
19
|
-
fn.apply(context, args);
|
|
13
|
+
if (!immediate) fn.apply(context, args);
|
|
20
14
|
};
|
|
21
|
-
|
|
22
|
-
if (timeout)
|
|
23
|
-
clearTimeout(timeout);
|
|
15
|
+
const callNow = immediate && !timeout;
|
|
16
|
+
if (timeout) clearTimeout(timeout);
|
|
24
17
|
timeout = setTimeout(later, wait);
|
|
25
|
-
if (callNow)
|
|
26
|
-
fn.apply(context, args);
|
|
18
|
+
if (callNow) fn.apply(context, args);
|
|
27
19
|
};
|
|
28
20
|
}
|
|
29
21
|
export default debounce;
|
package/debouncePromise.d.ts
CHANGED
|
@@ -1,11 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Copy pasted from [chodorowicz/ts-debounce](https://github.com/chodorowicz/ts-debounce/blob/master/src/index.ts)
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* @categroy functionn
|
|
8
|
+
*/
|
|
9
|
+
export type DebounceOptions<Result> = {
|
|
10
|
+
isImmediate?: boolean;
|
|
11
|
+
maxWait?: number;
|
|
12
|
+
callback?: (data: Result) => void;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* @categroy functionn
|
|
16
|
+
*/
|
|
17
|
+
export interface DebouncedFunction<Args extends any[], F extends (...args: Args) => any> {
|
|
18
|
+
(this: ThisParameterType<F>, ...args: Args & Parameters<F>): Promise<ReturnType<F>>;
|
|
19
|
+
cancel: (reason?: any) => void;
|
|
20
|
+
}
|
|
4
21
|
/**
|
|
5
22
|
* Debounce function (with `Promise`)
|
|
6
23
|
*
|
|
7
24
|
* @category function
|
|
8
25
|
* @borrows [chodorowicz/ts-debounce](https://github.com/chodorowicz/ts-debounce)
|
|
26
|
+
* @license MIT: Jakub Chodorowicz
|
|
9
27
|
*/
|
|
10
|
-
export declare
|
|
28
|
+
export declare function debouncePromise<Args extends any[], F extends (...args: Args) => any>(func: F, waitMilliseconds?: number, options?: DebounceOptions<ReturnType<F>>): DebouncedFunction<Args, F>;
|
|
11
29
|
export default debouncePromise;
|
package/debouncePromise.mjs
CHANGED
|
@@ -1,9 +1,79 @@
|
|
|
1
|
-
import { debounce as tsDebounce } from "ts-debounce";
|
|
1
|
+
// import { debounce as tsDebounce } from "ts-debounce";
|
|
2
|
+
// export { type Options as DebounceOptions } from "ts-debounce";
|
|
3
|
+
// export { type DebouncedFunction } from "ts-debounce";
|
|
4
|
+
// /**
|
|
5
|
+
// * Debounce function (with `Promise`)
|
|
6
|
+
// *
|
|
7
|
+
// * @category function
|
|
8
|
+
// * @borrows [chodorowicz/ts-debounce](https://github.com/chodorowicz/ts-debounce)
|
|
9
|
+
// */
|
|
10
|
+
// export const debouncePromise = tsDebounce;
|
|
11
|
+
// export default debouncePromise;
|
|
2
12
|
/**
|
|
13
|
+
* Copy pasted from [chodorowicz/ts-debounce](https://github.com/chodorowicz/ts-debounce/blob/master/src/index.ts)
|
|
14
|
+
*
|
|
15
|
+
* @module
|
|
16
|
+
*/ /**
|
|
17
|
+
* @categroy functionn
|
|
18
|
+
*/ /**
|
|
3
19
|
* Debounce function (with `Promise`)
|
|
4
20
|
*
|
|
5
21
|
* @category function
|
|
6
22
|
* @borrows [chodorowicz/ts-debounce](https://github.com/chodorowicz/ts-debounce)
|
|
7
|
-
|
|
8
|
-
export
|
|
23
|
+
* @license MIT: Jakub Chodorowicz
|
|
24
|
+
*/ export function debouncePromise(func, waitMilliseconds = 50, options = {}) {
|
|
25
|
+
let timeoutId;
|
|
26
|
+
const isImmediate = options.isImmediate ?? false;
|
|
27
|
+
const callback = options.callback ?? false;
|
|
28
|
+
const maxWait = options.maxWait;
|
|
29
|
+
let lastInvokeTime = Date.now();
|
|
30
|
+
let promises = [];
|
|
31
|
+
function nextInvokeTimeout() {
|
|
32
|
+
if (maxWait !== undefined) {
|
|
33
|
+
const timeSinceLastInvocation = Date.now() - lastInvokeTime;
|
|
34
|
+
if (timeSinceLastInvocation + waitMilliseconds >= maxWait) {
|
|
35
|
+
return maxWait - timeSinceLastInvocation;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return waitMilliseconds;
|
|
39
|
+
}
|
|
40
|
+
const debouncedFunction = function(...args) {
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
42
|
+
const context = this;
|
|
43
|
+
return new Promise((resolve, reject)=>{
|
|
44
|
+
const invokeFunction = function() {
|
|
45
|
+
timeoutId = undefined;
|
|
46
|
+
lastInvokeTime = Date.now();
|
|
47
|
+
if (!isImmediate) {
|
|
48
|
+
const result = func.apply(context, args);
|
|
49
|
+
callback && callback(result);
|
|
50
|
+
promises.forEach(({ resolve })=>resolve(result));
|
|
51
|
+
promises = [];
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
const shouldCallNow = isImmediate && timeoutId === undefined;
|
|
55
|
+
if (timeoutId !== undefined) {
|
|
56
|
+
clearTimeout(timeoutId);
|
|
57
|
+
}
|
|
58
|
+
timeoutId = setTimeout(invokeFunction, nextInvokeTimeout());
|
|
59
|
+
if (shouldCallNow) {
|
|
60
|
+
const result = func.apply(context, args);
|
|
61
|
+
callback && callback(result);
|
|
62
|
+
return resolve(result);
|
|
63
|
+
}
|
|
64
|
+
promises.push({
|
|
65
|
+
resolve,
|
|
66
|
+
reject
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
debouncedFunction.cancel = function(reason) {
|
|
71
|
+
if (timeoutId !== undefined) {
|
|
72
|
+
clearTimeout(timeoutId);
|
|
73
|
+
}
|
|
74
|
+
promises.forEach(({ reject })=>reject(reason));
|
|
75
|
+
promises = [];
|
|
76
|
+
};
|
|
77
|
+
return debouncedFunction;
|
|
78
|
+
}
|
|
9
79
|
export default debouncePromise;
|
package/debounceRaf.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Debounce function (with `requestAnimationFrame`)
|
|
3
3
|
*
|
|
4
|
-
* (c) 2021 Chris Ferdinandi, MIT License, https://gomakethings.com
|
|
5
4
|
* @category function
|
|
6
5
|
* @borrows [vanillajstoolkit/debounce](https://vanillajstoolkit.com/helpers/debounce/)
|
|
6
|
+
* @license (c) 2021 Chris Ferdinandi, MIT License, https://gomakethings.com
|
|
7
7
|
*/
|
|
8
8
|
export declare function debounceRaf<T extends (...args: any[]) => any>(this: unknown, fn: T): (this: unknown, ...args: Parameters<T>) => void;
|
|
9
9
|
export default debounceRaf;
|
package/debounceRaf.mjs
CHANGED
|
@@ -1,25 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Debounce function (with `requestAnimationFrame`)
|
|
3
3
|
*
|
|
4
|
-
* (c) 2021 Chris Ferdinandi, MIT License, https://gomakethings.com
|
|
5
4
|
* @category function
|
|
6
5
|
* @borrows [vanillajstoolkit/debounce](https://vanillajstoolkit.com/helpers/debounce/)
|
|
7
|
-
|
|
8
|
-
export function debounceRaf(fn) {
|
|
9
|
-
|
|
10
|
-
return function
|
|
11
|
-
var args = [];
|
|
12
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
13
|
-
args[_i] = arguments[_i];
|
|
14
|
-
}
|
|
6
|
+
* @license (c) 2021 Chris Ferdinandi, MIT License, https://gomakethings.com
|
|
7
|
+
*/ export function debounceRaf(fn) {
|
|
8
|
+
let timeout;
|
|
9
|
+
return function(...args) {
|
|
15
10
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
16
|
-
|
|
11
|
+
const context = this;
|
|
17
12
|
// If there's a timer, cancel it
|
|
18
13
|
if (timeout) {
|
|
19
14
|
window.cancelAnimationFrame(timeout);
|
|
20
15
|
}
|
|
21
16
|
// Setup the new requestAnimationFrame()
|
|
22
|
-
timeout = window.requestAnimationFrame(function
|
|
17
|
+
timeout = window.requestAnimationFrame(function() {
|
|
23
18
|
fn.apply(context, args);
|
|
24
19
|
});
|
|
25
20
|
};
|
package/decode.mjs
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @category security
|
|
3
3
|
* @see https://stackoverflow.com/a/22405578/9122820
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
return str.replace(/.{3}/g, function (c) {
|
|
4
|
+
*/ export function decode(str) {
|
|
5
|
+
return str.replace(/.{3}/g, function(c) {
|
|
7
6
|
return String.fromCharCode(parseInt(c, 10));
|
|
8
7
|
});
|
|
9
8
|
}
|
package/encode.mjs
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @category security
|
|
3
3
|
* @see https://stackoverflow.com/a/22405578/9122820
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
return str.replace(/./g, function (c) {
|
|
4
|
+
*/ export function encode(str) {
|
|
5
|
+
return str.replace(/./g, function(c) {
|
|
7
6
|
return ("00" + c.charCodeAt(0)).slice(-3);
|
|
8
7
|
});
|
|
9
8
|
}
|
package/ensureInt.mjs
CHANGED
|
@@ -2,8 +2,5 @@
|
|
|
2
2
|
* Ensure input to be an integer
|
|
3
3
|
*
|
|
4
4
|
* @category cast
|
|
5
|
-
*/
|
|
6
|
-
export var ensureInt = function (input) {
|
|
7
|
-
return typeof input === "string" ? parseInt(input, 10) : Math.round(input);
|
|
8
|
-
};
|
|
5
|
+
*/ export const ensureInt = (input)=>typeof input === "string" ? parseInt(input, 10) : Math.round(input);
|
|
9
6
|
export default ensureInt;
|
package/env.mjs
CHANGED
package/errorToString.d.ts
CHANGED
package/errorToString.mjs
CHANGED
|
@@ -2,9 +2,7 @@ import isString from "./isString";
|
|
|
2
2
|
/**
|
|
3
3
|
* Ensure to transform a JavaScript `Error` into a string (uses its `message`)
|
|
4
4
|
*
|
|
5
|
-
* @category
|
|
6
|
-
|
|
7
|
-
export
|
|
8
|
-
return e instanceof Error ? e.message : isString(e) ? e : "";
|
|
9
|
-
};
|
|
5
|
+
* @category error
|
|
6
|
+
* @category cast
|
|
7
|
+
*/ export const errorToString = (e)=>e instanceof Error ? e.message : isString(e) ? e : "";
|
|
10
8
|
export default errorToString;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @category array
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var idxInArray = arr.indexOf(arr[i]);
|
|
3
|
+
*/ export function findDuplicatedIndexes(arr) {
|
|
4
|
+
const indexes = {};
|
|
5
|
+
for(let i = 0; i < arr.length; i++){
|
|
6
|
+
const idxInArray = arr.indexOf(arr[i]);
|
|
8
7
|
if (idxInArray !== i && idxInArray !== -1) {
|
|
9
8
|
indexes[i] = true;
|
|
10
9
|
}
|
package/forin.d.ts
CHANGED
package/forin.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* To easily get typed native `for in`
|
|
3
3
|
*
|
|
4
|
-
* @category
|
|
5
|
-
|
|
6
|
-
export function forin(object, cb) {
|
|
7
|
-
for
|
|
4
|
+
* @category native
|
|
5
|
+
* @category object
|
|
6
|
+
*/ export function forin(object, cb) {
|
|
7
|
+
for(const key in object){
|
|
8
8
|
cb(key, object[key]);
|
|
9
9
|
}
|
|
10
10
|
}
|
package/gbToBytes.mjs
CHANGED
package/getEmptyArray.d.ts
CHANGED
package/getEmptyArray.mjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import isNumber from "./isNumber";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
3
|
* Returns an array of undefined values of the desired length, useful to build
|
|
5
4
|
* skeleton UIs.
|
|
6
5
|
*
|
|
7
6
|
* @category array
|
|
8
|
-
*/
|
|
9
|
-
export function getEmptyArray /* <T extends undefined | null = undefined> */(length) {
|
|
7
|
+
*/ export function getEmptyArray(length) {
|
|
10
8
|
if (!isNumber(length)) {
|
|
11
9
|
length = parseInt(length, 10);
|
|
12
10
|
}
|
|
13
|
-
return Array.from({
|
|
11
|
+
return Array.from({
|
|
12
|
+
length
|
|
13
|
+
});
|
|
14
14
|
}
|
|
15
15
|
export default getEmptyArray;
|
package/getKeys.d.ts
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
* Type safe replacement for `Object.keys(myObject)` to iterate over a record
|
|
3
3
|
* without loosing the key's types in simple `string`s.
|
|
4
4
|
*
|
|
5
|
-
* @category
|
|
5
|
+
* @category native
|
|
6
|
+
* @category object
|
|
6
7
|
* @see https://stackoverflow.com/a/59459000/1938970
|
|
7
8
|
*/
|
|
8
9
|
export declare const getKeys: <T extends object>(obj: T) => (keyof T)[];
|
package/getKeys.mjs
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* Type safe replacement for `Object.keys(myObject)` to iterate over a record
|
|
3
3
|
* without loosing the key's types in simple `string`s.
|
|
4
4
|
*
|
|
5
|
-
* @category
|
|
5
|
+
* @category native
|
|
6
|
+
* @category object
|
|
6
7
|
* @see https://stackoverflow.com/a/59459000/1938970
|
|
7
|
-
*/
|
|
8
|
-
export var getKeys = Object.keys;
|
|
8
|
+
*/ export const getKeys = Object.keys;
|
|
9
9
|
export default getKeys;
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @category responsive
|
|
3
|
+
*/
|
|
1
4
|
export type GetMediaQueryWidthResolversBreakpoints = Record<string, number>;
|
|
5
|
+
/**
|
|
6
|
+
* @category responsive
|
|
7
|
+
*/
|
|
2
8
|
export declare function getMediaQueryWidthResolvers<TBreakpointsConfig extends GetMediaQueryWidthResolversBreakpoints>(customBreakpoints: TBreakpointsConfig): {
|
|
3
9
|
max: (br: Extract<keyof TBreakpointsConfig, string>) => string;
|
|
4
10
|
min: (br: Extract<keyof TBreakpointsConfig, string>) => string;
|