@ntnyq/utils 0.9.1 → 0.9.2
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/dist/index.d.ts +8 -1
- package/dist/index.js +25 -13
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -65,6 +65,13 @@ declare function isError(value: unknown): value is Error;
|
|
|
65
65
|
declare function isNativePromise<T = unknown>(value: unknown): value is Promise<T>;
|
|
66
66
|
declare function isPromise<T = unknown>(value: unknown): value is Promise<T>;
|
|
67
67
|
declare function isIterable<T = unknown>(value: unknown): value is Iterable<T>;
|
|
68
|
+
declare function isBlob(value: unknown): value is Blob;
|
|
69
|
+
declare function isFormData(value: unknown): value is FormData;
|
|
70
|
+
declare function isFile(value: unknown): value is File;
|
|
71
|
+
type UrlString = string & {
|
|
72
|
+
readonly __brand: "UrlString";
|
|
73
|
+
};
|
|
74
|
+
declare function isUrlString(value: unknown): value is UrlString;
|
|
68
75
|
//#endregion
|
|
69
76
|
//#region src/is/isDeepEqual.d.ts
|
|
70
77
|
/**
|
|
@@ -857,4 +864,4 @@ declare const RE_LINE_COMMENT: RegExp;
|
|
|
857
864
|
*/
|
|
858
865
|
declare const RE_BLOCK_COMMENT: RegExp;
|
|
859
866
|
//#endregion
|
|
860
|
-
export { AnyFn, Arrayable, Awaitable, Callable, CleanObjectOptions, Color, CreatePadStringOptions, DeepRequired, ElementOf, GetStringSimilarityOptions, InteropModuleDefault, JsonArray, JsonObject, JsonPrimitive, JsonValue, LiteralUnion, MayBe, Merge, NOOP, NonEmptyObject, NonEmptyString, Nullable, OpenExternalURLOptions, Overwrite, Prettify, PrettifyV2, Primitive, RE_BLOCK_COMMENT, RE_COMMENTS, RE_LINE_COMMENT, RamdomNumberOptions, ResolvedOptions, SPECIAL_CHAR, STORAGE_UNITS, SortObjectOptions, StorageUnit, TIME_UNITS, ThrottleDebounceOptions, TimeUnit, ToIntegerOptions, ValueOf, Whitespace, at, cAF, chunk, clamp, cleanObject, convertFromBytes, convertFromMilliseconds, convertStorageUnit, convertTimeUnit, convertToBytes, convertToMilliseconds, createPadString, debounce, enhance, ensurePrefix, ensureSuffix, escapeHTML, flattenArrayable, getObjectType, getRoot, getStringLength, getStringSimilarity, hasOwn, interopDefault, intersect, isArray, isArrayEqual, isBigInt, isBoolean, isBrowser, isDeepEqual, isElementVisibleInViewport, isEmptyArray, isEmptyMap, isEmptyObject, isEmptySet, isEmptyString, isEmptyStringOrWhitespace, isError, isFunction, isHTMLElement, isInteger, isIterable, isMap, isNaN, isNativePromise, isNil, isNonEmptyArray, isNonEmptyString, isNull, isNullOrUndefined, isNumber, isNumbericString, isObject, isPromise, isRegExp, isSet, isString, isTruthy, isUndefined, isWhitespaceString, isZero, join, last, mergeArrayable, noop, omit, once, openExternalURL, pick, rAF, randomHexColor, randomNumber, randomRGBAColor, randomRGBColor, randomString, removeFileExtension, resolveSubOptions, scrollElementIntoView, slash, slugify, sortObject, throttle, toArray, toInteger, unescapeHTML, unindent, unique, uniqueBy, waitFor, warnOnce };
|
|
867
|
+
export { AnyFn, Arrayable, Awaitable, Callable, CleanObjectOptions, Color, CreatePadStringOptions, DeepRequired, ElementOf, GetStringSimilarityOptions, InteropModuleDefault, JsonArray, JsonObject, JsonPrimitive, JsonValue, LiteralUnion, MayBe, Merge, NOOP, NonEmptyObject, NonEmptyString, Nullable, OpenExternalURLOptions, Overwrite, Prettify, PrettifyV2, Primitive, RE_BLOCK_COMMENT, RE_COMMENTS, RE_LINE_COMMENT, RamdomNumberOptions, ResolvedOptions, SPECIAL_CHAR, STORAGE_UNITS, SortObjectOptions, StorageUnit, TIME_UNITS, ThrottleDebounceOptions, TimeUnit, ToIntegerOptions, UrlString, ValueOf, Whitespace, at, cAF, chunk, clamp, cleanObject, convertFromBytes, convertFromMilliseconds, convertStorageUnit, convertTimeUnit, convertToBytes, convertToMilliseconds, createPadString, debounce, enhance, ensurePrefix, ensureSuffix, escapeHTML, flattenArrayable, getObjectType, getRoot, getStringLength, getStringSimilarity, hasOwn, interopDefault, intersect, isArray, isArrayEqual, isBigInt, isBlob, isBoolean, isBrowser, isDeepEqual, isElementVisibleInViewport, isEmptyArray, isEmptyMap, isEmptyObject, isEmptySet, isEmptyString, isEmptyStringOrWhitespace, isError, isFile, isFormData, isFunction, isHTMLElement, isInteger, isIterable, isMap, isNaN, isNativePromise, isNil, isNonEmptyArray, isNonEmptyString, isNull, isNullOrUndefined, isNumber, isNumbericString, isObject, isPromise, isRegExp, isSet, isString, isTruthy, isUndefined, isUrlString, isWhitespaceString, isZero, join, last, mergeArrayable, noop, omit, once, openExternalURL, pick, rAF, randomHexColor, randomNumber, randomRGBAColor, randomRGBColor, randomString, removeFileExtension, resolveSubOptions, scrollElementIntoView, slash, slugify, sortObject, throttle, toArray, toInteger, unescapeHTML, unindent, unique, uniqueBy, waitFor, warnOnce };
|
package/dist/index.js
CHANGED
|
@@ -139,6 +139,24 @@ function isPromise(value) {
|
|
|
139
139
|
function isIterable(value) {
|
|
140
140
|
return isFunction(value?.[Symbol.iterator]);
|
|
141
141
|
}
|
|
142
|
+
function isBlob(value) {
|
|
143
|
+
return getObjectType(value) === "Blob";
|
|
144
|
+
}
|
|
145
|
+
function isFormData(value) {
|
|
146
|
+
return getObjectType(value) === "FormData";
|
|
147
|
+
}
|
|
148
|
+
function isFile(value) {
|
|
149
|
+
return getObjectType(value) === "File";
|
|
150
|
+
}
|
|
151
|
+
function isUrlString(value) {
|
|
152
|
+
if (!isString(value)) return false;
|
|
153
|
+
try {
|
|
154
|
+
new URL(value);
|
|
155
|
+
return true;
|
|
156
|
+
} catch {
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
142
160
|
|
|
143
161
|
//#endregion
|
|
144
162
|
//#region src/is/isDeepEqual.ts
|
|
@@ -178,9 +196,7 @@ function scrollElementIntoView(element, options = {}) {
|
|
|
178
196
|
}
|
|
179
197
|
const parentRect = parent.getBoundingClientRect();
|
|
180
198
|
const elementRect = element.getBoundingClientRect();
|
|
181
|
-
|
|
182
|
-
const isOutOfView = isHorizontal ? elementRect.left < parentRect.left || elementRect.right > parentRect.right : elementRect.top < parentRect.top || elementRect.bottom > parentRect.bottom;
|
|
183
|
-
if (isOutOfView) parent.scrollIntoView(scrollIntoViewOptions);
|
|
199
|
+
if (parent.scrollWidth > parent.scrollHeight ? elementRect.left < parentRect.left || elementRect.right > parentRect.right : elementRect.top < parentRect.top || elementRect.bottom > parentRect.bottom) parent.scrollIntoView(scrollIntoViewOptions);
|
|
184
200
|
}
|
|
185
201
|
|
|
186
202
|
//#endregion
|
|
@@ -193,8 +209,7 @@ function scrollElementIntoView(element, options = {}) {
|
|
|
193
209
|
*/
|
|
194
210
|
function openExternalURL(url, options = {}) {
|
|
195
211
|
const { target = "_blank" } = options;
|
|
196
|
-
|
|
197
|
-
return proxy;
|
|
212
|
+
return window.open(url, target);
|
|
198
213
|
}
|
|
199
214
|
|
|
200
215
|
//#endregion
|
|
@@ -290,8 +305,7 @@ function getRoot() {
|
|
|
290
305
|
*/
|
|
291
306
|
function rAF(fn) {
|
|
292
307
|
const root = getRoot();
|
|
293
|
-
|
|
294
|
-
return raf.call(root, fn);
|
|
308
|
+
return root.requestAnimationFrame.call(root, fn);
|
|
295
309
|
}
|
|
296
310
|
/**
|
|
297
311
|
* Cancel animation frame
|
|
@@ -301,8 +315,7 @@ function rAF(fn) {
|
|
|
301
315
|
*/
|
|
302
316
|
function cAF(id) {
|
|
303
317
|
const root = getRoot();
|
|
304
|
-
|
|
305
|
-
return caf.call(root, id);
|
|
318
|
+
return root.cancelAnimationFrame.call(root, id);
|
|
306
319
|
}
|
|
307
320
|
|
|
308
321
|
//#endregion
|
|
@@ -545,7 +558,7 @@ function convertStorageUnit(value, fromUnit, toUnit) {
|
|
|
545
558
|
*/
|
|
546
559
|
function at(array, index) {
|
|
547
560
|
const length = array.length;
|
|
548
|
-
if (!length) return
|
|
561
|
+
if (!length) return;
|
|
549
562
|
if (index < 0) index += length;
|
|
550
563
|
return array[index];
|
|
551
564
|
}
|
|
@@ -590,8 +603,7 @@ function unique(array) {
|
|
|
590
603
|
*/
|
|
591
604
|
function uniqueBy(array, equalFn) {
|
|
592
605
|
return array.reduce((acc, cur) => {
|
|
593
|
-
|
|
594
|
-
if (idx === -1) acc.push(cur);
|
|
606
|
+
if (acc.findIndex((item) => equalFn(item, cur)) === -1) acc.push(cur);
|
|
595
607
|
return acc;
|
|
596
608
|
}, []);
|
|
597
609
|
}
|
|
@@ -1165,4 +1177,4 @@ const RE_LINE_COMMENT = /\/\/.*/;
|
|
|
1165
1177
|
const RE_BLOCK_COMMENT = /\/\*[\s\S]*?\*\//g;
|
|
1166
1178
|
|
|
1167
1179
|
//#endregion
|
|
1168
|
-
export { Color, NOOP, RE_BLOCK_COMMENT, RE_COMMENTS, RE_LINE_COMMENT, SPECIAL_CHAR, STORAGE_UNITS, TIME_UNITS, at, cAF, chunk, clamp, cleanObject, convertFromBytes, convertFromMilliseconds, convertStorageUnit, convertTimeUnit, convertToBytes, convertToMilliseconds, createPadString, debounce, enhance, ensurePrefix, ensureSuffix, escapeHTML, flattenArrayable, getObjectType, getRoot, getStringLength, getStringSimilarity, hasOwn, interopDefault, intersect, isArray, isArrayEqual, isBigInt, isBoolean, isBrowser, isDeepEqual, isElementVisibleInViewport, isEmptyArray, isEmptyMap, isEmptyObject, isEmptySet, isEmptyString, isEmptyStringOrWhitespace, isError, isFunction, isHTMLElement, isInteger, isIterable, isMap, isNaN, isNativePromise, isNil, isNonEmptyArray, isNonEmptyString, isNull, isNullOrUndefined, isNumber, isNumbericString, isObject, isPromise, isRegExp, isSet, isString, isTruthy, isUndefined, isWhitespaceString, isZero, join, last, mergeArrayable, noop, omit, once, openExternalURL, pick, rAF, randomHexColor, randomNumber, randomRGBAColor, randomRGBColor, randomString, removeFileExtension, resolveSubOptions, scrollElementIntoView, slash, slugify, sortObject, throttle, toArray, toInteger, unescapeHTML, unindent, unique, uniqueBy, waitFor, warnOnce };
|
|
1180
|
+
export { Color, NOOP, RE_BLOCK_COMMENT, RE_COMMENTS, RE_LINE_COMMENT, SPECIAL_CHAR, STORAGE_UNITS, TIME_UNITS, at, cAF, chunk, clamp, cleanObject, convertFromBytes, convertFromMilliseconds, convertStorageUnit, convertTimeUnit, convertToBytes, convertToMilliseconds, createPadString, debounce, enhance, ensurePrefix, ensureSuffix, escapeHTML, flattenArrayable, getObjectType, getRoot, getStringLength, getStringSimilarity, hasOwn, interopDefault, intersect, isArray, isArrayEqual, isBigInt, isBlob, isBoolean, isBrowser, isDeepEqual, isElementVisibleInViewport, isEmptyArray, isEmptyMap, isEmptyObject, isEmptySet, isEmptyString, isEmptyStringOrWhitespace, isError, isFile, isFormData, isFunction, isHTMLElement, isInteger, isIterable, isMap, isNaN, isNativePromise, isNil, isNonEmptyArray, isNonEmptyString, isNull, isNullOrUndefined, isNumber, isNumbericString, isObject, isPromise, isRegExp, isSet, isString, isTruthy, isUndefined, isUrlString, isWhitespaceString, isZero, join, last, mergeArrayable, noop, omit, once, openExternalURL, pick, rAF, randomHexColor, randomNumber, randomRGBAColor, randomRGBColor, randomString, removeFileExtension, resolveSubOptions, scrollElementIntoView, slash, slugify, sortObject, throttle, toArray, toInteger, unescapeHTML, unindent, unique, uniqueBy, waitFor, warnOnce };
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ntnyq/utils",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.9.
|
|
5
|
-
"packageManager": "pnpm@10.
|
|
4
|
+
"version": "0.9.2",
|
|
5
|
+
"packageManager": "pnpm@10.16.1",
|
|
6
6
|
"description": "Common used utils.",
|
|
7
7
|
"keywords": [
|
|
8
8
|
"utils"
|
|
@@ -43,15 +43,15 @@
|
|
|
43
43
|
"typecheck": "tsc --noEmit"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@ntnyq/eslint-config": "^5.
|
|
46
|
+
"@ntnyq/eslint-config": "^5.5.0",
|
|
47
47
|
"@ntnyq/prettier-config": "^3.0.1",
|
|
48
48
|
"bumpp": "^10.2.3",
|
|
49
|
-
"eslint": "^9.
|
|
49
|
+
"eslint": "^9.35.0",
|
|
50
50
|
"husky": "^9.1.7",
|
|
51
51
|
"nano-staged": "^0.8.0",
|
|
52
52
|
"npm-run-all2": "^8.0.4",
|
|
53
53
|
"prettier": "^3.6.2",
|
|
54
|
-
"tsdown": "^0.
|
|
54
|
+
"tsdown": "^0.15.1",
|
|
55
55
|
"typescript": "^5.9.2",
|
|
56
56
|
"vitest": "^3.2.4"
|
|
57
57
|
},
|