@domql/utils 2.3.89 → 2.3.90
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 +17 -0
- package/dist/cjs/array.js +18 -1
- package/dist/cjs/object.js +14 -1
- package/object.js +13 -1
- package/package.json +2 -2
package/array.js
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
+
import { isArray, isNumber, isString } from './types'
|
|
4
|
+
|
|
3
5
|
export const arrayContainsOtherArray = (arr1, arr2) => {
|
|
4
6
|
return arr2.every(val => arr1.includes(val))
|
|
5
7
|
}
|
|
8
|
+
|
|
9
|
+
export const removeFromArray = (arr, index) => {
|
|
10
|
+
if (isString(index)) index = parseInt(index)
|
|
11
|
+
if (isNumber(index)) {
|
|
12
|
+
if (index < 0 || index >= arr.length || isNaN(index)) {
|
|
13
|
+
throw new Error('Invalid index')
|
|
14
|
+
}
|
|
15
|
+
arr.splice(index, 1)
|
|
16
|
+
} else if (isArray(index)) {
|
|
17
|
+
index.forEach(idx => removeFromArray(arr, idx))
|
|
18
|
+
} else {
|
|
19
|
+
throw new Error('Invalid index')
|
|
20
|
+
}
|
|
21
|
+
return arr
|
|
22
|
+
}
|
package/dist/cjs/array.js
CHANGED
|
@@ -18,9 +18,26 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var array_exports = {};
|
|
20
20
|
__export(array_exports, {
|
|
21
|
-
arrayContainsOtherArray: () => arrayContainsOtherArray
|
|
21
|
+
arrayContainsOtherArray: () => arrayContainsOtherArray,
|
|
22
|
+
removeFromArray: () => removeFromArray
|
|
22
23
|
});
|
|
23
24
|
module.exports = __toCommonJS(array_exports);
|
|
25
|
+
var import_types = require("./types");
|
|
24
26
|
const arrayContainsOtherArray = (arr1, arr2) => {
|
|
25
27
|
return arr2.every((val) => arr1.includes(val));
|
|
26
28
|
};
|
|
29
|
+
const removeFromArray = (arr, index) => {
|
|
30
|
+
if ((0, import_types.isString)(index))
|
|
31
|
+
index = parseInt(index);
|
|
32
|
+
if ((0, import_types.isNumber)(index)) {
|
|
33
|
+
if (index < 0 || index >= arr.length || isNaN(index)) {
|
|
34
|
+
throw new Error("Invalid index");
|
|
35
|
+
}
|
|
36
|
+
arr.splice(index, 1);
|
|
37
|
+
} else if ((0, import_types.isArray)(index)) {
|
|
38
|
+
index.forEach((idx) => removeFromArray(arr, idx));
|
|
39
|
+
} else {
|
|
40
|
+
throw new Error("Invalid index");
|
|
41
|
+
}
|
|
42
|
+
return arr;
|
|
43
|
+
};
|
package/dist/cjs/object.js
CHANGED
|
@@ -37,7 +37,8 @@ __export(object_exports, {
|
|
|
37
37
|
mergeIfExisted: () => mergeIfExisted,
|
|
38
38
|
overwrite: () => overwrite,
|
|
39
39
|
overwriteDeep: () => overwriteDeep,
|
|
40
|
-
overwriteObj: () => overwriteObj
|
|
40
|
+
overwriteObj: () => overwriteObj,
|
|
41
|
+
removeFromObject: () => removeFromObject
|
|
41
42
|
});
|
|
42
43
|
module.exports = __toCommonJS(object_exports);
|
|
43
44
|
var import_globals = require("@domql/globals");
|
|
@@ -323,3 +324,15 @@ const isEqualDeep = (param, element) => {
|
|
|
323
324
|
}
|
|
324
325
|
return true;
|
|
325
326
|
};
|
|
327
|
+
const removeFromObject = (obj, props) => {
|
|
328
|
+
if (props === void 0 || props === null)
|
|
329
|
+
return obj;
|
|
330
|
+
if ((0, import_types.is)(props)("string", "number")) {
|
|
331
|
+
delete obj[props];
|
|
332
|
+
} else if ((0, import_types.isArray)(props)) {
|
|
333
|
+
props.forEach((prop) => delete obj[prop]);
|
|
334
|
+
} else {
|
|
335
|
+
throw new Error("Invalid input: props must be a string or an array of strings");
|
|
336
|
+
}
|
|
337
|
+
return obj;
|
|
338
|
+
};
|
package/object.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
import { window } from '@domql/globals'
|
|
4
|
-
import { isFunction, isObjectLike, isObject, isArray, isString } from './types.js'
|
|
4
|
+
import { isFunction, isObjectLike, isObject, isArray, isString, is } from './types.js'
|
|
5
5
|
|
|
6
6
|
export const exec = (param, element, state, context) => {
|
|
7
7
|
if (isFunction(param)) {
|
|
@@ -332,3 +332,15 @@ export const isEqualDeep = (param, element) => {
|
|
|
332
332
|
}
|
|
333
333
|
return true
|
|
334
334
|
}
|
|
335
|
+
|
|
336
|
+
export const removeFromObject = (obj, props) => {
|
|
337
|
+
if (props === undefined || props === null) return obj
|
|
338
|
+
if (is(props)('string', 'number')) {
|
|
339
|
+
delete obj[props]
|
|
340
|
+
} else if (isArray(props)) {
|
|
341
|
+
props.forEach(prop => delete obj[prop])
|
|
342
|
+
} else {
|
|
343
|
+
throw new Error('Invalid input: props must be a string or an array of strings')
|
|
344
|
+
}
|
|
345
|
+
return obj
|
|
346
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/utils",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.90",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "index.js",
|
|
@@ -22,5 +22,5 @@
|
|
|
22
22
|
"@domql/globals": "latest",
|
|
23
23
|
"@domql/tags": "latest"
|
|
24
24
|
},
|
|
25
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "ab1a0f74fc9a7cc67cd5e732c7a8577d98fbb9b0"
|
|
26
26
|
}
|