@domql/utils 2.5.92 → 2.5.93

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/array.js CHANGED
@@ -118,3 +118,15 @@ export const addItemAfterEveryElement = (array, item) => {
118
118
 
119
119
  return result
120
120
  }
121
+
122
+ export const reorderArrayByValues = (array, valueToMove, insertBeforeValue) => {
123
+ const newArray = [...array] // Create a copy of the original array
124
+ const indexToMove = newArray.indexOf(valueToMove) // Find the index of the value to move
125
+ const indexToInsertBefore = newArray.indexOf(insertBeforeValue) // Find the index to insert before
126
+ if (indexToMove !== -1 && indexToInsertBefore !== -1) {
127
+ const removedItem = newArray.splice(indexToMove, 1)[0] // Remove the item to move
128
+ const insertIndex = indexToInsertBefore < indexToMove ? indexToInsertBefore : indexToInsertBefore + 1 // Adjust insert index
129
+ newArray.splice(insertIndex, 0, removedItem) // Insert the removed item before the specified value
130
+ }
131
+ return newArray
132
+ }
package/dist/cjs/array.js CHANGED
@@ -30,6 +30,7 @@ __export(array_exports, {
30
30
  removeFromArray: () => removeFromArray,
31
31
  removeValueFromArray: () => removeValueFromArray,
32
32
  removeValueFromArrayAll: () => removeValueFromArrayAll,
33
+ reorderArrayByValues: () => reorderArrayByValues,
33
34
  swapItemsInArray: () => swapItemsInArray
34
35
  });
35
36
  module.exports = __toCommonJS(array_exports);
@@ -124,3 +125,14 @@ const addItemAfterEveryElement = (array, item) => {
124
125
  }
125
126
  return result;
126
127
  };
128
+ const reorderArrayByValues = (array, valueToMove, insertBeforeValue) => {
129
+ const newArray = [...array];
130
+ const indexToMove = newArray.indexOf(valueToMove);
131
+ const indexToInsertBefore = newArray.indexOf(insertBeforeValue);
132
+ if (indexToMove !== -1 && indexToInsertBefore !== -1) {
133
+ const removedItem = newArray.splice(indexToMove, 1)[0];
134
+ const insertIndex = indexToInsertBefore < indexToMove ? indexToInsertBefore : indexToInsertBefore + 1;
135
+ newArray.splice(insertIndex, 0, removedItem);
136
+ }
137
+ return newArray;
138
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/utils",
3
- "version": "2.5.92",
3
+ "version": "2.5.93",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "index.js",
@@ -23,7 +23,7 @@
23
23
  "build": "yarn build:cjs",
24
24
  "prepublish": "rimraf -I dist && yarn build && yarn copy:package:cjs"
25
25
  },
26
- "gitHead": "41f831e7064481d010f7a763e9466931c6389f87",
26
+ "gitHead": "6c5a9e10c74137700ad69ff9108b6ccc09745cc7",
27
27
  "devDependencies": {
28
28
  "@babel/core": "^7.12.0"
29
29
  }