@calilio-global/zip-validator
v1.0.3
Published
Validate zip codes countrywise
Downloads
32
Readme
@calilio-global/zip-validator
Node.js module for parsing and validating zipCodes. Country specific validation is supported for most countries.
Note: I haven't tested all combinations of zipCodes for the extended country regular expressions. Please raise a PR with necessary test coverage for as many countries possible.
Install
npm install @calilio-global/zip-validatorUsage
// commonjs
const { zipCodeValidator, zipCodeValidatorExistsForCountry } = require('@calilio-global/zip-validator');
// ES6
import { zipCodeValidator, zipCodeValidatorExistsForCountry } from '@calilio-global/zip-validator';
zipCodeValidator('W85TT', 'GB'); // returns true
zipCodeValidator('1234567', 'GB'); // returns false
zipCodeValidatorExistsForCountry('GB'); // returns true
zipCodeValidatorExistsForCountry('Moon'); // returns false
country codes: US, GB, CA, JP, INTL(International), etcTesting
Run the unit tests with:
npm testCountries not supported
Note: INTL can be used for those
[
'AE', 'AG', 'AO', 'AQ', 'AW', 'BF', 'BI', 'BJ',
'BO', 'BQ', 'BS', 'BV', 'BW', 'BZ', 'CD', 'CF',
'CG', 'CI', 'CM', 'CW', 'DJ', 'DM', 'ER', 'FJ',
'GA', 'GD', 'GH', 'GM', 'GQ', 'GY', 'HK', 'JM',
'KI', 'KM', 'KN', 'KP', 'LC', 'LY', 'ML', 'MO',
'MR', 'MS', 'MW', 'NR', 'NU', 'PS', 'QA', 'RW',
'SB', 'SC', 'SL', 'SR', 'SS', 'ST', 'SX', 'SY',
'TD', 'TF', 'TG', 'TK', 'TL', 'TO', 'TT', 'TV',
'UG', 'VU', 'WS', 'YE', 'ZW'
]Publish package
Change the following in package.json file
"main": "dist/index.js",