@koine/utils 2.0.0-beta.72 → 2.0.0-beta.73
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.js +10 -0
- package/Emitter.js +19 -0
- package/accentSets.js +29 -0
- package/addOrReplaceAtIdx.js +14 -0
- package/areEqual.js +45 -0
- package/arrayFilterFalsy.js +1 -0
- package/arrayFindLastIndex.js +8 -0
- package/arrayOfAll.js +1 -0
- package/arraySum.js +1 -0
- package/arrayToLookup.js +4 -0
- package/arrayUniqueByProperties.js +1 -0
- package/buildUrlQueryString.js +20 -0
- package/capitalize.js +2 -0
- package/changeCaseCamel.js +18 -0
- package/changeCaseCapital.js +11 -0
- package/changeCaseConstant.js +7 -0
- package/changeCaseDot.js +2 -0
- package/changeCaseHelpers.d.ts +0 -5
- package/changeCaseHelpers.js +71 -0
- package/changeCaseKebab.js +2 -0
- package/changeCaseNone.js +7 -0
- package/changeCasePascal.js +10 -0
- package/changeCasePascalSnake.js +2 -0
- package/changeCasePath.js +2 -0
- package/changeCaseSentence.js +16 -0
- package/changeCaseSnake.js +2 -0
- package/changeCaseTrain.js +2 -0
- package/chunkByChunks.js +31 -0
- package/chunkBySize.js +7 -0
- package/clamp.js +1 -0
- package/clsx.js +39 -0
- package/convertRange.js +1 -0
- package/cookie.js +1 -0
- package/createPalette.js +11 -0
- package/debounce.js +17 -0
- package/debouncePromise.js +51 -0
- package/debounceRaf.js +12 -0
- package/decode.js +1 -0
- package/encode.js +1 -0
- package/ensureInt.js +1 -0
- package/env.js +1 -0
- package/errorToString.js +2 -0
- package/escapeRegExp.js +1 -0
- package/findDuplicatedIndexes.js +10 -0
- package/forin.js +5 -0
- package/gbToBytes.js +1 -0
- package/getEmptyArray.js +4 -0
- package/getKeys.js +1 -0
- package/getMediaQueryWidthResolvers.js +41 -0
- package/getMediaQueryWidthTailwindScreens.js +26 -0
- package/getNonce.js +2 -0
- package/getParamAmong.js +5 -0
- package/getParamAsInt.js +8 -0
- package/getParamAsString.js +2 -0
- package/getType.js +1 -0
- package/getUrlHashParams.js +8 -0
- package/getUrlHashPathname.js +1 -0
- package/getUrlPathnameParts.js +5 -0
- package/getUrlQueryParams.js +21 -0
- package/imgEmptyPixel.js +1 -0
- package/index.js +156 -0
- package/invariant.js +16 -0
- package/isAbsoluteUrl.js +2 -0
- package/isAnyObject.js +2 -0
- package/isArray.js +2 -0
- package/isBlob.js +2 -0
- package/isBoolean.js +2 -0
- package/isBrowser.js +1 -0
- package/isBrowserNow.js +2 -0
- package/isDate.js +2 -0
- package/isEmptyArray.js +2 -0
- package/isEmptyObject.js +2 -0
- package/isEmptyString.js +1 -0
- package/isError.js +2 -0
- package/isExternalUrl.js +10 -0
- package/isFile.js +2 -0
- package/isFloat.js +2 -0
- package/isFormData.js +2 -0
- package/isFullArray.js +2 -0
- package/isFullObject.js +2 -0
- package/isFullString.js +2 -0
- package/isFunction.js +1 -0
- package/isInt.js +2 -0
- package/isMap.js +2 -0
- package/isNaNValue.js +2 -0
- package/isNegativeNumber.js +2 -0
- package/isNull.js +2 -0
- package/isNullOrUndefined.js +4 -0
- package/isNumber.js +2 -0
- package/isNumericLiteral.js +1 -0
- package/isObject.js +2 -0
- package/isObjectLike.js +2 -0
- package/isObjectStringKeyed.js +2 -0
- package/isOneOf.js +7 -0
- package/isPlainObject.js +5 -0
- package/isPositiveNumber.js +2 -0
- package/isPrimitive.js +12 -0
- package/isPromise.js +2 -0
- package/isRegExp.js +2 -0
- package/isServer.js +2 -0
- package/isServerNow.js +2 -0
- package/isSet.js +2 -0
- package/isString.js +2 -0
- package/isSymbol.js +2 -0
- package/isType.js +12 -0
- package/isUndefined.js +2 -0
- package/isWeakMap.js +2 -0
- package/isWeakSet.js +2 -0
- package/kbToBytes.js +1 -0
- package/location.js +1 -0
- package/lowercase.js +1 -0
- package/mapListBy.js +4 -0
- package/matchSorter.js +238 -0
- package/mbToBytes.js +1 -0
- package/mergeObjects.js +28 -0
- package/mergeUrlQueryParams.js +13 -0
- package/moveSortableArrayItemByKey.js +8 -0
- package/noop.js +1 -0
- package/normaliseUrl.js +2 -0
- package/normaliseUrlPathname.js +2 -0
- package/objectFlat.js +16 -0
- package/objectFlip.js +4 -0
- package/objectMergeWithDefaults.js +20 -0
- package/objectOmit.js +7 -0
- package/objectPick.js +8 -0
- package/objectSort.js +1 -0
- package/objectSortByKeysMatching.js +2 -0
- package/objectToArray.js +1 -0
- package/package.json +1 -1
- package/parseCookie.js +32 -0
- package/parseURL.js +13 -0
- package/quaranteneProps.js +15 -0
- package/randomInt.js +1 -0
- package/randomKey.js +4 -0
- package/readCookie.js +33 -0
- package/removeAccents.js +9 -0
- package/removeCookie.js +9 -0
- package/removeDuplicates.js +1 -0
- package/removeDuplicatesByKey.js +12 -0
- package/removeDuplicatesComparing.js +6 -0
- package/removeIndexesFromArray.js +9 -0
- package/removeTrailingSlash.js +1 -0
- package/removeUrlQueryParams.js +13 -0
- package/render.js +112 -0
- package/round.js +3 -0
- package/roundTo.js +10 -0
- package/serializeCookie.js +68 -0
- package/setCookie.js +44 -0
- package/shuffle.js +16 -0
- package/slugify.js +10 -0
- package/split.js +1 -0
- package/splitReverse.js +1 -0
- package/swapMap.js +7 -0
- package/throttle.js +14 -0
- package/titleCase.js +3 -0
- package/toNumber.js +2 -0
- package/toRgba.js +7 -0
- package/transformToUrlPathname.js +4 -0
- package/truncate.js +5 -0
- package/tryUntil.js +14 -0
- package/types.js +1 -0
- package/uid.js +5 -0
- package/updateLinkParams.js +6 -0
- package/updateUrlQueryParams.js +10 -0
- package/uppercase.js +1 -0
- package/uuid.js +4 -0
- package/uuidNumeric.js +1 -0
- package/wait.js +1 -0
- package/without.js +1 -0
package/Defer.js
ADDED
package/Emitter.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export let Emitter = (namespace) => {
|
|
2
|
+
const all = new Map();
|
|
3
|
+
return {
|
|
4
|
+
on(name, handler) {
|
|
5
|
+
const handlers = all.get(`${namespace}.${String(name)}`);
|
|
6
|
+
const added = handlers && handlers.push(handler);
|
|
7
|
+
if (!added) {
|
|
8
|
+
all.set(`${namespace}.${String(name)}`, [handler]);
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
emit(name, data) {
|
|
12
|
+
(all.get(`${namespace}.${String(name)}`) || [])
|
|
13
|
+
.slice()
|
|
14
|
+
.map((handler) => {
|
|
15
|
+
handler(data);
|
|
16
|
+
});
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
};
|
package/accentSets.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export let accentsSets = [
|
|
2
|
+
["a", "ÀÁÂÃÅÆĀĂĄẠẢẤẦẨẪẬẮẰẲẴẶ"],
|
|
3
|
+
["ae", "Ä"],
|
|
4
|
+
["c", "ÇĆĈČ"],
|
|
5
|
+
["d", "ÐĎĐÞ"],
|
|
6
|
+
["e", "ÈÉÊËĒĔĖĘĚẸẺẼẾỀỂỄỆ"],
|
|
7
|
+
["g", "ĜĞĢǴ"],
|
|
8
|
+
["h", "ĤḦ"],
|
|
9
|
+
["i", "ÌÍÎÏĨĪĮİỈỊ"],
|
|
10
|
+
["j", "Ĵ"],
|
|
11
|
+
["ij", "IJ"],
|
|
12
|
+
["k", "Ķ"],
|
|
13
|
+
["l", "ĹĻĽŁ"],
|
|
14
|
+
["m", "Ḿ"],
|
|
15
|
+
["n", "ÑŃŅŇ"],
|
|
16
|
+
["o", "ÒÓÔÕØŌŎŐỌỎỐỒỔỖỘỚỜỞỠỢǪǬƠ"],
|
|
17
|
+
["oe", "΅"],
|
|
18
|
+
["p", "ṕ"],
|
|
19
|
+
["r", "ŔŖŘ"],
|
|
20
|
+
["s", "ŚŜŞŠ"],
|
|
21
|
+
["ss", "ß"],
|
|
22
|
+
["t", "ŢŤ"],
|
|
23
|
+
["u", "ÙÚÛŨŪŬŮŰŲỤỦỨỪỬỮỰƯ"],
|
|
24
|
+
["ue", "Ü"],
|
|
25
|
+
["w", "ẂŴẀẄ"],
|
|
26
|
+
["x", "ẍ"],
|
|
27
|
+
["y", "ÝŶŸỲỴỶỸ"],
|
|
28
|
+
["z", "ŹŻŽ"],
|
|
29
|
+
];
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export let addOrReplaceAtIdx = (list, newItem, newIdx) => {
|
|
2
|
+
if (list.length === 0) {
|
|
3
|
+
return [newItem];
|
|
4
|
+
}
|
|
5
|
+
if (typeof newIdx === "undefined" || list.length - 1 < newIdx) {
|
|
6
|
+
return [...list, newItem];
|
|
7
|
+
}
|
|
8
|
+
return list.map((item, idx) => {
|
|
9
|
+
if (idx === newIdx) {
|
|
10
|
+
return newItem;
|
|
11
|
+
}
|
|
12
|
+
return item;
|
|
13
|
+
});
|
|
14
|
+
};
|
package/areEqual.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { isArray } from "./isArray";
|
|
2
|
+
import { isObject } from "./isObject";
|
|
3
|
+
let areEqualArrays = (a, b) => {
|
|
4
|
+
if (!b)
|
|
5
|
+
return false;
|
|
6
|
+
if (a.length !== b.length)
|
|
7
|
+
return false;
|
|
8
|
+
for (let i = 0; i < a.length; i++) {
|
|
9
|
+
if (!areEqual(a[i], b[i]))
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
return true;
|
|
13
|
+
};
|
|
14
|
+
let areEqualObjects = (a, b) => {
|
|
15
|
+
if (!b)
|
|
16
|
+
return false;
|
|
17
|
+
const aKeys = Object.keys(a);
|
|
18
|
+
for (const _key of aKeys) {
|
|
19
|
+
const key = _key;
|
|
20
|
+
if (!areEqual(a[key], b[key])) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return true;
|
|
25
|
+
};
|
|
26
|
+
export let areEqual = (a, b) => {
|
|
27
|
+
if (!a && !b) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
if (!b && a !== b) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
const areObjects = isObject(a) && isObject(b);
|
|
34
|
+
if (areObjects && !areEqualObjects(a, b)) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
const areArrays = isArray(a) && isArray(b);
|
|
38
|
+
if (areArrays && !areEqualArrays(a, b)) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
if (!areObjects && !areArrays && a !== b) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
return true;
|
|
45
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export let arrayFilterFalsy = (list) => (list ? list.filter((r) => !!r) : []);
|
package/arrayOfAll.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export let arrayOfAll = () => (array) => array;
|
package/arraySum.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export let arraySum = (numbers) => numbers.reduce((sum, current) => sum + current, 0);
|
package/arrayToLookup.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export let arrayUniqueByProperties = (array, keys) => array.filter((item, idx, arr) => arr.findIndex((itemWith) => keys.every((k) => itemWith[k] === item[k])) === idx);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { isArray } from "./isArray";
|
|
2
|
+
import { isNull } from "./isNull";
|
|
3
|
+
import { isUndefined } from "./isUndefined";
|
|
4
|
+
export let buildUrlQueryString = (params) => {
|
|
5
|
+
let output = "";
|
|
6
|
+
if (!params)
|
|
7
|
+
return output;
|
|
8
|
+
for (const key in params) {
|
|
9
|
+
const value = params[key];
|
|
10
|
+
if (isArray(value)) {
|
|
11
|
+
for (let i = 0; i < value.length; i++) {
|
|
12
|
+
output += `${key}=${encodeURIComponent(value[i] + "")}&`;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
else if (!isNull(value) && !isUndefined(value)) {
|
|
16
|
+
output += `${key}=${encodeURIComponent(value + "")}&`;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return output ? `?${output.replace(/&+$/, "")}` : "";
|
|
20
|
+
};
|
package/capitalize.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { capitalCaseTransformFactory, lowerFactory, pascalCaseTransformFactory, splitPrefixSuffix, upperFactory, } from "./changeCaseHelpers";
|
|
2
|
+
export let changeCaseCamel = (input, options) => {
|
|
3
|
+
const [prefix, words, suffix] = splitPrefixSuffix(input, options);
|
|
4
|
+
const lower = lowerFactory(options?.locale);
|
|
5
|
+
const upper = upperFactory(options?.locale);
|
|
6
|
+
const transform = options?.mergeAmbiguousCharacters
|
|
7
|
+
? capitalCaseTransformFactory(lower, upper)
|
|
8
|
+
: pascalCaseTransformFactory(lower, upper);
|
|
9
|
+
return (prefix +
|
|
10
|
+
words
|
|
11
|
+
.map((word, index) => {
|
|
12
|
+
if (index === 0)
|
|
13
|
+
return lower(word);
|
|
14
|
+
return transform(word, index);
|
|
15
|
+
})
|
|
16
|
+
.join(options?.delimiter ?? "") +
|
|
17
|
+
suffix);
|
|
18
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { capitalCaseTransformFactory, lowerFactory, splitPrefixSuffix, upperFactory, } from "./changeCaseHelpers";
|
|
2
|
+
export let changeCaseCapital = (input, options) => {
|
|
3
|
+
const [prefix, words, suffix] = splitPrefixSuffix(input, options);
|
|
4
|
+
const lower = lowerFactory(options?.locale);
|
|
5
|
+
const upper = upperFactory(options?.locale);
|
|
6
|
+
return (prefix +
|
|
7
|
+
words
|
|
8
|
+
.map(capitalCaseTransformFactory(lower, upper))
|
|
9
|
+
.join(options?.delimiter ?? " ") +
|
|
10
|
+
suffix);
|
|
11
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { splitPrefixSuffix, upperFactory, } from "./changeCaseHelpers";
|
|
2
|
+
export let changeCaseConstant = (input, options) => {
|
|
3
|
+
const [prefix, words, suffix] = splitPrefixSuffix(input, options);
|
|
4
|
+
return (prefix +
|
|
5
|
+
words.map(upperFactory(options?.locale)).join(options?.delimiter ?? "_") +
|
|
6
|
+
suffix);
|
|
7
|
+
};
|
package/changeCaseDot.js
ADDED
package/changeCaseHelpers.d.ts
CHANGED
|
@@ -12,8 +12,3 @@ export interface Options {
|
|
|
12
12
|
}
|
|
13
13
|
export declare let split: (value: string) => string[];
|
|
14
14
|
export declare let splitSeparateNumbers: (value: string) => string[];
|
|
15
|
-
export declare let lowerFactory: (locale: Locale) => (input: string) => string;
|
|
16
|
-
export declare let upperFactory: (locale: Locale) => (input: string) => string;
|
|
17
|
-
export declare let capitalCaseTransformFactory: (lower: (input: string) => string, upper: (input: string) => string) => (word: string) => string;
|
|
18
|
-
export declare let pascalCaseTransformFactory: (lower: (input: string) => string, upper: (input: string) => string) => (word: string, index: number) => string;
|
|
19
|
-
export declare let splitPrefixSuffix: (input: string, options?: Options) => [string, string[], string];
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
let SPLIT_LOWER_UPPER_RE = /([\p{Ll}\d])(\p{Lu})/gu;
|
|
2
|
+
let SPLIT_UPPER_UPPER_RE = /(\p{Lu})([\p{Lu}][\p{Ll}])/gu;
|
|
3
|
+
let SPLIT_SEPARATE_NUMBER_RE = /(\d)\p{Ll}|(\p{L})\d/u;
|
|
4
|
+
let DEFAULT_STRIP_REGEXP = /[^\p{L}\d]+/giu;
|
|
5
|
+
let SPLIT_REPLACE_VALUE = "$1\0$2";
|
|
6
|
+
let DEFAULT_PREFIX_SUFFIX_CHARACTERS = "";
|
|
7
|
+
export let split = (value) => {
|
|
8
|
+
let result = value.trim();
|
|
9
|
+
result = result
|
|
10
|
+
.replace(SPLIT_LOWER_UPPER_RE, SPLIT_REPLACE_VALUE)
|
|
11
|
+
.replace(SPLIT_UPPER_UPPER_RE, SPLIT_REPLACE_VALUE);
|
|
12
|
+
result = result.replace(DEFAULT_STRIP_REGEXP, "\0");
|
|
13
|
+
let start = 0;
|
|
14
|
+
let end = result.length;
|
|
15
|
+
while (result.charAt(start) === "\0")
|
|
16
|
+
start++;
|
|
17
|
+
if (start === end)
|
|
18
|
+
return [];
|
|
19
|
+
while (result.charAt(end - 1) === "\0")
|
|
20
|
+
end--;
|
|
21
|
+
return result.slice(start, end).split(/\0/g);
|
|
22
|
+
};
|
|
23
|
+
export let splitSeparateNumbers = (value) => {
|
|
24
|
+
const words = split(value);
|
|
25
|
+
for (let i = 0; i < words.length; i++) {
|
|
26
|
+
const word = words[i];
|
|
27
|
+
const match = SPLIT_SEPARATE_NUMBER_RE.exec(word);
|
|
28
|
+
if (match) {
|
|
29
|
+
const offset = match.index + (match[1] ?? match[2]).length;
|
|
30
|
+
words.splice(i, 1, word.slice(0, offset), word.slice(offset));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return words;
|
|
34
|
+
};
|
|
35
|
+
export let lowerFactory = (locale) => locale === false
|
|
36
|
+
? (input) => input.toLowerCase()
|
|
37
|
+
: (input) => input.toLocaleLowerCase(locale);
|
|
38
|
+
export let upperFactory = (locale) => locale === false
|
|
39
|
+
? (input) => input.toUpperCase()
|
|
40
|
+
: (input) => input.toLocaleUpperCase(locale);
|
|
41
|
+
export let capitalCaseTransformFactory = (lower, upper) => (word) => `${upper(word[0])}${lower(word.slice(1))}`;
|
|
42
|
+
export let pascalCaseTransformFactory = (lower, upper) => (word, index) => {
|
|
43
|
+
const char0 = word[0];
|
|
44
|
+
const initial = index > 0 && char0 >= "0" && char0 <= "9" ? "_" + char0 : upper(char0);
|
|
45
|
+
return initial + lower(word.slice(1));
|
|
46
|
+
};
|
|
47
|
+
export let splitPrefixSuffix = (input, options = {}) => {
|
|
48
|
+
const splitFn = options.split ?? (options.separateNumbers ? splitSeparateNumbers : split);
|
|
49
|
+
const prefixCharacters = options.prefixCharacters ?? DEFAULT_PREFIX_SUFFIX_CHARACTERS;
|
|
50
|
+
const suffixCharacters = options.suffixCharacters ?? DEFAULT_PREFIX_SUFFIX_CHARACTERS;
|
|
51
|
+
let prefixIndex = 0;
|
|
52
|
+
let suffixIndex = input.length;
|
|
53
|
+
while (prefixIndex < input.length) {
|
|
54
|
+
const char = input.charAt(prefixIndex);
|
|
55
|
+
if (!prefixCharacters.includes(char))
|
|
56
|
+
break;
|
|
57
|
+
prefixIndex++;
|
|
58
|
+
}
|
|
59
|
+
while (suffixIndex > prefixIndex) {
|
|
60
|
+
const index = suffixIndex - 1;
|
|
61
|
+
const char = input.charAt(index);
|
|
62
|
+
if (!suffixCharacters.includes(char))
|
|
63
|
+
break;
|
|
64
|
+
suffixIndex = index;
|
|
65
|
+
}
|
|
66
|
+
return [
|
|
67
|
+
input.slice(0, prefixIndex),
|
|
68
|
+
splitFn(input.slice(prefixIndex, suffixIndex)),
|
|
69
|
+
input.slice(suffixIndex),
|
|
70
|
+
];
|
|
71
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { lowerFactory, splitPrefixSuffix, } from "./changeCaseHelpers";
|
|
2
|
+
export let changeCaseNone = (input, options) => {
|
|
3
|
+
const [prefix, words, suffix] = splitPrefixSuffix(input, options);
|
|
4
|
+
return (prefix +
|
|
5
|
+
words.map(lowerFactory(options?.locale)).join(options?.delimiter ?? " ") +
|
|
6
|
+
suffix);
|
|
7
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { capitalCaseTransformFactory, lowerFactory, pascalCaseTransformFactory, splitPrefixSuffix, upperFactory, } from "./changeCaseHelpers";
|
|
2
|
+
export let changeCasePascal = (input, options) => {
|
|
3
|
+
const [prefix, words, suffix] = splitPrefixSuffix(input, options);
|
|
4
|
+
const lower = lowerFactory(options?.locale);
|
|
5
|
+
const upper = upperFactory(options?.locale);
|
|
6
|
+
const transform = options?.mergeAmbiguousCharacters
|
|
7
|
+
? capitalCaseTransformFactory(lower, upper)
|
|
8
|
+
: pascalCaseTransformFactory(lower, upper);
|
|
9
|
+
return prefix + words.map(transform).join(options?.delimiter ?? "") + suffix;
|
|
10
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { capitalCaseTransformFactory, lowerFactory, splitPrefixSuffix, upperFactory, } from "./changeCaseHelpers";
|
|
2
|
+
export let changeCaseSentence = (input, options) => {
|
|
3
|
+
const [prefix, words, suffix] = splitPrefixSuffix(input, options);
|
|
4
|
+
const lower = lowerFactory(options?.locale);
|
|
5
|
+
const upper = upperFactory(options?.locale);
|
|
6
|
+
const transform = capitalCaseTransformFactory(lower, upper);
|
|
7
|
+
return (prefix +
|
|
8
|
+
words
|
|
9
|
+
.map((word, index) => {
|
|
10
|
+
if (index === 0)
|
|
11
|
+
return transform(word);
|
|
12
|
+
return lower(word);
|
|
13
|
+
})
|
|
14
|
+
.join(options?.delimiter ?? " ") +
|
|
15
|
+
suffix);
|
|
16
|
+
};
|
package/chunkByChunks.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export let chunkByChunks = (arr, nrOfChunks, balanced) => {
|
|
2
|
+
if (nrOfChunks < 2)
|
|
3
|
+
return [arr];
|
|
4
|
+
const len = arr.length;
|
|
5
|
+
const output = [];
|
|
6
|
+
let i = 0;
|
|
7
|
+
let size;
|
|
8
|
+
if (len % nrOfChunks === 0) {
|
|
9
|
+
size = Math.floor(len / nrOfChunks);
|
|
10
|
+
while (i < len) {
|
|
11
|
+
output.push(arr.slice(i, (i += size)));
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
else if (balanced) {
|
|
15
|
+
while (i < len) {
|
|
16
|
+
size = Math.ceil((len - i) / nrOfChunks--);
|
|
17
|
+
output.push(arr.slice(i, (i += size)));
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
nrOfChunks--;
|
|
22
|
+
size = Math.floor(len / nrOfChunks);
|
|
23
|
+
if (len % size === 0)
|
|
24
|
+
size--;
|
|
25
|
+
while (i < size * nrOfChunks) {
|
|
26
|
+
output.push(arr.slice(i, (i += size)));
|
|
27
|
+
}
|
|
28
|
+
output.push(arr.slice(size * nrOfChunks));
|
|
29
|
+
}
|
|
30
|
+
return output;
|
|
31
|
+
};
|
package/chunkBySize.js
ADDED
package/clamp.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export let clamp = (num, min, max) => Math.min(Math.max(num, min), max);
|
package/clsx.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
let toVal = (mix) => {
|
|
2
|
+
let k, y, str = "";
|
|
3
|
+
if (typeof mix === "string" || typeof mix === "number") {
|
|
4
|
+
str += mix;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof mix === "object") {
|
|
7
|
+
if (Array.isArray(mix)) {
|
|
8
|
+
for (k = 0; k < mix.length; k++) {
|
|
9
|
+
if (mix[k]) {
|
|
10
|
+
if ((y = toVal(mix[k]))) {
|
|
11
|
+
str && (str += " ");
|
|
12
|
+
str += y;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
for (k in mix) {
|
|
19
|
+
if (mix[k]) {
|
|
20
|
+
str && (str += " ");
|
|
21
|
+
str += k;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return str;
|
|
27
|
+
};
|
|
28
|
+
export let clsx = function () {
|
|
29
|
+
let i = 0, tmp, x, str = "";
|
|
30
|
+
while (i < arguments.length) {
|
|
31
|
+
if ((tmp = arguments[i++])) {
|
|
32
|
+
if ((x = toVal(tmp))) {
|
|
33
|
+
str && (str += " ");
|
|
34
|
+
str += x;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return str;
|
|
39
|
+
};
|
package/convertRange.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export let convertRange = (num, r1, r2) => ((num - r1[0]) * (r2[1] - r2[0])) / (r1[1] - r1[0]) + r2[0];
|
package/cookie.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export let defaultAttributesClient = { path: "/" };
|
package/createPalette.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export let createPalette = (name, shades) => {
|
|
2
|
+
const map = shades.reduce((map, def) => {
|
|
3
|
+
map[def[0]] = def[1];
|
|
4
|
+
return map;
|
|
5
|
+
}, {});
|
|
6
|
+
const tailwindPalette = shades.reduce((map, def) => {
|
|
7
|
+
map[`${name}-${def[0]}`] = def[1];
|
|
8
|
+
return map;
|
|
9
|
+
}, {});
|
|
10
|
+
return [map, tailwindPalette, Object.values(map)];
|
|
11
|
+
};
|
package/debounce.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export let debounce = (fn, wait, immediate) => {
|
|
2
|
+
let timeout;
|
|
3
|
+
return function (...args) {
|
|
4
|
+
const context = this;
|
|
5
|
+
const later = function () {
|
|
6
|
+
timeout = null;
|
|
7
|
+
if (!immediate)
|
|
8
|
+
fn.apply(context, args);
|
|
9
|
+
};
|
|
10
|
+
const callNow = immediate && !timeout;
|
|
11
|
+
if (timeout)
|
|
12
|
+
clearTimeout(timeout);
|
|
13
|
+
timeout = setTimeout(later, wait);
|
|
14
|
+
if (callNow)
|
|
15
|
+
fn.apply(context, args);
|
|
16
|
+
};
|
|
17
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export let debouncePromise = (func, waitMilliseconds = 50, options = {}) => {
|
|
2
|
+
let timeoutId;
|
|
3
|
+
const isImmediate = options.isImmediate ?? false;
|
|
4
|
+
const callback = options.callback ?? false;
|
|
5
|
+
const maxWait = options.maxWait;
|
|
6
|
+
let lastInvokeTime = Date.now();
|
|
7
|
+
let promises = [];
|
|
8
|
+
function nextInvokeTimeout() {
|
|
9
|
+
if (maxWait !== undefined) {
|
|
10
|
+
const timeSinceLastInvocation = Date.now() - lastInvokeTime;
|
|
11
|
+
if (timeSinceLastInvocation + waitMilliseconds >= maxWait) {
|
|
12
|
+
return maxWait - timeSinceLastInvocation;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return waitMilliseconds;
|
|
16
|
+
}
|
|
17
|
+
const debouncedFunction = function (...args) {
|
|
18
|
+
const context = this;
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
const invokeFunction = function () {
|
|
21
|
+
timeoutId = undefined;
|
|
22
|
+
lastInvokeTime = Date.now();
|
|
23
|
+
if (!isImmediate) {
|
|
24
|
+
const result = func.apply(context, args);
|
|
25
|
+
callback && callback(result);
|
|
26
|
+
promises.forEach(({ resolve }) => resolve(result));
|
|
27
|
+
promises = [];
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const shouldCallNow = isImmediate && timeoutId === undefined;
|
|
31
|
+
if (timeoutId !== undefined) {
|
|
32
|
+
clearTimeout(timeoutId);
|
|
33
|
+
}
|
|
34
|
+
timeoutId = setTimeout(invokeFunction, nextInvokeTimeout());
|
|
35
|
+
if (shouldCallNow) {
|
|
36
|
+
const result = func.apply(context, args);
|
|
37
|
+
callback && callback(result);
|
|
38
|
+
return resolve(result);
|
|
39
|
+
}
|
|
40
|
+
promises.push({ resolve, reject });
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
debouncedFunction.cancel = function (reason) {
|
|
44
|
+
if (timeoutId !== undefined) {
|
|
45
|
+
clearTimeout(timeoutId);
|
|
46
|
+
}
|
|
47
|
+
promises.forEach(({ reject }) => reject(reason));
|
|
48
|
+
promises = [];
|
|
49
|
+
};
|
|
50
|
+
return debouncedFunction;
|
|
51
|
+
};
|
package/debounceRaf.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export function debounceRaf(fn) {
|
|
2
|
+
let timeout;
|
|
3
|
+
return function (...args) {
|
|
4
|
+
const context = this;
|
|
5
|
+
if (timeout) {
|
|
6
|
+
window.cancelAnimationFrame(timeout);
|
|
7
|
+
}
|
|
8
|
+
timeout = window.requestAnimationFrame(function () {
|
|
9
|
+
fn.apply(context, args);
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
}
|
package/decode.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export let decode = (str) => str.replace(/.{3}/g, (c) => String.fromCharCode(parseInt(c, 10)));
|
package/encode.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export let encode = (str) => str.replace(/./g, (c) => ("00" + c.charCodeAt(0)).slice(-3));
|
package/ensureInt.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export let ensureInt = (input) => typeof input === "string" ? parseInt(input, 10) : Math.round(input);
|
package/env.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
package/errorToString.js
ADDED
package/escapeRegExp.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export let escapeRegExp = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
package/forin.js
ADDED
package/gbToBytes.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export let gbToBytes = (bytes) => bytes * 1000 * 1000 * 1000;
|
package/getEmptyArray.js
ADDED
package/getKeys.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export let getKeys = Object.keys;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export let getMediaQueryWidthResolvers = (customBreakpoints) => {
|
|
2
|
+
const breakpoints = {
|
|
3
|
+
xs: 0,
|
|
4
|
+
...customBreakpoints,
|
|
5
|
+
};
|
|
6
|
+
const sortedBreakpointsNames = Object.keys(breakpoints).map((key) => {
|
|
7
|
+
const br = key;
|
|
8
|
+
return [br, breakpoints[br]];
|
|
9
|
+
})
|
|
10
|
+
.sort((a, b) => a[1] - b[1])
|
|
11
|
+
.map((item) => item[0]);
|
|
12
|
+
const getNextBreakpoint = (breakpoint) => {
|
|
13
|
+
const index = sortedBreakpointsNames.indexOf(breakpoint);
|
|
14
|
+
return sortedBreakpointsNames[index + 1];
|
|
15
|
+
};
|
|
16
|
+
const min = (br) => `(min-width: ${breakpoints[br]}px)`;
|
|
17
|
+
const max = (br) => `(max-width: ${breakpoints[br] - 0.02}px)`;
|
|
18
|
+
const up = min;
|
|
19
|
+
const down = (br) => {
|
|
20
|
+
const brNext = getNextBreakpoint(br);
|
|
21
|
+
return brNext && `(max-width: ${breakpoints[brNext] - 0.02}px)`;
|
|
22
|
+
};
|
|
23
|
+
const between = (br1, br2) => {
|
|
24
|
+
br2 = br2 || getNextBreakpoint(br1);
|
|
25
|
+
return br2
|
|
26
|
+
? `(min-width: ${breakpoints[br1]}px) and (max-width: ${breakpoints[br2] - 0.02}px)`
|
|
27
|
+
: min(br1);
|
|
28
|
+
};
|
|
29
|
+
const only = (br) => {
|
|
30
|
+
const brNext = getNextBreakpoint(br);
|
|
31
|
+
return brNext ? between(br, brNext) : min(br);
|
|
32
|
+
};
|
|
33
|
+
return {
|
|
34
|
+
max,
|
|
35
|
+
min,
|
|
36
|
+
down,
|
|
37
|
+
up,
|
|
38
|
+
between,
|
|
39
|
+
only,
|
|
40
|
+
};
|
|
41
|
+
};
|