rattail 0.0.7 → 0.0.8

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/lib/index.cjs CHANGED
@@ -58,6 +58,7 @@ __export(src_exports, {
58
58
  classes: () => classes,
59
59
  cloneDeep: () => cloneDeep,
60
60
  cloneDeepWith: () => cloneDeepWith,
61
+ copyText: () => copyText,
61
62
  createNamespaceFn: () => createNamespaceFn,
62
63
  createStorage: () => createStorage,
63
64
  debounce: () => debounce,
@@ -80,9 +81,13 @@ __export(src_exports, {
80
81
  isArray: () => isArray,
81
82
  isArrayBuffer: () => isArrayBuffer,
82
83
  isBoolean: () => isBoolean,
84
+ isDOMException: () => isDOMException,
83
85
  isDataView: () => isDataView,
84
86
  isDate: () => isDate,
85
87
  isEmpty: () => isEmpty,
88
+ isEqual: () => isEqual,
89
+ isEqualWith: () => isEqualWith,
90
+ isError: () => isError,
86
91
  isFunction: () => isFunction,
87
92
  isMap: () => isMap,
88
93
  isNonEmptyArray: () => isNonEmptyArray,
@@ -118,7 +123,9 @@ __export(src_exports, {
118
123
  prettyJSONObject: () => prettyJSONObject,
119
124
  preventDefault: () => preventDefault,
120
125
  raf: () => raf,
126
+ randomColor: () => randomColor,
121
127
  randomNumber: () => randomNumber,
128
+ randomString: () => randomString,
122
129
  removeArrayBlank: () => removeArrayBlank,
123
130
  removeArrayEmpty: () => removeArrayEmpty,
124
131
  removeItem: () => removeItem,
@@ -129,6 +136,7 @@ __export(src_exports, {
129
136
  slash: () => slash,
130
137
  sum: () => sum,
131
138
  sumBy: () => sumBy,
139
+ sumHash: () => sumHash,
132
140
  supportTouch: () => supportTouch,
133
141
  throttle: () => throttle,
134
142
  times: () => times,
@@ -163,11 +171,17 @@ function isNumber(val) {
163
171
  function isSymbol(val) {
164
172
  return typeof val === "symbol";
165
173
  }
174
+ function isError(val) {
175
+ return toRawType(val) === "Error";
176
+ }
177
+ function isDOMException(val) {
178
+ return toRawType(val) === "DOMException";
179
+ }
166
180
  function isNumeric(val) {
167
181
  return isNumber(val) || isString(val) && /^[-+]?\d+$/.test(val);
168
182
  }
169
183
  function isPlainObject(val) {
170
- return Object.prototype.toString.call(val) === "[object Object]";
184
+ return toRawType(val) === "Object";
171
185
  }
172
186
  function isObject(val) {
173
187
  return typeof val === "object" && val !== null;
@@ -260,6 +274,102 @@ function getGlobalThis() {
260
274
  function isNonEmptyArray(val) {
261
275
  return isArray(val) && !!val.length;
262
276
  }
277
+ function isEqualWith(value, other, fn) {
278
+ const valueStack = /* @__PURE__ */ new WeakMap();
279
+ const otherStack = /* @__PURE__ */ new WeakMap();
280
+ function baseIsEqual(value2, other2, valueStack2, otherStack2) {
281
+ const customEqual = fn(value2, other2);
282
+ if (customEqual === true) {
283
+ return true;
284
+ }
285
+ if (value2 === other2) {
286
+ return true;
287
+ }
288
+ if (value2 !== value2 && other2 !== other2) {
289
+ return true;
290
+ }
291
+ if (!isObject(value2) || !isObject(other2)) {
292
+ return value2 === other2;
293
+ }
294
+ if (value2.constructor !== other2.constructor) {
295
+ return false;
296
+ }
297
+ if (toRawType(value2) === "String" && toRawType(other2) === "String" || toRawType(value2) === "Number" && toRawType(other2) === "Number" || toRawType(value2) === "Boolean" && toRawType(other2) === "Boolean" || toRawType(value2) === "BigInt" && toRawType(other2) === "BigInt" || toRawType(value2) === "Symbol" && toRawType(other2) === "Symbol") {
298
+ return value2.valueOf() === other2.valueOf();
299
+ }
300
+ if (isDate(value2) && isDate(other2)) {
301
+ return value2.getTime() === other2.getTime();
302
+ }
303
+ if (isRegExp(value2) && isRegExp(other2)) {
304
+ return value2.source === other2.source && value2.flags === other2.flags;
305
+ }
306
+ if (isError(value2) && isError(other2)) {
307
+ return value2.name === other2.name && value2.message === other2.message && value2.cause === other2.cause;
308
+ }
309
+ if (isDOMException(value2) && isDOMException(other2)) {
310
+ return value2.name === other2.name && value2.message === other2.message;
311
+ }
312
+ if (isTypedArray(value2) && isTypedArray(other2) || isDataView(value2) && isDataView(other2)) {
313
+ if (value2.byteLength !== other2.byteLength) {
314
+ return false;
315
+ }
316
+ const valueTypedArray = new Uint8Array(value2.buffer);
317
+ const otherTypedArray = new Uint8Array(other2.buffer);
318
+ return valueTypedArray.every((v, i) => v === otherTypedArray[i]);
319
+ }
320
+ if (isArrayBuffer(value2) && isArrayBuffer(other2)) {
321
+ if (value2.byteLength !== other2.byteLength) {
322
+ return false;
323
+ }
324
+ const valueTypedArray = new Uint8Array(value2);
325
+ const otherTypedArray = new Uint8Array(other2);
326
+ return valueTypedArray.every((v, i) => v === otherTypedArray[i]);
327
+ }
328
+ if (valueStack2.get(value2) === other2 && otherStack2.get(other2) === value2) {
329
+ return true;
330
+ }
331
+ valueStack2.set(value2, other2);
332
+ otherStack2.set(other2, value2);
333
+ if (isMap(value2) && isMap(other2) || isSet(value2) && isSet(other2)) {
334
+ if (value2.size !== other2.size) {
335
+ return false;
336
+ }
337
+ const valueArray = [...value2];
338
+ const otherArray = [...other2];
339
+ const result = valueArray.every((v, i) => baseIsEqual(v, otherArray[i], valueStack2, otherStack2));
340
+ valueStack2.delete(value2);
341
+ otherStack2.delete(other2);
342
+ return result;
343
+ }
344
+ if (isArray(value2) && isArray(other2)) {
345
+ if (value2.length !== other2.length) {
346
+ return false;
347
+ }
348
+ const result = value2.every((v, i) => baseIsEqual(v, other2[i], valueStack2, otherStack2));
349
+ valueStack2.delete(value2);
350
+ otherStack2.delete(other2);
351
+ return result;
352
+ }
353
+ if (isPlainObject(value2) && isPlainObject(other2)) {
354
+ const valueOwnKeys = [...Object.keys(value2), ...Object.getOwnPropertySymbols(value2)];
355
+ const otherOwnKeys = [...Object.keys(other2), ...Object.getOwnPropertySymbols(other2)];
356
+ if (valueOwnKeys.length !== otherOwnKeys.length) {
357
+ return false;
358
+ }
359
+ const result = valueOwnKeys.every(
360
+ (k) => baseIsEqual(value2[k], other2[k], valueStack2, otherStack2)
361
+ );
362
+ valueStack2.delete(value2);
363
+ otherStack2.delete(other2);
364
+ return result;
365
+ }
366
+ return false;
367
+ }
368
+ return baseIsEqual(value, other, valueStack, otherStack);
369
+ }
370
+ function isEqual(value, other) {
371
+ return isEqualWith(value, other, () => void 0);
372
+ }
263
373
 
264
374
  // src/array.ts
265
375
  function uniq(arr) {
@@ -350,6 +460,24 @@ function upperFirst(s) {
350
460
  function lowerFirst(s) {
351
461
  return s.charAt(0).toLowerCase() + s.slice(1);
352
462
  }
463
+ function randomString(length = 10) {
464
+ let str = baseRandomString();
465
+ while (str.length < length) {
466
+ str += baseRandomString();
467
+ }
468
+ function baseRandomString() {
469
+ return Math.random().toString(36).slice(2);
470
+ }
471
+ return str.slice(0, length);
472
+ }
473
+ function randomColor() {
474
+ const letters = "0123456789abcdef";
475
+ let color = "#";
476
+ for (let i = 0; i < 6; i++) {
477
+ color += letters[Math.floor(Math.random() * 16)];
478
+ }
479
+ return color;
480
+ }
353
481
 
354
482
  // src/util.ts
355
483
  function requestAnimationFrame(fn) {
@@ -507,6 +635,17 @@ function createStorage(storage) {
507
635
  }
508
636
  var sessionStorage = createStorage(globalThis.sessionStorage);
509
637
  var localStorage = createStorage(globalThis.localStorage);
638
+ function copyText(value) {
639
+ if (!value) return;
640
+ const textArea = document.createElement("textarea");
641
+ textArea.value = value;
642
+ textArea.style.position = "fixed";
643
+ textArea.style.opacity = "0";
644
+ document.body.appendChild(textArea);
645
+ textArea.select();
646
+ document.execCommand("copy");
647
+ document.body.removeChild(textArea);
648
+ }
510
649
 
511
650
  // src/function.ts
512
651
  function NOOP() {
@@ -671,7 +810,7 @@ function cloneDeepWith(value, fn) {
671
810
  if (toRawType(value2) === "String" || toRawType(value2) === "Number" || toRawType(value2) === "Boolean") {
672
811
  return newConstructor(value2, value2.valueOf());
673
812
  }
674
- if (isWeakMap(value2) || isWeakSet(value2)) {
813
+ if (isWeakMap(value2) || isWeakSet(value2) || isError(value2) || isDOMException(value2)) {
675
814
  return {};
676
815
  }
677
816
  if (isTypedArray(value2)) {
@@ -694,11 +833,10 @@ function cloneDeepWith(value, fn) {
694
833
  if (isPlainObject(value2)) {
695
834
  const result = Object.create(Reflect.getPrototypeOf(value2));
696
835
  cache2.set(value2, result);
697
- for (const key3 in value2) {
698
- if (hasOwn(value2, key3)) {
699
- result[key3] = baseCloneDeep(value2[key3], cache2);
700
- }
701
- }
836
+ const ownKeys = [...Object.keys(value2), ...Object.getOwnPropertySymbols(value2)];
837
+ ownKeys.forEach((key3) => {
838
+ result[key3] = baseCloneDeep(value2[key3], cache2);
839
+ });
702
840
  return result;
703
841
  }
704
842
  return value2;
@@ -774,6 +912,40 @@ function sample(arr) {
774
912
  }
775
913
  return arr[randomNumber(0, arr.length - 1)];
776
914
  }
915
+ function sumHash(value) {
916
+ function sum2(hash, value2) {
917
+ for (let i = 0; i < value2.length; i++) {
918
+ const chr = value2.charCodeAt(i);
919
+ hash = (hash << 5) - hash + chr;
920
+ hash |= 0;
921
+ }
922
+ return hash < 0 ? hash * -2 : hash;
923
+ }
924
+ function baseSumHash(hash, value2, key3, seen) {
925
+ hash = sum2(hash, key3);
926
+ hash = sum2(hash, toTypeString(value2));
927
+ hash = sum2(hash, typeof value2);
928
+ if (value2 === null) {
929
+ return sum2(hash, "null");
930
+ }
931
+ if (value2 === void 0) {
932
+ return sum2(hash, "undefined");
933
+ }
934
+ if (isObject(value2) || isFunction(value2)) {
935
+ if (seen.includes(value2)) {
936
+ return sum2(hash, `[Circular]${key3}`);
937
+ }
938
+ seen.push(value2);
939
+ hash = Object.keys(value2).sort().reduce((hash2, key4) => baseSumHash(hash2, value2[key4], key4, seen), hash);
940
+ if (isFunction(value2.valueOf)) {
941
+ return sum2(hash, String(value2.valueOf()));
942
+ }
943
+ return hash;
944
+ }
945
+ return sum2(hash, value2.toString());
946
+ }
947
+ return baseSumHash(0, value, "", []).toString(16).padStart(8, "0");
948
+ }
777
949
 
778
950
  // src/index.ts
779
951
  __reExport(src_exports, require("mitt"), module.exports);
@@ -790,6 +962,7 @@ var import_mitt = __toESM(require("mitt"), 1);
790
962
  classes,
791
963
  cloneDeep,
792
964
  cloneDeepWith,
965
+ copyText,
793
966
  createNamespaceFn,
794
967
  createStorage,
795
968
  debounce,
@@ -812,9 +985,13 @@ var import_mitt = __toESM(require("mitt"), 1);
812
985
  isArray,
813
986
  isArrayBuffer,
814
987
  isBoolean,
988
+ isDOMException,
815
989
  isDataView,
816
990
  isDate,
817
991
  isEmpty,
992
+ isEqual,
993
+ isEqualWith,
994
+ isError,
818
995
  isFunction,
819
996
  isMap,
820
997
  isNonEmptyArray,
@@ -850,7 +1027,9 @@ var import_mitt = __toESM(require("mitt"), 1);
850
1027
  prettyJSONObject,
851
1028
  preventDefault,
852
1029
  raf,
1030
+ randomColor,
853
1031
  randomNumber,
1032
+ randomString,
854
1033
  removeArrayBlank,
855
1034
  removeArrayEmpty,
856
1035
  removeItem,
@@ -861,6 +1040,7 @@ var import_mitt = __toESM(require("mitt"), 1);
861
1040
  slash,
862
1041
  sum,
863
1042
  sumBy,
1043
+ sumHash,
864
1044
  supportTouch,
865
1045
  throttle,
866
1046
  times,
package/lib/index.d.cts CHANGED
@@ -43,6 +43,7 @@ interface Storage extends globalThis.Storage {
43
43
  declare function createStorage(storage: globalThis.Storage): Storage;
44
44
  declare const sessionStorage: Storage;
45
45
  declare const localStorage: Storage;
46
+ declare function copyText(value: string): void;
46
47
 
47
48
  declare function NOOP(): void;
48
49
  declare function debounce<F extends (...args: any[]) => any>(fn: F, delay?: number): (this: unknown, ...args: Parameters<F>) => void;
@@ -56,6 +57,8 @@ declare function isString(val: unknown): val is string;
56
57
  declare function isBoolean(val: unknown): val is boolean;
57
58
  declare function isNumber(val: unknown): val is number;
58
59
  declare function isSymbol(val: unknown): val is symbol;
60
+ declare function isError(val: unknown): val is Error;
61
+ declare function isDOMException(val: unknown): val is DOMException;
59
62
  declare function isNumeric(val: unknown): val is number | string;
60
63
  declare function isPlainObject(val: unknown): val is Record<string, any>;
61
64
  declare function isObject(val: unknown): val is Record<string, any>;
@@ -67,7 +70,7 @@ declare function isRegExp(val: unknown): val is RegExp;
67
70
  declare function isWeakMap(val: unknown): val is WeakMap<any, any>;
68
71
  declare function isWeakSet(val: unknown): val is WeakSet<any>;
69
72
  declare function isArrayBuffer(val: unknown): val is ArrayBuffer;
70
- declare function isTypedArray(val: unknown): boolean;
73
+ declare function isTypedArray(val: unknown): val is Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array;
71
74
  declare function isDataView(val: unknown): val is DataView;
72
75
  declare function toRawType(value: unknown): string;
73
76
  declare function isFunction(val: unknown): val is Function;
@@ -82,6 +85,8 @@ declare function inMobile(): boolean;
82
85
  declare function hasOwn<T extends object>(val: T, key: PropertyKey): key is keyof T;
83
86
  declare function getGlobalThis(): typeof globalThis;
84
87
  declare function isNonEmptyArray(val: unknown): val is Array<any>;
88
+ declare function isEqualWith(value: any, other: any, fn: (value: any, other: any) => any): boolean;
89
+ declare function isEqual(value: any, other: any): boolean;
85
90
 
86
91
  declare function toNumber(val: number | string | boolean | undefined | null): number;
87
92
  declare function clamp(num: number, min: number, max: number): number;
@@ -98,6 +103,8 @@ declare function slash(path: string): string;
98
103
  declare function genStringKey(): string;
99
104
  declare function upperFirst(s: string): string;
100
105
  declare function lowerFirst(s: string): string;
106
+ declare function randomString(length?: number): string;
107
+ declare function randomColor(): string;
101
108
 
102
109
  declare function mergeWith<TObject extends Record<string, any>, TSource extends Record<string, any>>(object: TObject, source: TSource, fn: (objValue: any, srcValue: any, key: string | number | symbol, object?: TObject, source?: TSource) => any): TObject & TSource;
103
110
  declare function merge<TObject extends Record<string, any>, TSource extends Record<string, any>>(object: TObject, source: TSource): TObject & TSource;
@@ -115,5 +122,6 @@ declare function maxBy<T>(arr: T[], fn: (val: T) => number): T | undefined;
115
122
  declare function mean(arr: number[]): number;
116
123
  declare function meanBy<T>(arr: T[], fn: (val: T) => number): number;
117
124
  declare function sample<T>(arr: T[]): T | undefined;
125
+ declare function sumHash(value: any): string;
118
126
 
119
- export { type BEM, type ClassName, type Classes, NOOP, type Storage, at, call, camelize, cancelAnimationFrame, clamp, clampArrayRange, classes, cloneDeep, cloneDeepWith, createNamespaceFn, createStorage, debounce, delay, doubleRaf, find, genNumberKey, genStringKey, getAllParentScroller, getGlobalThis, getParentScroller, getRect, getScrollLeft, getScrollTop, getStyle, hasOwn, inBrowser, inMobile, inViewport, isArray, isArrayBuffer, isBoolean, isDataView, isDate, isEmpty, isFunction, isMap, isNonEmptyArray, isNullish, isNumber, isNumeric, isObject, isPlainObject, isPromise, isRegExp, isSet, isString, isSymbol, isTruthy, isTypedArray, isWeakMap, isWeakSet, isWindow, kebabCase, localStorage, lowerFirst, maxBy, mean, meanBy, merge, mergeWith, minBy, normalizeToArray, objectToString, once, pascalCase, prettyJSONObject, preventDefault, raf, randomNumber, removeArrayBlank, removeArrayEmpty, removeItem, requestAnimationFrame, sample, sessionStorage, shuffle, slash, sum, sumBy, supportTouch, throttle, times, toArrayBuffer, toDataURL, toNumber, toRawType, toText, toTypeString, toggleItem, tryParseJSON, uniq, uniqBy, upperFirst };
127
+ export { type BEM, type ClassName, type Classes, NOOP, type Storage, at, call, camelize, cancelAnimationFrame, clamp, clampArrayRange, classes, cloneDeep, cloneDeepWith, copyText, createNamespaceFn, createStorage, debounce, delay, doubleRaf, find, genNumberKey, genStringKey, getAllParentScroller, getGlobalThis, getParentScroller, getRect, getScrollLeft, getScrollTop, getStyle, hasOwn, inBrowser, inMobile, inViewport, isArray, isArrayBuffer, isBoolean, isDOMException, isDataView, isDate, isEmpty, isEqual, isEqualWith, isError, isFunction, isMap, isNonEmptyArray, isNullish, isNumber, isNumeric, isObject, isPlainObject, isPromise, isRegExp, isSet, isString, isSymbol, isTruthy, isTypedArray, isWeakMap, isWeakSet, isWindow, kebabCase, localStorage, lowerFirst, maxBy, mean, meanBy, merge, mergeWith, minBy, normalizeToArray, objectToString, once, pascalCase, prettyJSONObject, preventDefault, raf, randomColor, randomNumber, randomString, removeArrayBlank, removeArrayEmpty, removeItem, requestAnimationFrame, sample, sessionStorage, shuffle, slash, sum, sumBy, sumHash, supportTouch, throttle, times, toArrayBuffer, toDataURL, toNumber, toRawType, toText, toTypeString, toggleItem, tryParseJSON, uniq, uniqBy, upperFirst };
package/lib/index.d.ts CHANGED
@@ -43,6 +43,7 @@ interface Storage extends globalThis.Storage {
43
43
  declare function createStorage(storage: globalThis.Storage): Storage;
44
44
  declare const sessionStorage: Storage;
45
45
  declare const localStorage: Storage;
46
+ declare function copyText(value: string): void;
46
47
 
47
48
  declare function NOOP(): void;
48
49
  declare function debounce<F extends (...args: any[]) => any>(fn: F, delay?: number): (this: unknown, ...args: Parameters<F>) => void;
@@ -56,6 +57,8 @@ declare function isString(val: unknown): val is string;
56
57
  declare function isBoolean(val: unknown): val is boolean;
57
58
  declare function isNumber(val: unknown): val is number;
58
59
  declare function isSymbol(val: unknown): val is symbol;
60
+ declare function isError(val: unknown): val is Error;
61
+ declare function isDOMException(val: unknown): val is DOMException;
59
62
  declare function isNumeric(val: unknown): val is number | string;
60
63
  declare function isPlainObject(val: unknown): val is Record<string, any>;
61
64
  declare function isObject(val: unknown): val is Record<string, any>;
@@ -67,7 +70,7 @@ declare function isRegExp(val: unknown): val is RegExp;
67
70
  declare function isWeakMap(val: unknown): val is WeakMap<any, any>;
68
71
  declare function isWeakSet(val: unknown): val is WeakSet<any>;
69
72
  declare function isArrayBuffer(val: unknown): val is ArrayBuffer;
70
- declare function isTypedArray(val: unknown): boolean;
73
+ declare function isTypedArray(val: unknown): val is Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array;
71
74
  declare function isDataView(val: unknown): val is DataView;
72
75
  declare function toRawType(value: unknown): string;
73
76
  declare function isFunction(val: unknown): val is Function;
@@ -82,6 +85,8 @@ declare function inMobile(): boolean;
82
85
  declare function hasOwn<T extends object>(val: T, key: PropertyKey): key is keyof T;
83
86
  declare function getGlobalThis(): typeof globalThis;
84
87
  declare function isNonEmptyArray(val: unknown): val is Array<any>;
88
+ declare function isEqualWith(value: any, other: any, fn: (value: any, other: any) => any): boolean;
89
+ declare function isEqual(value: any, other: any): boolean;
85
90
 
86
91
  declare function toNumber(val: number | string | boolean | undefined | null): number;
87
92
  declare function clamp(num: number, min: number, max: number): number;
@@ -98,6 +103,8 @@ declare function slash(path: string): string;
98
103
  declare function genStringKey(): string;
99
104
  declare function upperFirst(s: string): string;
100
105
  declare function lowerFirst(s: string): string;
106
+ declare function randomString(length?: number): string;
107
+ declare function randomColor(): string;
101
108
 
102
109
  declare function mergeWith<TObject extends Record<string, any>, TSource extends Record<string, any>>(object: TObject, source: TSource, fn: (objValue: any, srcValue: any, key: string | number | symbol, object?: TObject, source?: TSource) => any): TObject & TSource;
103
110
  declare function merge<TObject extends Record<string, any>, TSource extends Record<string, any>>(object: TObject, source: TSource): TObject & TSource;
@@ -115,5 +122,6 @@ declare function maxBy<T>(arr: T[], fn: (val: T) => number): T | undefined;
115
122
  declare function mean(arr: number[]): number;
116
123
  declare function meanBy<T>(arr: T[], fn: (val: T) => number): number;
117
124
  declare function sample<T>(arr: T[]): T | undefined;
125
+ declare function sumHash(value: any): string;
118
126
 
119
- export { type BEM, type ClassName, type Classes, NOOP, type Storage, at, call, camelize, cancelAnimationFrame, clamp, clampArrayRange, classes, cloneDeep, cloneDeepWith, createNamespaceFn, createStorage, debounce, delay, doubleRaf, find, genNumberKey, genStringKey, getAllParentScroller, getGlobalThis, getParentScroller, getRect, getScrollLeft, getScrollTop, getStyle, hasOwn, inBrowser, inMobile, inViewport, isArray, isArrayBuffer, isBoolean, isDataView, isDate, isEmpty, isFunction, isMap, isNonEmptyArray, isNullish, isNumber, isNumeric, isObject, isPlainObject, isPromise, isRegExp, isSet, isString, isSymbol, isTruthy, isTypedArray, isWeakMap, isWeakSet, isWindow, kebabCase, localStorage, lowerFirst, maxBy, mean, meanBy, merge, mergeWith, minBy, normalizeToArray, objectToString, once, pascalCase, prettyJSONObject, preventDefault, raf, randomNumber, removeArrayBlank, removeArrayEmpty, removeItem, requestAnimationFrame, sample, sessionStorage, shuffle, slash, sum, sumBy, supportTouch, throttle, times, toArrayBuffer, toDataURL, toNumber, toRawType, toText, toTypeString, toggleItem, tryParseJSON, uniq, uniqBy, upperFirst };
127
+ export { type BEM, type ClassName, type Classes, NOOP, type Storage, at, call, camelize, cancelAnimationFrame, clamp, clampArrayRange, classes, cloneDeep, cloneDeepWith, copyText, createNamespaceFn, createStorage, debounce, delay, doubleRaf, find, genNumberKey, genStringKey, getAllParentScroller, getGlobalThis, getParentScroller, getRect, getScrollLeft, getScrollTop, getStyle, hasOwn, inBrowser, inMobile, inViewport, isArray, isArrayBuffer, isBoolean, isDOMException, isDataView, isDate, isEmpty, isEqual, isEqualWith, isError, isFunction, isMap, isNonEmptyArray, isNullish, isNumber, isNumeric, isObject, isPlainObject, isPromise, isRegExp, isSet, isString, isSymbol, isTruthy, isTypedArray, isWeakMap, isWeakSet, isWindow, kebabCase, localStorage, lowerFirst, maxBy, mean, meanBy, merge, mergeWith, minBy, normalizeToArray, objectToString, once, pascalCase, prettyJSONObject, preventDefault, raf, randomColor, randomNumber, randomString, removeArrayBlank, removeArrayEmpty, removeItem, requestAnimationFrame, sample, sessionStorage, shuffle, slash, sum, sumBy, sumHash, supportTouch, throttle, times, toArrayBuffer, toDataURL, toNumber, toRawType, toText, toTypeString, toggleItem, tryParseJSON, uniq, uniqBy, upperFirst };
package/lib/index.js CHANGED
@@ -35,11 +35,17 @@ function isNumber(val) {
35
35
  function isSymbol(val) {
36
36
  return typeof val === "symbol";
37
37
  }
38
+ function isError(val) {
39
+ return toRawType(val) === "Error";
40
+ }
41
+ function isDOMException(val) {
42
+ return toRawType(val) === "DOMException";
43
+ }
38
44
  function isNumeric(val) {
39
45
  return isNumber(val) || isString(val) && /^[-+]?\d+$/.test(val);
40
46
  }
41
47
  function isPlainObject(val) {
42
- return Object.prototype.toString.call(val) === "[object Object]";
48
+ return toRawType(val) === "Object";
43
49
  }
44
50
  function isObject(val) {
45
51
  return typeof val === "object" && val !== null;
@@ -132,6 +138,102 @@ function getGlobalThis() {
132
138
  function isNonEmptyArray(val) {
133
139
  return isArray(val) && !!val.length;
134
140
  }
141
+ function isEqualWith(value, other, fn) {
142
+ const valueStack = /* @__PURE__ */ new WeakMap();
143
+ const otherStack = /* @__PURE__ */ new WeakMap();
144
+ function baseIsEqual(value2, other2, valueStack2, otherStack2) {
145
+ const customEqual = fn(value2, other2);
146
+ if (customEqual === true) {
147
+ return true;
148
+ }
149
+ if (value2 === other2) {
150
+ return true;
151
+ }
152
+ if (value2 !== value2 && other2 !== other2) {
153
+ return true;
154
+ }
155
+ if (!isObject(value2) || !isObject(other2)) {
156
+ return value2 === other2;
157
+ }
158
+ if (value2.constructor !== other2.constructor) {
159
+ return false;
160
+ }
161
+ if (toRawType(value2) === "String" && toRawType(other2) === "String" || toRawType(value2) === "Number" && toRawType(other2) === "Number" || toRawType(value2) === "Boolean" && toRawType(other2) === "Boolean" || toRawType(value2) === "BigInt" && toRawType(other2) === "BigInt" || toRawType(value2) === "Symbol" && toRawType(other2) === "Symbol") {
162
+ return value2.valueOf() === other2.valueOf();
163
+ }
164
+ if (isDate(value2) && isDate(other2)) {
165
+ return value2.getTime() === other2.getTime();
166
+ }
167
+ if (isRegExp(value2) && isRegExp(other2)) {
168
+ return value2.source === other2.source && value2.flags === other2.flags;
169
+ }
170
+ if (isError(value2) && isError(other2)) {
171
+ return value2.name === other2.name && value2.message === other2.message && value2.cause === other2.cause;
172
+ }
173
+ if (isDOMException(value2) && isDOMException(other2)) {
174
+ return value2.name === other2.name && value2.message === other2.message;
175
+ }
176
+ if (isTypedArray(value2) && isTypedArray(other2) || isDataView(value2) && isDataView(other2)) {
177
+ if (value2.byteLength !== other2.byteLength) {
178
+ return false;
179
+ }
180
+ const valueTypedArray = new Uint8Array(value2.buffer);
181
+ const otherTypedArray = new Uint8Array(other2.buffer);
182
+ return valueTypedArray.every((v, i) => v === otherTypedArray[i]);
183
+ }
184
+ if (isArrayBuffer(value2) && isArrayBuffer(other2)) {
185
+ if (value2.byteLength !== other2.byteLength) {
186
+ return false;
187
+ }
188
+ const valueTypedArray = new Uint8Array(value2);
189
+ const otherTypedArray = new Uint8Array(other2);
190
+ return valueTypedArray.every((v, i) => v === otherTypedArray[i]);
191
+ }
192
+ if (valueStack2.get(value2) === other2 && otherStack2.get(other2) === value2) {
193
+ return true;
194
+ }
195
+ valueStack2.set(value2, other2);
196
+ otherStack2.set(other2, value2);
197
+ if (isMap(value2) && isMap(other2) || isSet(value2) && isSet(other2)) {
198
+ if (value2.size !== other2.size) {
199
+ return false;
200
+ }
201
+ const valueArray = [...value2];
202
+ const otherArray = [...other2];
203
+ const result = valueArray.every((v, i) => baseIsEqual(v, otherArray[i], valueStack2, otherStack2));
204
+ valueStack2.delete(value2);
205
+ otherStack2.delete(other2);
206
+ return result;
207
+ }
208
+ if (isArray(value2) && isArray(other2)) {
209
+ if (value2.length !== other2.length) {
210
+ return false;
211
+ }
212
+ const result = value2.every((v, i) => baseIsEqual(v, other2[i], valueStack2, otherStack2));
213
+ valueStack2.delete(value2);
214
+ otherStack2.delete(other2);
215
+ return result;
216
+ }
217
+ if (isPlainObject(value2) && isPlainObject(other2)) {
218
+ const valueOwnKeys = [...Object.keys(value2), ...Object.getOwnPropertySymbols(value2)];
219
+ const otherOwnKeys = [...Object.keys(other2), ...Object.getOwnPropertySymbols(other2)];
220
+ if (valueOwnKeys.length !== otherOwnKeys.length) {
221
+ return false;
222
+ }
223
+ const result = valueOwnKeys.every(
224
+ (k) => baseIsEqual(value2[k], other2[k], valueStack2, otherStack2)
225
+ );
226
+ valueStack2.delete(value2);
227
+ otherStack2.delete(other2);
228
+ return result;
229
+ }
230
+ return false;
231
+ }
232
+ return baseIsEqual(value, other, valueStack, otherStack);
233
+ }
234
+ function isEqual(value, other) {
235
+ return isEqualWith(value, other, () => void 0);
236
+ }
135
237
 
136
238
  // src/array.ts
137
239
  function uniq(arr) {
@@ -222,6 +324,24 @@ function upperFirst(s) {
222
324
  function lowerFirst(s) {
223
325
  return s.charAt(0).toLowerCase() + s.slice(1);
224
326
  }
327
+ function randomString(length = 10) {
328
+ let str = baseRandomString();
329
+ while (str.length < length) {
330
+ str += baseRandomString();
331
+ }
332
+ function baseRandomString() {
333
+ return Math.random().toString(36).slice(2);
334
+ }
335
+ return str.slice(0, length);
336
+ }
337
+ function randomColor() {
338
+ const letters = "0123456789abcdef";
339
+ let color = "#";
340
+ for (let i = 0; i < 6; i++) {
341
+ color += letters[Math.floor(Math.random() * 16)];
342
+ }
343
+ return color;
344
+ }
225
345
 
226
346
  // src/util.ts
227
347
  function requestAnimationFrame(fn) {
@@ -379,6 +499,17 @@ function createStorage(storage) {
379
499
  }
380
500
  var sessionStorage = createStorage(globalThis.sessionStorage);
381
501
  var localStorage = createStorage(globalThis.localStorage);
502
+ function copyText(value) {
503
+ if (!value) return;
504
+ const textArea = document.createElement("textarea");
505
+ textArea.value = value;
506
+ textArea.style.position = "fixed";
507
+ textArea.style.opacity = "0";
508
+ document.body.appendChild(textArea);
509
+ textArea.select();
510
+ document.execCommand("copy");
511
+ document.body.removeChild(textArea);
512
+ }
382
513
 
383
514
  // src/function.ts
384
515
  function NOOP() {
@@ -543,7 +674,7 @@ function cloneDeepWith(value, fn) {
543
674
  if (toRawType(value2) === "String" || toRawType(value2) === "Number" || toRawType(value2) === "Boolean") {
544
675
  return newConstructor(value2, value2.valueOf());
545
676
  }
546
- if (isWeakMap(value2) || isWeakSet(value2)) {
677
+ if (isWeakMap(value2) || isWeakSet(value2) || isError(value2) || isDOMException(value2)) {
547
678
  return {};
548
679
  }
549
680
  if (isTypedArray(value2)) {
@@ -566,11 +697,10 @@ function cloneDeepWith(value, fn) {
566
697
  if (isPlainObject(value2)) {
567
698
  const result = Object.create(Reflect.getPrototypeOf(value2));
568
699
  cache2.set(value2, result);
569
- for (const key3 in value2) {
570
- if (hasOwn(value2, key3)) {
571
- result[key3] = baseCloneDeep(value2[key3], cache2);
572
- }
573
- }
700
+ const ownKeys = [...Object.keys(value2), ...Object.getOwnPropertySymbols(value2)];
701
+ ownKeys.forEach((key3) => {
702
+ result[key3] = baseCloneDeep(value2[key3], cache2);
703
+ });
574
704
  return result;
575
705
  }
576
706
  return value2;
@@ -646,6 +776,40 @@ function sample(arr) {
646
776
  }
647
777
  return arr[randomNumber(0, arr.length - 1)];
648
778
  }
779
+ function sumHash(value) {
780
+ function sum2(hash, value2) {
781
+ for (let i = 0; i < value2.length; i++) {
782
+ const chr = value2.charCodeAt(i);
783
+ hash = (hash << 5) - hash + chr;
784
+ hash |= 0;
785
+ }
786
+ return hash < 0 ? hash * -2 : hash;
787
+ }
788
+ function baseSumHash(hash, value2, key3, seen) {
789
+ hash = sum2(hash, key3);
790
+ hash = sum2(hash, toTypeString(value2));
791
+ hash = sum2(hash, typeof value2);
792
+ if (value2 === null) {
793
+ return sum2(hash, "null");
794
+ }
795
+ if (value2 === void 0) {
796
+ return sum2(hash, "undefined");
797
+ }
798
+ if (isObject(value2) || isFunction(value2)) {
799
+ if (seen.includes(value2)) {
800
+ return sum2(hash, `[Circular]${key3}`);
801
+ }
802
+ seen.push(value2);
803
+ hash = Object.keys(value2).sort().reduce((hash2, key4) => baseSumHash(hash2, value2[key4], key4, seen), hash);
804
+ if (isFunction(value2.valueOf)) {
805
+ return sum2(hash, String(value2.valueOf()));
806
+ }
807
+ return hash;
808
+ }
809
+ return sum2(hash, value2.toString());
810
+ }
811
+ return baseSumHash(0, value, "", []).toString(16).padStart(8, "0");
812
+ }
649
813
 
650
814
  // src/index.ts
651
815
  export * from "mitt";
@@ -661,6 +825,7 @@ export {
661
825
  classes,
662
826
  cloneDeep,
663
827
  cloneDeepWith,
828
+ copyText,
664
829
  createNamespaceFn,
665
830
  createStorage,
666
831
  debounce,
@@ -683,9 +848,13 @@ export {
683
848
  isArray,
684
849
  isArrayBuffer,
685
850
  isBoolean,
851
+ isDOMException,
686
852
  isDataView,
687
853
  isDate,
688
854
  isEmpty,
855
+ isEqual,
856
+ isEqualWith,
857
+ isError,
689
858
  isFunction,
690
859
  isMap,
691
860
  isNonEmptyArray,
@@ -721,7 +890,9 @@ export {
721
890
  prettyJSONObject,
722
891
  preventDefault,
723
892
  raf,
893
+ randomColor,
724
894
  randomNumber,
895
+ randomString,
725
896
  removeArrayBlank,
726
897
  removeArrayEmpty,
727
898
  removeItem,
@@ -732,6 +903,7 @@ export {
732
903
  slash,
733
904
  sum,
734
905
  sumBy,
906
+ sumHash,
735
907
  supportTouch,
736
908
  throttle,
737
909
  times,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rattail",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "type": "module",
5
5
  "main": "lib/index.cjs",
6
6
  "module": "lib/index.js",
@@ -36,16 +36,16 @@
36
36
  "commit-msg": "pnpm exec vr commit-lint -p $1"
37
37
  },
38
38
  "nano-staged": {
39
- "*.{md}": "pnpm format",
39
+ "*.{md}": "prettier --write",
40
40
  "*.{ts}": [
41
- "pnpm format",
42
- "pnpm lint"
41
+ "prettier --write",
42
+ "eslint --fix"
43
43
  ]
44
44
  },
45
45
  "devDependencies": {
46
46
  "@types/node": "^22.8.1",
47
47
  "@varlet/eslint-config": "latest",
48
- "@varlet/release": "^0.3.0",
48
+ "@varlet/release": "^0.3.1",
49
49
  "@vitest/coverage-istanbul": "^2.1.3",
50
50
  "eslint": "^8.53.0",
51
51
  "jsdom": "^25.0.1",