@koine/utils 2.0.0-beta.165 → 2.0.0-beta.166

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.
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- let addOrReplaceAtIdx=(e,d,t)=>0===e.length?[d]:void 0===t||e.length-1<t?[...e,d]:e.map((e,a)=>a===t?d:e);
5
+ let addOrReplaceAtIdx=(e,d,l)=>void 0!==l&&l>=0&&l<e.length?[...e.slice(0,l),d,...e.slice(l+1)]:[...e,d];
6
6
 
7
7
  exports.addOrReplaceAtIdx = addOrReplaceAtIdx;
8
8
  exports.default = addOrReplaceAtIdx;
@@ -4,6 +4,10 @@
4
4
  * array, therefore the `newItem` must match the type of the `list` items.
5
5
  *
6
6
  * @category array
7
+ * @param list The original array to modify.
8
+ * @param newItem The item to add or replace.
9
+ * @param newIdx The index at which to replace the item (if defined).
10
+ * @returns A new array with the item added or replaced.
7
11
  */
8
12
  export declare let addOrReplaceAtIdx: <T>(list: T[], newItem: T, newIdx?: number) => T[];
9
13
  export default addOrReplaceAtIdx;
@@ -1,3 +1,3 @@
1
- let addOrReplaceAtIdx=(e,d,t)=>0===e.length?[d]:void 0===t||e.length-1<t?[...e,d]:e.map((e,a)=>a===t?d:e);
1
+ let addOrReplaceAtIdx=(e,d,l)=>void 0!==l&&l>=0&&l<e.length?[...e.slice(0,l),d,...e.slice(l+1)]:[...e,d];
2
2
 
3
3
  export { addOrReplaceAtIdx, addOrReplaceAtIdx as default };
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- let arrayUniqueByProperties=(e,r)=>e.filter((e,t,i)=>i.findIndex(t=>r.every(r=>t[r]===e[r]))===t);
5
+ const arrayUniqueByProperties=(e,r)=>{let t=new Set;return e.filter(e=>{let a=r.map(r=>e[r]).join("|");return !t.has(a)&&(t.add(a),!0)})};
6
6
 
7
7
  exports.arrayUniqueByProperties = arrayUniqueByProperties;
8
8
  exports.default = arrayUniqueByProperties;
@@ -6,5 +6,5 @@
6
6
  * @param keys The keys to compare in each array item
7
7
  * @returns The filtered array
8
8
  */
9
- export declare let arrayUniqueByProperties: <T extends any[]>(array: T, keys: (keyof T[number])[]) => T;
9
+ export declare const arrayUniqueByProperties: <T>(array: T[], keys: (keyof T)[]) => T[];
10
10
  export default arrayUniqueByProperties;
@@ -1,3 +1,3 @@
1
- let arrayUniqueByProperties=(e,r)=>e.filter((e,t,i)=>i.findIndex(t=>r.every(r=>t[r]===e[r]))===t);
1
+ const arrayUniqueByProperties=(e,r)=>{let t=new Set;return e.filter(e=>{let a=r.map(r=>e[r]).join("|");return !t.has(a)&&(t.add(a),!0)})};
2
2
 
3
3
  export { arrayUniqueByProperties, arrayUniqueByProperties as default };
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- let moveSortableArrayItemByKey=(e,r,t,l)=>{let a=e.map(e=>e[r]),o=a.indexOf(t[r]),y=a.indexOf(l[r]),[m]=e.splice(o,1);return e.splice(y,0,m),[...e]};
5
+ let moveSortableArrayItemByKey=(e,r,t,l)=>{let a=e.map(e=>e[r]),o=a.indexOf(t[r]),y=a.indexOf(l[r]);if(o>=0&&y>=0){let r=[...e],[t]=r.splice(o,1);return r.splice(y,0,t),r}return e};
6
6
 
7
7
  exports.default = moveSortableArrayItemByKey;
8
8
  exports.moveSortableArrayItemByKey = moveSortableArrayItemByKey;
@@ -1,3 +1,3 @@
1
- let moveSortableArrayItemByKey=(e,r,t,l)=>{let a=e.map(e=>e[r]),o=a.indexOf(t[r]),y=a.indexOf(l[r]),[m]=e.splice(o,1);return e.splice(y,0,m),[...e]};
1
+ let moveSortableArrayItemByKey=(e,r,t,l)=>{let a=e.map(e=>e[r]),o=a.indexOf(t[r]),y=a.indexOf(l[r]);if(o>=0&&y>=0){let r=[...e],[t]=r.splice(o,1);return r.splice(y,0,t),r}return e};
2
2
 
3
3
  export { moveSortableArrayItemByKey as default, moveSortableArrayItemByKey };
package/package.json CHANGED
@@ -1015,5 +1015,5 @@
1015
1015
  "module": "./index.esm.js",
1016
1016
  "main": "./index.cjs.js",
1017
1017
  "types": "./index.esm.d.ts",
1018
- "version": "2.0.0-beta.165"
1018
+ "version": "2.0.0-beta.166"
1019
1019
  }