Giter Club home page Giter Club logo

postal-code-helpers's Introduction

Postal code helpers npm version

Lightweight helpers for working with international postal code data to extract, validate or locate postal codes based on GeoNames data.

Installation

npm i postal-code-helpers
import postalCodeHelpers from 'postal-code-helpers';

Usage

Extract postal code from string

postalCodeHelpers.extract('this is a postal code 10999', 'DE'); 
// ['10999']

postalCodeHelpers.extract('this .10247, is a r23412345341 postal code 10999', 'DE'); 
// ['10247', '10999']

postalCodeHelpers.extract('this is a post code 1099921342345 inside a 1024 string', 'DE'); 
// null

Validate postal code

Validates a postal codes against the country pattern. Attention: This validation does not check whether a postal code actually exists!

postalCodeHelpers.validate('10999', 'DE');
// true

postalCodeHelpers.validate('1234', 'DE'); 
// false

Locate countries for postal codes

postalCodeHelpers.locate('SE1 6DR'); 
// [ 'GB' ]

postalCodeHelpers.locate('this is not a postal code'); 
// null

Data source

Geonames

Supported countries

AD, AL, AM, AR, AS, AT, AU, AX, AZ, BA, BB, BD, BE, BG, BH, BL, BM, BN, BR, BY, CA, CH, CL, CN, CO, CS, CR, CU, CV, CX, CY, CZ, DE, DK, DO, DZ, EC, EE, EG, ES, ET, FI, FM, FO, FR, GB, GE, GF, GG, GL, GP, GR, GT, GU, GW, HN, HR, HT, HU, ID, IE, IL, IM, IN, IQ, IR, IS, IT, JE, JO, JP, KE, KG, KH, KP, KR, KW, KZ, LA, LB, LI, LK, LR, LS, LT, LU, LV, MA, MC, MD, ME, MF, MG, MH, MK, MM, MN, MP, MQ, MT, MV, MW, MX, MY, MZ, NC, NE, NF, NG, NI, NL, NO, NP, NZ, OM, PF, PG, PH, PK, PL, PM, PR, PT, PW, PY, RE, RO, RS, RU, SA, SD, SE, SG, SH, SI, SJ, SK, SM, SN, SO, SV, SZ, TC, TH, TJ, TM, TN, TR, TW, UA, US, UY, UZ, VA, VE, VI, VN, WF, YT, ZA, ZM

postal-code-helpers's People

Contributors

stephangeorg avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

majacq

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.