rattail 1.0.21 → 1.0.23

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
@@ -158,6 +158,7 @@ __export(src_exports, {
158
158
  round: () => round,
159
159
  sample: () => sample,
160
160
  sessionStorage: () => sessionStorage,
161
+ set: () => set,
161
162
  shuffle: () => shuffle,
162
163
  slash: () => slash,
163
164
  sum: () => sum,
@@ -776,6 +777,27 @@ function promiseWithResolvers() {
776
777
  return { promise, resolve, reject };
777
778
  }
778
779
 
780
+ // src/object/set.ts
781
+ function set(object, path, value) {
782
+ if (!isObject(object)) {
783
+ return;
784
+ }
785
+ const keys = [...path];
786
+ if (keys.length === 0) {
787
+ return;
788
+ }
789
+ let target = object;
790
+ while (keys.length > 1) {
791
+ const key3 = keys.shift();
792
+ const nextKey = keys[0];
793
+ if (!isObject(target[key3])) {
794
+ target[key3] = isNumber(nextKey) ? [] : {};
795
+ }
796
+ target = target[key3];
797
+ }
798
+ target[keys[0]] = value;
799
+ }
800
+
779
801
  // src/util/index.ts
780
802
  var util_exports = {};
781
803
  __export(util_exports, {
@@ -1666,6 +1688,7 @@ function ceil(val, precision = 0) {
1666
1688
  round,
1667
1689
  sample,
1668
1690
  sessionStorage,
1691
+ set,
1669
1692
  shuffle,
1670
1693
  slash,
1671
1694
  sum,
package/lib/index.d.cts CHANGED
@@ -58,6 +58,8 @@ type PromiseWithResolvers<T> = {
58
58
  };
59
59
  declare function promiseWithResolvers<T>(): PromiseWithResolvers<T>;
60
60
 
61
+ declare function set<T extends object | any[]>(object: T, path: (string | number)[], value: any): void;
62
+
61
63
  declare function cancelAnimationFrame(handle: number): void;
62
64
 
63
65
  type ClassName = string | undefined | null;
@@ -130,20 +132,20 @@ interface Motion {
130
132
  }
131
133
  declare function motion(options: MotionOptions): Motion;
132
134
 
133
- declare function duration(): {
134
- value: number;
135
- years: (value: number) => any;
136
- months: (value: number) => any;
137
- weeks: (value: number) => any;
138
- days: (value: number) => any;
139
- hours: (value: number) => any;
140
- minutes: (value: number) => any;
141
- seconds: (value: number) => any;
142
- milliseconds: (value: number) => any;
143
- valueOf: (options?: {
135
+ interface DurationContext {
136
+ years(value: number): this;
137
+ months(value: number): this;
138
+ weeks(value: number): this;
139
+ days(value: number): this;
140
+ hours(value: number): this;
141
+ minutes(value: number): this;
142
+ seconds(value: number): this;
143
+ milliseconds(value: number): this;
144
+ valueOf(options?: {
144
145
  milliseconds: boolean;
145
- }) => number;
146
- };
146
+ }): number;
147
+ }
148
+ declare function duration(): DurationContext;
147
149
 
148
150
  declare function call<P extends any[], R>(fn?: ((...arg: P) => R) | ((...arg: P) => R)[] | null, ...args: P): R | R[] | undefined;
149
151
 
@@ -310,4 +312,4 @@ declare function floor(val: number, precision?: number): number;
310
312
 
311
313
  declare function ceil(val: number, precision?: number): number;
312
314
 
313
- export { type BEM, type ClassName, type Classes, 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, objectToString, omit, omitBy, once, pascalCase, pick, pickBy, prettyJSONObject, preventDefault, promiseWithResolvers, raf, randomColor, randomNumber, randomString, removeArrayBlank, removeArrayEmpty, removeItem, requestAnimationFrame, round, sample, sessionStorage, shuffle, slash, sum, sumBy, sumHash, supportTouch, throttle, times, toArrayBuffer, toDataURL, toNumber, toRawType, toText, toTypeString, toggleItem, tryParseJSON, uniq, uniqBy, upperFirst, xor, xorWith };
315
+ 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, 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 };
package/lib/index.d.ts CHANGED
@@ -58,6 +58,8 @@ type PromiseWithResolvers<T> = {
58
58
  };
59
59
  declare function promiseWithResolvers<T>(): PromiseWithResolvers<T>;
60
60
 
61
+ declare function set<T extends object | any[]>(object: T, path: (string | number)[], value: any): void;
62
+
61
63
  declare function cancelAnimationFrame(handle: number): void;
62
64
 
63
65
  type ClassName = string | undefined | null;
@@ -130,20 +132,20 @@ interface Motion {
130
132
  }
131
133
  declare function motion(options: MotionOptions): Motion;
132
134
 
133
- declare function duration(): {
134
- value: number;
135
- years: (value: number) => any;
136
- months: (value: number) => any;
137
- weeks: (value: number) => any;
138
- days: (value: number) => any;
139
- hours: (value: number) => any;
140
- minutes: (value: number) => any;
141
- seconds: (value: number) => any;
142
- milliseconds: (value: number) => any;
143
- valueOf: (options?: {
135
+ interface DurationContext {
136
+ years(value: number): this;
137
+ months(value: number): this;
138
+ weeks(value: number): this;
139
+ days(value: number): this;
140
+ hours(value: number): this;
141
+ minutes(value: number): this;
142
+ seconds(value: number): this;
143
+ milliseconds(value: number): this;
144
+ valueOf(options?: {
144
145
  milliseconds: boolean;
145
- }) => number;
146
- };
146
+ }): number;
147
+ }
148
+ declare function duration(): DurationContext;
147
149
 
148
150
  declare function call<P extends any[], R>(fn?: ((...arg: P) => R) | ((...arg: P) => R)[] | null, ...args: P): R | R[] | undefined;
149
151
 
@@ -310,4 +312,4 @@ declare function floor(val: number, precision?: number): number;
310
312
 
311
313
  declare function ceil(val: number, precision?: number): number;
312
314
 
313
- export { type BEM, type ClassName, type Classes, 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, objectToString, omit, omitBy, once, pascalCase, pick, pickBy, prettyJSONObject, preventDefault, promiseWithResolvers, raf, randomColor, randomNumber, randomString, removeArrayBlank, removeArrayEmpty, removeItem, requestAnimationFrame, round, sample, sessionStorage, shuffle, slash, sum, sumBy, sumHash, supportTouch, throttle, times, toArrayBuffer, toDataURL, toNumber, toRawType, toText, toTypeString, toggleItem, tryParseJSON, uniq, uniqBy, upperFirst, xor, xorWith };
315
+ 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, 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 };
@@ -148,6 +148,7 @@ var Rattail = (() => {
148
148
  round: () => round,
149
149
  sample: () => sample,
150
150
  sessionStorage: () => sessionStorage,
151
+ set: () => set,
151
152
  shuffle: () => shuffle,
152
153
  slash: () => slash,
153
154
  sum: () => sum,
@@ -765,6 +766,27 @@ var Rattail = (() => {
765
766
  return { promise, resolve, reject };
766
767
  }
767
768
 
769
+ // src/object/set.ts
770
+ function set(object, path, value) {
771
+ if (!isObject(object)) {
772
+ return;
773
+ }
774
+ const keys = [...path];
775
+ if (keys.length === 0) {
776
+ return;
777
+ }
778
+ let target = object;
779
+ while (keys.length > 1) {
780
+ const key3 = keys.shift();
781
+ const nextKey = keys[0];
782
+ if (!isObject(target[key3])) {
783
+ target[key3] = isNumber(nextKey) ? [] : {};
784
+ }
785
+ target = target[key3];
786
+ }
787
+ target[keys[0]] = value;
788
+ }
789
+
768
790
  // src/util/cancelAnimationFrame.ts
769
791
  function cancelAnimationFrame(handle) {
770
792
  const globalThis2 = getGlobalThis();
package/lib/index.js CHANGED
@@ -146,6 +146,7 @@ __export(src_exports, {
146
146
  round: () => round,
147
147
  sample: () => sample,
148
148
  sessionStorage: () => sessionStorage,
149
+ set: () => set,
149
150
  shuffle: () => shuffle,
150
151
  slash: () => slash,
151
152
  sum: () => sum,
@@ -763,6 +764,27 @@ function promiseWithResolvers() {
763
764
  return { promise, resolve, reject };
764
765
  }
765
766
 
767
+ // src/object/set.ts
768
+ function set(object, path, value) {
769
+ if (!isObject(object)) {
770
+ return;
771
+ }
772
+ const keys = [...path];
773
+ if (keys.length === 0) {
774
+ return;
775
+ }
776
+ let target = object;
777
+ while (keys.length > 1) {
778
+ const key3 = keys.shift();
779
+ const nextKey = keys[0];
780
+ if (!isObject(target[key3])) {
781
+ target[key3] = isNumber(nextKey) ? [] : {};
782
+ }
783
+ target = target[key3];
784
+ }
785
+ target[keys[0]] = value;
786
+ }
787
+
766
788
  // src/util/index.ts
767
789
  var util_exports = {};
768
790
  __export(util_exports, {
@@ -1653,6 +1675,7 @@ export {
1653
1675
  round,
1654
1676
  sample,
1655
1677
  sessionStorage,
1678
+ set,
1656
1679
  shuffle,
1657
1680
  slash,
1658
1681
  sum,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rattail",
3
- "version": "1.0.21",
3
+ "version": "1.0.23",
4
4
  "description": "A utilities library for front-end developers, lightweight and ts-friendly",
5
5
  "keywords": [
6
6
  "utilities library",