rattail 0.0.9 → 0.0.10

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
  call: () => call,
54
54
  camelize: () => camelize,
55
55
  cancelAnimationFrame: () => cancelAnimationFrame,
56
+ chunk: () => chunk,
56
57
  clamp: () => clamp,
57
58
  clampArrayRange: () => clampArrayRange,
58
59
  classes: () => classes,
@@ -371,6 +372,43 @@ function isEqual(value, other) {
371
372
  return isEqualWith(value, other, () => void 0);
372
373
  }
373
374
 
375
+ // src/number.ts
376
+ function toNumber(val) {
377
+ if (val == null) {
378
+ return 0;
379
+ }
380
+ if (isString(val)) {
381
+ val = parseFloat(val);
382
+ val = Number.isNaN(val) ? 0 : val;
383
+ return val;
384
+ }
385
+ if (isBoolean(val)) {
386
+ return Number(val);
387
+ }
388
+ return val;
389
+ }
390
+ function clamp(num, min, max) {
391
+ return Math.min(max, Math.max(min, num));
392
+ }
393
+ function clampArrayRange(index, arr) {
394
+ return clamp(index, 0, arr.length - 1);
395
+ }
396
+ var key = 0;
397
+ function genNumberKey() {
398
+ return key++;
399
+ }
400
+ function randomNumber(min = 0, max = 100) {
401
+ return Math.floor(Math.random() * (max - min + 1)) + min;
402
+ }
403
+ function times(num, fn) {
404
+ return Array.from({ length: num }, (_, index) => fn(index));
405
+ }
406
+ function delay(time) {
407
+ return new Promise((resolve) => {
408
+ setTimeout(resolve, time);
409
+ });
410
+ }
411
+
374
412
  // src/array.ts
375
413
  function uniq(arr) {
376
414
  return [...new Set(arr)];
@@ -430,6 +468,16 @@ function shuffle(arr) {
430
468
  }
431
469
  return arr;
432
470
  }
471
+ function chunk(arr, size = 1) {
472
+ size = clamp(size, 1, arr.length);
473
+ const result = [];
474
+ let index = 0;
475
+ while (index < arr.length) {
476
+ result.push(arr.slice(index, index + size));
477
+ index += size;
478
+ }
479
+ return result;
480
+ }
433
481
 
434
482
  // src/string.ts
435
483
  function pascalCase(s) {
@@ -450,9 +498,9 @@ function slash(path) {
450
498
  }
451
499
  return path.replace(/\\/g, "/");
452
500
  }
453
- var key = 0;
501
+ var key2 = 0;
454
502
  function genStringKey() {
455
- return `generated-key-${key++}`;
503
+ return `generated-key-${key2++}`;
456
504
  }
457
505
  function upperFirst(s) {
458
506
  return s.charAt(0).toUpperCase() + s.slice(1);
@@ -704,43 +752,6 @@ function once(fn) {
704
752
  };
705
753
  }
706
754
 
707
- // src/number.ts
708
- function toNumber(val) {
709
- if (val == null) {
710
- return 0;
711
- }
712
- if (isString(val)) {
713
- val = parseFloat(val);
714
- val = Number.isNaN(val) ? 0 : val;
715
- return val;
716
- }
717
- if (isBoolean(val)) {
718
- return Number(val);
719
- }
720
- return val;
721
- }
722
- function clamp(num, min, max) {
723
- return Math.min(max, Math.max(min, num));
724
- }
725
- function clampArrayRange(index, arr) {
726
- return clamp(index, 0, arr.length - 1);
727
- }
728
- var key2 = 0;
729
- function genNumberKey() {
730
- return key2++;
731
- }
732
- function randomNumber(min = 0, max = 100) {
733
- return Math.floor(Math.random() * (max - min + 1)) + min;
734
- }
735
- function times(num, fn) {
736
- return Array.from({ length: num }, (_, index) => fn(index));
737
- }
738
- function delay(time) {
739
- return new Promise((resolve) => {
740
- setTimeout(resolve, time);
741
- });
742
- }
743
-
744
755
  // src/collection.ts
745
756
  function mergeWith(object, source, fn) {
746
757
  function baseMerge(target, src) {
@@ -957,6 +968,7 @@ var import_mitt = __toESM(require("mitt"), 1);
957
968
  call,
958
969
  camelize,
959
970
  cancelAnimationFrame,
971
+ chunk,
960
972
  clamp,
961
973
  clampArrayRange,
962
974
  classes,
package/lib/index.d.cts CHANGED
@@ -11,6 +11,7 @@ declare const removeArrayEmpty: <T>(arr: Array<T | null | undefined | "">) => T[
11
11
  declare function find<T>(arr: Array<T>, fn: (item: T, index: number, array: Array<T>) => any, from?: 'start' | 'end'): [T, number] | [null, -1];
12
12
  declare function at<T>(arr: T[], index: number): T | undefined;
13
13
  declare function shuffle<T>(arr: T[]): T[];
14
+ declare function chunk<T>(arr: T[], size?: number): T[][];
14
15
 
15
16
  declare function requestAnimationFrame(fn: FrameRequestCallback): number;
16
17
  declare function cancelAnimationFrame(handle: number): void;
@@ -124,4 +125,4 @@ declare function meanBy<T>(arr: T[], fn: (val: T) => number): number;
124
125
  declare function sample<T>(arr: T[]): T | undefined;
125
126
  declare function sumHash(value: any): string;
126
127
 
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 };
128
+ export { type BEM, type ClassName, type Classes, NOOP, type Storage, at, call, camelize, cancelAnimationFrame, chunk, 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
@@ -11,6 +11,7 @@ declare const removeArrayEmpty: <T>(arr: Array<T | null | undefined | "">) => T[
11
11
  declare function find<T>(arr: Array<T>, fn: (item: T, index: number, array: Array<T>) => any, from?: 'start' | 'end'): [T, number] | [null, -1];
12
12
  declare function at<T>(arr: T[], index: number): T | undefined;
13
13
  declare function shuffle<T>(arr: T[]): T[];
14
+ declare function chunk<T>(arr: T[], size?: number): T[][];
14
15
 
15
16
  declare function requestAnimationFrame(fn: FrameRequestCallback): number;
16
17
  declare function cancelAnimationFrame(handle: number): void;
@@ -124,4 +125,4 @@ declare function meanBy<T>(arr: T[], fn: (val: T) => number): number;
124
125
  declare function sample<T>(arr: T[]): T | undefined;
125
126
  declare function sumHash(value: any): string;
126
127
 
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 };
128
+ export { type BEM, type ClassName, type Classes, NOOP, type Storage, at, call, camelize, cancelAnimationFrame, chunk, 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
@@ -235,6 +235,43 @@ function isEqual(value, other) {
235
235
  return isEqualWith(value, other, () => void 0);
236
236
  }
237
237
 
238
+ // src/number.ts
239
+ function toNumber(val) {
240
+ if (val == null) {
241
+ return 0;
242
+ }
243
+ if (isString(val)) {
244
+ val = parseFloat(val);
245
+ val = Number.isNaN(val) ? 0 : val;
246
+ return val;
247
+ }
248
+ if (isBoolean(val)) {
249
+ return Number(val);
250
+ }
251
+ return val;
252
+ }
253
+ function clamp(num, min, max) {
254
+ return Math.min(max, Math.max(min, num));
255
+ }
256
+ function clampArrayRange(index, arr) {
257
+ return clamp(index, 0, arr.length - 1);
258
+ }
259
+ var key = 0;
260
+ function genNumberKey() {
261
+ return key++;
262
+ }
263
+ function randomNumber(min = 0, max = 100) {
264
+ return Math.floor(Math.random() * (max - min + 1)) + min;
265
+ }
266
+ function times(num, fn) {
267
+ return Array.from({ length: num }, (_, index) => fn(index));
268
+ }
269
+ function delay(time) {
270
+ return new Promise((resolve) => {
271
+ setTimeout(resolve, time);
272
+ });
273
+ }
274
+
238
275
  // src/array.ts
239
276
  function uniq(arr) {
240
277
  return [...new Set(arr)];
@@ -294,6 +331,16 @@ function shuffle(arr) {
294
331
  }
295
332
  return arr;
296
333
  }
334
+ function chunk(arr, size = 1) {
335
+ size = clamp(size, 1, arr.length);
336
+ const result = [];
337
+ let index = 0;
338
+ while (index < arr.length) {
339
+ result.push(arr.slice(index, index + size));
340
+ index += size;
341
+ }
342
+ return result;
343
+ }
297
344
 
298
345
  // src/string.ts
299
346
  function pascalCase(s) {
@@ -314,9 +361,9 @@ function slash(path) {
314
361
  }
315
362
  return path.replace(/\\/g, "/");
316
363
  }
317
- var key = 0;
364
+ var key2 = 0;
318
365
  function genStringKey() {
319
- return `generated-key-${key++}`;
366
+ return `generated-key-${key2++}`;
320
367
  }
321
368
  function upperFirst(s) {
322
369
  return s.charAt(0).toUpperCase() + s.slice(1);
@@ -568,43 +615,6 @@ function once(fn) {
568
615
  };
569
616
  }
570
617
 
571
- // src/number.ts
572
- function toNumber(val) {
573
- if (val == null) {
574
- return 0;
575
- }
576
- if (isString(val)) {
577
- val = parseFloat(val);
578
- val = Number.isNaN(val) ? 0 : val;
579
- return val;
580
- }
581
- if (isBoolean(val)) {
582
- return Number(val);
583
- }
584
- return val;
585
- }
586
- function clamp(num, min, max) {
587
- return Math.min(max, Math.max(min, num));
588
- }
589
- function clampArrayRange(index, arr) {
590
- return clamp(index, 0, arr.length - 1);
591
- }
592
- var key2 = 0;
593
- function genNumberKey() {
594
- return key2++;
595
- }
596
- function randomNumber(min = 0, max = 100) {
597
- return Math.floor(Math.random() * (max - min + 1)) + min;
598
- }
599
- function times(num, fn) {
600
- return Array.from({ length: num }, (_, index) => fn(index));
601
- }
602
- function delay(time) {
603
- return new Promise((resolve) => {
604
- setTimeout(resolve, time);
605
- });
606
- }
607
-
608
618
  // src/collection.ts
609
619
  function mergeWith(object, source, fn) {
610
620
  function baseMerge(target, src) {
@@ -820,6 +830,7 @@ export {
820
830
  call,
821
831
  camelize,
822
832
  cancelAnimationFrame,
833
+ chunk,
823
834
  clamp,
824
835
  clampArrayRange,
825
836
  classes,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rattail",
3
- "version": "0.0.9",
3
+ "version": "0.0.10",
4
4
  "type": "module",
5
5
  "main": "lib/index.cjs",
6
6
  "module": "lib/index.js",