es-toolkit 1.23.0-dev.745 → 1.23.0-dev.746

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.
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Drops elements from the end of an array while the predicate function returns truthy.
3
+ *
4
+ * @template T - The type of elements in the array.
5
+ * @param {T[]} arr - The array from which to drop elements.
6
+ * @param {(item: T, index: number, arr: T[]) => unknown} canContinueDropping - A predicate function that determines
7
+ * whether to continue dropping elements. The function is called with each element, index, and array, and dropping
8
+ * continues as long as it returns true.
9
+ * @returns {T[]} A new array with the elements remaining after the predicate returns false.
10
+ *
11
+ * @example
12
+ * const array = [5, 4, 3, 2, 1];
13
+ * const result = dropRightWhile(array, x => x < 3);
14
+ * result will be [5, 4, 3] since elements less than 3 are dropped.
15
+ */
16
+ declare function dropRightWhile<T>(arr: readonly T[], canContinueDropping: (item: T, index: number, arr: readonly T[]) => unknown): T[];
17
+ /**
18
+ * Drops elements from the end of an array while the specified object properties match.
19
+ *
20
+ * @template T - The type of elements in the array.
21
+ * @param {T[]} arr - The array from which to drop elements.
22
+ * @param {Partial<T>} objectToDrop - An object specifying the properties to match for dropping elements.
23
+ * @returns {T[]} A new array with the elements remaining after the predicate returns false.
24
+ *
25
+ * @example
26
+ * const array = [{ a: 1 }, { a: 2 }, { a: 3 }];
27
+ * const result = dropRightWhile(array, { a: 3 });
28
+ * result will be [{ a: 1 }, { a: 2 }] since the last object matches the properties of the provided object.
29
+ */
30
+ declare function dropRightWhile<T>(arr: readonly T[], objectToDrop: Partial<T>): T[];
31
+ /**
32
+ * Drops elements from the end of an array while the specified property matches a given value.
33
+ *
34
+ * @template T - The type of elements in the array.
35
+ * @param {T[]} arr - The array from which to drop elements.
36
+ * @param {[keyof T, unknown]} propertyToDrop - A tuple containing the property key and the value to match for dropping elements.
37
+ * @returns {T[]} A new array with the elements remaining after the predicate returns false.
38
+ *
39
+ * @example
40
+ * const array = [{ id: 1 }, { id: 2 }, { id: 3 }];
41
+ * const result = dropRightWhile(array, ['id', 3]);
42
+ * result will be [{ id: 1 }, { id: 2 }] since the last object has the id property matching the value 3.
43
+ */
44
+ declare function dropRightWhile<T>(arr: readonly T[], propertyToDrop: [keyof T, unknown]): T[];
45
+ /**
46
+ * Drops elements from the end of an array while the specified property name matches.
47
+ *
48
+ * @template T - The type of elements in the array.
49
+ * @param {T[]} arr - The array from which to drop elements.
50
+ * @param {string} propertyToDrop - The name of the property to match for dropping elements.
51
+ * @returns {T[]} A new array with the elements remaining after the predicate returns false.
52
+ *
53
+ * @example
54
+ * const array = [{ isActive: false }, { isActive: true }, { isActive: true }];
55
+ * const result = dropRightWhile(array, 'isActive');
56
+ * result will be [{ isActive: false }] since it drops elements until it finds one with a falsy isActive property.
57
+ */
58
+ declare function dropRightWhile<T>(arr: readonly T[], propertyToDrop: string): T[];
59
+
60
+ export { dropRightWhile };
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Drops elements from the end of an array while the predicate function returns truthy.
3
+ *
4
+ * @template T - The type of elements in the array.
5
+ * @param {T[]} arr - The array from which to drop elements.
6
+ * @param {(item: T, index: number, arr: T[]) => unknown} canContinueDropping - A predicate function that determines
7
+ * whether to continue dropping elements. The function is called with each element, index, and array, and dropping
8
+ * continues as long as it returns true.
9
+ * @returns {T[]} A new array with the elements remaining after the predicate returns false.
10
+ *
11
+ * @example
12
+ * const array = [5, 4, 3, 2, 1];
13
+ * const result = dropRightWhile(array, x => x < 3);
14
+ * result will be [5, 4, 3] since elements less than 3 are dropped.
15
+ */
16
+ declare function dropRightWhile<T>(arr: readonly T[], canContinueDropping: (item: T, index: number, arr: readonly T[]) => unknown): T[];
17
+ /**
18
+ * Drops elements from the end of an array while the specified object properties match.
19
+ *
20
+ * @template T - The type of elements in the array.
21
+ * @param {T[]} arr - The array from which to drop elements.
22
+ * @param {Partial<T>} objectToDrop - An object specifying the properties to match for dropping elements.
23
+ * @returns {T[]} A new array with the elements remaining after the predicate returns false.
24
+ *
25
+ * @example
26
+ * const array = [{ a: 1 }, { a: 2 }, { a: 3 }];
27
+ * const result = dropRightWhile(array, { a: 3 });
28
+ * result will be [{ a: 1 }, { a: 2 }] since the last object matches the properties of the provided object.
29
+ */
30
+ declare function dropRightWhile<T>(arr: readonly T[], objectToDrop: Partial<T>): T[];
31
+ /**
32
+ * Drops elements from the end of an array while the specified property matches a given value.
33
+ *
34
+ * @template T - The type of elements in the array.
35
+ * @param {T[]} arr - The array from which to drop elements.
36
+ * @param {[keyof T, unknown]} propertyToDrop - A tuple containing the property key and the value to match for dropping elements.
37
+ * @returns {T[]} A new array with the elements remaining after the predicate returns false.
38
+ *
39
+ * @example
40
+ * const array = [{ id: 1 }, { id: 2 }, { id: 3 }];
41
+ * const result = dropRightWhile(array, ['id', 3]);
42
+ * result will be [{ id: 1 }, { id: 2 }] since the last object has the id property matching the value 3.
43
+ */
44
+ declare function dropRightWhile<T>(arr: readonly T[], propertyToDrop: [keyof T, unknown]): T[];
45
+ /**
46
+ * Drops elements from the end of an array while the specified property name matches.
47
+ *
48
+ * @template T - The type of elements in the array.
49
+ * @param {T[]} arr - The array from which to drop elements.
50
+ * @param {string} propertyToDrop - The name of the property to match for dropping elements.
51
+ * @returns {T[]} A new array with the elements remaining after the predicate returns false.
52
+ *
53
+ * @example
54
+ * const array = [{ isActive: false }, { isActive: true }, { isActive: true }];
55
+ * const result = dropRightWhile(array, 'isActive');
56
+ * result will be [{ isActive: false }] since it drops elements until it finds one with a falsy isActive property.
57
+ */
58
+ declare function dropRightWhile<T>(arr: readonly T[], propertyToDrop: string): T[];
59
+
60
+ export { dropRightWhile };
@@ -0,0 +1,27 @@
1
+ import { dropRightWhile as dropRightWhile$1 } from '../../array/dropRightWhile.mjs';
2
+ import { property } from '../object/property.mjs';
3
+ import { matches } from '../predicate/matches.mjs';
4
+ import { matchesProperty } from '../predicate/matchesProperty.mjs';
5
+
6
+ function dropRightWhile(arr, predicate) {
7
+ switch (typeof predicate) {
8
+ case 'function': {
9
+ return dropRightWhile$1(arr, (item, index, arr) => Boolean(predicate(item, index, arr)));
10
+ }
11
+ case 'object': {
12
+ if (Array.isArray(predicate) && predicate.length === 2) {
13
+ const key = predicate[0];
14
+ const value = predicate[1];
15
+ return dropRightWhile$1(arr, matchesProperty(key, value));
16
+ }
17
+ else {
18
+ return dropRightWhile$1(arr, matches(predicate));
19
+ }
20
+ }
21
+ case 'string': {
22
+ return dropRightWhile$1(arr, property(predicate));
23
+ }
24
+ }
25
+ }
26
+
27
+ export { dropRightWhile };
@@ -4,7 +4,6 @@ export { countBy } from '../array/countBy.mjs';
4
4
  export { differenceBy } from '../array/differenceBy.mjs';
5
5
  export { differenceWith } from '../array/differenceWith.mjs';
6
6
  export { dropRight } from '../array/dropRight.mjs';
7
- export { dropRightWhile } from '../array/dropRightWhile.mjs';
8
7
  export { flatMap } from '../array/flatMap.mjs';
9
8
  export { flatMapDeep } from '../array/flatMapDeep.mjs';
10
9
  export { forEachRight } from '../array/forEachRight.mjs';
@@ -97,6 +96,7 @@ export { concat } from './array/concat.mjs';
97
96
  export { difference } from './array/difference.mjs';
98
97
  export { drop } from './array/drop.mjs';
99
98
  export { dropWhile } from './array/dropWhile.mjs';
99
+ export { dropRightWhile } from './array/dropRightWhile.mjs';
100
100
  export { every } from './array/every.mjs';
101
101
  export { fill } from './array/fill.mjs';
102
102
  export { filter } from './array/filter.mjs';
@@ -4,7 +4,6 @@ export { countBy } from '../array/countBy.js';
4
4
  export { differenceBy } from '../array/differenceBy.js';
5
5
  export { differenceWith } from '../array/differenceWith.js';
6
6
  export { dropRight } from '../array/dropRight.js';
7
- export { dropRightWhile } from '../array/dropRightWhile.js';
8
7
  export { flatMap } from '../array/flatMap.js';
9
8
  export { flatMapDeep } from '../array/flatMapDeep.js';
10
9
  export { forEachRight } from '../array/forEachRight.js';
@@ -97,6 +96,7 @@ export { concat } from './array/concat.js';
97
96
  export { difference } from './array/difference.js';
98
97
  export { drop } from './array/drop.js';
99
98
  export { dropWhile } from './array/dropWhile.js';
99
+ export { dropRightWhile } from './array/dropRightWhile.js';
100
100
  export { every } from './array/every.js';
101
101
  export { fill } from './array/fill.js';
102
102
  export { filter } from './array/filter.js';
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const zipWith = require('../_chunk/zipWith-EOU_KZ.js');
5
+ const zipWith = require('../_chunk/zipWith-CV0XAX.js');
6
6
  const promise_index = require('../_chunk/index-BGZDR9.js');
7
7
  const flowRight$1 = require('../_chunk/flowRight-Cf9ldK.js');
8
8
  const noop = require('../_chunk/noop-2IwLUk.js');
@@ -397,6 +397,27 @@ function dropWhile(arr, predicate) {
397
397
  }
398
398
  }
399
399
 
400
+ function dropRightWhile(arr, predicate) {
401
+ switch (typeof predicate) {
402
+ case 'function': {
403
+ return zipWith.dropRightWhile(arr, (item, index, arr) => Boolean(predicate(item, index, arr)));
404
+ }
405
+ case 'object': {
406
+ if (Array.isArray(predicate) && predicate.length === 2) {
407
+ const key = predicate[0];
408
+ const value = predicate[1];
409
+ return zipWith.dropRightWhile(arr, matchesProperty(key, value));
410
+ }
411
+ else {
412
+ return zipWith.dropRightWhile(arr, matches(predicate));
413
+ }
414
+ }
415
+ case 'string': {
416
+ return zipWith.dropRightWhile(arr, property(predicate));
417
+ }
418
+ }
419
+ }
420
+
400
421
  function identity(x) {
401
422
  return x;
402
423
  }
@@ -1991,7 +2012,6 @@ exports.countBy = zipWith.countBy;
1991
2012
  exports.differenceBy = zipWith.differenceBy;
1992
2013
  exports.differenceWith = zipWith.differenceWith;
1993
2014
  exports.dropRight = zipWith.dropRight;
1994
- exports.dropRightWhile = zipWith.dropRightWhile;
1995
2015
  exports.first = zipWith.head;
1996
2016
  exports.flatMap = zipWith.flatMap;
1997
2017
  exports.flatMapDeep = zipWith.flatMapDeep;
@@ -2103,6 +2123,7 @@ exports.defaults = defaults;
2103
2123
  exports.defer = defer;
2104
2124
  exports.difference = difference;
2105
2125
  exports.drop = drop;
2126
+ exports.dropRightWhile = dropRightWhile;
2106
2127
  exports.dropWhile = dropWhile;
2107
2128
  exports.endsWith = endsWith;
2108
2129
  exports.every = every;
@@ -4,7 +4,6 @@ export { countBy } from '../array/countBy.mjs';
4
4
  export { differenceBy } from '../array/differenceBy.mjs';
5
5
  export { differenceWith } from '../array/differenceWith.mjs';
6
6
  export { dropRight } from '../array/dropRight.mjs';
7
- export { dropRightWhile } from '../array/dropRightWhile.mjs';
8
7
  export { flatMap } from '../array/flatMap.mjs';
9
8
  export { flatMapDeep } from '../array/flatMapDeep.mjs';
10
9
  export { forEachRight } from '../array/forEachRight.mjs';
@@ -99,6 +98,7 @@ export { concat } from './array/concat.mjs';
99
98
  export { difference } from './array/difference.mjs';
100
99
  export { drop } from './array/drop.mjs';
101
100
  export { dropWhile } from './array/dropWhile.mjs';
101
+ export { dropRightWhile } from './array/dropRightWhile.mjs';
102
102
  export { every } from './array/every.mjs';
103
103
  export { fill } from './array/fill.mjs';
104
104
  export { filter } from './array/filter.mjs';
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const zipWith = require('./_chunk/zipWith-EOU_KZ.js');
5
+ const zipWith = require('./_chunk/zipWith-CV0XAX.js');
6
6
  const array_index = require('./array/index.js');
7
7
  const promise_index = require('./_chunk/index-BGZDR9.js');
8
8
  const function_index = require('./function/index.js');
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "es-toolkit",
3
3
  "description": "A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.",
4
- "version": "1.23.0-dev.745+df19ff14",
4
+ "version": "1.23.0-dev.746+55cae8b0",
5
5
  "homepage": "https://es-toolkit.slash.page",
6
6
  "bugs": "https://github.com/toss/es-toolkit/issues",
7
7
  "repository": {