@koine/utils 1.0.26 → 1.0.29
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/{async.d.ts → Defer.d.ts} +5 -5
- package/{async.js → Defer.js} +2 -7
- package/{emitter.d.ts → Emitter.d.ts} +1 -0
- package/{emitter.js → Emitter.js} +1 -0
- package/accentSets.d.ts +16 -0
- package/accentSets.js +38 -0
- package/addOrReplaceAtIdx.d.ts +5 -0
- package/addOrReplaceAtIdx.js +19 -0
- package/arrayToLookup.d.ts +7 -0
- package/arrayToLookup.js +13 -0
- package/buildUrlQueryString.d.ts +12 -0
- package/buildUrlQueryString.js +24 -0
- package/changeUrlPath.d.ts +10 -0
- package/changeUrlPath.js +18 -0
- package/chunkByChunks.d.ts +7 -0
- package/chunkByChunks.js +37 -0
- package/chunkBySize.d.ts +6 -0
- package/chunkBySize.js +12 -0
- package/clamp.d.ts +8 -0
- package/clamp.js +10 -0
- package/clsx.d.ts +9 -0
- package/clsx.js +49 -0
- package/convertRange.d.ts +14 -0
- package/convertRange.js +16 -0
- package/cookie.d.ts +7 -26
- package/cookie.js +3 -221
- package/decode.d.ts +6 -0
- package/decode.js +10 -0
- package/encode.d.ts +6 -0
- package/encode.js +10 -0
- package/{cast.d.ts → ensureInt.d.ts} +3 -1
- package/{cast.js → ensureInt.js} +3 -4
- package/findDuplicatedIndexes.d.ts +5 -0
- package/findDuplicatedIndexes.js +14 -0
- package/getKeys.d.ts +9 -0
- package/getKeys.js +9 -0
- package/getNonce.d.ts +6 -0
- package/getNonce.js +9 -0
- package/getType.d.ts +22 -0
- package/getType.js +19 -0
- package/getUrlHashParams.d.ts +9 -0
- package/getUrlHashParams.js +16 -0
- package/getUrlHashPathname.d.ts +9 -0
- package/getUrlHashPathname.js +13 -0
- package/getUrlPathnameParts.d.ts +12 -0
- package/getUrlPathnameParts.js +20 -0
- package/getUrlQueryParams.d.ts +14 -0
- package/getUrlQueryParams.js +38 -0
- package/index.d.ts +107 -15
- package/index.js +108 -16
- package/isAnyObject.d.ts +8 -0
- package/isAnyObject.js +10 -0
- package/isArray.d.ts +7 -0
- package/isArray.js +10 -0
- package/isBlob.d.ts +7 -0
- package/isBlob.js +10 -0
- package/isBoolean.d.ts +7 -0
- package/isBoolean.js +10 -0
- package/isBrowser.d.ts +6 -0
- package/{ssr.js → isBrowser.js} +5 -2
- package/isDate.d.ts +7 -0
- package/isDate.js +10 -0
- package/isEmptyArray.d.ts +7 -0
- package/isEmptyArray.js +10 -0
- package/isEmptyObject.d.ts +9 -0
- package/isEmptyObject.js +10 -0
- package/isEmptyString.d.ts +7 -0
- package/isEmptyString.js +9 -0
- package/isError.d.ts +7 -0
- package/isError.js +10 -0
- package/isExternalUrl.d.ts +9 -0
- package/isExternalUrl.js +21 -0
- package/isFile.d.ts +7 -0
- package/isFile.js +10 -0
- package/isFloat.d.ts +7 -0
- package/isFloat.js +10 -0
- package/isFormData.d.ts +7 -0
- package/isFormData.js +10 -0
- package/isFullArray.d.ts +7 -0
- package/isFullArray.js +10 -0
- package/isFullObject.d.ts +8 -0
- package/isFullObject.js +10 -0
- package/isFullString.d.ts +7 -0
- package/isFullString.js +10 -0
- package/isFunction.d.ts +8 -0
- package/isFunction.js +9 -0
- package/{detect.d.ts → isIE.d.ts} +3 -4
- package/isIE.js +18 -0
- package/isInt.d.ts +7 -0
- package/isInt.js +10 -0
- package/isMap.d.ts +7 -0
- package/isMap.js +10 -0
- package/isMobile.d.ts +7 -0
- package/{detect.js → isMobile.js} +4 -15
- package/isNaNValue.d.ts +7 -0
- package/isNaNValue.js +10 -0
- package/isNegativeNumber.d.ts +7 -0
- package/isNegativeNumber.js +10 -0
- package/isNull.d.ts +7 -0
- package/isNull.js +10 -0
- package/isNullOrUndefined.d.ts +7 -0
- package/isNullOrUndefined.js +10 -0
- package/isNumber.d.ts +9 -0
- package/isNumber.js +12 -0
- package/isObject.d.ts +8 -0
- package/isObject.js +10 -0
- package/isObjectLike.d.ts +10 -0
- package/isObjectLike.js +12 -0
- package/isOneOf.d.ts +9 -0
- package/isOneOf.js +10 -0
- package/isPlainObject.d.ts +8 -0
- package/isPlainObject.js +13 -0
- package/isPositiveNumber.d.ts +7 -0
- package/isPositiveNumber.js +10 -0
- package/isPrimitive.d.ts +7 -0
- package/isPrimitive.js +20 -0
- package/isPromise.d.ts +7 -0
- package/isPromise.js +10 -0
- package/isRegExp.d.ts +7 -0
- package/isRegExp.js +10 -0
- package/isServer.d.ts +6 -0
- package/isServer.js +8 -0
- package/isSet.d.ts +7 -0
- package/isSet.js +10 -0
- package/isString.d.ts +7 -0
- package/isString.js +10 -0
- package/isSymbol.d.ts +7 -0
- package/isSymbol.js +10 -0
- package/isType.d.ts +11 -0
- package/isType.js +22 -0
- package/isUndefined.d.ts +7 -0
- package/isUndefined.js +10 -0
- package/isWeakMap.d.ts +7 -0
- package/isWeakMap.js +10 -0
- package/isWeakSet.d.ts +7 -0
- package/isWeakSet.js +10 -0
- package/location.d.ts +2 -145
- package/location.js +1 -299
- package/mapListBy.d.ts +7 -0
- package/mapListBy.js +14 -0
- package/{match-sorter.d.ts → matchSorter.d.ts} +1 -0
- package/{match-sorter.js → matchSorter.js} +2 -1
- package/mergeObjects.d.ts +7 -0
- package/{objects.js → mergeObjects.js} +2 -31
- package/mergeUrlQueryParams.d.ts +9 -0
- package/mergeUrlQueryParams.js +22 -0
- package/navigateToHashParams.d.ts +9 -0
- package/navigateToHashParams.js +22 -0
- package/navigateToMergedHashParams.d.ts +8 -0
- package/navigateToMergedHashParams.js +14 -0
- package/navigateToMergedParams.d.ts +9 -0
- package/navigateToMergedParams.js +14 -0
- package/navigateToParams.d.ts +10 -0
- package/navigateToParams.js +18 -0
- package/navigateWithoutUrlParam.d.ts +8 -0
- package/navigateWithoutUrlParam.js +19 -0
- package/node/{async.js → Defer.js} +3 -9
- package/node/{emitter.js → Emitter.js} +1 -0
- package/node/accentSets.js +41 -0
- package/node/addOrReplaceAtIdx.js +23 -0
- package/node/arrayToLookup.js +17 -0
- package/node/buildUrlQueryString.js +28 -0
- package/node/changeUrlPath.js +22 -0
- package/node/chunkByChunks.js +41 -0
- package/node/chunkBySize.js +16 -0
- package/node/clamp.js +14 -0
- package/node/clsx.js +53 -0
- package/node/convertRange.js +20 -0
- package/node/cookie.js +4 -227
- package/node/decode.js +14 -0
- package/node/encode.js +14 -0
- package/node/{cast.js → ensureInt.js} +4 -6
- package/node/findDuplicatedIndexes.js +18 -0
- package/node/getKeys.js +12 -0
- package/node/getNonce.js +13 -0
- package/node/getType.js +23 -0
- package/node/getUrlHashParams.js +20 -0
- package/node/getUrlHashPathname.js +17 -0
- package/node/getUrlPathnameParts.js +24 -0
- package/node/getUrlQueryParams.js +42 -0
- package/node/index.js +108 -16
- package/node/isAnyObject.js +14 -0
- package/node/isArray.js +14 -0
- package/node/isBlob.js +14 -0
- package/node/isBoolean.js +14 -0
- package/node/{ssr.js → isBrowser.js} +6 -3
- package/node/isDate.js +14 -0
- package/node/isEmptyArray.js +14 -0
- package/node/isEmptyObject.js +14 -0
- package/node/isEmptyString.js +13 -0
- package/node/isError.js +14 -0
- package/node/isExternalUrl.js +25 -0
- package/node/isFile.js +14 -0
- package/node/isFloat.js +14 -0
- package/node/isFormData.js +14 -0
- package/node/isFullArray.js +14 -0
- package/node/isFullObject.js +14 -0
- package/node/isFullString.js +14 -0
- package/node/isFunction.js +13 -0
- package/node/isIE.js +22 -0
- package/node/isInt.js +14 -0
- package/node/isMap.js +14 -0
- package/node/{detect.js → isMobile.js} +6 -18
- package/node/isNaNValue.js +14 -0
- package/node/isNegativeNumber.js +14 -0
- package/node/isNull.js +14 -0
- package/node/isNullOrUndefined.js +13 -0
- package/node/isNumber.js +16 -0
- package/node/isObject.js +14 -0
- package/node/isObjectLike.js +16 -0
- package/node/isOneOf.js +14 -0
- package/node/isPlainObject.js +17 -0
- package/node/isPositiveNumber.js +14 -0
- package/node/isPrimitive.js +24 -0
- package/node/isPromise.js +14 -0
- package/node/isRegExp.js +14 -0
- package/node/isServer.js +11 -0
- package/node/isSet.js +14 -0
- package/node/isString.js +14 -0
- package/node/isSymbol.js +14 -0
- package/node/isType.js +26 -0
- package/node/isUndefined.js +14 -0
- package/node/isWeakMap.js +14 -0
- package/node/isWeakSet.js +14 -0
- package/node/location.js +0 -321
- package/node/mapListBy.js +18 -0
- package/node/{match-sorter.js → matchSorter.js} +3 -2
- package/node/{objects.js → mergeObjects.js} +5 -36
- package/node/mergeUrlQueryParams.js +26 -0
- package/node/navigateToHashParams.js +26 -0
- package/node/navigateToMergedHashParams.js +18 -0
- package/node/navigateToMergedParams.js +18 -0
- package/node/navigateToParams.js +22 -0
- package/node/navigateWithoutUrlParam.js +23 -0
- package/node/normaliseUrl.js +18 -0
- package/node/normaliseUrlPathname.js +18 -0
- package/node/{analytics-google.js → pageview.js} +12 -10
- package/node/parseCookie.js +52 -0
- package/node/parseURL.js +24 -0
- package/node/randomInt.js +13 -0
- package/node/{misc.js → randomKey.js} +2 -0
- package/node/readCookie.js +38 -0
- package/node/redirectTo.js +19 -0
- package/node/removeAccents.js +19 -0
- package/node/removeCookie.js +19 -0
- package/node/removeDuplicatesByKey.js +25 -0
- package/node/removeDuplicatesComparing.js +14 -0
- package/node/removeIndexesFromArray.js +18 -0
- package/node/removeTrailingSlash.js +14 -0
- package/node/{math.js → roundTo.js} +3 -32
- package/node/serializeCookie.js +108 -0
- package/node/setCookie.js +61 -0
- package/node/shuffle.js +36 -0
- package/node/slugify.js +27 -0
- package/node/swapMap.js +18 -0
- package/node/{typography.js → titleCase.js} +3 -12
- package/node/toNumber.js +12 -0
- package/node/{colors.js → toRgba.js} +4 -0
- package/node/transformToUrlPathname.js +20 -0
- package/node/truncate.js +17 -0
- package/node/uid.js +4 -13
- package/node/updateLinkParams.js +18 -0
- package/node/updateUrlQueryParams.js +22 -0
- package/node/uuid.js +17 -0
- package/node/wait.js +13 -0
- package/node/whitelistObject.js +19 -0
- package/normaliseUrl.d.ts +10 -0
- package/normaliseUrl.js +14 -0
- package/normaliseUrlPathname.d.ts +10 -0
- package/normaliseUrlPathname.js +14 -0
- package/package.json +1 -1
- package/{analytics-google.d.ts → pageview.d.ts} +3 -0
- package/{analytics-google.js → pageview.js} +12 -10
- package/parseCookie.d.ts +11 -0
- package/parseCookie.js +48 -0
- package/parseURL.d.ts +17 -0
- package/parseURL.js +20 -0
- package/randomInt.d.ts +7 -0
- package/randomInt.js +9 -0
- package/{misc.d.ts → randomKey.d.ts} +2 -0
- package/{misc.js → randomKey.js} +2 -0
- package/readCookie.d.ts +3 -0
- package/readCookie.js +34 -0
- package/redirectTo.d.ts +9 -0
- package/redirectTo.js +15 -0
- package/removeAccents.d.ts +6 -0
- package/removeAccents.js +15 -0
- package/removeCookie.d.ts +10 -0
- package/removeCookie.js +15 -0
- package/removeDuplicatesByKey.d.ts +8 -0
- package/removeDuplicatesByKey.js +21 -0
- package/removeDuplicatesComparing.d.ts +5 -0
- package/removeDuplicatesComparing.js +10 -0
- package/removeIndexesFromArray.d.ts +5 -0
- package/removeIndexesFromArray.js +14 -0
- package/removeTrailingSlash.d.ts +7 -0
- package/removeTrailingSlash.js +10 -0
- package/roundTo.d.ts +8 -0
- package/{math.js → roundTo.js} +2 -28
- package/serializeCookie.d.ts +27 -0
- package/serializeCookie.js +104 -0
- package/setCookie.d.ts +10 -0
- package/setCookie.js +57 -0
- package/shuffle.d.ts +16 -0
- package/shuffle.js +32 -0
- package/{text.d.ts → slugify.d.ts} +2 -5
- package/slugify.js +23 -0
- package/swapMap.d.ts +7 -0
- package/swapMap.js +14 -0
- package/{typography.d.ts → titleCase.d.ts} +2 -4
- package/{typography.js → titleCase.js} +2 -10
- package/toNumber.d.ts +5 -0
- package/toNumber.js +8 -0
- package/{colors.d.ts → toRgba.d.ts} +4 -0
- package/{colors.js → toRgba.js} +4 -0
- package/transformToUrlPathname.d.ts +11 -0
- package/transformToUrlPathname.js +16 -0
- package/truncate.d.ts +7 -0
- package/truncate.js +13 -0
- package/uid.d.ts +3 -6
- package/uid.js +3 -11
- package/updateLinkParams.d.ts +10 -0
- package/updateLinkParams.js +14 -0
- package/updateUrlQueryParams.d.ts +9 -0
- package/updateUrlQueryParams.js +18 -0
- package/uuid.d.ts +8 -0
- package/uuid.js +13 -0
- package/wait.d.ts +7 -0
- package/wait.js +9 -0
- package/whitelistObject.d.ts +8 -0
- package/whitelistObject.js +15 -0
- package/arrays.d.ts +0 -41
- package/arrays.js +0 -153
- package/is.d.ts +0 -288
- package/is.js +0 -376
- package/math.d.ts +0 -28
- package/node/arrays.js +0 -166
- package/node/is.js +0 -417
- package/node/security.js +0 -29
- package/node/text.js +0 -70
- package/objects.d.ts +0 -22
- package/security.d.ts +0 -12
- package/security.js +0 -23
- package/ssr.d.ts +0 -2
- package/text.js +0 -65
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file
|
|
3
|
+
*
|
|
4
|
+
* @category cookie
|
|
5
|
+
*
|
|
6
|
+
* All cookie related code is inspired and adapted from:
|
|
7
|
+
* - [js-cookie](https://github.com/js-cookie/js-cookie)
|
|
8
|
+
* - [cookie](https://github.com/jshttp/cookie)
|
|
9
|
+
*/
|
|
10
|
+
import { type CookieAttributesServer } from "./cookie";
|
|
11
|
+
/**
|
|
12
|
+
* Serialize data into a cookie header.
|
|
13
|
+
*
|
|
14
|
+
* Serialize the a name value pair into a cookie string suitable for
|
|
15
|
+
* http headers. An optional attributes object specified cookie parameters.
|
|
16
|
+
*
|
|
17
|
+
* serialize('foo', 'bar', { httpOnly: true })
|
|
18
|
+
* => "foo=bar; httpOnly"
|
|
19
|
+
*
|
|
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
|
+
*/
|
|
26
|
+
export declare function serializeCookie(name: string, val: string, attributes?: CookieAttributesServer): string;
|
|
27
|
+
export default serializeCookie;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file
|
|
3
|
+
*
|
|
4
|
+
* @category cookie
|
|
5
|
+
*
|
|
6
|
+
* All cookie related code is inspired and adapted from:
|
|
7
|
+
* - [js-cookie](https://github.com/js-cookie/js-cookie)
|
|
8
|
+
* - [cookie](https://github.com/jshttp/cookie)
|
|
9
|
+
*/
|
|
10
|
+
import { isNumber } from "./isNumber";
|
|
11
|
+
/**
|
|
12
|
+
* RegExp to match field-content in RFC 7230 sec 3.2
|
|
13
|
+
*
|
|
14
|
+
* field-content = field-vchar [ 1*( SP / HTAB ) field-vchar ]
|
|
15
|
+
* field-vchar = VCHAR / obs-text
|
|
16
|
+
* obs-text = %x80-FF
|
|
17
|
+
*/
|
|
18
|
+
// eslint-disable-next-line no-control-regex
|
|
19
|
+
var fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;
|
|
20
|
+
/**
|
|
21
|
+
* Serialize data into a cookie header.
|
|
22
|
+
*
|
|
23
|
+
* Serialize the a name value pair into a cookie string suitable for
|
|
24
|
+
* http headers. An optional attributes object specified cookie parameters.
|
|
25
|
+
*
|
|
26
|
+
* serialize('foo', 'bar', { httpOnly: true })
|
|
27
|
+
* => "foo=bar; httpOnly"
|
|
28
|
+
*
|
|
29
|
+
* @category cookie
|
|
30
|
+
*
|
|
31
|
+
* All cookie related code is inspired and adapted from:
|
|
32
|
+
* - [js-cookie](https://github.com/js-cookie/js-cookie)
|
|
33
|
+
* - [cookie](https://github.com/jshttp/cookie)
|
|
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);
|
|
40
|
+
if (process.env["NODE_ENV"] !== "production") {
|
|
41
|
+
if (!fieldContentRegExp.test(name)) {
|
|
42
|
+
throw new TypeError("argument name is invalid");
|
|
43
|
+
}
|
|
44
|
+
if (typeof attributes.encode !== "function") {
|
|
45
|
+
throw new TypeError("option encode is invalid");
|
|
46
|
+
}
|
|
47
|
+
if (value && !fieldContentRegExp.test(value)) {
|
|
48
|
+
throw new TypeError("argument val is invalid");
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
var str = name + "=" + value;
|
|
52
|
+
if (null != maxAge) {
|
|
53
|
+
maxAge = maxAge - 0;
|
|
54
|
+
if (isNaN(maxAge) || !isFinite(maxAge)) {
|
|
55
|
+
throw new TypeError("option maxAge is invalid");
|
|
56
|
+
}
|
|
57
|
+
str += "; Max-Age=" + Math.floor(maxAge);
|
|
58
|
+
}
|
|
59
|
+
if (domain) {
|
|
60
|
+
if (process.env["NODE_ENV"] !== "production") {
|
|
61
|
+
if (!fieldContentRegExp.test(domain)) {
|
|
62
|
+
throw new TypeError("option domain is invalid");
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
str += "; Domain=" + domain;
|
|
66
|
+
}
|
|
67
|
+
if (path) {
|
|
68
|
+
if (process.env["NODE_ENV"] !== "production") {
|
|
69
|
+
if (!fieldContentRegExp.test(path)) {
|
|
70
|
+
throw new TypeError("option path is invalid");
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
str += "; Path=" + path;
|
|
74
|
+
}
|
|
75
|
+
if (expires) {
|
|
76
|
+
if (isNumber(expires)) {
|
|
77
|
+
expires = new Date(Date.now() + expires * 864e5);
|
|
78
|
+
}
|
|
79
|
+
str += "; Expires=" + expires.toUTCString();
|
|
80
|
+
}
|
|
81
|
+
if (httpOnly) {
|
|
82
|
+
str += "; HttpOnly";
|
|
83
|
+
}
|
|
84
|
+
if (secure) {
|
|
85
|
+
str += "; Secure";
|
|
86
|
+
}
|
|
87
|
+
if (sameSite) {
|
|
88
|
+
switch (sameSite.toLowerCase()) {
|
|
89
|
+
case "lax":
|
|
90
|
+
str += "; SameSite=Lax";
|
|
91
|
+
break;
|
|
92
|
+
case "strict":
|
|
93
|
+
str += "; SameSite=Strict";
|
|
94
|
+
break;
|
|
95
|
+
case "none":
|
|
96
|
+
str += "; SameSite=None";
|
|
97
|
+
break;
|
|
98
|
+
// default:
|
|
99
|
+
// throw new TypeError('option sameSite is invalid');
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return str;
|
|
103
|
+
}
|
|
104
|
+
export default serializeCookie;
|
package/setCookie.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type CookieAttributesClient } from "./cookie";
|
|
2
|
+
/**
|
|
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
|
+
*/
|
|
9
|
+
export declare function setCookie<T extends string = string>(name: string, value: string | T, attributes?: CookieAttributesClient): string | undefined;
|
|
10
|
+
export default setCookie;
|
package/setCookie.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { __assign, __rest } from "tslib";
|
|
2
|
+
import { defaultAttributesClient } from "./cookie";
|
|
3
|
+
import isNumber from "./isNumber";
|
|
4
|
+
function converterWrite(value) {
|
|
5
|
+
return encodeURIComponent(value).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g, decodeURIComponent);
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* @category cookie
|
|
9
|
+
*
|
|
10
|
+
* All cookie related code is inspired and adapted from:
|
|
11
|
+
* - [js-cookie](https://github.com/js-cookie/js-cookie)
|
|
12
|
+
* - [cookie](https://github.com/jshttp/cookie)
|
|
13
|
+
*/
|
|
14
|
+
export function setCookie(name, value, attributes) {
|
|
15
|
+
if (attributes === void 0) { attributes = {}; }
|
|
16
|
+
// eslint-disable-next-line prefer-const
|
|
17
|
+
var expires = attributes.expires, restAttrs = __rest(attributes, ["expires"]);
|
|
18
|
+
var cleanedAttrs = __assign(__assign({ expires: "" }, defaultAttributesClient), restAttrs);
|
|
19
|
+
if (typeof document === "undefined") {
|
|
20
|
+
if (process.env["NODE_ENV"] !== "production") {
|
|
21
|
+
console.warn("@koine/utils:cookie setCookie, document is undefined");
|
|
22
|
+
}
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (isNumber(expires)) {
|
|
26
|
+
expires = new Date(Date.now() + expires * 864e5);
|
|
27
|
+
}
|
|
28
|
+
if (expires) {
|
|
29
|
+
cleanedAttrs.expires = expires.toUTCString();
|
|
30
|
+
}
|
|
31
|
+
name = encodeURIComponent(name)
|
|
32
|
+
.replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent)
|
|
33
|
+
.replace(/[()]/g, escape);
|
|
34
|
+
var stringifiedAttributes = "";
|
|
35
|
+
for (var name_1 in attributes) {
|
|
36
|
+
var attrName = name_1;
|
|
37
|
+
if (!attributes[attrName]) {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
stringifiedAttributes += "; " + attrName;
|
|
41
|
+
if (attributes[attrName] === true) {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
// Considers RFC 6265 section 5.2:
|
|
45
|
+
// ...
|
|
46
|
+
// 3. If the remaining unparsed-attributes contains a %x3B (";")
|
|
47
|
+
// character:
|
|
48
|
+
// Consume the characters of the unparsed-attributes up to,
|
|
49
|
+
// not including, the first %x3B (";") character.
|
|
50
|
+
// ...
|
|
51
|
+
stringifiedAttributes +=
|
|
52
|
+
"=" + String(attributes[attrName]).split(";")[0];
|
|
53
|
+
}
|
|
54
|
+
return (document.cookie =
|
|
55
|
+
name + "=" + converterWrite(value) + stringifiedAttributes);
|
|
56
|
+
}
|
|
57
|
+
export default setCookie;
|
package/shuffle.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates an array of shuffled values, using a version of the
|
|
3
|
+
* [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
|
|
4
|
+
*
|
|
5
|
+
* @see lodash.shuffle
|
|
6
|
+
* @since 0.1.0
|
|
7
|
+
* @category arrays
|
|
8
|
+
* @param {Array} array The array to shuffle.
|
|
9
|
+
* @returns {Array} Returns the new shuffled array.
|
|
10
|
+
* @example
|
|
11
|
+
*
|
|
12
|
+
* shuffle([1, 2, 3, 4])
|
|
13
|
+
* // => [4, 1, 3, 2]
|
|
14
|
+
*/
|
|
15
|
+
export declare function shuffle<T>(array: T[]): T[];
|
|
16
|
+
export default shuffle;
|
package/shuffle.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { __spreadArray } from "tslib";
|
|
2
|
+
/**
|
|
3
|
+
* Creates an array of shuffled values, using a version of the
|
|
4
|
+
* [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
|
|
5
|
+
*
|
|
6
|
+
* @see lodash.shuffle
|
|
7
|
+
* @since 0.1.0
|
|
8
|
+
* @category arrays
|
|
9
|
+
* @param {Array} array The array to shuffle.
|
|
10
|
+
* @returns {Array} Returns the new shuffled array.
|
|
11
|
+
* @example
|
|
12
|
+
*
|
|
13
|
+
* shuffle([1, 2, 3, 4])
|
|
14
|
+
* // => [4, 1, 3, 2]
|
|
15
|
+
*/
|
|
16
|
+
export function shuffle(array) {
|
|
17
|
+
var length = array == null ? 0 : array.length;
|
|
18
|
+
if (!length) {
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
var index = -1;
|
|
22
|
+
var lastIndex = length - 1;
|
|
23
|
+
var result = __spreadArray([], array, true);
|
|
24
|
+
while (++index < length) {
|
|
25
|
+
var rand = index + Math.floor(Math.random() * (lastIndex - index + 1));
|
|
26
|
+
var value = result[rand];
|
|
27
|
+
result[rand] = result[index];
|
|
28
|
+
result[index] = value;
|
|
29
|
+
}
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
export default shuffle;
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* First value is the `to`, second is `from`, from *which* chars do we translates *to*
|
|
3
|
-
*/
|
|
4
|
-
export declare type AccentsSet = [string, string];
|
|
5
|
-
export declare function removeAccents(text?: string, sets?: AccentsSet[]): string;
|
|
6
1
|
/**
|
|
7
2
|
* Slugify a text
|
|
8
3
|
*
|
|
9
4
|
* - replaces the accented letters
|
|
10
5
|
* - replaces the punctuation with dashes
|
|
11
6
|
*
|
|
7
|
+
* @category text
|
|
12
8
|
* @see https://gist.github.com/mathewbyrne/1280286#gistcomment-3498021
|
|
13
9
|
*/
|
|
14
10
|
export declare function slugify(text: string, separator?: string): string;
|
|
11
|
+
export default slugify;
|
package/slugify.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { accentsSets } from "./accentSets";
|
|
2
|
+
import { removeAccents } from "./removeAccents";
|
|
3
|
+
/**
|
|
4
|
+
* Slugify a text
|
|
5
|
+
*
|
|
6
|
+
* - replaces the accented letters
|
|
7
|
+
* - replaces the punctuation with dashes
|
|
8
|
+
*
|
|
9
|
+
* @category text
|
|
10
|
+
* @see https://gist.github.com/mathewbyrne/1280286#gistcomment-3498021
|
|
11
|
+
*/
|
|
12
|
+
export function slugify(text, separator) {
|
|
13
|
+
if (separator === void 0) { separator = "-"; }
|
|
14
|
+
return removeAccents(text.toString().toLowerCase().trim(), accentsSets.concat([["-", "[·/_,:;']"]]))
|
|
15
|
+
.replace(/\s+/g, "-") // replace spaces with -
|
|
16
|
+
.replace(/&/g, "-and-") // replace & with 'and'
|
|
17
|
+
.replace(/[^\w-]+/g, "") // remove all non-word chars
|
|
18
|
+
.replace(/--+/g, "-") // replace multiple - with single -
|
|
19
|
+
.replace(/^-+/, "") // trim - from start of text
|
|
20
|
+
.replace(/-+$/, "") // trim - from end of text
|
|
21
|
+
.replace(/-/g, separator);
|
|
22
|
+
}
|
|
23
|
+
export default slugify;
|
package/swapMap.d.ts
ADDED
package/swapMap.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Swap object map key/value
|
|
3
|
+
*
|
|
4
|
+
* @category objects
|
|
5
|
+
*/
|
|
6
|
+
export function swapMap(map) {
|
|
7
|
+
if (map === void 0) { map = {}; }
|
|
8
|
+
var output = {};
|
|
9
|
+
for (var key in map) {
|
|
10
|
+
output[map[key]] = key;
|
|
11
|
+
}
|
|
12
|
+
return output;
|
|
13
|
+
}
|
|
14
|
+
export default swapMap;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* @category typography
|
|
2
3
|
* @see https://github.com/blakeembrey/change-case/blob/master/packages/title-case/src/index.ts
|
|
3
4
|
* @author Blake Embrey (hello@blakeembrey.com)
|
|
4
5
|
*/
|
|
5
6
|
export declare const titleCase: (input?: null | string) => string;
|
|
6
|
-
|
|
7
|
-
* Truncate string
|
|
8
|
-
*/
|
|
9
|
-
export declare const truncate: (input: undefined | null | string, length: number) => string;
|
|
7
|
+
export default titleCase;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* @category typography
|
|
2
3
|
* @see https://github.com/blakeembrey/change-case/blob/master/packages/title-case/src/index.ts
|
|
3
4
|
* @author Blake Embrey (hello@blakeembrey.com)
|
|
4
5
|
*/
|
|
@@ -7,13 +8,4 @@ export var titleCase = function (input) {
|
|
|
7
8
|
? input.replace(/\w\S*/g, function (txt) { return txt.charAt(0).toUpperCase() + txt.substring(1).toLowerCase(); })
|
|
8
9
|
: "";
|
|
9
10
|
};
|
|
10
|
-
|
|
11
|
-
* Truncate string
|
|
12
|
-
*/
|
|
13
|
-
export var truncate = function (input, length) {
|
|
14
|
-
return input
|
|
15
|
-
? input.length > length
|
|
16
|
-
? input.substring(0, length) + "..."
|
|
17
|
-
: input
|
|
18
|
-
: "";
|
|
19
|
-
};
|
|
11
|
+
export default titleCase;
|
package/toNumber.d.ts
ADDED
package/toNumber.js
ADDED
package/{colors.js → toRgba.js}
RENAMED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
// export const toRgb = (hexColor: string) => hexRgb(hexColor, { format: "css" });
|
|
3
3
|
// export const toRgba = (hexColor: string, alpha: number) =>
|
|
4
4
|
// hexRgb(hexColor, { format: "css", alpha });
|
|
5
|
+
/**
|
|
6
|
+
* @category colors
|
|
7
|
+
*/
|
|
5
8
|
export function toRgba(hex, alpha) {
|
|
6
9
|
if (alpha === void 0) { alpha = 1; }
|
|
7
10
|
var r = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
|
@@ -10,3 +13,4 @@ export function toRgba(hex, alpha) {
|
|
|
10
13
|
}
|
|
11
14
|
return "";
|
|
12
15
|
}
|
|
16
|
+
export default toRgba;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transform string in a URL pathname (relative URL)
|
|
3
|
+
*
|
|
4
|
+
* - adds an initial slash
|
|
5
|
+
* - encode the string
|
|
6
|
+
* - replaces whitespaces with dashes
|
|
7
|
+
*
|
|
8
|
+
* @category location
|
|
9
|
+
*/
|
|
10
|
+
export declare function transformToUrlPathname(toPathname?: string): string;
|
|
11
|
+
export default transformToUrlPathname;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import isString from "./isString";
|
|
2
|
+
/**
|
|
3
|
+
* Transform string in a URL pathname (relative URL)
|
|
4
|
+
*
|
|
5
|
+
* - adds an initial slash
|
|
6
|
+
* - encode the string
|
|
7
|
+
* - replaces whitespaces with dashes
|
|
8
|
+
*
|
|
9
|
+
* @category location
|
|
10
|
+
*/
|
|
11
|
+
export function transformToUrlPathname(toPathname) {
|
|
12
|
+
return isString(toPathname)
|
|
13
|
+
? "/".concat(encodeURIComponent(toPathname.replace(/\s/g, "-").toLowerCase()))
|
|
14
|
+
: "";
|
|
15
|
+
}
|
|
16
|
+
export default transformToUrlPathname;
|
package/truncate.d.ts
ADDED
package/truncate.js
ADDED
package/uid.d.ts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Super basic UID increment-based generator
|
|
3
|
-
*/
|
|
4
|
-
export declare const uid: (prefix?: string) => string;
|
|
5
|
-
/**
|
|
6
|
-
* Uuid, tiny custom helper instead of node's uuid/v4
|
|
7
3
|
*
|
|
8
|
-
* @
|
|
4
|
+
* @category uid
|
|
9
5
|
*/
|
|
10
|
-
export declare const
|
|
6
|
+
export declare const uid: (prefix?: string) => string;
|
|
7
|
+
export default uid;
|
package/uid.js
CHANGED
|
@@ -1,20 +1,12 @@
|
|
|
1
1
|
var lastId = 0;
|
|
2
2
|
/**
|
|
3
3
|
* Super basic UID increment-based generator
|
|
4
|
+
*
|
|
5
|
+
* @category uid
|
|
4
6
|
*/
|
|
5
7
|
export var uid = function (prefix) {
|
|
6
8
|
if (prefix === void 0) { prefix = "id"; }
|
|
7
9
|
lastId++;
|
|
8
10
|
return "".concat(prefix, "-").concat(lastId);
|
|
9
11
|
};
|
|
10
|
-
|
|
11
|
-
* Uuid, tiny custom helper instead of node's uuid/v4
|
|
12
|
-
*
|
|
13
|
-
* @see https://stackoverflow.com/a/2117523/1938970
|
|
14
|
-
*/
|
|
15
|
-
export var uuid = function () {
|
|
16
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
|
|
17
|
-
var r = (Math.random() * 16) | 0, v = c == "x" ? r : (r & 0x3) | 0x8;
|
|
18
|
-
return v.toString(16);
|
|
19
|
-
});
|
|
20
|
-
};
|
|
12
|
+
export default uid;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type AnyQueryParams } from "./location";
|
|
2
|
+
/**
|
|
3
|
+
* Update link `<a href="">` merging the given new query parameters.
|
|
4
|
+
* it returns the newly created `href` URL value
|
|
5
|
+
*
|
|
6
|
+
* @category location
|
|
7
|
+
* @pure
|
|
8
|
+
*/
|
|
9
|
+
export declare function updateLinkParams($anchor: HTMLAnchorElement, newParams: NonNullable<AnyQueryParams>): string;
|
|
10
|
+
export default updateLinkParams;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import updateUrlQueryParams from "./updateUrlQueryParams";
|
|
2
|
+
/**
|
|
3
|
+
* Update link `<a href="">` merging the given new query parameters.
|
|
4
|
+
* it returns the newly created `href` URL value
|
|
5
|
+
*
|
|
6
|
+
* @category location
|
|
7
|
+
* @pure
|
|
8
|
+
*/
|
|
9
|
+
export function updateLinkParams($anchor, newParams) {
|
|
10
|
+
var href = updateUrlQueryParams($anchor.href, newParams);
|
|
11
|
+
$anchor.href = href;
|
|
12
|
+
return href;
|
|
13
|
+
}
|
|
14
|
+
export default updateLinkParams;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type AnyQueryParams } from "./location";
|
|
2
|
+
/**
|
|
3
|
+
* Update a URL string query parameters merging the given new query parameters
|
|
4
|
+
*
|
|
5
|
+
* @category location
|
|
6
|
+
* @pure
|
|
7
|
+
*/
|
|
8
|
+
export declare function updateUrlQueryParams(url: string, newParams?: NonNullable<AnyQueryParams>): string;
|
|
9
|
+
export default updateUrlQueryParams;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import buildUrlQueryString from "./buildUrlQueryString";
|
|
2
|
+
import getUrlQueryParams from "./getUrlQueryParams";
|
|
3
|
+
import mergeUrlQueryParams from "./mergeUrlQueryParams";
|
|
4
|
+
/**
|
|
5
|
+
* Update a URL string query parameters merging the given new query parameters
|
|
6
|
+
*
|
|
7
|
+
* @category location
|
|
8
|
+
* @pure
|
|
9
|
+
*/
|
|
10
|
+
export function updateUrlQueryParams(url, newParams) {
|
|
11
|
+
if (newParams === void 0) { newParams = {}; }
|
|
12
|
+
var parts = url.split("?");
|
|
13
|
+
var allParams = parts[1]
|
|
14
|
+
? mergeUrlQueryParams(getUrlQueryParams(url), newParams)
|
|
15
|
+
: newParams;
|
|
16
|
+
return parts[0] + buildUrlQueryString(allParams);
|
|
17
|
+
}
|
|
18
|
+
export default updateUrlQueryParams;
|
package/uuid.d.ts
ADDED
package/uuid.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Uuid, tiny custom helper instead of node's uuid/v4
|
|
3
|
+
*
|
|
4
|
+
* @category uid
|
|
5
|
+
* @see https://stackoverflow.com/a/2117523/1938970
|
|
6
|
+
*/
|
|
7
|
+
export var uuid = function () {
|
|
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;
|
|
10
|
+
return v.toString(16);
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
export default uuid;
|
package/wait.d.ts
ADDED
package/wait.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whitelist an object properties by selecting only the given keys, it returns a
|
|
3
|
+
* new object.
|
|
4
|
+
*
|
|
5
|
+
* @category objects
|
|
6
|
+
*/
|
|
7
|
+
export declare function whitelistObject<T extends object, Keys extends (keyof T)[]>(object: T, keys: Keys): Pick<T, Keys[number]>;
|
|
8
|
+
export default whitelistObject;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whitelist an object properties by selecting only the given keys, it returns a
|
|
3
|
+
* new object.
|
|
4
|
+
*
|
|
5
|
+
* @category objects
|
|
6
|
+
*/
|
|
7
|
+
export function whitelistObject(object, keys) {
|
|
8
|
+
var output = {};
|
|
9
|
+
var len = keys.length;
|
|
10
|
+
while (len--) {
|
|
11
|
+
output[keys[len]] = object[keys[len]];
|
|
12
|
+
}
|
|
13
|
+
return output;
|
|
14
|
+
}
|
|
15
|
+
export default whitelistObject;
|
package/arrays.d.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Creates an array of shuffled values, using a version of the
|
|
3
|
-
* [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
|
|
4
|
-
*
|
|
5
|
-
* @see lodash.shuffle
|
|
6
|
-
* @since 0.1.0
|
|
7
|
-
* @category Array
|
|
8
|
-
* @param {Array} array The array to shuffle.
|
|
9
|
-
* @returns {Array} Returns the new shuffled array.
|
|
10
|
-
* @example
|
|
11
|
-
*
|
|
12
|
-
* shuffle([1, 2, 3, 4])
|
|
13
|
-
* // => [4, 1, 3, 2]
|
|
14
|
-
*/
|
|
15
|
-
export declare function shuffle<T>(array: T[]): T[];
|
|
16
|
-
/**
|
|
17
|
-
* Maps an array of objects into a map keyed with the given key
|
|
18
|
-
*/
|
|
19
|
-
export declare function mapListBy<T extends Record<string | number | symbol, any>>(array?: T[], key?: keyof T): Record<T[keyof T], T>;
|
|
20
|
-
/**
|
|
21
|
-
* Maps a simple flat array to a lookup dictionary object
|
|
22
|
-
*/
|
|
23
|
-
export declare function arrayToLookup<T extends string | number | symbol>(array?: T[]): Record<T, 1>;
|
|
24
|
-
/**
|
|
25
|
-
* Remove duplicated array objects, equality is determined by a strict (`===`)
|
|
26
|
-
* comparison of each object's given key
|
|
27
|
-
*/
|
|
28
|
-
export declare function removeDuplicatesByKey<T extends Record<string | number | symbol, any>>(array?: T[], key?: keyof T): T[];
|
|
29
|
-
export declare function addOrReplaceAtIdx<T>(list: T[], newItem: T, newIdx?: number): T[];
|
|
30
|
-
/**
|
|
31
|
-
* @see https://stackoverflow.com/a/40682136/1938970
|
|
32
|
-
*/
|
|
33
|
-
export declare function chunkBySize<T>(arr: T[], size: number): T[][];
|
|
34
|
-
/**
|
|
35
|
-
* TODO: untested
|
|
36
|
-
* @see https://stackoverflow.com/a/8189268/1938970
|
|
37
|
-
*/
|
|
38
|
-
export declare function chunkByChunks<T>(arr: T[], nrOfChunks: number, balanced?: boolean): T[][];
|
|
39
|
-
export declare function removeDuplicatesComparing<T>(from: any[], to: T[]): T[];
|
|
40
|
-
export declare function findDuplicatedIndexes(arr: any[]): Record<number, true>;
|
|
41
|
-
export declare function removeIndexesFromArray<T>(arr: T[], indexes: Record<number, true>): T[];
|