@ntnyq/utils 0.6.0 → 0.6.1
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.cjs +90 -7
- package/dist/index.d.cts +41 -3
- package/dist/index.d.ts +41 -3
- package/dist/index.js +82 -6
- package/package.json +7 -7
package/dist/index.cjs
CHANGED
|
@@ -22,6 +22,9 @@ var index_exports = {};
|
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
Color: () => Color,
|
|
24
24
|
NOOP: () => NOOP,
|
|
25
|
+
RE_BLOCK_COMMENT: () => RE_BLOCK_COMMENT,
|
|
26
|
+
RE_COMMENTS: () => RE_COMMENTS,
|
|
27
|
+
RE_LINE_COMMENT: () => RE_LINE_COMMENT,
|
|
25
28
|
at: () => at,
|
|
26
29
|
cAF: () => cAF,
|
|
27
30
|
chunk: () => chunk,
|
|
@@ -33,7 +36,7 @@ __export(index_exports, {
|
|
|
33
36
|
enhance: () => enhance,
|
|
34
37
|
ensurePrefix: () => ensurePrefix,
|
|
35
38
|
ensureSuffix: () => ensureSuffix,
|
|
36
|
-
|
|
39
|
+
escapeHTML: () => escapeHTML,
|
|
37
40
|
flattenArrayable: () => flattenArrayable,
|
|
38
41
|
getObjectType: () => getObjectType,
|
|
39
42
|
hasOwn: () => hasOwn,
|
|
@@ -46,6 +49,7 @@ __export(index_exports, {
|
|
|
46
49
|
isBoolean: () => isBoolean,
|
|
47
50
|
isBrowser: () => isBrowser,
|
|
48
51
|
isDeepEqual: () => isDeepEqual,
|
|
52
|
+
isElementVisibleInViewport: () => isElementVisibleInViewport,
|
|
49
53
|
isEmptyArray: () => isEmptyArray,
|
|
50
54
|
isEmptyMap: () => isEmptyMap,
|
|
51
55
|
isEmptyObject: () => isEmptyObject,
|
|
@@ -89,11 +93,14 @@ __export(index_exports, {
|
|
|
89
93
|
randomRGBColor: () => randomRGBColor,
|
|
90
94
|
randomString: () => randomString,
|
|
91
95
|
resolveSubOptions: () => resolveSubOptions,
|
|
96
|
+
scrollIntoView: () => scrollIntoView,
|
|
92
97
|
seconds: () => seconds,
|
|
93
98
|
slash: () => slash,
|
|
99
|
+
slugify: () => slugify,
|
|
94
100
|
sortObject: () => sortObject,
|
|
95
101
|
throttle: () => throttle,
|
|
96
102
|
toArray: () => toArray,
|
|
103
|
+
unescapeHTML: () => unescapeHTML,
|
|
97
104
|
unindent: () => unindent,
|
|
98
105
|
unique: () => unique,
|
|
99
106
|
uniqueBy: () => uniqueBy,
|
|
@@ -234,8 +241,8 @@ function isIterable(value) {
|
|
|
234
241
|
}
|
|
235
242
|
|
|
236
243
|
// src/fn/noop.ts
|
|
237
|
-
|
|
238
|
-
}
|
|
244
|
+
function noop() {
|
|
245
|
+
}
|
|
239
246
|
var NOOP = noop;
|
|
240
247
|
|
|
241
248
|
// src/fn/once.ts
|
|
@@ -254,6 +261,32 @@ function once(func) {
|
|
|
254
261
|
// src/env/isBrowser.ts
|
|
255
262
|
var isBrowser = () => typeof document !== "undefined";
|
|
256
263
|
|
|
264
|
+
// src/dom/scrollIntoView.ts
|
|
265
|
+
function scrollIntoView(element, parent, options = {
|
|
266
|
+
behavior: "smooth",
|
|
267
|
+
block: "center",
|
|
268
|
+
inline: "center"
|
|
269
|
+
}) {
|
|
270
|
+
if (parent === document.body) {
|
|
271
|
+
parent.scrollIntoView(options);
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
const parentRect = parent.getBoundingClientRect();
|
|
275
|
+
const elementRect = element.getBoundingClientRect();
|
|
276
|
+
const isHorizontal = parent.scrollWidth > parent.scrollHeight;
|
|
277
|
+
const isOutOfView = isHorizontal ? elementRect.left < parentRect.left || elementRect.right > parentRect.right : elementRect.top < parentRect.top || elementRect.bottom > parentRect.bottom;
|
|
278
|
+
if (isOutOfView) {
|
|
279
|
+
parent.scrollIntoView(options);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// src/dom/isVisibleInViewport.ts
|
|
284
|
+
function isElementVisibleInViewport(element, targetWindow = window) {
|
|
285
|
+
const { top, left, bottom, right } = element.getBoundingClientRect();
|
|
286
|
+
const { innerWidth, innerHeight } = targetWindow;
|
|
287
|
+
return (top >= 0 && top <= innerHeight || bottom >= 0 && bottom <= innerHeight) && (left >= 0 && left <= innerWidth || right >= 0 && right <= innerWidth);
|
|
288
|
+
}
|
|
289
|
+
|
|
257
290
|
// src/misc/raf.ts
|
|
258
291
|
var root = isBrowser() ? window : globalThis;
|
|
259
292
|
var prev = Date.now();
|
|
@@ -365,9 +398,39 @@ function warnOnce(message) {
|
|
|
365
398
|
console.warn(message);
|
|
366
399
|
}
|
|
367
400
|
|
|
368
|
-
// src/html/
|
|
369
|
-
|
|
370
|
-
|
|
401
|
+
// src/html/escape.ts
|
|
402
|
+
var htmlEscapeMap = {
|
|
403
|
+
"&": "&",
|
|
404
|
+
"<": "<",
|
|
405
|
+
">": ">",
|
|
406
|
+
"'": "'",
|
|
407
|
+
'"': """
|
|
408
|
+
};
|
|
409
|
+
var htmlEscapeRegexp = /[&<>'"]/g;
|
|
410
|
+
function escapeHTML(str) {
|
|
411
|
+
return str.replace(
|
|
412
|
+
htmlEscapeRegexp,
|
|
413
|
+
(char) => htmlEscapeMap[char]
|
|
414
|
+
);
|
|
415
|
+
}
|
|
416
|
+
var htmlUnescapeMap = {
|
|
417
|
+
"&": "&",
|
|
418
|
+
"&": "&",
|
|
419
|
+
"<": "<",
|
|
420
|
+
"<": "<",
|
|
421
|
+
">": ">",
|
|
422
|
+
">": ">",
|
|
423
|
+
"'": "'",
|
|
424
|
+
"'": "'",
|
|
425
|
+
""": '"',
|
|
426
|
+
""": '"'
|
|
427
|
+
};
|
|
428
|
+
var htmlUnescapeRegexp = /&(amp|#38|lt|#60|gt|#62|apos|#39|quot|#34);/g;
|
|
429
|
+
function unescapeHTML(str) {
|
|
430
|
+
return str.replace(
|
|
431
|
+
htmlUnescapeRegexp,
|
|
432
|
+
(char) => htmlUnescapeMap[char]
|
|
433
|
+
);
|
|
371
434
|
}
|
|
372
435
|
|
|
373
436
|
// src/array/at.ts
|
|
@@ -475,6 +538,14 @@ function randomString(length = 16, chars = "0123456789abcdefghijklmnopqrstuvwxyz
|
|
|
475
538
|
return result.join("");
|
|
476
539
|
}
|
|
477
540
|
|
|
541
|
+
// src/string/slugify.ts
|
|
542
|
+
var rControl = /[\u0000-\u001F]/g;
|
|
543
|
+
var rSpecial = /[\s~`!@#$%^&*()\-_+=[\]{}|\\;:"'“”‘’<>,.?/]+/g;
|
|
544
|
+
var rCombining = /[\u0300-\u036F]/g;
|
|
545
|
+
function slugify(str) {
|
|
546
|
+
return str.normalize("NFKD").replace(rCombining, "").replace(rControl, "").replace(rSpecial, "-").replace(/-{2,}/g, "-").replace(/^-+|-+$/g, "").replace(/^(\d)/, "_$1").toLowerCase();
|
|
547
|
+
}
|
|
548
|
+
|
|
478
549
|
// src/string/unindent.ts
|
|
479
550
|
var _RE_FULL_WS = /^\s*$/;
|
|
480
551
|
function unindent(input) {
|
|
@@ -730,10 +801,18 @@ async function interopDefault(mod) {
|
|
|
730
801
|
function resolveSubOptions(options, key) {
|
|
731
802
|
return typeof options[key] === "boolean" ? {} : options[key] || {};
|
|
732
803
|
}
|
|
804
|
+
|
|
805
|
+
// src/constants/regexp.ts
|
|
806
|
+
var RE_COMMENTS = /(?:<!--|\/\*)([\s\S]*?)(?:-->|\*\/)/g;
|
|
807
|
+
var RE_LINE_COMMENT = /\/\/.*/;
|
|
808
|
+
var RE_BLOCK_COMMENT = /\/\*[\s\S]*?\*\//g;
|
|
733
809
|
// Annotate the CommonJS export names for ESM import in node:
|
|
734
810
|
0 && (module.exports = {
|
|
735
811
|
Color,
|
|
736
812
|
NOOP,
|
|
813
|
+
RE_BLOCK_COMMENT,
|
|
814
|
+
RE_COMMENTS,
|
|
815
|
+
RE_LINE_COMMENT,
|
|
737
816
|
at,
|
|
738
817
|
cAF,
|
|
739
818
|
chunk,
|
|
@@ -745,7 +824,7 @@ function resolveSubOptions(options, key) {
|
|
|
745
824
|
enhance,
|
|
746
825
|
ensurePrefix,
|
|
747
826
|
ensureSuffix,
|
|
748
|
-
|
|
827
|
+
escapeHTML,
|
|
749
828
|
flattenArrayable,
|
|
750
829
|
getObjectType,
|
|
751
830
|
hasOwn,
|
|
@@ -758,6 +837,7 @@ function resolveSubOptions(options, key) {
|
|
|
758
837
|
isBoolean,
|
|
759
838
|
isBrowser,
|
|
760
839
|
isDeepEqual,
|
|
840
|
+
isElementVisibleInViewport,
|
|
761
841
|
isEmptyArray,
|
|
762
842
|
isEmptyMap,
|
|
763
843
|
isEmptyObject,
|
|
@@ -801,11 +881,14 @@ function resolveSubOptions(options, key) {
|
|
|
801
881
|
randomRGBColor,
|
|
802
882
|
randomString,
|
|
803
883
|
resolveSubOptions,
|
|
884
|
+
scrollIntoView,
|
|
804
885
|
seconds,
|
|
805
886
|
slash,
|
|
887
|
+
slugify,
|
|
806
888
|
sortObject,
|
|
807
889
|
throttle,
|
|
808
890
|
toArray,
|
|
891
|
+
unescapeHTML,
|
|
809
892
|
unindent,
|
|
810
893
|
unique,
|
|
811
894
|
uniqueBy,
|
package/dist/index.d.cts
CHANGED
|
@@ -48,7 +48,7 @@ declare function isIterable<T = unknown>(value: unknown): value is Iterable<T>;
|
|
|
48
48
|
/**
|
|
49
49
|
* A function that does nothing.
|
|
50
50
|
*/
|
|
51
|
-
declare
|
|
51
|
+
declare function noop(): void;
|
|
52
52
|
/**
|
|
53
53
|
* Alias of {@link noop}.
|
|
54
54
|
*/
|
|
@@ -66,6 +66,17 @@ declare function once<T extends unknown[]>(func: (...args: T) => void): (this: u
|
|
|
66
66
|
*/
|
|
67
67
|
declare const isBrowser: () => boolean;
|
|
68
68
|
|
|
69
|
+
/**
|
|
70
|
+
* Scroll element into view if it is out of view.
|
|
71
|
+
*
|
|
72
|
+
* @param element - element to scroll
|
|
73
|
+
* @param parent - parent element
|
|
74
|
+
* @param options - scroll options
|
|
75
|
+
*/
|
|
76
|
+
declare function scrollIntoView(element: HTMLElement, parent: HTMLElement, options?: ScrollIntoViewOptions): void;
|
|
77
|
+
|
|
78
|
+
declare function isElementVisibleInViewport(element: HTMLElement, targetWindow?: Window): boolean;
|
|
79
|
+
|
|
69
80
|
/**
|
|
70
81
|
* @file raf.ts
|
|
71
82
|
*/
|
|
@@ -141,7 +152,14 @@ declare function debounce<T extends ((...args: any[]) => undefined | void) | und
|
|
|
141
152
|
|
|
142
153
|
declare function warnOnce(message: string): void;
|
|
143
154
|
|
|
144
|
-
|
|
155
|
+
/**
|
|
156
|
+
* Escape html chars
|
|
157
|
+
*/
|
|
158
|
+
declare function escapeHTML(str: string): string;
|
|
159
|
+
/**
|
|
160
|
+
* Unescape html chars
|
|
161
|
+
*/
|
|
162
|
+
declare function unescapeHTML(str: string): string;
|
|
145
163
|
|
|
146
164
|
/**
|
|
147
165
|
* Get array item by index, negative for backward
|
|
@@ -355,6 +373,11 @@ declare function slash(input: string): string;
|
|
|
355
373
|
*/
|
|
356
374
|
declare function randomString(length?: number, chars?: string): string;
|
|
357
375
|
|
|
376
|
+
/**
|
|
377
|
+
* Default slugify function
|
|
378
|
+
*/
|
|
379
|
+
declare function slugify(str: string): string;
|
|
380
|
+
|
|
358
381
|
/**
|
|
359
382
|
* Remove common leading whitespace from a template string
|
|
360
383
|
* Empty lines at the beginning and end of the template string are also removed.
|
|
@@ -524,4 +547,19 @@ interface RamdomNumberOptions {
|
|
|
524
547
|
*/
|
|
525
548
|
declare function randomNumber(min: number, max?: number, options?: RamdomNumberOptions): number;
|
|
526
549
|
|
|
527
|
-
|
|
550
|
+
/**
|
|
551
|
+
* 注释正则
|
|
552
|
+
*
|
|
553
|
+
* 匹配 \<!-- 或 /* 开头的注释,直到 --> 或 *\/ 结尾
|
|
554
|
+
*/
|
|
555
|
+
declare const RE_COMMENTS: RegExp;
|
|
556
|
+
/**
|
|
557
|
+
* JavaScript line comment
|
|
558
|
+
*/
|
|
559
|
+
declare const RE_LINE_COMMENT: RegExp;
|
|
560
|
+
/**
|
|
561
|
+
* JavaScript block comment
|
|
562
|
+
*/
|
|
563
|
+
declare const RE_BLOCK_COMMENT: RegExp;
|
|
564
|
+
|
|
565
|
+
export { type AnyFn, type Arrayable, type Awaitable, type Callable, type CleanObjectOptions, Color, type CreatePadStringOptions, type InteropModuleDefault, type JsonArray, type JsonObject, type JsonPrimitive, type JsonValue, type LiteralUnion, type MayBe, NOOP, type NonEmptyObject, type NonEmptyString, type Nullable, type Overwrite, type Prettify, type PrettifyV2, type PrimitiveType, RE_BLOCK_COMMENT, RE_COMMENTS, RE_LINE_COMMENT, type RamdomNumberOptions, type ResolvedOptions, type SortObjectOptions, type ThrottleDebounceOptions, type Whitespace, at, cAF, chunk, clamp, cleanObject, createPadString, days, debounce, enhance, ensurePrefix, ensureSuffix, escapeHTML, flattenArrayable, getObjectType, hasOwn, hours, interopDefault, intersect, isArray, isArrayEqual, isBigInt, isBoolean, isBrowser, isDeepEqual, isElementVisibleInViewport, isEmptyArray, isEmptyMap, isEmptyObject, isEmptySet, isEmptyString, isEmptyStringOrWhitespace, isError, isFunction, isInteger, isIterable, isMap, isNaN, isNativePromise, isNil, isNonEmptyArray, isNonEmptyString, isNull, isNullOrUndefined, isNumber, isNumbericString, isObject, isPromise, isRegExp, isSet, isString, isUndefined, isWhitespaceString, isZero, join, last, mergeArrayable, minutes, noop, omit, once, pick, rAF, randomHexColor, randomNumber, randomRGBAColor, randomRGBColor, randomString, resolveSubOptions, scrollIntoView, seconds, slash, slugify, sortObject, throttle, toArray, unescapeHTML, unindent, unique, uniqueBy, waitFor, warnOnce, weeks };
|
package/dist/index.d.ts
CHANGED
|
@@ -48,7 +48,7 @@ declare function isIterable<T = unknown>(value: unknown): value is Iterable<T>;
|
|
|
48
48
|
/**
|
|
49
49
|
* A function that does nothing.
|
|
50
50
|
*/
|
|
51
|
-
declare
|
|
51
|
+
declare function noop(): void;
|
|
52
52
|
/**
|
|
53
53
|
* Alias of {@link noop}.
|
|
54
54
|
*/
|
|
@@ -66,6 +66,17 @@ declare function once<T extends unknown[]>(func: (...args: T) => void): (this: u
|
|
|
66
66
|
*/
|
|
67
67
|
declare const isBrowser: () => boolean;
|
|
68
68
|
|
|
69
|
+
/**
|
|
70
|
+
* Scroll element into view if it is out of view.
|
|
71
|
+
*
|
|
72
|
+
* @param element - element to scroll
|
|
73
|
+
* @param parent - parent element
|
|
74
|
+
* @param options - scroll options
|
|
75
|
+
*/
|
|
76
|
+
declare function scrollIntoView(element: HTMLElement, parent: HTMLElement, options?: ScrollIntoViewOptions): void;
|
|
77
|
+
|
|
78
|
+
declare function isElementVisibleInViewport(element: HTMLElement, targetWindow?: Window): boolean;
|
|
79
|
+
|
|
69
80
|
/**
|
|
70
81
|
* @file raf.ts
|
|
71
82
|
*/
|
|
@@ -141,7 +152,14 @@ declare function debounce<T extends ((...args: any[]) => undefined | void) | und
|
|
|
141
152
|
|
|
142
153
|
declare function warnOnce(message: string): void;
|
|
143
154
|
|
|
144
|
-
|
|
155
|
+
/**
|
|
156
|
+
* Escape html chars
|
|
157
|
+
*/
|
|
158
|
+
declare function escapeHTML(str: string): string;
|
|
159
|
+
/**
|
|
160
|
+
* Unescape html chars
|
|
161
|
+
*/
|
|
162
|
+
declare function unescapeHTML(str: string): string;
|
|
145
163
|
|
|
146
164
|
/**
|
|
147
165
|
* Get array item by index, negative for backward
|
|
@@ -355,6 +373,11 @@ declare function slash(input: string): string;
|
|
|
355
373
|
*/
|
|
356
374
|
declare function randomString(length?: number, chars?: string): string;
|
|
357
375
|
|
|
376
|
+
/**
|
|
377
|
+
* Default slugify function
|
|
378
|
+
*/
|
|
379
|
+
declare function slugify(str: string): string;
|
|
380
|
+
|
|
358
381
|
/**
|
|
359
382
|
* Remove common leading whitespace from a template string
|
|
360
383
|
* Empty lines at the beginning and end of the template string are also removed.
|
|
@@ -524,4 +547,19 @@ interface RamdomNumberOptions {
|
|
|
524
547
|
*/
|
|
525
548
|
declare function randomNumber(min: number, max?: number, options?: RamdomNumberOptions): number;
|
|
526
549
|
|
|
527
|
-
|
|
550
|
+
/**
|
|
551
|
+
* 注释正则
|
|
552
|
+
*
|
|
553
|
+
* 匹配 \<!-- 或 /* 开头的注释,直到 --> 或 *\/ 结尾
|
|
554
|
+
*/
|
|
555
|
+
declare const RE_COMMENTS: RegExp;
|
|
556
|
+
/**
|
|
557
|
+
* JavaScript line comment
|
|
558
|
+
*/
|
|
559
|
+
declare const RE_LINE_COMMENT: RegExp;
|
|
560
|
+
/**
|
|
561
|
+
* JavaScript block comment
|
|
562
|
+
*/
|
|
563
|
+
declare const RE_BLOCK_COMMENT: RegExp;
|
|
564
|
+
|
|
565
|
+
export { type AnyFn, type Arrayable, type Awaitable, type Callable, type CleanObjectOptions, Color, type CreatePadStringOptions, type InteropModuleDefault, type JsonArray, type JsonObject, type JsonPrimitive, type JsonValue, type LiteralUnion, type MayBe, NOOP, type NonEmptyObject, type NonEmptyString, type Nullable, type Overwrite, type Prettify, type PrettifyV2, type PrimitiveType, RE_BLOCK_COMMENT, RE_COMMENTS, RE_LINE_COMMENT, type RamdomNumberOptions, type ResolvedOptions, type SortObjectOptions, type ThrottleDebounceOptions, type Whitespace, at, cAF, chunk, clamp, cleanObject, createPadString, days, debounce, enhance, ensurePrefix, ensureSuffix, escapeHTML, flattenArrayable, getObjectType, hasOwn, hours, interopDefault, intersect, isArray, isArrayEqual, isBigInt, isBoolean, isBrowser, isDeepEqual, isElementVisibleInViewport, isEmptyArray, isEmptyMap, isEmptyObject, isEmptySet, isEmptyString, isEmptyStringOrWhitespace, isError, isFunction, isInteger, isIterable, isMap, isNaN, isNativePromise, isNil, isNonEmptyArray, isNonEmptyString, isNull, isNullOrUndefined, isNumber, isNumbericString, isObject, isPromise, isRegExp, isSet, isString, isUndefined, isWhitespaceString, isZero, join, last, mergeArrayable, minutes, noop, omit, once, pick, rAF, randomHexColor, randomNumber, randomRGBAColor, randomRGBColor, randomString, resolveSubOptions, scrollIntoView, seconds, slash, slugify, sortObject, throttle, toArray, unescapeHTML, unindent, unique, uniqueBy, waitFor, warnOnce, weeks };
|
package/dist/index.js
CHANGED
|
@@ -129,8 +129,8 @@ function isIterable(value) {
|
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
// src/fn/noop.ts
|
|
132
|
-
|
|
133
|
-
}
|
|
132
|
+
function noop() {
|
|
133
|
+
}
|
|
134
134
|
var NOOP = noop;
|
|
135
135
|
|
|
136
136
|
// src/fn/once.ts
|
|
@@ -149,6 +149,32 @@ function once(func) {
|
|
|
149
149
|
// src/env/isBrowser.ts
|
|
150
150
|
var isBrowser = () => typeof document !== "undefined";
|
|
151
151
|
|
|
152
|
+
// src/dom/scrollIntoView.ts
|
|
153
|
+
function scrollIntoView(element, parent, options = {
|
|
154
|
+
behavior: "smooth",
|
|
155
|
+
block: "center",
|
|
156
|
+
inline: "center"
|
|
157
|
+
}) {
|
|
158
|
+
if (parent === document.body) {
|
|
159
|
+
parent.scrollIntoView(options);
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
const parentRect = parent.getBoundingClientRect();
|
|
163
|
+
const elementRect = element.getBoundingClientRect();
|
|
164
|
+
const isHorizontal = parent.scrollWidth > parent.scrollHeight;
|
|
165
|
+
const isOutOfView = isHorizontal ? elementRect.left < parentRect.left || elementRect.right > parentRect.right : elementRect.top < parentRect.top || elementRect.bottom > parentRect.bottom;
|
|
166
|
+
if (isOutOfView) {
|
|
167
|
+
parent.scrollIntoView(options);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// src/dom/isVisibleInViewport.ts
|
|
172
|
+
function isElementVisibleInViewport(element, targetWindow = window) {
|
|
173
|
+
const { top, left, bottom, right } = element.getBoundingClientRect();
|
|
174
|
+
const { innerWidth, innerHeight } = targetWindow;
|
|
175
|
+
return (top >= 0 && top <= innerHeight || bottom >= 0 && bottom <= innerHeight) && (left >= 0 && left <= innerWidth || right >= 0 && right <= innerWidth);
|
|
176
|
+
}
|
|
177
|
+
|
|
152
178
|
// src/misc/raf.ts
|
|
153
179
|
var root = isBrowser() ? window : globalThis;
|
|
154
180
|
var prev = Date.now();
|
|
@@ -260,9 +286,39 @@ function warnOnce(message) {
|
|
|
260
286
|
console.warn(message);
|
|
261
287
|
}
|
|
262
288
|
|
|
263
|
-
// src/html/
|
|
264
|
-
|
|
265
|
-
|
|
289
|
+
// src/html/escape.ts
|
|
290
|
+
var htmlEscapeMap = {
|
|
291
|
+
"&": "&",
|
|
292
|
+
"<": "<",
|
|
293
|
+
">": ">",
|
|
294
|
+
"'": "'",
|
|
295
|
+
'"': """
|
|
296
|
+
};
|
|
297
|
+
var htmlEscapeRegexp = /[&<>'"]/g;
|
|
298
|
+
function escapeHTML(str) {
|
|
299
|
+
return str.replace(
|
|
300
|
+
htmlEscapeRegexp,
|
|
301
|
+
(char) => htmlEscapeMap[char]
|
|
302
|
+
);
|
|
303
|
+
}
|
|
304
|
+
var htmlUnescapeMap = {
|
|
305
|
+
"&": "&",
|
|
306
|
+
"&": "&",
|
|
307
|
+
"<": "<",
|
|
308
|
+
"<": "<",
|
|
309
|
+
">": ">",
|
|
310
|
+
">": ">",
|
|
311
|
+
"'": "'",
|
|
312
|
+
"'": "'",
|
|
313
|
+
""": '"',
|
|
314
|
+
""": '"'
|
|
315
|
+
};
|
|
316
|
+
var htmlUnescapeRegexp = /&(amp|#38|lt|#60|gt|#62|apos|#39|quot|#34);/g;
|
|
317
|
+
function unescapeHTML(str) {
|
|
318
|
+
return str.replace(
|
|
319
|
+
htmlUnescapeRegexp,
|
|
320
|
+
(char) => htmlUnescapeMap[char]
|
|
321
|
+
);
|
|
266
322
|
}
|
|
267
323
|
|
|
268
324
|
// src/array/at.ts
|
|
@@ -370,6 +426,14 @@ function randomString(length = 16, chars = "0123456789abcdefghijklmnopqrstuvwxyz
|
|
|
370
426
|
return result.join("");
|
|
371
427
|
}
|
|
372
428
|
|
|
429
|
+
// src/string/slugify.ts
|
|
430
|
+
var rControl = /[\u0000-\u001F]/g;
|
|
431
|
+
var rSpecial = /[\s~`!@#$%^&*()\-_+=[\]{}|\\;:"'“”‘’<>,.?/]+/g;
|
|
432
|
+
var rCombining = /[\u0300-\u036F]/g;
|
|
433
|
+
function slugify(str) {
|
|
434
|
+
return str.normalize("NFKD").replace(rCombining, "").replace(rControl, "").replace(rSpecial, "-").replace(/-{2,}/g, "-").replace(/^-+|-+$/g, "").replace(/^(\d)/, "_$1").toLowerCase();
|
|
435
|
+
}
|
|
436
|
+
|
|
373
437
|
// src/string/unindent.ts
|
|
374
438
|
var _RE_FULL_WS = /^\s*$/;
|
|
375
439
|
function unindent(input) {
|
|
@@ -625,9 +689,17 @@ async function interopDefault(mod) {
|
|
|
625
689
|
function resolveSubOptions(options, key) {
|
|
626
690
|
return typeof options[key] === "boolean" ? {} : options[key] || {};
|
|
627
691
|
}
|
|
692
|
+
|
|
693
|
+
// src/constants/regexp.ts
|
|
694
|
+
var RE_COMMENTS = /(?:<!--|\/\*)([\s\S]*?)(?:-->|\*\/)/g;
|
|
695
|
+
var RE_LINE_COMMENT = /\/\/.*/;
|
|
696
|
+
var RE_BLOCK_COMMENT = /\/\*[\s\S]*?\*\//g;
|
|
628
697
|
export {
|
|
629
698
|
Color,
|
|
630
699
|
NOOP,
|
|
700
|
+
RE_BLOCK_COMMENT,
|
|
701
|
+
RE_COMMENTS,
|
|
702
|
+
RE_LINE_COMMENT,
|
|
631
703
|
at,
|
|
632
704
|
cAF,
|
|
633
705
|
chunk,
|
|
@@ -639,7 +711,7 @@ export {
|
|
|
639
711
|
enhance,
|
|
640
712
|
ensurePrefix,
|
|
641
713
|
ensureSuffix,
|
|
642
|
-
|
|
714
|
+
escapeHTML,
|
|
643
715
|
flattenArrayable,
|
|
644
716
|
getObjectType,
|
|
645
717
|
hasOwn,
|
|
@@ -652,6 +724,7 @@ export {
|
|
|
652
724
|
isBoolean,
|
|
653
725
|
isBrowser,
|
|
654
726
|
isDeepEqual,
|
|
727
|
+
isElementVisibleInViewport,
|
|
655
728
|
isEmptyArray,
|
|
656
729
|
isEmptyMap,
|
|
657
730
|
isEmptyObject,
|
|
@@ -695,11 +768,14 @@ export {
|
|
|
695
768
|
randomRGBColor,
|
|
696
769
|
randomString,
|
|
697
770
|
resolveSubOptions,
|
|
771
|
+
scrollIntoView,
|
|
698
772
|
seconds,
|
|
699
773
|
slash,
|
|
774
|
+
slugify,
|
|
700
775
|
sortObject,
|
|
701
776
|
throttle,
|
|
702
777
|
toArray,
|
|
778
|
+
unescapeHTML,
|
|
703
779
|
unindent,
|
|
704
780
|
unique,
|
|
705
781
|
uniqueBy,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ntnyq/utils",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.6.
|
|
4
|
+
"version": "0.6.1",
|
|
5
5
|
"description": "Common used utils.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"utils"
|
|
@@ -39,16 +39,16 @@
|
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@ntnyq/eslint-config": "^4.0.0-beta.7",
|
|
41
41
|
"@ntnyq/prettier-config": "^2.0.0",
|
|
42
|
-
"@vitest/coverage-v8": "^3.0.
|
|
42
|
+
"@vitest/coverage-v8": "^3.0.7",
|
|
43
43
|
"bumpp": "^10.0.3",
|
|
44
|
-
"eslint": "^9.
|
|
44
|
+
"eslint": "^9.21.0",
|
|
45
45
|
"husky": "^9.1.7",
|
|
46
46
|
"nano-staged": "^0.8.0",
|
|
47
47
|
"npm-run-all2": "^7.0.2",
|
|
48
|
-
"prettier": "^3.5.
|
|
49
|
-
"tsup": "^8.
|
|
50
|
-
"typescript": "^5.
|
|
51
|
-
"vitest": "^3.0.
|
|
48
|
+
"prettier": "^3.5.2",
|
|
49
|
+
"tsup": "^8.4.0",
|
|
50
|
+
"typescript": "^5.8.2",
|
|
51
|
+
"vitest": "^3.0.7"
|
|
52
52
|
},
|
|
53
53
|
"engines": {
|
|
54
54
|
"node": ">=18.18.0"
|