A parser to find where a state name or abbreviation is in a string.
Full documentation is available at the zerodep.app page.
All @zerodep packages support both ESM and CJS.
import { addressState } from '@zerodep/address-state';
// or
const { addressState } = require('@zerodep/address-state');
// American address
addressState('1234 Main Street, Los Angeles California, 90210');
// [
// {
// stateAbbr: 'CA',
// source: 'California',
// ndx: 30,
// length: 10
// },
// ]
// Canadian address
addressState('13375 rue rita pierrefonds quebec h8z1j3');
// [
// {
// "stateAbbr": "QC",
// "source": "quebec",
// "ndx": 27,
// "length": 6
// }
// ]
addressCountry('#4 Washington Street, Portland OR 97603');
// [
// {
// "stateAbbr": "OR",
// "source": "OR",
// "ndx": 31,
// "length": 2
// },
// {
// "stateAbbr": "WA",
// "source": "Washington",
// "ndx": 3,
// "length": 10
// }
// ]
addressState('1234 oregon street, toronto ont');
// [
// {
// "stateAbbr": "ON",
// "source": "ont",
// "ndx": 28,
// "length": 3
// },
// {
// "stateAbbr": "OR",
// "source": "oregon",
// "ndx": 5,
// "length": 6
// }
// ]