@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
package/is.js
DELETED
|
@@ -1,376 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file
|
|
3
|
-
*
|
|
4
|
-
* Same as [is-what](https://github.com/mesqueeb/is-what) plus:
|
|
5
|
-
*
|
|
6
|
-
* - `isFormData`
|
|
7
|
-
* - `isInt`
|
|
8
|
-
* - `isFloat`
|
|
9
|
-
*/
|
|
10
|
-
/**
|
|
11
|
-
* Returns the object type of the given payload
|
|
12
|
-
*
|
|
13
|
-
* @param {*} payload
|
|
14
|
-
* @returns {string}
|
|
15
|
-
*/
|
|
16
|
-
export function getType(payload) {
|
|
17
|
-
return Object.prototype.toString.call(payload).slice(8, -1);
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Returns whether the payload is undefined
|
|
21
|
-
*
|
|
22
|
-
* @param {*} payload
|
|
23
|
-
* @returns {payload is undefined}
|
|
24
|
-
*/
|
|
25
|
-
export function isUndefined(payload) {
|
|
26
|
-
return getType(payload) === "Undefined";
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Returns whether the payload is null
|
|
30
|
-
*
|
|
31
|
-
* @param {*} payload
|
|
32
|
-
* @returns {payload is null}
|
|
33
|
-
*/
|
|
34
|
-
export function isNull(payload) {
|
|
35
|
-
return getType(payload) === "Null";
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Returns whether the payload is a plain JavaScript object (excluding special classes or objects with other prototypes)
|
|
39
|
-
*
|
|
40
|
-
* @param {*} payload
|
|
41
|
-
* @returns {payload is PlainObject}
|
|
42
|
-
*/
|
|
43
|
-
export function isPlainObject(payload) {
|
|
44
|
-
if (getType(payload) !== "Object")
|
|
45
|
-
return false;
|
|
46
|
-
return (payload.constructor === Object &&
|
|
47
|
-
Object.getPrototypeOf(payload) === Object.prototype);
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Returns whether the payload is a plain JavaScript object (excluding special classes or objects with other prototypes)
|
|
51
|
-
*
|
|
52
|
-
* @param {*} payload
|
|
53
|
-
* @returns {payload is PlainObject}
|
|
54
|
-
*/
|
|
55
|
-
export function isObject(payload) {
|
|
56
|
-
return isPlainObject(payload);
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Returns whether the payload is a an empty object (excluding special classes or objects with other prototypes)
|
|
60
|
-
*
|
|
61
|
-
* @param {*} payload
|
|
62
|
-
* @returns {payload is { [K in any]: never }}
|
|
63
|
-
*/
|
|
64
|
-
export function isEmptyObject(payload) {
|
|
65
|
-
return isPlainObject(payload) && Object.keys(payload).length === 0;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Returns whether the payload is a an empty object (excluding special classes or objects with other prototypes)
|
|
69
|
-
*
|
|
70
|
-
* @param {*} payload
|
|
71
|
-
* @returns {payload is PlainObject}
|
|
72
|
-
*/
|
|
73
|
-
export function isFullObject(payload) {
|
|
74
|
-
return isPlainObject(payload) && Object.keys(payload).length > 0;
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Returns whether the payload is an any kind of object (including special classes or objects with different prototypes)
|
|
78
|
-
*
|
|
79
|
-
* @param {*} payload
|
|
80
|
-
* @returns {payload is PlainObject}
|
|
81
|
-
*/
|
|
82
|
-
export function isAnyObject(payload) {
|
|
83
|
-
return getType(payload) === "Object";
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Returns whether the payload is an object like a type passed in < >
|
|
87
|
-
*
|
|
88
|
-
* Usage: isObjectLike<{id: any}>(payload) // will make sure it's an object and has an `id` prop.
|
|
89
|
-
*
|
|
90
|
-
* @template T this must be passed in < >
|
|
91
|
-
* @param {*} payload
|
|
92
|
-
* @returns {payload is T}
|
|
93
|
-
*/
|
|
94
|
-
export function isObjectLike(payload) {
|
|
95
|
-
return isAnyObject(payload);
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Returns whether the payload is a function (regular or async)
|
|
99
|
-
*
|
|
100
|
-
* @param {*} payload
|
|
101
|
-
* @returns {payload is AnyFunction}
|
|
102
|
-
*/
|
|
103
|
-
export function isFunction(payload) {
|
|
104
|
-
return typeof payload === "function";
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Returns whether the payload is an array
|
|
108
|
-
*
|
|
109
|
-
* @param {any} payload
|
|
110
|
-
* @returns {payload is any[]}
|
|
111
|
-
*/
|
|
112
|
-
export function isArray(payload) {
|
|
113
|
-
return getType(payload) === "Array";
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Returns whether the payload is a an array with at least 1 item
|
|
117
|
-
*
|
|
118
|
-
* @param {*} payload
|
|
119
|
-
* @returns {payload is any[]}
|
|
120
|
-
*/
|
|
121
|
-
export function isFullArray(payload) {
|
|
122
|
-
return isArray(payload) && payload.length > 0;
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Returns whether the payload is a an empty array
|
|
126
|
-
*
|
|
127
|
-
* @param {*} payload
|
|
128
|
-
* @returns {payload is []}
|
|
129
|
-
*/
|
|
130
|
-
export function isEmptyArray(payload) {
|
|
131
|
-
return isArray(payload) && payload.length === 0;
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Returns whether the payload is a string
|
|
135
|
-
*
|
|
136
|
-
* @param {*} payload
|
|
137
|
-
* @returns {payload is string}
|
|
138
|
-
*/
|
|
139
|
-
export function isString(payload) {
|
|
140
|
-
return getType(payload) === "String";
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Returns whether the payload is a string, BUT returns false for ''
|
|
144
|
-
*
|
|
145
|
-
* @param {*} payload
|
|
146
|
-
* @returns {payload is string}
|
|
147
|
-
*/
|
|
148
|
-
export function isFullString(payload) {
|
|
149
|
-
return isString(payload) && payload !== "";
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* Returns whether the payload is ''
|
|
153
|
-
*
|
|
154
|
-
* @param {*} payload
|
|
155
|
-
* @returns {payload is string}
|
|
156
|
-
*/
|
|
157
|
-
export function isEmptyString(payload) {
|
|
158
|
-
return payload === "";
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Returns whether the payload is a number (but not NaN)
|
|
162
|
-
*
|
|
163
|
-
* This will return `false` for `NaN`!!
|
|
164
|
-
*
|
|
165
|
-
* @param {*} payload
|
|
166
|
-
* @returns {payload is number}
|
|
167
|
-
*/
|
|
168
|
-
export function isNumber(payload) {
|
|
169
|
-
return getType(payload) === "Number" && !isNaN(payload);
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Returns whether the payload is a positive number (but not 0)
|
|
173
|
-
*
|
|
174
|
-
* @param {*} payload
|
|
175
|
-
* @returns {payload is number}
|
|
176
|
-
*/
|
|
177
|
-
export function isPositiveNumber(payload) {
|
|
178
|
-
return isNumber(payload) && payload > 0;
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* Returns whether the payload is a negative number (but not 0)
|
|
182
|
-
*
|
|
183
|
-
* @param {*} payload
|
|
184
|
-
* @returns {payload is number}
|
|
185
|
-
*/
|
|
186
|
-
export function isNegativeNumber(payload) {
|
|
187
|
-
return isNumber(payload) && payload < 0;
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* Returns whether the payload is a boolean
|
|
191
|
-
*
|
|
192
|
-
* @param {*} payload
|
|
193
|
-
* @returns {payload is boolean}
|
|
194
|
-
*/
|
|
195
|
-
export function isBoolean(payload) {
|
|
196
|
-
return getType(payload) === "Boolean";
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* Returns whether the payload is a regular expression (RegExp)
|
|
200
|
-
*
|
|
201
|
-
* @param {*} payload
|
|
202
|
-
* @returns {payload is RegExp}
|
|
203
|
-
*/
|
|
204
|
-
export function isRegExp(payload) {
|
|
205
|
-
return getType(payload) === "RegExp";
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* Returns whether the payload is a Map
|
|
209
|
-
*
|
|
210
|
-
* @param {*} payload
|
|
211
|
-
* @returns {payload is Map<any, any>}
|
|
212
|
-
*/
|
|
213
|
-
export function isMap(payload) {
|
|
214
|
-
return getType(payload) === "Map";
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* Returns whether the payload is a WeakMap
|
|
218
|
-
*
|
|
219
|
-
* @param {*} payload
|
|
220
|
-
* @returns {payload is WeakMap<any, any>}
|
|
221
|
-
*/
|
|
222
|
-
export function isWeakMap(payload) {
|
|
223
|
-
return getType(payload) === "WeakMap";
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* Returns whether the payload is a Set
|
|
227
|
-
*
|
|
228
|
-
* @param {*} payload
|
|
229
|
-
* @returns {payload is Set<any>}
|
|
230
|
-
*/
|
|
231
|
-
export function isSet(payload) {
|
|
232
|
-
return getType(payload) === "Set";
|
|
233
|
-
}
|
|
234
|
-
/**
|
|
235
|
-
* Returns whether the payload is a WeakSet
|
|
236
|
-
*
|
|
237
|
-
* @param {*} payload
|
|
238
|
-
* @returns {payload is WeakSet<any>}
|
|
239
|
-
*/
|
|
240
|
-
export function isWeakSet(payload) {
|
|
241
|
-
return getType(payload) === "WeakSet";
|
|
242
|
-
}
|
|
243
|
-
/**
|
|
244
|
-
* Returns whether the payload is a Symbol
|
|
245
|
-
*
|
|
246
|
-
* @param {*} payload
|
|
247
|
-
* @returns {payload is symbol}
|
|
248
|
-
*/
|
|
249
|
-
export function isSymbol(payload) {
|
|
250
|
-
return getType(payload) === "Symbol";
|
|
251
|
-
}
|
|
252
|
-
/**
|
|
253
|
-
* Returns whether the payload is a Date, and that the date is valid
|
|
254
|
-
*
|
|
255
|
-
* @param {*} payload
|
|
256
|
-
* @returns {payload is Date}
|
|
257
|
-
*/
|
|
258
|
-
export function isDate(payload) {
|
|
259
|
-
return getType(payload) === "Date" && !isNaN(payload);
|
|
260
|
-
}
|
|
261
|
-
/**
|
|
262
|
-
* Returns whether the payload is a Blob
|
|
263
|
-
*
|
|
264
|
-
* @param {*} payload
|
|
265
|
-
* @returns {payload is Blob}
|
|
266
|
-
*/
|
|
267
|
-
export function isBlob(payload) {
|
|
268
|
-
return getType(payload) === "Blob";
|
|
269
|
-
}
|
|
270
|
-
/**
|
|
271
|
-
* Returns whether the payload is a File
|
|
272
|
-
*
|
|
273
|
-
* @param {*} payload
|
|
274
|
-
* @returns {payload is File}
|
|
275
|
-
*/
|
|
276
|
-
export function isFile(payload) {
|
|
277
|
-
return getType(payload) === "File";
|
|
278
|
-
}
|
|
279
|
-
/**
|
|
280
|
-
* Returns whether the payload is a Promise
|
|
281
|
-
*
|
|
282
|
-
* @param {*} payload
|
|
283
|
-
* @returns {payload is Promise<any>}
|
|
284
|
-
*/
|
|
285
|
-
export function isPromise(payload) {
|
|
286
|
-
return getType(payload) === "Promise";
|
|
287
|
-
}
|
|
288
|
-
/**
|
|
289
|
-
* Returns whether the payload is an Error
|
|
290
|
-
*
|
|
291
|
-
* @param {*} payload
|
|
292
|
-
* @returns {payload is Error}
|
|
293
|
-
*/
|
|
294
|
-
export function isError(payload) {
|
|
295
|
-
return getType(payload) === "Error";
|
|
296
|
-
}
|
|
297
|
-
/**
|
|
298
|
-
* Returns whether the payload is literally the value `NaN` (it's `NaN` and also a `number`)
|
|
299
|
-
*
|
|
300
|
-
* @param {*} payload
|
|
301
|
-
* @returns {payload is typeof NaN}
|
|
302
|
-
*/
|
|
303
|
-
export function isNaNValue(payload) {
|
|
304
|
-
return getType(payload) === "Number" && isNaN(payload);
|
|
305
|
-
}
|
|
306
|
-
/**
|
|
307
|
-
* Returns whether the payload is a primitive type (eg. Boolean | Null | Undefined | Number | String | Symbol)
|
|
308
|
-
*
|
|
309
|
-
* @param {*} payload
|
|
310
|
-
* @returns {(payload is boolean | null | undefined | number | string | symbol)}
|
|
311
|
-
*/
|
|
312
|
-
export function isPrimitive(payload) {
|
|
313
|
-
return (isBoolean(payload) ||
|
|
314
|
-
isNull(payload) ||
|
|
315
|
-
isUndefined(payload) ||
|
|
316
|
-
isNumber(payload) ||
|
|
317
|
-
isString(payload) ||
|
|
318
|
-
isSymbol(payload));
|
|
319
|
-
}
|
|
320
|
-
/**
|
|
321
|
-
* Returns true whether the payload is null or undefined
|
|
322
|
-
*
|
|
323
|
-
* @param {*} payload
|
|
324
|
-
* @returns {(payload is null | undefined)}
|
|
325
|
-
*/
|
|
326
|
-
export var isNullOrUndefined = isOneOf(isNull, isUndefined);
|
|
327
|
-
export function isOneOf(a, b, c, d, e) {
|
|
328
|
-
return function (value) {
|
|
329
|
-
return a(value) ||
|
|
330
|
-
b(value) ||
|
|
331
|
-
(!!c && c(value)) ||
|
|
332
|
-
(!!d && d(value)) ||
|
|
333
|
-
(!!e && e(value));
|
|
334
|
-
};
|
|
335
|
-
}
|
|
336
|
-
/**
|
|
337
|
-
* Does a generic check to check that the given payload is of a given type.
|
|
338
|
-
* In cases like Number, it will return true for NaN as NaN is a Number (thanks javascript!);
|
|
339
|
-
* It will, however, differentiate between object and null
|
|
340
|
-
*
|
|
341
|
-
* @template T
|
|
342
|
-
* @param {*} payload
|
|
343
|
-
* @param {T} type
|
|
344
|
-
* @throws {TypeError} Will throw type error if type is an invalid type
|
|
345
|
-
* @returns {payload is T}
|
|
346
|
-
*/
|
|
347
|
-
export function isType(payload, type) {
|
|
348
|
-
if (!(type instanceof Function)) {
|
|
349
|
-
throw new TypeError("Type must be a function");
|
|
350
|
-
}
|
|
351
|
-
if (!Object.prototype.hasOwnProperty.call(type, "prototype")) {
|
|
352
|
-
throw new TypeError("Type is not a class");
|
|
353
|
-
}
|
|
354
|
-
// Classes usually have names (as functions usually have names)
|
|
355
|
-
var name = type.name;
|
|
356
|
-
return (getType(payload) === name ||
|
|
357
|
-
Boolean(payload && payload.constructor === type));
|
|
358
|
-
}
|
|
359
|
-
/**
|
|
360
|
-
* Returns whether the payload is a FormData
|
|
361
|
-
*/
|
|
362
|
-
export function isFormData(payload) {
|
|
363
|
-
return getType(payload) === "FormData";
|
|
364
|
-
}
|
|
365
|
-
/**
|
|
366
|
-
* Returns whether the payload is an integer number
|
|
367
|
-
*/
|
|
368
|
-
export function isInt(payload) {
|
|
369
|
-
return isNumber(payload) && payload % 1 === 0;
|
|
370
|
-
}
|
|
371
|
-
/**
|
|
372
|
-
* Returns whether the payload is a float number
|
|
373
|
-
*/
|
|
374
|
-
export function isFloat(payload) {
|
|
375
|
-
return isNumber(payload) && payload % 1 !== 0;
|
|
376
|
-
}
|
package/math.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get random int (min and max included)
|
|
3
|
-
*/
|
|
4
|
-
export declare function randomInt(min: number, max: number): number;
|
|
5
|
-
/**
|
|
6
|
-
* Returns a number whose value is limited to the given range.
|
|
7
|
-
*
|
|
8
|
-
* @see https://stackoverflow.com/a/11409944/1938970
|
|
9
|
-
*/
|
|
10
|
-
export declare function clamp(num: number, min: number, max: number): number;
|
|
11
|
-
/**
|
|
12
|
-
* Round to given number of the given number of decimals
|
|
13
|
-
*
|
|
14
|
-
* @see https://stackoverflow.com/a/15762794/1938970
|
|
15
|
-
*/
|
|
16
|
-
export declare function roundTo(num: number, decimals?: number): string;
|
|
17
|
-
/**
|
|
18
|
-
* Convert range of a number
|
|
19
|
-
*
|
|
20
|
-
* e.g. converting number 5 in a scale/range from 0 10 to a scale/range from 50
|
|
21
|
-
* to 100 would return 75
|
|
22
|
-
* ```
|
|
23
|
-
* convertRange(5, [0, 10], [50, 100]);
|
|
24
|
-
* ```
|
|
25
|
-
*
|
|
26
|
-
* @see https://stackoverflow.com/a/14224813
|
|
27
|
-
*/
|
|
28
|
-
export declare function convertRange(num: number, r1: number[], r2: number[]): number;
|
package/node/arrays.js
DELETED
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.removeIndexesFromArray = exports.findDuplicatedIndexes = exports.removeDuplicatesComparing = exports.chunkByChunks = exports.chunkBySize = exports.addOrReplaceAtIdx = exports.removeDuplicatesByKey = exports.arrayToLookup = exports.mapListBy = exports.shuffle = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
|
-
/**
|
|
6
|
-
* Creates an array of shuffled values, using a version of the
|
|
7
|
-
* [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
|
|
8
|
-
*
|
|
9
|
-
* @see lodash.shuffle
|
|
10
|
-
* @since 0.1.0
|
|
11
|
-
* @category Array
|
|
12
|
-
* @param {Array} array The array to shuffle.
|
|
13
|
-
* @returns {Array} Returns the new shuffled array.
|
|
14
|
-
* @example
|
|
15
|
-
*
|
|
16
|
-
* shuffle([1, 2, 3, 4])
|
|
17
|
-
* // => [4, 1, 3, 2]
|
|
18
|
-
*/
|
|
19
|
-
function shuffle(array) {
|
|
20
|
-
var length = array == null ? 0 : array.length;
|
|
21
|
-
if (!length) {
|
|
22
|
-
return [];
|
|
23
|
-
}
|
|
24
|
-
var index = -1;
|
|
25
|
-
var lastIndex = length - 1;
|
|
26
|
-
var result = tslib_1.__spreadArray([], array, true);
|
|
27
|
-
while (++index < length) {
|
|
28
|
-
var rand = index + Math.floor(Math.random() * (lastIndex - index + 1));
|
|
29
|
-
var value = result[rand];
|
|
30
|
-
result[rand] = result[index];
|
|
31
|
-
result[index] = value;
|
|
32
|
-
}
|
|
33
|
-
return result;
|
|
34
|
-
}
|
|
35
|
-
exports.shuffle = shuffle;
|
|
36
|
-
/**
|
|
37
|
-
* Maps an array of objects into a map keyed with the given key
|
|
38
|
-
*/
|
|
39
|
-
function mapListBy(array, key) {
|
|
40
|
-
if (array === void 0) { array = []; }
|
|
41
|
-
if (key === void 0) { key = ""; }
|
|
42
|
-
return array.reduce(function (obj, item) {
|
|
43
|
-
obj[item[key]] = item;
|
|
44
|
-
return obj;
|
|
45
|
-
}, {});
|
|
46
|
-
}
|
|
47
|
-
exports.mapListBy = mapListBy;
|
|
48
|
-
/**
|
|
49
|
-
* Maps a simple flat array to a lookup dictionary object
|
|
50
|
-
*/
|
|
51
|
-
function arrayToLookup(array) {
|
|
52
|
-
if (array === void 0) { array = []; }
|
|
53
|
-
return array.reduce(function (obj, item) {
|
|
54
|
-
obj[item] = 1;
|
|
55
|
-
return obj;
|
|
56
|
-
}, {});
|
|
57
|
-
}
|
|
58
|
-
exports.arrayToLookup = arrayToLookup;
|
|
59
|
-
/**
|
|
60
|
-
* Remove duplicated array objects, equality is determined by a strict (`===`)
|
|
61
|
-
* comparison of each object's given key
|
|
62
|
-
*/
|
|
63
|
-
function removeDuplicatesByKey(array, key) {
|
|
64
|
-
if (array === void 0) { array = []; }
|
|
65
|
-
if (key === void 0) { key = ""; }
|
|
66
|
-
var keysMap = {};
|
|
67
|
-
var output = [];
|
|
68
|
-
for (var i = 0; i < array.length; i++) {
|
|
69
|
-
var item = array[i];
|
|
70
|
-
if (!keysMap[item[key]]) {
|
|
71
|
-
output.push(item);
|
|
72
|
-
keysMap[item[key]] = true;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return output;
|
|
76
|
-
}
|
|
77
|
-
exports.removeDuplicatesByKey = removeDuplicatesByKey;
|
|
78
|
-
function addOrReplaceAtIdx(list, newItem, newIdx) {
|
|
79
|
-
if (list.length === 0) {
|
|
80
|
-
return [newItem];
|
|
81
|
-
}
|
|
82
|
-
if (typeof newIdx === "undefined" || list.length - 1 < newIdx) {
|
|
83
|
-
return tslib_1.__spreadArray(tslib_1.__spreadArray([], list, true), [newItem], false);
|
|
84
|
-
}
|
|
85
|
-
return list.map(function (item, idx) {
|
|
86
|
-
if (idx === newIdx) {
|
|
87
|
-
return newItem;
|
|
88
|
-
}
|
|
89
|
-
return item;
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
exports.addOrReplaceAtIdx = addOrReplaceAtIdx;
|
|
93
|
-
/**
|
|
94
|
-
* @see https://stackoverflow.com/a/40682136/1938970
|
|
95
|
-
*/
|
|
96
|
-
function chunkBySize(arr, size) {
|
|
97
|
-
var output = [];
|
|
98
|
-
for (var i = 0; i < arr.length; i += size) {
|
|
99
|
-
output.push(arr.slice(i, i + size));
|
|
100
|
-
}
|
|
101
|
-
return output;
|
|
102
|
-
}
|
|
103
|
-
exports.chunkBySize = chunkBySize;
|
|
104
|
-
/**
|
|
105
|
-
* TODO: untested
|
|
106
|
-
* @see https://stackoverflow.com/a/8189268/1938970
|
|
107
|
-
*/
|
|
108
|
-
function chunkByChunks(arr, nrOfChunks, balanced) {
|
|
109
|
-
if (nrOfChunks < 2)
|
|
110
|
-
return [arr];
|
|
111
|
-
var len = arr.length;
|
|
112
|
-
var output = [];
|
|
113
|
-
var i = 0;
|
|
114
|
-
var size;
|
|
115
|
-
if (len % nrOfChunks === 0) {
|
|
116
|
-
size = Math.floor(len / nrOfChunks);
|
|
117
|
-
while (i < len) {
|
|
118
|
-
output.push(arr.slice(i, (i += size)));
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
else if (balanced) {
|
|
122
|
-
while (i < len) {
|
|
123
|
-
size = Math.ceil((len - i) / nrOfChunks--);
|
|
124
|
-
output.push(arr.slice(i, (i += size)));
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
nrOfChunks--;
|
|
129
|
-
size = Math.floor(len / nrOfChunks);
|
|
130
|
-
if (len % size === 0)
|
|
131
|
-
size--;
|
|
132
|
-
while (i < size * nrOfChunks) {
|
|
133
|
-
output.push(arr.slice(i, (i += size)));
|
|
134
|
-
}
|
|
135
|
-
output.push(arr.slice(size * nrOfChunks));
|
|
136
|
-
}
|
|
137
|
-
return output;
|
|
138
|
-
}
|
|
139
|
-
exports.chunkByChunks = chunkByChunks;
|
|
140
|
-
function removeDuplicatesComparing(from, to) {
|
|
141
|
-
var indexes = findDuplicatedIndexes(from);
|
|
142
|
-
return removeIndexesFromArray(to, indexes);
|
|
143
|
-
}
|
|
144
|
-
exports.removeDuplicatesComparing = removeDuplicatesComparing;
|
|
145
|
-
function findDuplicatedIndexes(arr) {
|
|
146
|
-
var indexes = {};
|
|
147
|
-
for (var i = 0; i < arr.length; i++) {
|
|
148
|
-
var idxInArray = arr.indexOf(arr[i]);
|
|
149
|
-
if (idxInArray !== i && idxInArray !== -1) {
|
|
150
|
-
indexes[i] = true;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
return indexes;
|
|
154
|
-
}
|
|
155
|
-
exports.findDuplicatedIndexes = findDuplicatedIndexes;
|
|
156
|
-
function removeIndexesFromArray(arr, indexes) {
|
|
157
|
-
var output = [];
|
|
158
|
-
for (var i = 0; i < arr.length; i++) {
|
|
159
|
-
// eslint-disable-next-line no-prototype-builtins
|
|
160
|
-
if (!indexes.hasOwnProperty(i)) {
|
|
161
|
-
output.push(arr[i]);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
return output;
|
|
165
|
-
}
|
|
166
|
-
exports.removeIndexesFromArray = removeIndexesFromArray;
|