Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/forms / src / validators / __match.ts
Size: Mime:
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