Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default function matcher(pattern) {
// prettier-ignore
const matcherCreator = (
pattern === '*' ? wildcard
: is.string(pattern) ? string
: is.array(pattern) ? array
: is.stringableFunc(pattern) ? string
: is.func(pattern) ? predicate
: is.symbol(pattern) ? symbol
: null
)
if (matcherCreator === null) {
throw new Error(`invalid pattern: ${pattern}`)
}
return matcherCreator(pattern)
}
function getFnCallDescriptor(fnDescriptor, args) {
let context = null
let fn
if (is.func(fnDescriptor)) {
fn = fnDescriptor
} else {
if (is.array(fnDescriptor)) {
;[context, fn] = fnDescriptor
} else {
;({ context, fn } = fnDescriptor)
}
if (context && is.string(fn) && is.func(context[fn])) {
fn = context[fn]
}
}
return { context, fn, args }
}
let context = null
let fn
if (is.array(fnDescriptor)) {
;[context, fn] = fnDescriptor
check(fn, is.notUndef, `${effectName}: argument of type [context, fn] has undefined or null \`fn\``)
} else if (is.object(fnDescriptor)) {
;({ context, fn } = fnDescriptor)
check(fn, is.notUndef, `${effectName}: argument of type {context, fn} has undefined or null \`fn\``)
} else {
check(fnDescriptor, is.func, `${effectName}: argument fn is not function`)
return
}
if (context && is.string(fn)) {
check(context[fn], is.func, `${effectName}: context arguments has no such method - "${fn}"`)
return
}
check(fn, is.func, `${effectName}: unpacked fn argument (from [context, fn] or {context, fn}) is not a function`)
}