@arrai-innovations/reactive-helpers 2.3.4 → 2.4.0
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/package.json +1 -1
- package/utils/getFakeId.js +10 -5
package/package.json
CHANGED
package/utils/getFakeId.js
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
|
-
import { isArray } from "lodash";
|
|
1
|
+
import { isArray, isSet } from "lodash";
|
|
2
2
|
|
|
3
|
-
export function getFakeId(
|
|
3
|
+
export function getFakeId(arraySetOrObject, key = "id") {
|
|
4
|
+
// sets are assumed to be of ids
|
|
5
|
+
// arrays are assumed to be objects with an property matching the passed key
|
|
6
|
+
// objects are assumed to have keys that are ids
|
|
4
7
|
let fakeId;
|
|
5
8
|
let test;
|
|
6
|
-
if (
|
|
7
|
-
test = () =>
|
|
9
|
+
if (isSet(arraySetOrObject)) {
|
|
10
|
+
test = () => arraySetOrObject.has(fakeId);
|
|
11
|
+
} else if (isArray(arraySetOrObject)) {
|
|
12
|
+
test = () => arraySetOrObject.some((item) => item[key] === fakeId);
|
|
8
13
|
} else {
|
|
9
|
-
test = () => fakeId in
|
|
14
|
+
test = () => fakeId in arraySetOrObject;
|
|
10
15
|
}
|
|
11
16
|
do {
|
|
12
17
|
fakeId = Math.floor(Math.random() * Number.MIN_SAFE_INTEGER);
|