@ntnyq/utils 0.5.2 → 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 CHANGED
@@ -15,7 +15,6 @@ var __copyProps = (to, from, except, desc) => {
15
15
  }
16
16
  return to;
17
17
  };
18
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
19
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
19
 
21
20
  // src/index.ts
@@ -23,6 +22,9 @@ var index_exports = {};
23
22
  __export(index_exports, {
24
23
  Color: () => Color,
25
24
  NOOP: () => NOOP,
25
+ RE_BLOCK_COMMENT: () => RE_BLOCK_COMMENT,
26
+ RE_COMMENTS: () => RE_COMMENTS,
27
+ RE_LINE_COMMENT: () => RE_LINE_COMMENT,
26
28
  at: () => at,
27
29
  cAF: () => cAF,
28
30
  chunk: () => chunk,
@@ -34,7 +36,7 @@ __export(index_exports, {
34
36
  enhance: () => enhance,
35
37
  ensurePrefix: () => ensurePrefix,
36
38
  ensureSuffix: () => ensureSuffix,
37
- escapeHtml: () => escapeHtml,
39
+ escapeHTML: () => escapeHTML,
38
40
  flattenArrayable: () => flattenArrayable,
39
41
  getObjectType: () => getObjectType,
40
42
  hasOwn: () => hasOwn,
@@ -47,6 +49,7 @@ __export(index_exports, {
47
49
  isBoolean: () => isBoolean,
48
50
  isBrowser: () => isBrowser,
49
51
  isDeepEqual: () => isDeepEqual,
52
+ isElementVisibleInViewport: () => isElementVisibleInViewport,
50
53
  isEmptyArray: () => isEmptyArray,
51
54
  isEmptyMap: () => isEmptyMap,
52
55
  isEmptyObject: () => isEmptyObject,
@@ -90,11 +93,14 @@ __export(index_exports, {
90
93
  randomRGBColor: () => randomRGBColor,
91
94
  randomString: () => randomString,
92
95
  resolveSubOptions: () => resolveSubOptions,
96
+ scrollIntoView: () => scrollIntoView,
93
97
  seconds: () => seconds,
94
98
  slash: () => slash,
99
+ slugify: () => slugify,
95
100
  sortObject: () => sortObject,
96
101
  throttle: () => throttle,
97
102
  toArray: () => toArray,
103
+ unescapeHTML: () => unescapeHTML,
98
104
  unindent: () => unindent,
99
105
  unique: () => unique,
100
106
  uniqueBy: () => uniqueBy,
@@ -235,8 +241,8 @@ function isIterable(value) {
235
241
  }
236
242
 
237
243
  // src/fn/noop.ts
238
- var noop = () => {
239
- };
244
+ function noop() {
245
+ }
240
246
  var NOOP = noop;
241
247
 
242
248
  // src/fn/once.ts
@@ -255,6 +261,32 @@ function once(func) {
255
261
  // src/env/isBrowser.ts
256
262
  var isBrowser = () => typeof document !== "undefined";
257
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
+
258
290
  // src/misc/raf.ts
259
291
  var root = isBrowser() ? window : globalThis;
260
292
  var prev = Date.now();
@@ -358,17 +390,47 @@ function debounce(delay, callback, options = {}) {
358
390
 
359
391
  // src/misc/warnOnce.ts
360
392
  var warned = /* @__PURE__ */ new Set();
361
- var warnOnce = (message) => {
393
+ function warnOnce(message) {
362
394
  if (warned.has(message)) {
363
395
  return;
364
396
  }
365
397
  warned.add(message);
366
398
  console.warn(message);
367
- };
399
+ }
368
400
 
369
- // src/html/escapeHtml.ts
370
- function escapeHtml(unsafe) {
371
- return unsafe.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
401
+ // src/html/escape.ts
402
+ var htmlEscapeMap = {
403
+ "&": "&amp;",
404
+ "<": "&lt;",
405
+ ">": "&gt;",
406
+ "'": "&#39;",
407
+ '"': "&quot;"
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
+ "&amp;": "&",
418
+ "&#38;": "&",
419
+ "&lt;": "<",
420
+ "&#60;": "<",
421
+ "&gt;": ">",
422
+ "&#62;": ">",
423
+ "&apos;": "'",
424
+ "&#39;": "'",
425
+ "&quot;": '"',
426
+ "&#34;": '"'
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
+ );
372
434
  }
373
435
 
374
436
  // src/array/at.ts
@@ -476,6 +538,14 @@ function randomString(length = 16, chars = "0123456789abcdefghijklmnopqrstuvwxyz
476
538
  return result.join("");
477
539
  }
478
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
+
479
549
  // src/string/unindent.ts
480
550
  var _RE_FULL_WS = /^\s*$/;
481
551
  function unindent(input) {
@@ -721,19 +791,6 @@ function sortObject(obj, options = {}) {
721
791
  return sortKeys(obj);
722
792
  }
723
793
 
724
- // src/vendor/index.ts
725
- var vendor_exports = {};
726
-
727
- // src/vendor/changeCase.ts
728
- var changeCase_exports = {};
729
- __reExport(changeCase_exports, require("change-case"));
730
-
731
- // src/vendor/index.ts
732
- __reExport(vendor_exports, changeCase_exports);
733
-
734
- // src/index.ts
735
- __reExport(index_exports, vendor_exports, module.exports);
736
-
737
794
  // src/module/interopDefault.ts
738
795
  async function interopDefault(mod) {
739
796
  const resolved = await mod;
@@ -744,10 +801,18 @@ async function interopDefault(mod) {
744
801
  function resolveSubOptions(options, key) {
745
802
  return typeof options[key] === "boolean" ? {} : options[key] || {};
746
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;
747
809
  // Annotate the CommonJS export names for ESM import in node:
748
810
  0 && (module.exports = {
749
811
  Color,
750
812
  NOOP,
813
+ RE_BLOCK_COMMENT,
814
+ RE_COMMENTS,
815
+ RE_LINE_COMMENT,
751
816
  at,
752
817
  cAF,
753
818
  chunk,
@@ -759,7 +824,7 @@ function resolveSubOptions(options, key) {
759
824
  enhance,
760
825
  ensurePrefix,
761
826
  ensureSuffix,
762
- escapeHtml,
827
+ escapeHTML,
763
828
  flattenArrayable,
764
829
  getObjectType,
765
830
  hasOwn,
@@ -772,6 +837,7 @@ function resolveSubOptions(options, key) {
772
837
  isBoolean,
773
838
  isBrowser,
774
839
  isDeepEqual,
840
+ isElementVisibleInViewport,
775
841
  isEmptyArray,
776
842
  isEmptyMap,
777
843
  isEmptyObject,
@@ -815,11 +881,14 @@ function resolveSubOptions(options, key) {
815
881
  randomRGBColor,
816
882
  randomString,
817
883
  resolveSubOptions,
884
+ scrollIntoView,
818
885
  seconds,
819
886
  slash,
887
+ slugify,
820
888
  sortObject,
821
889
  throttle,
822
890
  toArray,
891
+ unescapeHTML,
823
892
  unindent,
824
893
  unique,
825
894
  uniqueBy,
package/dist/index.d.cts CHANGED
@@ -1,5 +1,3 @@
1
- export * from 'change-case';
2
-
3
1
  /**
4
2
  * check if two values are deeply equal
5
3
  */
@@ -50,11 +48,11 @@ declare function isIterable<T = unknown>(value: unknown): value is Iterable<T>;
50
48
  /**
51
49
  * A function that does nothing.
52
50
  */
53
- declare const noop: () => void;
51
+ declare function noop(): void;
54
52
  /**
55
53
  * Alias of {@link noop}.
56
54
  */
57
- declare const NOOP: () => void;
55
+ declare const NOOP: typeof noop;
58
56
 
59
57
  declare function once<T extends unknown[]>(func: (...args: T) => void): (this: unknown, ...args: T) => boolean;
60
58
 
@@ -68,6 +66,17 @@ declare function once<T extends unknown[]>(func: (...args: T) => void): (this: u
68
66
  */
69
67
  declare const isBrowser: () => boolean;
70
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
+
71
80
  /**
72
81
  * @file raf.ts
73
82
  */
@@ -141,9 +150,16 @@ declare function debounce<T extends ((...args: any[]) => undefined | void) | und
141
150
  cancel: () => void;
142
151
  };
143
152
 
144
- declare const warnOnce: (message: string) => void;
153
+ declare function warnOnce(message: string): void;
145
154
 
146
- declare function escapeHtml(unsafe: string): string;
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;
147
163
 
148
164
  /**
149
165
  * Get array item by index, negative for backward
@@ -193,6 +209,19 @@ type JsonPrimitive = boolean | number | string | null;
193
209
  */
194
210
  type JsonValue = JsonArray | JsonObject | JsonPrimitive;
195
211
 
212
+ /**
213
+ * A literal type that supports custom further strings but preserves autocompletion in IDEs.
214
+ *
215
+ * @see https://github.com/microsoft/TypeScript/issues/29729#issuecomment-471566609
216
+ */
217
+ type LiteralUnion<Union extends Base, Base = string> = Union | (Base & {
218
+ zz_IGNORE_ME?: never;
219
+ });
220
+ /**
221
+ * Non empty object `{}`
222
+ */
223
+ type NonEmptyObject<T> = T extends Record<string, never> ? never : T;
224
+
196
225
  /**
197
226
  * interop module
198
227
  */
@@ -344,6 +373,11 @@ declare function slash(input: string): string;
344
373
  */
345
374
  declare function randomString(length?: number, chars?: string): string;
346
375
 
376
+ /**
377
+ * Default slugify function
378
+ */
379
+ declare function slugify(str: string): string;
380
+
347
381
  /**
348
382
  * Remove common leading whitespace from a template string
349
383
  * Empty lines at the beginning and end of the template string are also removed.
@@ -513,4 +547,19 @@ interface RamdomNumberOptions {
513
547
  */
514
548
  declare function randomNumber(min: number, max?: number, options?: RamdomNumberOptions): number;
515
549
 
516
- 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 MayBe, NOOP, type NonEmptyString, type Nullable, type Overwrite, type Prettify, type PrettifyV2, type PrimitiveType, 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, 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, seconds, slash, sortObject, throttle, toArray, unindent, unique, uniqueBy, waitFor, warnOnce, weeks };
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
@@ -1,5 +1,3 @@
1
- export * from 'change-case';
2
-
3
1
  /**
4
2
  * check if two values are deeply equal
5
3
  */
@@ -50,11 +48,11 @@ declare function isIterable<T = unknown>(value: unknown): value is Iterable<T>;
50
48
  /**
51
49
  * A function that does nothing.
52
50
  */
53
- declare const noop: () => void;
51
+ declare function noop(): void;
54
52
  /**
55
53
  * Alias of {@link noop}.
56
54
  */
57
- declare const NOOP: () => void;
55
+ declare const NOOP: typeof noop;
58
56
 
59
57
  declare function once<T extends unknown[]>(func: (...args: T) => void): (this: unknown, ...args: T) => boolean;
60
58
 
@@ -68,6 +66,17 @@ declare function once<T extends unknown[]>(func: (...args: T) => void): (this: u
68
66
  */
69
67
  declare const isBrowser: () => boolean;
70
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
+
71
80
  /**
72
81
  * @file raf.ts
73
82
  */
@@ -141,9 +150,16 @@ declare function debounce<T extends ((...args: any[]) => undefined | void) | und
141
150
  cancel: () => void;
142
151
  };
143
152
 
144
- declare const warnOnce: (message: string) => void;
153
+ declare function warnOnce(message: string): void;
145
154
 
146
- declare function escapeHtml(unsafe: string): string;
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;
147
163
 
148
164
  /**
149
165
  * Get array item by index, negative for backward
@@ -193,6 +209,19 @@ type JsonPrimitive = boolean | number | string | null;
193
209
  */
194
210
  type JsonValue = JsonArray | JsonObject | JsonPrimitive;
195
211
 
212
+ /**
213
+ * A literal type that supports custom further strings but preserves autocompletion in IDEs.
214
+ *
215
+ * @see https://github.com/microsoft/TypeScript/issues/29729#issuecomment-471566609
216
+ */
217
+ type LiteralUnion<Union extends Base, Base = string> = Union | (Base & {
218
+ zz_IGNORE_ME?: never;
219
+ });
220
+ /**
221
+ * Non empty object `{}`
222
+ */
223
+ type NonEmptyObject<T> = T extends Record<string, never> ? never : T;
224
+
196
225
  /**
197
226
  * interop module
198
227
  */
@@ -344,6 +373,11 @@ declare function slash(input: string): string;
344
373
  */
345
374
  declare function randomString(length?: number, chars?: string): string;
346
375
 
376
+ /**
377
+ * Default slugify function
378
+ */
379
+ declare function slugify(str: string): string;
380
+
347
381
  /**
348
382
  * Remove common leading whitespace from a template string
349
383
  * Empty lines at the beginning and end of the template string are also removed.
@@ -513,4 +547,19 @@ interface RamdomNumberOptions {
513
547
  */
514
548
  declare function randomNumber(min: number, max?: number, options?: RamdomNumberOptions): number;
515
549
 
516
- 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 MayBe, NOOP, type NonEmptyString, type Nullable, type Overwrite, type Prettify, type PrettifyV2, type PrimitiveType, 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, 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, seconds, slash, sortObject, throttle, toArray, unindent, unique, uniqueBy, waitFor, warnOnce, weeks };
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
@@ -1,106 +1,3 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
18
-
19
- // src/index.ts
20
- var index_exports = {};
21
- __export(index_exports, {
22
- Color: () => Color,
23
- NOOP: () => NOOP,
24
- at: () => at,
25
- cAF: () => cAF,
26
- chunk: () => chunk,
27
- clamp: () => clamp,
28
- cleanObject: () => cleanObject,
29
- createPadString: () => createPadString,
30
- days: () => days,
31
- debounce: () => debounce,
32
- enhance: () => enhance,
33
- ensurePrefix: () => ensurePrefix,
34
- ensureSuffix: () => ensureSuffix,
35
- escapeHtml: () => escapeHtml,
36
- flattenArrayable: () => flattenArrayable,
37
- getObjectType: () => getObjectType,
38
- hasOwn: () => hasOwn,
39
- hours: () => hours,
40
- interopDefault: () => interopDefault,
41
- intersect: () => intersect,
42
- isArray: () => isArray,
43
- isArrayEqual: () => isArrayEqual,
44
- isBigInt: () => isBigInt,
45
- isBoolean: () => isBoolean,
46
- isBrowser: () => isBrowser,
47
- isDeepEqual: () => isDeepEqual,
48
- isEmptyArray: () => isEmptyArray,
49
- isEmptyMap: () => isEmptyMap,
50
- isEmptyObject: () => isEmptyObject,
51
- isEmptySet: () => isEmptySet,
52
- isEmptyString: () => isEmptyString,
53
- isEmptyStringOrWhitespace: () => isEmptyStringOrWhitespace,
54
- isError: () => isError,
55
- isFunction: () => isFunction,
56
- isInteger: () => isInteger,
57
- isIterable: () => isIterable,
58
- isMap: () => isMap,
59
- isNaN: () => isNaN,
60
- isNativePromise: () => isNativePromise,
61
- isNil: () => isNil,
62
- isNonEmptyArray: () => isNonEmptyArray,
63
- isNonEmptyString: () => isNonEmptyString,
64
- isNull: () => isNull,
65
- isNullOrUndefined: () => isNullOrUndefined,
66
- isNumber: () => isNumber,
67
- isNumbericString: () => isNumbericString,
68
- isObject: () => isObject,
69
- isPromise: () => isPromise,
70
- isRegExp: () => isRegExp,
71
- isSet: () => isSet,
72
- isString: () => isString,
73
- isUndefined: () => isUndefined,
74
- isWhitespaceString: () => isWhitespaceString,
75
- isZero: () => isZero,
76
- join: () => join,
77
- last: () => last,
78
- mergeArrayable: () => mergeArrayable,
79
- minutes: () => minutes,
80
- noop: () => noop,
81
- omit: () => omit,
82
- once: () => once,
83
- pick: () => pick,
84
- rAF: () => rAF,
85
- randomHexColor: () => randomHexColor,
86
- randomNumber: () => randomNumber,
87
- randomRGBAColor: () => randomRGBAColor,
88
- randomRGBColor: () => randomRGBColor,
89
- randomString: () => randomString,
90
- resolveSubOptions: () => resolveSubOptions,
91
- seconds: () => seconds,
92
- slash: () => slash,
93
- sortObject: () => sortObject,
94
- throttle: () => throttle,
95
- toArray: () => toArray,
96
- unindent: () => unindent,
97
- unique: () => unique,
98
- uniqueBy: () => uniqueBy,
99
- waitFor: () => waitFor,
100
- warnOnce: () => warnOnce,
101
- weeks: () => weeks
102
- });
103
-
104
1
  // src/is/isDeepEqual.ts
105
2
  function isDeepEqual(value1, value2) {
106
3
  const type1 = getObjectType(value1);
@@ -232,8 +129,8 @@ function isIterable(value) {
232
129
  }
233
130
 
234
131
  // src/fn/noop.ts
235
- var noop = () => {
236
- };
132
+ function noop() {
133
+ }
237
134
  var NOOP = noop;
238
135
 
239
136
  // src/fn/once.ts
@@ -252,6 +149,32 @@ function once(func) {
252
149
  // src/env/isBrowser.ts
253
150
  var isBrowser = () => typeof document !== "undefined";
254
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
+
255
178
  // src/misc/raf.ts
256
179
  var root = isBrowser() ? window : globalThis;
257
180
  var prev = Date.now();
@@ -355,17 +278,47 @@ function debounce(delay, callback, options = {}) {
355
278
 
356
279
  // src/misc/warnOnce.ts
357
280
  var warned = /* @__PURE__ */ new Set();
358
- var warnOnce = (message) => {
281
+ function warnOnce(message) {
359
282
  if (warned.has(message)) {
360
283
  return;
361
284
  }
362
285
  warned.add(message);
363
286
  console.warn(message);
364
- };
287
+ }
365
288
 
366
- // src/html/escapeHtml.ts
367
- function escapeHtml(unsafe) {
368
- return unsafe.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
289
+ // src/html/escape.ts
290
+ var htmlEscapeMap = {
291
+ "&": "&amp;",
292
+ "<": "&lt;",
293
+ ">": "&gt;",
294
+ "'": "&#39;",
295
+ '"': "&quot;"
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
+ "&amp;": "&",
306
+ "&#38;": "&",
307
+ "&lt;": "<",
308
+ "&#60;": "<",
309
+ "&gt;": ">",
310
+ "&#62;": ">",
311
+ "&apos;": "'",
312
+ "&#39;": "'",
313
+ "&quot;": '"',
314
+ "&#34;": '"'
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
+ );
369
322
  }
370
323
 
371
324
  // src/array/at.ts
@@ -473,6 +426,14 @@ function randomString(length = 16, chars = "0123456789abcdefghijklmnopqrstuvwxyz
473
426
  return result.join("");
474
427
  }
475
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
+
476
437
  // src/string/unindent.ts
477
438
  var _RE_FULL_WS = /^\s*$/;
478
439
  function unindent(input) {
@@ -718,20 +679,6 @@ function sortObject(obj, options = {}) {
718
679
  return sortKeys(obj);
719
680
  }
720
681
 
721
- // src/vendor/index.ts
722
- var vendor_exports = {};
723
-
724
- // src/vendor/changeCase.ts
725
- var changeCase_exports = {};
726
- __reExport(changeCase_exports, change_case_star);
727
- import * as change_case_star from "change-case";
728
-
729
- // src/vendor/index.ts
730
- __reExport(vendor_exports, changeCase_exports);
731
-
732
- // src/index.ts
733
- __reExport(index_exports, vendor_exports);
734
-
735
682
  // src/module/interopDefault.ts
736
683
  async function interopDefault(mod) {
737
684
  const resolved = await mod;
@@ -742,9 +689,17 @@ async function interopDefault(mod) {
742
689
  function resolveSubOptions(options, key) {
743
690
  return typeof options[key] === "boolean" ? {} : options[key] || {};
744
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;
745
697
  export {
746
698
  Color,
747
699
  NOOP,
700
+ RE_BLOCK_COMMENT,
701
+ RE_COMMENTS,
702
+ RE_LINE_COMMENT,
748
703
  at,
749
704
  cAF,
750
705
  chunk,
@@ -756,7 +711,7 @@ export {
756
711
  enhance,
757
712
  ensurePrefix,
758
713
  ensureSuffix,
759
- escapeHtml,
714
+ escapeHTML,
760
715
  flattenArrayable,
761
716
  getObjectType,
762
717
  hasOwn,
@@ -769,6 +724,7 @@ export {
769
724
  isBoolean,
770
725
  isBrowser,
771
726
  isDeepEqual,
727
+ isElementVisibleInViewport,
772
728
  isEmptyArray,
773
729
  isEmptyMap,
774
730
  isEmptyObject,
@@ -812,11 +768,14 @@ export {
812
768
  randomRGBColor,
813
769
  randomString,
814
770
  resolveSubOptions,
771
+ scrollIntoView,
815
772
  seconds,
816
773
  slash,
774
+ slugify,
817
775
  sortObject,
818
776
  throttle,
819
777
  toArray,
778
+ unescapeHTML,
820
779
  unindent,
821
780
  unique,
822
781
  uniqueBy,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ntnyq/utils",
3
3
  "type": "module",
4
- "version": "0.5.2",
4
+ "version": "0.6.1",
5
5
  "description": "Common used utils.",
6
6
  "keywords": [
7
7
  "utils"
@@ -36,28 +36,25 @@
36
36
  "dist"
37
37
  ],
38
38
  "sideEffects": false,
39
- "dependencies": {
40
- "change-case": "^5.4.4"
41
- },
42
39
  "devDependencies": {
43
- "@ntnyq/eslint-config": "^4.0.0-beta.4",
44
- "@ntnyq/prettier-config": "^2.0.0-beta.2",
45
- "@vitest/coverage-v8": "^3.0.5",
40
+ "@ntnyq/eslint-config": "^4.0.0-beta.7",
41
+ "@ntnyq/prettier-config": "^2.0.0",
42
+ "@vitest/coverage-v8": "^3.0.7",
46
43
  "bumpp": "^10.0.3",
47
- "eslint": "^9.20.1",
44
+ "eslint": "^9.21.0",
48
45
  "husky": "^9.1.7",
49
46
  "nano-staged": "^0.8.0",
50
47
  "npm-run-all2": "^7.0.2",
51
- "prettier": "^3.5.1",
52
- "tsup": "^8.3.6",
53
- "typescript": "^5.7.3",
54
- "vitest": "^3.0.5"
48
+ "prettier": "^3.5.2",
49
+ "tsup": "^8.4.0",
50
+ "typescript": "^5.8.2",
51
+ "vitest": "^3.0.7"
55
52
  },
56
53
  "engines": {
57
54
  "node": ">=18.18.0"
58
55
  },
59
56
  "nano-staged": {
60
- "*.{js,ts,mjs,cjs,json,md,yml,yaml}": "eslint --fix"
57
+ "*.{js,ts,mjs,cjs,md,yml,yaml,json}": "eslint --fix"
61
58
  },
62
59
  "scripts": {
63
60
  "build": "tsup",