@softsky/utils 2.3.1 → 2.3.2

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/README.md CHANGED
@@ -67,6 +67,18 @@ Compare must return true when found position to push in.
67
67
  For example if we return `[false, false, true, false]`,
68
68
  Array will become `[false, false, Element, true, false]`.
69
69
 
70
+ ---
71
+ ${\textsf{\color{CornflowerBlue}function}}$ removeFromArray - Delete value from array.
72
+ Only deletes first encountered.
73
+
74
+ Returns index of deleted value.
75
+
76
+ ---
77
+ ${\textsf{\color{CornflowerBlue}function}}$ removeLastFromArray - Delete value from array.
78
+ Only deletes last encountered.
79
+
80
+ Returns index of deleted value.
81
+
70
82
  ---
71
83
 
72
84
 
package/dist/arrays.d.ts CHANGED
@@ -29,3 +29,17 @@ export declare function permutations<T>(array: T[]): T[][];
29
29
  * Array will become `[false, false, Element, true, false]`.
30
30
  */
31
31
  export declare function pushToSorted<T>(array: T[], element: T, compare: (element: T) => boolean): void;
32
+ /**
33
+ * Delete value from array.
34
+ * Only deletes first encountered.
35
+ *
36
+ * Returns index of deleted value.
37
+ */
38
+ export declare function removeFromArray<T>(array: T[], value: T): number;
39
+ /**
40
+ * Delete value from array.
41
+ * Only deletes last encountered.
42
+ *
43
+ * Returns index of deleted value.
44
+ */
45
+ export declare function removeLastFromArray<T>(array: T[], value: T): number;
package/dist/arrays.js CHANGED
@@ -104,3 +104,27 @@ export function pushToSorted(array, element, compare) {
104
104
  const index = array.findIndex(compare);
105
105
  array.splice(index === -1 ? array.length : index, 0, element);
106
106
  }
107
+ /**
108
+ * Delete value from array.
109
+ * Only deletes first encountered.
110
+ *
111
+ * Returns index of deleted value.
112
+ */
113
+ export function removeFromArray(array, value) {
114
+ const index = array.indexOf(value);
115
+ if (index !== -1)
116
+ array.splice(index, 1);
117
+ return index;
118
+ }
119
+ /**
120
+ * Delete value from array.
121
+ * Only deletes last encountered.
122
+ *
123
+ * Returns index of deleted value.
124
+ */
125
+ export function removeLastFromArray(array, value) {
126
+ const index = array.lastIndexOf(value);
127
+ if (index !== -1)
128
+ array.splice(index, 1);
129
+ return index;
130
+ }
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@softsky/utils",
3
- "version": "2.3.1",
3
+ "version": "2.3.2",
4
4
  "description": "JavaScript/TypeScript utilities",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
7
7
  "lint": "eslint \"./src/**/*.ts\" --fix && tsc",
8
8
  "gen-readme": "bun ./generate-readme.ts",
9
- "prepublishOnly": "bun run test && bun run lint && bun run gen-readme",
9
+ "prepublishOnly": "npm i && bun run test && bun run lint && bun run gen-readme",
10
10
  "test": "bun test"
11
11
  },
12
12
  "repository": {