es-toolkit 1.17.0-dev.564 → 1.17.0-dev.566

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,62 @@
1
+ /**
2
+ * Iterates through an array in reverse order and returns the index of the first item that matches the given predicate function.
3
+ *
4
+ * @template T
5
+ * @param {T[]} arr - The array to search through.
6
+ * @param {(item: T, index: number, arr: T[]) => unknown} doesMatch - A function that takes an item, its index, and the array, and returns a truthy value if the item matches the criteria.
7
+ * @returns {number} - The index of the first item that matches the predicate, or `undefined` if no match is found.
8
+ *
9
+ * @example
10
+ * // Using a predicate function
11
+ * const items = [1, 2, 3, 4, 5];
12
+ * const result = findLastIndex(items, (item) => item > 3)
13
+ * console.log(result); // 4
14
+ */
15
+ declare function findLastIndex<T>(arr: readonly T[], doesMatch: (item: T, index: number, arr: readonly T[]) => unknown): number;
16
+ /**
17
+ * Finds the index of the first item in an array that matches the given partial object.
18
+ *
19
+ * @template T
20
+ * @param {readonly T[]} arr - The array to search through.
21
+ * @param {Partial<T>} doesMatch - A partial object that specifies the properties to match.
22
+ * @returns {number} - The index of the first item that matches the partial object, or `undefined` if no match is found.
23
+ *
24
+ * @example
25
+ * // Using a partial object
26
+ * const items = [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }];
27
+ * const result = findLastIndex(items, { name: 'Bob' });
28
+ * console.log(result); // 1
29
+ */
30
+ declare function findLastIndex<T>(arr: readonly T[], doesMatch: Partial<T>): number;
31
+ /**
32
+ * Finds the index of the first item in an array that matches a property with a specific value.
33
+ *
34
+ * @template T
35
+ * @param {readonly T[]} arr - The array to search through.
36
+ * @param {[keyof T, unknown]} doesMatchProperty - An array where the first element is the property key and the second element is the value to match.
37
+ * @returns {number} - The index of the first item that has the specified property value, or `undefined` if no match is found.
38
+ *
39
+ * @example
40
+ * // Using a property-value pair
41
+ * const items = [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }];
42
+ * const result = findLastIndex(items, ['name', 'Alice']);
43
+ * console.log(result); // 0
44
+ */
45
+ declare function findLastIndex<T>(arr: readonly T[], doesMatchProperty: [keyof T, unknown]): number;
46
+ /**
47
+ * Finds the index of the first item in an array that has a specific property, where the property name is provided as a string.
48
+ *
49
+ * @template T
50
+ * @param {readonly T[]} arr - The array to search through.
51
+ * @param {string} propertyToCheck - The property name to check.
52
+ * @returns {number} - The index of the first item that has the specified property, or `undefined` if no match is found.
53
+ *
54
+ * @example
55
+ * // Using a property name
56
+ * const items = [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }];
57
+ * const result = findLastIndex(items, 'name');
58
+ * console.log(result); // 1
59
+ */
60
+ declare function findLastIndex<T>(arr: readonly T[], propertyToCheck: string): number;
61
+
62
+ export { findLastIndex };
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Iterates through an array in reverse order and returns the index of the first item that matches the given predicate function.
3
+ *
4
+ * @template T
5
+ * @param {T[]} arr - The array to search through.
6
+ * @param {(item: T, index: number, arr: T[]) => unknown} doesMatch - A function that takes an item, its index, and the array, and returns a truthy value if the item matches the criteria.
7
+ * @returns {number} - The index of the first item that matches the predicate, or `undefined` if no match is found.
8
+ *
9
+ * @example
10
+ * // Using a predicate function
11
+ * const items = [1, 2, 3, 4, 5];
12
+ * const result = findLastIndex(items, (item) => item > 3)
13
+ * console.log(result); // 4
14
+ */
15
+ declare function findLastIndex<T>(arr: readonly T[], doesMatch: (item: T, index: number, arr: readonly T[]) => unknown): number;
16
+ /**
17
+ * Finds the index of the first item in an array that matches the given partial object.
18
+ *
19
+ * @template T
20
+ * @param {readonly T[]} arr - The array to search through.
21
+ * @param {Partial<T>} doesMatch - A partial object that specifies the properties to match.
22
+ * @returns {number} - The index of the first item that matches the partial object, or `undefined` if no match is found.
23
+ *
24
+ * @example
25
+ * // Using a partial object
26
+ * const items = [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }];
27
+ * const result = findLastIndex(items, { name: 'Bob' });
28
+ * console.log(result); // 1
29
+ */
30
+ declare function findLastIndex<T>(arr: readonly T[], doesMatch: Partial<T>): number;
31
+ /**
32
+ * Finds the index of the first item in an array that matches a property with a specific value.
33
+ *
34
+ * @template T
35
+ * @param {readonly T[]} arr - The array to search through.
36
+ * @param {[keyof T, unknown]} doesMatchProperty - An array where the first element is the property key and the second element is the value to match.
37
+ * @returns {number} - The index of the first item that has the specified property value, or `undefined` if no match is found.
38
+ *
39
+ * @example
40
+ * // Using a property-value pair
41
+ * const items = [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }];
42
+ * const result = findLastIndex(items, ['name', 'Alice']);
43
+ * console.log(result); // 0
44
+ */
45
+ declare function findLastIndex<T>(arr: readonly T[], doesMatchProperty: [keyof T, unknown]): number;
46
+ /**
47
+ * Finds the index of the first item in an array that has a specific property, where the property name is provided as a string.
48
+ *
49
+ * @template T
50
+ * @param {readonly T[]} arr - The array to search through.
51
+ * @param {string} propertyToCheck - The property name to check.
52
+ * @returns {number} - The index of the first item that has the specified property, or `undefined` if no match is found.
53
+ *
54
+ * @example
55
+ * // Using a property name
56
+ * const items = [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }];
57
+ * const result = findLastIndex(items, 'name');
58
+ * console.log(result); // 1
59
+ */
60
+ declare function findLastIndex<T>(arr: readonly T[], propertyToCheck: string): number;
61
+
62
+ export { findLastIndex };
@@ -0,0 +1,26 @@
1
+ import { property } from '../object/property.mjs';
2
+ import { matches } from '../predicate/matches.mjs';
3
+ import { matchesProperty } from '../predicate/matchesProperty.mjs';
4
+
5
+ function findLastIndex(source, doesMatch) {
6
+ switch (typeof doesMatch) {
7
+ case 'function': {
8
+ return source.findLastIndex(doesMatch);
9
+ }
10
+ case 'object': {
11
+ if (Array.isArray(doesMatch) && doesMatch.length === 2) {
12
+ const key = doesMatch[0];
13
+ const value = doesMatch[1];
14
+ return source.findLastIndex(matchesProperty(key, value));
15
+ }
16
+ else {
17
+ return source.findLastIndex(matches(doesMatch));
18
+ }
19
+ }
20
+ case 'string': {
21
+ return source.findLastIndex(property(doesMatch));
22
+ }
23
+ }
24
+ }
25
+
26
+ export { findLastIndex };
@@ -111,6 +111,7 @@ export { difference } from './array/difference.mjs';
111
111
  export { fill } from './array/fill.mjs';
112
112
  export { find } from './array/find.mjs';
113
113
  export { findIndex } from './array/findIndex.mjs';
114
+ export { findLastIndex } from './array/findLastIndex.mjs';
114
115
  export { flatten } from './array/flatten.mjs';
115
116
  export { flattenDeep } from './array/flattenDeep.mjs';
116
117
  export { flattenDepth } from './array/flattenDepth.mjs';
@@ -111,6 +111,7 @@ export { difference } from './array/difference.js';
111
111
  export { fill } from './array/fill.js';
112
112
  export { find } from './array/find.js';
113
113
  export { findIndex } from './array/findIndex.js';
114
+ export { findLastIndex } from './array/findLastIndex.js';
114
115
  export { flatten } from './array/flatten.js';
115
116
  export { flattenDeep } from './array/flattenDeep.js';
116
117
  export { flattenDepth } from './array/flattenDepth.js';
@@ -397,6 +397,27 @@ function findIndex(source, doesMatch) {
397
397
  }
398
398
  }
399
399
 
400
+ function findLastIndex(source, doesMatch) {
401
+ switch (typeof doesMatch) {
402
+ case 'function': {
403
+ return source.findLastIndex(doesMatch);
404
+ }
405
+ case 'object': {
406
+ if (Array.isArray(doesMatch) && doesMatch.length === 2) {
407
+ const key = doesMatch[0];
408
+ const value = doesMatch[1];
409
+ return source.findLastIndex(matchesProperty(key, value));
410
+ }
411
+ else {
412
+ return source.findLastIndex(matches(doesMatch));
413
+ }
414
+ }
415
+ case 'string': {
416
+ return source.findLastIndex(property(doesMatch));
417
+ }
418
+ }
419
+ }
420
+
400
421
  function flatten(value, depth = 1) {
401
422
  const result = [];
402
423
  const flooredDepth = Math.floor(depth);
@@ -1141,6 +1162,7 @@ exports.endsWith = endsWith;
1141
1162
  exports.fill = fill;
1142
1163
  exports.find = find;
1143
1164
  exports.findIndex = findIndex;
1165
+ exports.findLastIndex = findLastIndex;
1144
1166
  exports.flatten = flatten;
1145
1167
  exports.flattenDeep = flattenDeep;
1146
1168
  exports.flattenDepth = flattenDepth;
@@ -112,6 +112,7 @@ export { difference } from './array/difference.mjs';
112
112
  export { fill } from './array/fill.mjs';
113
113
  export { find } from './array/find.mjs';
114
114
  export { findIndex } from './array/findIndex.mjs';
115
+ export { findLastIndex } from './array/findLastIndex.mjs';
115
116
  export { flatten } from './array/flatten.mjs';
116
117
  export { flattenDeep } from './array/flattenDeep.mjs';
117
118
  export { flattenDepth } from './array/flattenDepth.mjs';
@@ -1,4 +1,4 @@
1
- const deburrMap = {
1
+ const deburrMap = new Map(Object.entries({
2
2
  Æ: 'Ae',
3
3
  Ð: 'D',
4
4
  Ø: 'O',
@@ -28,18 +28,18 @@ const deburrMap = {
28
28
  Ŧ: 'T',
29
29
  ŧ: 't',
30
30
  ſ: 's',
31
- };
31
+ }));
32
32
  function deburr(str) {
33
33
  str = str.normalize('NFD');
34
- const result = [];
34
+ let result = '';
35
35
  for (let i = 0; i < str.length; i++) {
36
36
  const char = str[i];
37
37
  if ((char >= '\u0300' && char <= '\u036f') || (char >= '\ufe20' && char <= '\ufe23')) {
38
38
  continue;
39
39
  }
40
- result.push(deburrMap[char] ?? char);
40
+ result += deburrMap.get(char) ?? char;
41
41
  }
42
- return result.join('');
42
+ return result;
43
43
  }
44
44
 
45
45
  export { deburr };
@@ -65,7 +65,7 @@ function lowerFirst(str) {
65
65
  return str.substring(0, 1).toLowerCase() + str.substring(1);
66
66
  }
67
67
 
68
- const deburrMap = {
68
+ const deburrMap = new Map(Object.entries({
69
69
  Æ: 'Ae',
70
70
  Ð: 'D',
71
71
  Ø: 'O',
@@ -95,18 +95,18 @@ const deburrMap = {
95
95
  Ŧ: 'T',
96
96
  ŧ: 't',
97
97
  ſ: 's',
98
- };
98
+ }));
99
99
  function deburr(str) {
100
100
  str = str.normalize('NFD');
101
- const result = [];
101
+ let result = '';
102
102
  for (let i = 0; i < str.length; i++) {
103
103
  const char = str[i];
104
104
  if ((char >= '\u0300' && char <= '\u036f') || (char >= '\ufe20' && char <= '\ufe23')) {
105
105
  continue;
106
106
  }
107
- result.push(deburrMap[char] ?? char);
107
+ result += deburrMap.get(char) ?? char;
108
108
  }
109
- return result.join('');
109
+ return result;
110
110
  }
111
111
 
112
112
  const htmlEscapes = {
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.17.0-dev.564+e264ed6c",
4
+ "version": "1.17.0-dev.566+851755cd",
5
5
  "homepage": "https://es-toolkit.slash.page",
6
6
  "bugs": "https://github.com/toss/es-toolkit/issues",
7
7
  "repository": {