radashi 12.9.3 → 12.9.5

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/radashi.cjs CHANGED
@@ -262,10 +262,10 @@ function replace(array, newItem, match) {
262
262
 
263
263
  // src/array/replaceOrAppend.ts
264
264
  function replaceOrAppend(array, newItem, match) {
265
- if (!array && !newItem) {
265
+ if (!array && newItem == null) {
266
266
  return [];
267
267
  }
268
- if (!newItem) {
268
+ if (newItem == null) {
269
269
  return [...array];
270
270
  }
271
271
  if (!array) {
@@ -303,12 +303,12 @@ function selectFirst(array, mapper, condition) {
303
303
  if (!array) {
304
304
  return void 0;
305
305
  }
306
- let foundIndex = -1;
307
- const found = array.find((item, index) => {
308
- foundIndex = index;
306
+ let foundItem;
307
+ const foundIndex = array.findIndex((item, index) => {
308
+ foundItem = item;
309
309
  return condition ? condition(item, index) : mapper(item, index) != null;
310
310
  });
311
- return found === void 0 ? void 0 : mapper(found, foundIndex);
311
+ return foundIndex === -1 ? void 0 : mapper(foundItem, foundIndex);
312
312
  }
313
313
 
314
314
  // src/array/shift.ts
@@ -352,8 +352,8 @@ function toggle(array, item, toKey, options) {
352
352
  } else {
353
353
  matcher = (x) => x === item;
354
354
  }
355
- const existing = array.find(matcher);
356
- if (existing !== void 0) {
355
+ const existingIndex = array.findIndex(matcher);
356
+ if (existingIndex !== -1) {
357
357
  return array.filter((x, idx) => !matcher(x, idx));
358
358
  }
359
359
  return (options == null ? void 0 : options.strategy) === "prepend" ? [item, ...array] : [...array, item];
@@ -469,7 +469,7 @@ declare function replace<T>(array: readonly T[], newItem: T, match: (item: T, id
469
469
  * ```
470
470
  * @version 12.1.0
471
471
  */
472
- declare function replaceOrAppend<T>(array: readonly T[], newItem: T, match: (a: T, idx: number) => boolean): T[];
472
+ declare function replaceOrAppend<T>(array: readonly T[], newItem: T | null | undefined, match: (a: T, idx: number) => boolean): T[];
473
473
 
474
474
  /**
475
475
  * Select performs a filter and a mapper inside of a reduce, only
package/dist/radashi.d.ts CHANGED
@@ -469,7 +469,7 @@ declare function replace<T>(array: readonly T[], newItem: T, match: (item: T, id
469
469
  * ```
470
470
  * @version 12.1.0
471
471
  */
472
- declare function replaceOrAppend<T>(array: readonly T[], newItem: T, match: (a: T, idx: number) => boolean): T[];
472
+ declare function replaceOrAppend<T>(array: readonly T[], newItem: T | null | undefined, match: (a: T, idx: number) => boolean): T[];
473
473
 
474
474
  /**
475
475
  * Select performs a filter and a mapper inside of a reduce, only
package/dist/radashi.js CHANGED
@@ -260,10 +260,10 @@ function replace(array, newItem, match) {
260
260
 
261
261
  // src/array/replaceOrAppend.ts
262
262
  function replaceOrAppend(array, newItem, match) {
263
- if (!array && !newItem) {
263
+ if (!array && newItem == null) {
264
264
  return [];
265
265
  }
266
- if (!newItem) {
266
+ if (newItem == null) {
267
267
  return [...array];
268
268
  }
269
269
  if (!array) {
@@ -301,12 +301,12 @@ function selectFirst(array, mapper, condition) {
301
301
  if (!array) {
302
302
  return void 0;
303
303
  }
304
- let foundIndex = -1;
305
- const found = array.find((item, index) => {
306
- foundIndex = index;
304
+ let foundItem;
305
+ const foundIndex = array.findIndex((item, index) => {
306
+ foundItem = item;
307
307
  return condition ? condition(item, index) : mapper(item, index) != null;
308
308
  });
309
- return found === void 0 ? void 0 : mapper(found, foundIndex);
309
+ return foundIndex === -1 ? void 0 : mapper(foundItem, foundIndex);
310
310
  }
311
311
 
312
312
  // src/array/shift.ts
@@ -350,8 +350,8 @@ function toggle(array, item, toKey, options) {
350
350
  } else {
351
351
  matcher = (x) => x === item;
352
352
  }
353
- const existing = array.find(matcher);
354
- if (existing !== void 0) {
353
+ const existingIndex = array.findIndex(matcher);
354
+ if (existingIndex !== -1) {
355
355
  return array.filter((x, idx) => !matcher(x, idx));
356
356
  }
357
357
  return (options == null ? void 0 : options.strategy) === "prepend" ? [item, ...array] : [...array, item];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "radashi",
3
- "version": "12.9.3",
3
+ "version": "12.9.5",
4
4
  "type": "module",
5
5
  "description": "The modern, community-first TypeScript toolkit with all of the fast, readable, and minimal utility functions you need. Type-safe, dependency-free, tree-shakeable, fully tested.",
6
6
  "repository": {