Repository URL to install this package:
|
Version:
3.2.1 ▾
|
import { isFunction, isArray } from 'exotic'
export type TestFn = (...args: any[]) => boolean
export interface TestObj {
test: (eh: any) => boolean
}
export type TestablePatternType = RegExp | TestFn | TestObj
function test(pattern: TestablePatternType, x?: any) {
if (arguments.length === 1) {
return (y: any) => test(pattern, y)
} else if (!pattern) {
console.error('[forms] pattern is not correct for validator')
console.log({ pattern, x })
return true
} else if (isArray(pattern)) {
console.warn('no support in test for array')
} else if (isFunction((pattern as any).test)) {
return (pattern as any).test(x)
} else if (isFunction(pattern)) {
return pattern(x)
} else {
console.error('[forms] pattern is not correct for validator')
console.log({ pattern, x })
return true
}
}
export { test }
export default test