@zag-js/utils 1.15.6 → 1.16.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/dist/index.d.mts CHANGED
@@ -3,7 +3,7 @@ declare const fromLength: (length: number) => number[];
3
3
  declare const first: <T>(v: T[]) => T | undefined;
4
4
  declare const last: <T>(v: T[]) => T | undefined;
5
5
  declare const isEmpty: <T>(v: T[]) => boolean;
6
- declare const has: <T>(v: T[], t: any) => boolean;
6
+ declare const has: <T>(v: T[], t: T) => boolean;
7
7
  declare const add: <T>(v: T[], ...items: T[]) => T[];
8
8
  declare const remove: <T>(v: T[], ...items: T[]) => T[];
9
9
  declare const removeAt: <T>(v: T[], i: number) => T[];
@@ -13,15 +13,16 @@ declare const diff: <T>(a: T[], b: T[]) => T[];
13
13
  declare const addOrRemove: <T>(v: T[], item: T) => T[];
14
14
  declare function clear<T>(v: T[]): T[];
15
15
  type IndexOptions = {
16
- step?: number;
17
- loop?: boolean;
16
+ step?: number | undefined;
17
+ loop?: boolean | undefined;
18
18
  };
19
19
  declare function nextIndex<T>(v: T[], idx: number, opts?: IndexOptions): number;
20
20
  declare function next<T>(v: T[], idx: number, opts?: IndexOptions): T | undefined;
21
21
  declare function prevIndex<T>(v: T[], idx: number, opts?: IndexOptions): number;
22
22
  declare function prev<T>(v: T[], index: number, opts?: IndexOptions): T | undefined;
23
- declare const chunk: <T>(v: T[], size: number) => T[][];
23
+ declare function chunk<T>(v: T[], size: number): T[][];
24
24
  declare function flatArray<T>(arr: T[]): T[];
25
+ declare function partition<T>(arr: T[], fn: (value: T) => boolean): [T[], T[]];
25
26
 
26
27
  declare const isEqual: (a: any, b: any) => boolean;
27
28
 
@@ -114,4 +115,4 @@ declare function ensure<T>(c: T | null | undefined, m: () => string): asserts c
114
115
  type RequiredBy<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
115
116
  declare function ensureProps<T, K extends keyof T>(props: T, keys: K[], scope?: string): asserts props is T & RequiredBy<T, K>;
116
117
 
117
- export { type IndexOptions, type MaybeFunction, type Nullable, type RafIntervalOptions, add, addOrRemove, callAll, cast, chunk, clampPercent, clampValue, clear, compact, createSplitProps, debounce, decrementValue, diff, ensure, ensureProps, first, flatArray, fromLength, getClosestValue, getClosestValueIndex, getMaxValueAtIndex, getMinValueAtIndex, getNextStepValue, getPercentValue, getPreviousStepValue, getValuePercent, getValueRanges, getValueSetterAtIndex, getValueTransformer, has, hasProp, identity, incrementValue, insertAt, invariant, isArray, isBoolean, isDev, isEmpty, isEqual, isFunction, isNaN, isNull, isNumber, isObject, isObjectLike, isPlainObject, isString, isValueAtMax, isValueAtMin, isValueWithinRange, json, last, match, mod, nan, next, nextIndex, noop, omit, pick, prev, prevIndex, remove, removeAt, roundToDpr, roundToStepPrecision, roundValue, runIfFn, setRafInterval, setRafTimeout, setValueAtIndex, snapValueToStep, splitProps, throttle, toArray, toFixedNumber, toPx, tryCatch, uniq, uuid, warn, wrap };
118
+ export { type IndexOptions, type MaybeFunction, type Nullable, type RafIntervalOptions, add, addOrRemove, callAll, cast, chunk, clampPercent, clampValue, clear, compact, createSplitProps, debounce, decrementValue, diff, ensure, ensureProps, first, flatArray, fromLength, getClosestValue, getClosestValueIndex, getMaxValueAtIndex, getMinValueAtIndex, getNextStepValue, getPercentValue, getPreviousStepValue, getValuePercent, getValueRanges, getValueSetterAtIndex, getValueTransformer, has, hasProp, identity, incrementValue, insertAt, invariant, isArray, isBoolean, isDev, isEmpty, isEqual, isFunction, isNaN, isNull, isNumber, isObject, isObjectLike, isPlainObject, isString, isValueAtMax, isValueAtMin, isValueWithinRange, json, last, match, mod, nan, next, nextIndex, noop, omit, partition, pick, prev, prevIndex, remove, removeAt, roundToDpr, roundToStepPrecision, roundValue, runIfFn, setRafInterval, setRafTimeout, setValueAtIndex, snapValueToStep, splitProps, throttle, toArray, toFixedNumber, toPx, tryCatch, uniq, uuid, warn, wrap };
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@ declare const fromLength: (length: number) => number[];
3
3
  declare const first: <T>(v: T[]) => T | undefined;
4
4
  declare const last: <T>(v: T[]) => T | undefined;
5
5
  declare const isEmpty: <T>(v: T[]) => boolean;
6
- declare const has: <T>(v: T[], t: any) => boolean;
6
+ declare const has: <T>(v: T[], t: T) => boolean;
7
7
  declare const add: <T>(v: T[], ...items: T[]) => T[];
8
8
  declare const remove: <T>(v: T[], ...items: T[]) => T[];
9
9
  declare const removeAt: <T>(v: T[], i: number) => T[];
@@ -13,15 +13,16 @@ declare const diff: <T>(a: T[], b: T[]) => T[];
13
13
  declare const addOrRemove: <T>(v: T[], item: T) => T[];
14
14
  declare function clear<T>(v: T[]): T[];
15
15
  type IndexOptions = {
16
- step?: number;
17
- loop?: boolean;
16
+ step?: number | undefined;
17
+ loop?: boolean | undefined;
18
18
  };
19
19
  declare function nextIndex<T>(v: T[], idx: number, opts?: IndexOptions): number;
20
20
  declare function next<T>(v: T[], idx: number, opts?: IndexOptions): T | undefined;
21
21
  declare function prevIndex<T>(v: T[], idx: number, opts?: IndexOptions): number;
22
22
  declare function prev<T>(v: T[], index: number, opts?: IndexOptions): T | undefined;
23
- declare const chunk: <T>(v: T[], size: number) => T[][];
23
+ declare function chunk<T>(v: T[], size: number): T[][];
24
24
  declare function flatArray<T>(arr: T[]): T[];
25
+ declare function partition<T>(arr: T[], fn: (value: T) => boolean): [T[], T[]];
25
26
 
26
27
  declare const isEqual: (a: any, b: any) => boolean;
27
28
 
@@ -114,4 +115,4 @@ declare function ensure<T>(c: T | null | undefined, m: () => string): asserts c
114
115
  type RequiredBy<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
115
116
  declare function ensureProps<T, K extends keyof T>(props: T, keys: K[], scope?: string): asserts props is T & RequiredBy<T, K>;
116
117
 
117
- export { type IndexOptions, type MaybeFunction, type Nullable, type RafIntervalOptions, add, addOrRemove, callAll, cast, chunk, clampPercent, clampValue, clear, compact, createSplitProps, debounce, decrementValue, diff, ensure, ensureProps, first, flatArray, fromLength, getClosestValue, getClosestValueIndex, getMaxValueAtIndex, getMinValueAtIndex, getNextStepValue, getPercentValue, getPreviousStepValue, getValuePercent, getValueRanges, getValueSetterAtIndex, getValueTransformer, has, hasProp, identity, incrementValue, insertAt, invariant, isArray, isBoolean, isDev, isEmpty, isEqual, isFunction, isNaN, isNull, isNumber, isObject, isObjectLike, isPlainObject, isString, isValueAtMax, isValueAtMin, isValueWithinRange, json, last, match, mod, nan, next, nextIndex, noop, omit, pick, prev, prevIndex, remove, removeAt, roundToDpr, roundToStepPrecision, roundValue, runIfFn, setRafInterval, setRafTimeout, setValueAtIndex, snapValueToStep, splitProps, throttle, toArray, toFixedNumber, toPx, tryCatch, uniq, uuid, warn, wrap };
118
+ export { type IndexOptions, type MaybeFunction, type Nullable, type RafIntervalOptions, add, addOrRemove, callAll, cast, chunk, clampPercent, clampValue, clear, compact, createSplitProps, debounce, decrementValue, diff, ensure, ensureProps, first, flatArray, fromLength, getClosestValue, getClosestValueIndex, getMaxValueAtIndex, getMinValueAtIndex, getNextStepValue, getPercentValue, getPreviousStepValue, getValuePercent, getValueRanges, getValueSetterAtIndex, getValueTransformer, has, hasProp, identity, incrementValue, insertAt, invariant, isArray, isBoolean, isDev, isEmpty, isEqual, isFunction, isNaN, isNull, isNumber, isObject, isObjectLike, isPlainObject, isString, isValueAtMax, isValueAtMin, isValueWithinRange, json, last, match, mod, nan, next, nextIndex, noop, omit, partition, pick, prev, prevIndex, remove, removeAt, roundToDpr, roundToStepPrecision, roundValue, runIfFn, setRafInterval, setRafTimeout, setValueAtIndex, snapValueToStep, splitProps, throttle, toArray, toFixedNumber, toPx, tryCatch, uniq, uuid, warn, wrap };
package/dist/index.js CHANGED
@@ -19,10 +19,7 @@ var diff = (a, b) => {
19
19
  const set = new Set(b);
20
20
  return a.filter((t) => !set.has(t));
21
21
  };
22
- var addOrRemove = (v, item) => {
23
- if (has(v, item)) return remove(v, item);
24
- return add(v, item);
25
- };
22
+ var addOrRemove = (v, item) => has(v, item) ? remove(v, item) : add(v, item);
26
23
  function clear(v) {
27
24
  while (v.length > 0) v.pop();
28
25
  return v;
@@ -47,14 +44,13 @@ function prevIndex(v, idx, opts = {}) {
47
44
  function prev(v, index, opts = {}) {
48
45
  return v[prevIndex(v, index, opts)];
49
46
  }
50
- var chunk = (v, size) => {
51
- const res = [];
47
+ function chunk(v, size) {
52
48
  return v.reduce((rows, value, index) => {
53
49
  if (index % size === 0) rows.push([value]);
54
50
  else last(rows)?.push(value);
55
51
  return rows;
56
- }, res);
57
- };
52
+ }, []);
53
+ }
58
54
  function flatArray(arr) {
59
55
  return arr.reduce((flat, item) => {
60
56
  if (Array.isArray(item)) {
@@ -63,6 +59,16 @@ function flatArray(arr) {
63
59
  return flat.concat(item);
64
60
  }, []);
65
61
  }
62
+ function partition(arr, fn) {
63
+ return arr.reduce(
64
+ ([pass, fail], value) => {
65
+ if (fn(value)) pass.push(value);
66
+ else fail.push(value);
67
+ return [pass, fail];
68
+ },
69
+ [[], []]
70
+ );
71
+ }
66
72
 
67
73
  // src/equal.ts
68
74
  var isArrayLike = (value) => value?.constructor.name === "Array";
@@ -475,6 +481,7 @@ exports.next = next;
475
481
  exports.nextIndex = nextIndex;
476
482
  exports.noop = noop;
477
483
  exports.omit = omit;
484
+ exports.partition = partition;
478
485
  exports.pick = pick;
479
486
  exports.prev = prev;
480
487
  exports.prevIndex = prevIndex;
package/dist/index.mjs CHANGED
@@ -17,10 +17,7 @@ var diff = (a, b) => {
17
17
  const set = new Set(b);
18
18
  return a.filter((t) => !set.has(t));
19
19
  };
20
- var addOrRemove = (v, item) => {
21
- if (has(v, item)) return remove(v, item);
22
- return add(v, item);
23
- };
20
+ var addOrRemove = (v, item) => has(v, item) ? remove(v, item) : add(v, item);
24
21
  function clear(v) {
25
22
  while (v.length > 0) v.pop();
26
23
  return v;
@@ -45,14 +42,13 @@ function prevIndex(v, idx, opts = {}) {
45
42
  function prev(v, index, opts = {}) {
46
43
  return v[prevIndex(v, index, opts)];
47
44
  }
48
- var chunk = (v, size) => {
49
- const res = [];
45
+ function chunk(v, size) {
50
46
  return v.reduce((rows, value, index) => {
51
47
  if (index % size === 0) rows.push([value]);
52
48
  else last(rows)?.push(value);
53
49
  return rows;
54
- }, res);
55
- };
50
+ }, []);
51
+ }
56
52
  function flatArray(arr) {
57
53
  return arr.reduce((flat, item) => {
58
54
  if (Array.isArray(item)) {
@@ -61,6 +57,16 @@ function flatArray(arr) {
61
57
  return flat.concat(item);
62
58
  }, []);
63
59
  }
60
+ function partition(arr, fn) {
61
+ return arr.reduce(
62
+ ([pass, fail], value) => {
63
+ if (fn(value)) pass.push(value);
64
+ else fail.push(value);
65
+ return [pass, fail];
66
+ },
67
+ [[], []]
68
+ );
69
+ }
64
70
 
65
71
  // src/equal.ts
66
72
  var isArrayLike = (value) => value?.constructor.name === "Array";
@@ -413,4 +419,4 @@ function ensureProps(props, keys, scope) {
413
419
  throw new Error(`[zag-js${scope ? ` > ${scope}` : ""}] missing required props: ${missingKeys.join(", ")}`);
414
420
  }
415
421
 
416
- export { add, addOrRemove, callAll, cast, chunk, clampPercent, clampValue, clear, compact, createSplitProps, debounce, decrementValue, diff, ensure, ensureProps, first, flatArray, fromLength, getClosestValue, getClosestValueIndex, getMaxValueAtIndex, getMinValueAtIndex, getNextStepValue, getPercentValue, getPreviousStepValue, getValuePercent, getValueRanges, getValueSetterAtIndex, getValueTransformer, has, hasProp, identity, incrementValue, insertAt, invariant, isArray, isBoolean, isDev, isEmpty, isEqual, isFunction, isNaN, isNull, isNumber, isObject, isObjectLike, isPlainObject, isString, isValueAtMax, isValueAtMin, isValueWithinRange, json, last, match, mod, nan, next, nextIndex, noop, omit, pick, prev, prevIndex, remove, removeAt, roundToDpr, roundToStepPrecision, roundValue, runIfFn, setRafInterval, setRafTimeout, setValueAtIndex, snapValueToStep, splitProps, throttle, toArray, toFixedNumber, toPx, tryCatch, uniq, uuid, warn, wrap };
422
+ export { add, addOrRemove, callAll, cast, chunk, clampPercent, clampValue, clear, compact, createSplitProps, debounce, decrementValue, diff, ensure, ensureProps, first, flatArray, fromLength, getClosestValue, getClosestValueIndex, getMaxValueAtIndex, getMinValueAtIndex, getNextStepValue, getPercentValue, getPreviousStepValue, getValuePercent, getValueRanges, getValueSetterAtIndex, getValueTransformer, has, hasProp, identity, incrementValue, insertAt, invariant, isArray, isBoolean, isDev, isEmpty, isEqual, isFunction, isNaN, isNull, isNumber, isObject, isObjectLike, isPlainObject, isString, isValueAtMax, isValueAtMin, isValueWithinRange, json, last, match, mod, nan, next, nextIndex, noop, omit, partition, pick, prev, prevIndex, remove, removeAt, roundToDpr, roundToStepPrecision, roundValue, runIfFn, setRafInterval, setRafTimeout, setValueAtIndex, snapValueToStep, splitProps, throttle, toArray, toFixedNumber, toPx, tryCatch, uniq, uuid, warn, wrap };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/utils",
3
- "version": "1.15.6",
3
+ "version": "1.16.0",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "js",