rattail 1.0.24 → 1.2.0

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
@@ -53,6 +53,7 @@ __export(src_exports, {
53
53
  at: () => at,
54
54
  baseRound: () => baseRound,
55
55
  call: () => call,
56
+ callOrReturn: () => callOrReturn,
56
57
  camelize: () => camelize,
57
58
  cancelAnimationFrame: () => cancelAnimationFrame,
58
59
  ceil: () => ceil,
@@ -86,6 +87,8 @@ __export(src_exports, {
86
87
  getScrollTop: () => getScrollTop,
87
88
  getStyle: () => getStyle,
88
89
  groupBy: () => groupBy,
90
+ hasDuplicates: () => hasDuplicates,
91
+ hasDuplicatesBy: () => hasDuplicatesBy,
89
92
  hasOwn: () => hasOwn,
90
93
  inBrowser: () => inBrowser,
91
94
  inMobile: () => inMobile,
@@ -156,6 +159,8 @@ __export(src_exports, {
156
159
  removeArrayBlank: () => removeArrayBlank,
157
160
  removeArrayEmpty: () => removeArrayEmpty,
158
161
  removeItem: () => removeItem,
162
+ removeItemBy: () => removeItemBy,
163
+ removeItemsBy: () => removeItemsBy,
159
164
  requestAnimationFrame: () => requestAnimationFrame,
160
165
  round: () => round,
161
166
  sample: () => sample,
@@ -535,6 +540,16 @@ function assert(condition, message) {
535
540
  }
536
541
  }
537
542
 
543
+ // src/general/hasDuplicates.ts
544
+ function hasDuplicates(arr) {
545
+ return uniq(arr).length !== arr.length;
546
+ }
547
+
548
+ // src/general/hasDuplicatesBy.ts
549
+ function hasDuplicatesBy(arr, fn) {
550
+ return uniqBy(arr, fn).length !== arr.length;
551
+ }
552
+
538
553
  // src/number/toNumber.ts
539
554
  function toNumber(val) {
540
555
  if (val == null) {
@@ -579,6 +594,30 @@ function removeItem(arr, item) {
579
594
  }
580
595
  }
581
596
 
597
+ // src/array/removeItemBy.ts
598
+ function removeItemBy(arr, fn) {
599
+ if (arr.length) {
600
+ const index = arr.findIndex((v) => fn(v));
601
+ if (index > -1) {
602
+ return arr.splice(index, 1);
603
+ }
604
+ }
605
+ }
606
+
607
+ // src/array/removeItemsBy.ts
608
+ function removeItemsBy(arr, fn) {
609
+ let i = 0;
610
+ const removedItems = [];
611
+ while (i < arr.length) {
612
+ if (fn(arr[i])) {
613
+ removedItems.push(...arr.splice(i, 1));
614
+ } else {
615
+ i++;
616
+ }
617
+ }
618
+ return removedItems;
619
+ }
620
+
582
621
  // src/array/toggleItem.ts
583
622
  function toggleItem(arr, item) {
584
623
  arr.includes(item) ? removeItem(arr, item) : arr.push(item);
@@ -1331,6 +1370,14 @@ function throttle(fn, delay2 = 200) {
1331
1370
  function NOOP() {
1332
1371
  }
1333
1372
 
1373
+ // src/function/callOrReturn.ts
1374
+ function callOrReturn(fnOrValue, ...args) {
1375
+ if (isFunction(fnOrValue)) {
1376
+ return fnOrValue(...args);
1377
+ }
1378
+ return fnOrValue;
1379
+ }
1380
+
1334
1381
  // src/collection/cloneDeepWith.ts
1335
1382
  function cloneDeepWith(value, fn) {
1336
1383
  const cache = /* @__PURE__ */ new WeakMap();
@@ -1595,6 +1642,7 @@ function ceil(val, precision = 0) {
1595
1642
  at,
1596
1643
  baseRound,
1597
1644
  call,
1645
+ callOrReturn,
1598
1646
  camelize,
1599
1647
  cancelAnimationFrame,
1600
1648
  ceil,
@@ -1628,6 +1676,8 @@ function ceil(val, precision = 0) {
1628
1676
  getScrollTop,
1629
1677
  getStyle,
1630
1678
  groupBy,
1679
+ hasDuplicates,
1680
+ hasDuplicatesBy,
1631
1681
  hasOwn,
1632
1682
  inBrowser,
1633
1683
  inMobile,
@@ -1698,6 +1748,8 @@ function ceil(val, precision = 0) {
1698
1748
  removeArrayBlank,
1699
1749
  removeArrayEmpty,
1700
1750
  removeItem,
1751
+ removeItemBy,
1752
+ removeItemsBy,
1701
1753
  requestAnimationFrame,
1702
1754
  round,
1703
1755
  sample,
package/lib/index.d.cts CHANGED
@@ -7,6 +7,10 @@ declare function chunk<T>(arr: T[], size?: number): T[][];
7
7
 
8
8
  declare function removeItem<T>(arr: T[], item: T): T[] | undefined;
9
9
 
10
+ declare function removeItemBy<T>(arr: T[], fn: (v: T) => any): T[] | undefined;
11
+
12
+ declare function removeItemsBy<T>(arr: T[], fn: (v: T) => any): T[];
13
+
10
14
  declare function toggleItem<T>(arr: T[], item: T): T[];
11
15
 
12
16
  declare function uniq<T>(arr: T[]): T[];
@@ -161,6 +165,8 @@ declare function throttle<F extends (...args: any[]) => any>(fn: F, delay?: numb
161
165
 
162
166
  declare function NOOP(): void;
163
167
 
168
+ declare function callOrReturn<T, A extends any[]>(fnOrValue: T | ((...args: A) => T), ...args: A): T;
169
+
164
170
  declare function getGlobalThis(): typeof globalThis;
165
171
 
166
172
  declare function hasOwn<T extends object>(val: T, key: PropertyKey): key is keyof T;
@@ -242,6 +248,10 @@ declare function isEmptyPlainObject(val: unknown): val is Record<string, any>;
242
248
 
243
249
  declare function assert(condition: boolean, message: string): asserts condition;
244
250
 
251
+ declare function hasDuplicates<T>(arr: T[]): boolean;
252
+
253
+ declare function hasDuplicatesBy<T>(arr: T[], fn: (a: T, b: T) => any): boolean;
254
+
245
255
  declare function clamp(num: number, min: number, max: number): number;
246
256
 
247
257
  declare function clampArrayRange(index: number, arr: unknown[]): number;
@@ -316,4 +326,4 @@ declare function floor(val: number, precision?: number): number;
316
326
 
317
327
  declare function ceil(val: number, precision?: number): number;
318
328
 
319
- export { type BEM, type ClassName, type Classes, type DurationContext, type Motion, type MotionOptions, type MotionState, NOOP, type PromiseWithResolvers, type Storage, assert, at, baseRound, call, camelize, cancelAnimationFrame, ceil, chunk, clamp, clampArrayRange, classes, cloneDeep, cloneDeepWith, copyText, createNamespaceFn, createStorage, debounce, delay, difference, differenceWith, doubleRaf, download, duration, ensurePrefix, ensureSuffix, find, floor, genNumberKey, genStringKey, getAllParentScroller, getGlobalThis, getParentScroller, getRect, getScrollLeft, getScrollTop, getStyle, groupBy, hasOwn, inBrowser, inMobile, inViewport, intersection, intersectionWith, isArray, isArrayBuffer, isBlob, isBoolean, isDOMException, isDataView, isDate, isEmpty, isEmptyPlainObject, isEqual, isEqualWith, isError, isFile, isFunction, isMap, isNonEmptyArray, isNullish, isNumber, isNumeric, isObject, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isString, isSymbol, isTruthy, isTypedArray, isWeakMap, isWeakSet, isWindow, kebabCase, localStorage, lowerFirst, mapObject, maxBy, mean, meanBy, merge, mergeWith, minBy, motion, normalizeToArray, objectEntries, objectKeys, objectToString, omit, omitBy, once, pascalCase, pick, pickBy, prettyJSONObject, preventDefault, promiseWithResolvers, raf, randomColor, randomNumber, randomString, removeArrayBlank, removeArrayEmpty, removeItem, requestAnimationFrame, round, sample, sessionStorage, set, shuffle, slash, sum, sumBy, sumHash, supportTouch, throttle, times, toArrayBuffer, toDataURL, toNumber, toRawType, toText, toTypeString, toggleItem, tryParseJSON, uniq, uniqBy, upperFirst, xor, xorWith };
329
+ export { type BEM, type ClassName, type Classes, type DurationContext, type Motion, type MotionOptions, type MotionState, NOOP, type PromiseWithResolvers, type Storage, assert, at, baseRound, call, callOrReturn, camelize, cancelAnimationFrame, ceil, chunk, clamp, clampArrayRange, classes, cloneDeep, cloneDeepWith, copyText, createNamespaceFn, createStorage, debounce, delay, difference, differenceWith, doubleRaf, download, duration, ensurePrefix, ensureSuffix, find, floor, genNumberKey, genStringKey, getAllParentScroller, getGlobalThis, getParentScroller, getRect, getScrollLeft, getScrollTop, getStyle, groupBy, hasDuplicates, hasDuplicatesBy, hasOwn, inBrowser, inMobile, inViewport, intersection, intersectionWith, isArray, isArrayBuffer, isBlob, isBoolean, isDOMException, isDataView, isDate, isEmpty, isEmptyPlainObject, isEqual, isEqualWith, isError, isFile, isFunction, isMap, isNonEmptyArray, isNullish, isNumber, isNumeric, isObject, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isString, isSymbol, isTruthy, isTypedArray, isWeakMap, isWeakSet, isWindow, kebabCase, localStorage, lowerFirst, mapObject, maxBy, mean, meanBy, merge, mergeWith, minBy, motion, normalizeToArray, objectEntries, objectKeys, objectToString, omit, omitBy, once, pascalCase, pick, pickBy, prettyJSONObject, preventDefault, promiseWithResolvers, raf, randomColor, randomNumber, randomString, removeArrayBlank, removeArrayEmpty, removeItem, removeItemBy, removeItemsBy, requestAnimationFrame, round, sample, sessionStorage, set, shuffle, slash, sum, sumBy, sumHash, supportTouch, throttle, times, toArrayBuffer, toDataURL, toNumber, toRawType, toText, toTypeString, toggleItem, tryParseJSON, uniq, uniqBy, upperFirst, xor, xorWith };
package/lib/index.d.ts CHANGED
@@ -7,6 +7,10 @@ declare function chunk<T>(arr: T[], size?: number): T[][];
7
7
 
8
8
  declare function removeItem<T>(arr: T[], item: T): T[] | undefined;
9
9
 
10
+ declare function removeItemBy<T>(arr: T[], fn: (v: T) => any): T[] | undefined;
11
+
12
+ declare function removeItemsBy<T>(arr: T[], fn: (v: T) => any): T[];
13
+
10
14
  declare function toggleItem<T>(arr: T[], item: T): T[];
11
15
 
12
16
  declare function uniq<T>(arr: T[]): T[];
@@ -161,6 +165,8 @@ declare function throttle<F extends (...args: any[]) => any>(fn: F, delay?: numb
161
165
 
162
166
  declare function NOOP(): void;
163
167
 
168
+ declare function callOrReturn<T, A extends any[]>(fnOrValue: T | ((...args: A) => T), ...args: A): T;
169
+
164
170
  declare function getGlobalThis(): typeof globalThis;
165
171
 
166
172
  declare function hasOwn<T extends object>(val: T, key: PropertyKey): key is keyof T;
@@ -242,6 +248,10 @@ declare function isEmptyPlainObject(val: unknown): val is Record<string, any>;
242
248
 
243
249
  declare function assert(condition: boolean, message: string): asserts condition;
244
250
 
251
+ declare function hasDuplicates<T>(arr: T[]): boolean;
252
+
253
+ declare function hasDuplicatesBy<T>(arr: T[], fn: (a: T, b: T) => any): boolean;
254
+
245
255
  declare function clamp(num: number, min: number, max: number): number;
246
256
 
247
257
  declare function clampArrayRange(index: number, arr: unknown[]): number;
@@ -316,4 +326,4 @@ declare function floor(val: number, precision?: number): number;
316
326
 
317
327
  declare function ceil(val: number, precision?: number): number;
318
328
 
319
- export { type BEM, type ClassName, type Classes, type DurationContext, type Motion, type MotionOptions, type MotionState, NOOP, type PromiseWithResolvers, type Storage, assert, at, baseRound, call, camelize, cancelAnimationFrame, ceil, chunk, clamp, clampArrayRange, classes, cloneDeep, cloneDeepWith, copyText, createNamespaceFn, createStorage, debounce, delay, difference, differenceWith, doubleRaf, download, duration, ensurePrefix, ensureSuffix, find, floor, genNumberKey, genStringKey, getAllParentScroller, getGlobalThis, getParentScroller, getRect, getScrollLeft, getScrollTop, getStyle, groupBy, hasOwn, inBrowser, inMobile, inViewport, intersection, intersectionWith, isArray, isArrayBuffer, isBlob, isBoolean, isDOMException, isDataView, isDate, isEmpty, isEmptyPlainObject, isEqual, isEqualWith, isError, isFile, isFunction, isMap, isNonEmptyArray, isNullish, isNumber, isNumeric, isObject, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isString, isSymbol, isTruthy, isTypedArray, isWeakMap, isWeakSet, isWindow, kebabCase, localStorage, lowerFirst, mapObject, maxBy, mean, meanBy, merge, mergeWith, minBy, motion, normalizeToArray, objectEntries, objectKeys, objectToString, omit, omitBy, once, pascalCase, pick, pickBy, prettyJSONObject, preventDefault, promiseWithResolvers, raf, randomColor, randomNumber, randomString, removeArrayBlank, removeArrayEmpty, removeItem, requestAnimationFrame, round, sample, sessionStorage, set, shuffle, slash, sum, sumBy, sumHash, supportTouch, throttle, times, toArrayBuffer, toDataURL, toNumber, toRawType, toText, toTypeString, toggleItem, tryParseJSON, uniq, uniqBy, upperFirst, xor, xorWith };
329
+ export { type BEM, type ClassName, type Classes, type DurationContext, type Motion, type MotionOptions, type MotionState, NOOP, type PromiseWithResolvers, type Storage, assert, at, baseRound, call, callOrReturn, camelize, cancelAnimationFrame, ceil, chunk, clamp, clampArrayRange, classes, cloneDeep, cloneDeepWith, copyText, createNamespaceFn, createStorage, debounce, delay, difference, differenceWith, doubleRaf, download, duration, ensurePrefix, ensureSuffix, find, floor, genNumberKey, genStringKey, getAllParentScroller, getGlobalThis, getParentScroller, getRect, getScrollLeft, getScrollTop, getStyle, groupBy, hasDuplicates, hasDuplicatesBy, hasOwn, inBrowser, inMobile, inViewport, intersection, intersectionWith, isArray, isArrayBuffer, isBlob, isBoolean, isDOMException, isDataView, isDate, isEmpty, isEmptyPlainObject, isEqual, isEqualWith, isError, isFile, isFunction, isMap, isNonEmptyArray, isNullish, isNumber, isNumeric, isObject, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isString, isSymbol, isTruthy, isTypedArray, isWeakMap, isWeakSet, isWindow, kebabCase, localStorage, lowerFirst, mapObject, maxBy, mean, meanBy, merge, mergeWith, minBy, motion, normalizeToArray, objectEntries, objectKeys, objectToString, omit, omitBy, once, pascalCase, pick, pickBy, prettyJSONObject, preventDefault, promiseWithResolvers, raf, randomColor, randomNumber, randomString, removeArrayBlank, removeArrayEmpty, removeItem, removeItemBy, removeItemsBy, requestAnimationFrame, round, sample, sessionStorage, set, shuffle, slash, sum, sumBy, sumHash, supportTouch, throttle, times, toArrayBuffer, toDataURL, toNumber, toRawType, toText, toTypeString, toggleItem, tryParseJSON, uniq, uniqBy, upperFirst, xor, xorWith };
@@ -43,6 +43,7 @@ var Rattail = (() => {
43
43
  at: () => at,
44
44
  baseRound: () => baseRound,
45
45
  call: () => call,
46
+ callOrReturn: () => callOrReturn,
46
47
  camelize: () => camelize,
47
48
  cancelAnimationFrame: () => cancelAnimationFrame,
48
49
  ceil: () => ceil,
@@ -76,6 +77,8 @@ var Rattail = (() => {
76
77
  getScrollTop: () => getScrollTop,
77
78
  getStyle: () => getStyle,
78
79
  groupBy: () => groupBy,
80
+ hasDuplicates: () => hasDuplicates,
81
+ hasDuplicatesBy: () => hasDuplicatesBy,
79
82
  hasOwn: () => hasOwn,
80
83
  inBrowser: () => inBrowser,
81
84
  inMobile: () => inMobile,
@@ -146,6 +149,8 @@ var Rattail = (() => {
146
149
  removeArrayBlank: () => removeArrayBlank,
147
150
  removeArrayEmpty: () => removeArrayEmpty,
148
151
  removeItem: () => removeItem,
152
+ removeItemBy: () => removeItemBy,
153
+ removeItemsBy: () => removeItemsBy,
149
154
  requestAnimationFrame: () => requestAnimationFrame,
150
155
  round: () => round,
151
156
  sample: () => sample,
@@ -524,6 +529,16 @@ var Rattail = (() => {
524
529
  }
525
530
  }
526
531
 
532
+ // src/general/hasDuplicates.ts
533
+ function hasDuplicates(arr) {
534
+ return uniq(arr).length !== arr.length;
535
+ }
536
+
537
+ // src/general/hasDuplicatesBy.ts
538
+ function hasDuplicatesBy(arr, fn) {
539
+ return uniqBy(arr, fn).length !== arr.length;
540
+ }
541
+
527
542
  // src/number/toNumber.ts
528
543
  function toNumber(val) {
529
544
  if (val == null) {
@@ -568,6 +583,30 @@ var Rattail = (() => {
568
583
  }
569
584
  }
570
585
 
586
+ // src/array/removeItemBy.ts
587
+ function removeItemBy(arr, fn) {
588
+ if (arr.length) {
589
+ const index = arr.findIndex((v) => fn(v));
590
+ if (index > -1) {
591
+ return arr.splice(index, 1);
592
+ }
593
+ }
594
+ }
595
+
596
+ // src/array/removeItemsBy.ts
597
+ function removeItemsBy(arr, fn) {
598
+ let i = 0;
599
+ const removedItems = [];
600
+ while (i < arr.length) {
601
+ if (fn(arr[i])) {
602
+ removedItems.push(...arr.splice(i, 1));
603
+ } else {
604
+ i++;
605
+ }
606
+ }
607
+ return removedItems;
608
+ }
609
+
571
610
  // src/array/toggleItem.ts
572
611
  function toggleItem(arr, item) {
573
612
  arr.includes(item) ? removeItem(arr, item) : arr.push(item);
@@ -1302,6 +1341,14 @@ var Rattail = (() => {
1302
1341
  function NOOP() {
1303
1342
  }
1304
1343
 
1344
+ // src/function/callOrReturn.ts
1345
+ function callOrReturn(fnOrValue, ...args) {
1346
+ if (isFunction(fnOrValue)) {
1347
+ return fnOrValue(...args);
1348
+ }
1349
+ return fnOrValue;
1350
+ }
1351
+
1305
1352
  // src/collection/cloneDeepWith.ts
1306
1353
  function cloneDeepWith(value, fn) {
1307
1354
  const cache = /* @__PURE__ */ new WeakMap();
package/lib/index.js CHANGED
@@ -41,6 +41,7 @@ __export(src_exports, {
41
41
  at: () => at,
42
42
  baseRound: () => baseRound,
43
43
  call: () => call,
44
+ callOrReturn: () => callOrReturn,
44
45
  camelize: () => camelize,
45
46
  cancelAnimationFrame: () => cancelAnimationFrame,
46
47
  ceil: () => ceil,
@@ -74,6 +75,8 @@ __export(src_exports, {
74
75
  getScrollTop: () => getScrollTop,
75
76
  getStyle: () => getStyle,
76
77
  groupBy: () => groupBy,
78
+ hasDuplicates: () => hasDuplicates,
79
+ hasDuplicatesBy: () => hasDuplicatesBy,
77
80
  hasOwn: () => hasOwn,
78
81
  inBrowser: () => inBrowser,
79
82
  inMobile: () => inMobile,
@@ -144,6 +147,8 @@ __export(src_exports, {
144
147
  removeArrayBlank: () => removeArrayBlank,
145
148
  removeArrayEmpty: () => removeArrayEmpty,
146
149
  removeItem: () => removeItem,
150
+ removeItemBy: () => removeItemBy,
151
+ removeItemsBy: () => removeItemsBy,
147
152
  requestAnimationFrame: () => requestAnimationFrame,
148
153
  round: () => round,
149
154
  sample: () => sample,
@@ -522,6 +527,16 @@ function assert(condition, message) {
522
527
  }
523
528
  }
524
529
 
530
+ // src/general/hasDuplicates.ts
531
+ function hasDuplicates(arr) {
532
+ return uniq(arr).length !== arr.length;
533
+ }
534
+
535
+ // src/general/hasDuplicatesBy.ts
536
+ function hasDuplicatesBy(arr, fn) {
537
+ return uniqBy(arr, fn).length !== arr.length;
538
+ }
539
+
525
540
  // src/number/toNumber.ts
526
541
  function toNumber(val) {
527
542
  if (val == null) {
@@ -566,6 +581,30 @@ function removeItem(arr, item) {
566
581
  }
567
582
  }
568
583
 
584
+ // src/array/removeItemBy.ts
585
+ function removeItemBy(arr, fn) {
586
+ if (arr.length) {
587
+ const index = arr.findIndex((v) => fn(v));
588
+ if (index > -1) {
589
+ return arr.splice(index, 1);
590
+ }
591
+ }
592
+ }
593
+
594
+ // src/array/removeItemsBy.ts
595
+ function removeItemsBy(arr, fn) {
596
+ let i = 0;
597
+ const removedItems = [];
598
+ while (i < arr.length) {
599
+ if (fn(arr[i])) {
600
+ removedItems.push(...arr.splice(i, 1));
601
+ } else {
602
+ i++;
603
+ }
604
+ }
605
+ return removedItems;
606
+ }
607
+
569
608
  // src/array/toggleItem.ts
570
609
  function toggleItem(arr, item) {
571
610
  arr.includes(item) ? removeItem(arr, item) : arr.push(item);
@@ -1319,6 +1358,14 @@ function throttle(fn, delay2 = 200) {
1319
1358
  function NOOP() {
1320
1359
  }
1321
1360
 
1361
+ // src/function/callOrReturn.ts
1362
+ function callOrReturn(fnOrValue, ...args) {
1363
+ if (isFunction(fnOrValue)) {
1364
+ return fnOrValue(...args);
1365
+ }
1366
+ return fnOrValue;
1367
+ }
1368
+
1322
1369
  // src/collection/cloneDeepWith.ts
1323
1370
  function cloneDeepWith(value, fn) {
1324
1371
  const cache = /* @__PURE__ */ new WeakMap();
@@ -1582,6 +1629,7 @@ export {
1582
1629
  at,
1583
1630
  baseRound,
1584
1631
  call,
1632
+ callOrReturn,
1585
1633
  camelize,
1586
1634
  cancelAnimationFrame,
1587
1635
  ceil,
@@ -1615,6 +1663,8 @@ export {
1615
1663
  getScrollTop,
1616
1664
  getStyle,
1617
1665
  groupBy,
1666
+ hasDuplicates,
1667
+ hasDuplicatesBy,
1618
1668
  hasOwn,
1619
1669
  inBrowser,
1620
1670
  inMobile,
@@ -1685,6 +1735,8 @@ export {
1685
1735
  removeArrayBlank,
1686
1736
  removeArrayEmpty,
1687
1737
  removeItem,
1738
+ removeItemBy,
1739
+ removeItemsBy,
1688
1740
  requestAnimationFrame,
1689
1741
  round,
1690
1742
  sample,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rattail",
3
- "version": "1.0.24",
3
+ "version": "1.2.0",
4
4
  "description": "A utilities library for front-end developers, lightweight and ts-friendly",
5
5
  "keywords": [
6
6
  "utilities library",