feat: allow wildcards when checking attributes in isActive, fix #1752
This commit is contained in:
3
packages/core/src/utilities/isRegExp.ts
Normal file
3
packages/core/src/utilities/isRegExp.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export default function isRegExp(value: any): boolean {
|
||||
return Object.prototype.toString.call(value) === '[object RegExp]'
|
||||
}
|
||||
@@ -1,16 +1,30 @@
|
||||
import isRegExp from './isRegExp'
|
||||
|
||||
/**
|
||||
* Check if object1 includes object2
|
||||
* @param object1 Object
|
||||
* @param object2 Object
|
||||
*/
|
||||
export default function objectIncludes(object1: Record<string, any>, object2: Record<string, any>): boolean {
|
||||
export default function objectIncludes(
|
||||
object1: Record<string, any>,
|
||||
object2: Record<string, any>,
|
||||
options: { strict: boolean } = { strict: true },
|
||||
): boolean {
|
||||
const keys = Object.keys(object2)
|
||||
|
||||
if (!keys.length) {
|
||||
return true
|
||||
}
|
||||
|
||||
return !!keys
|
||||
.filter(key => object2[key] === object1[key])
|
||||
.length
|
||||
return keys.every(key => {
|
||||
if (options.strict) {
|
||||
return object2[key] === object1[key]
|
||||
}
|
||||
|
||||
if (isRegExp(object2[key])) {
|
||||
return object2[key].test(object1[key])
|
||||
}
|
||||
|
||||
return object2[key] === object1[key]
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user