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 / isValidAddress.ts
Size: Mime:
/**
 * @see https://www.state.gov/m/fsi/tc/14582.htm
 * @see https://www.randomlists.com/random-addresses
 */
import { isString, isEmpty } from 'exotic'

// for running in browser
// const isString = x => typeof x === 'string'
// const isEmpty = x => x === ''

// actual code
const matchAddress = /\d{1,5}.?\d{0,3}\s[a-zA-Z\s]{2,30}\s[a-zA-Z\s]{2,15}/
const matchSymbolsToStrip = /\/,\-\./gm
function isValidAddress(value: string) {
  return (
    isString(value) === true &&
    isEmpty(value) === false &&
    matchAddress.test(value.replace(matchSymbolsToStrip, ''))
  )
}

// test
// const list = [
//   '1 Front Street',
//   'Block-2, 2/10 , 1 front street',
//   '5993 1 front rd',
//   '59931frontrd',
//   '7462 E. Green Ave. ',
//   '7986 Big Rock Cove Rd. ',
//   'front road',
//   'K K Pudur road,',
//   '111 K K Pudur road,',
// ]
// console.log(JSON.stringify(list.map(x => [x, isValidAddress(x)]), undefined, 2))

export { isValidAddress }