@domql/utils
Advanced tools
Comparing version 2.3.89 to 2.3.90
17
array.js
'use strict' | ||
import { isArray, isNumber, isString } from './types' | ||
export const arrayContainsOtherArray = (arr1, arr2) => { | ||
return arr2.every(val => arr1.includes(val)) | ||
} | ||
export const removeFromArray = (arr, index) => { | ||
if (isString(index)) index = parseInt(index) | ||
if (isNumber(index)) { | ||
if (index < 0 || index >= arr.length || isNaN(index)) { | ||
throw new Error('Invalid index') | ||
} | ||
arr.splice(index, 1) | ||
} else if (isArray(index)) { | ||
index.forEach(idx => removeFromArray(arr, idx)) | ||
} else { | ||
throw new Error('Invalid index') | ||
} | ||
return arr | ||
} |
@@ -21,7 +21,24 @@ "use strict"; | ||
__export(array_exports, { | ||
arrayContainsOtherArray: () => arrayContainsOtherArray | ||
arrayContainsOtherArray: () => arrayContainsOtherArray, | ||
removeFromArray: () => removeFromArray | ||
}); | ||
module.exports = __toCommonJS(array_exports); | ||
var import_types = require("./types"); | ||
const arrayContainsOtherArray = (arr1, arr2) => { | ||
return arr2.every((val) => arr1.includes(val)); | ||
}; | ||
const removeFromArray = (arr, index) => { | ||
if ((0, import_types.isString)(index)) | ||
index = parseInt(index); | ||
if ((0, import_types.isNumber)(index)) { | ||
if (index < 0 || index >= arr.length || isNaN(index)) { | ||
throw new Error("Invalid index"); | ||
} | ||
arr.splice(index, 1); | ||
} else if ((0, import_types.isArray)(index)) { | ||
index.forEach((idx) => removeFromArray(arr, idx)); | ||
} else { | ||
throw new Error("Invalid index"); | ||
} | ||
return arr; | ||
}; |
@@ -40,3 +40,4 @@ "use strict"; | ||
overwriteDeep: () => overwriteDeep, | ||
overwriteObj: () => overwriteObj | ||
overwriteObj: () => overwriteObj, | ||
removeFromObject: () => removeFromObject | ||
}); | ||
@@ -327,1 +328,13 @@ module.exports = __toCommonJS(object_exports); | ||
}; | ||
const removeFromObject = (obj, props) => { | ||
if (props === void 0 || props === null) | ||
return obj; | ||
if ((0, import_types.is)(props)("string", "number")) { | ||
delete obj[props]; | ||
} else if ((0, import_types.isArray)(props)) { | ||
props.forEach((prop) => delete obj[prop]); | ||
} else { | ||
throw new Error("Invalid input: props must be a string or an array of strings"); | ||
} | ||
return obj; | ||
}; |
'use strict' | ||
import { window } from '@domql/globals' | ||
import { isFunction, isObjectLike, isObject, isArray, isString } from './types.js' | ||
import { isFunction, isObjectLike, isObject, isArray, isString, is } from './types.js' | ||
@@ -335,1 +335,13 @@ export const exec = (param, element, state, context) => { | ||
} | ||
export const removeFromObject = (obj, props) => { | ||
if (props === undefined || props === null) return obj | ||
if (is(props)('string', 'number')) { | ||
delete obj[props] | ||
} else if (isArray(props)) { | ||
props.forEach(prop => delete obj[prop]) | ||
} else { | ||
throw new Error('Invalid input: props must be a string or an array of strings') | ||
} | ||
return obj | ||
} |
{ | ||
"name": "@domql/utils", | ||
"version": "2.3.89", | ||
"version": "2.3.90", | ||
"license": "MIT", | ||
@@ -25,3 +25,3 @@ "type": "module", | ||
}, | ||
"gitHead": "bb45c7f24e08fb579b72c90abeed9f0054c817b0" | ||
"gitHead": "ab1a0f74fc9a7cc67cd5e732c7a8577d98fbb9b0" | ||
} |
34736
1058