UNPKG

zip-state

Version:

Lightweight mapping of USPS ZIP Codes to their assigned region.

28 lines (27 loc) 4.93 kB
/* zip-state@1.0.3 CC0-1.0 https://alecperkins.net/zip-state */ "use strict"; (function (root, factory) { if (typeof define === 'function' && define.amd) { define([], factory); // AMD } else if (typeof module === 'object' && module.exports) { module.exports = factory(); // Node CommonJS module.exports.default = module.exports; // Transpiled Typescript } else { root.zipState = factory(); // Browser window } }(typeof self !== 'undefined' ? self : this, function () { const mapping = new Uint8Array([0,0,0,0,0,34,53,53,54,53,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,39,39,31,31,31,31,31,31,31,31,31,21,21,21,21,21,21,21,21,21,21,21,46,46,46,46,46,19,46,46,46,46,7,7,7,7,7,7,7,7,7,7,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,55,55,55,55,55,55,55,55,55,0,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,8,8,8,51,45,51,51,51,20,20,20,20,20,20,20,20,0,20,20,20,20,20,20,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,0,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,40,40,40,40,40,40,40,40,40,40,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,56,9,9,0,9,0,9,9,0,9,2,2,2,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,25,25,25,25,25,25,25,25,25,25,25,25,10,10,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,0,17,17,17,17,17,17,17,17,0,0,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,0,0,0,12,12,12,12,12,12,12,12,12,0,48,48,48,0,48,48,0,48,48,48,48,48,48,48,48,48,48,48,48,48,23,23,0,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,0,51,41,41,41,41,41,41,41,41,0,0,28,28,28,28,28,28,28,28,28,0,26,26,26,26,26,26,26,26,26,26,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,0,14,14,14,14,14,14,14,14,24,24,0,24,24,24,24,24,24,24,24,24,0,0,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,0,16,16,16,0,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,29,29,0,29,29,29,29,29,29,29,29,29,29,29,0,0,0,0,0,0,18,18,0,18,18,18,18,18,18,0,18,18,18,18,18,0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,36,36,0,43,36,36,36,36,36,36,36,36,0,36,36,36,36,36,36,36,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,0,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,0,0,0,50,50,50,50,50,50,50,50,50,50,50,50,13,13,13,13,13,13,13,0,44,44,44,44,44,44,44,44,0,0,4,4,4,4,0,4,4,4,0,4,4,0,0,4,4,4,0,0,0,0,33,33,0,33,33,33,33,33,33,33,33,33,33,33,33,43,0,0,0,30,30,30,0,30,30,30,0,30,30,0,5,5,5,5,5,5,5,5,5,0,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,0,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,57,57,57,57,57,11,11,52,37,37,37,37,37,37,37,37,37,37,47,47,47,47,47,47,47,0,47,47,47,47,47,47,47,1,1,1,1,1]); const regions = [null,"AK","AL","AR","AZ","CA","CO","CT","DE","FL","GA","HI","IA","ID","IL","IN","KS","KY","LA","MA","MD","ME","MI","MN","MO","MS","MT","NC","ND","NE","NV","NH","NJ","NM","NY","OH","OK","OR","PA","RI","SC","SD","TN","TX","UT","VA","VT","WA","WI","WV","WY","DC","GU","PR","VI","AE","AA","AP","AS","PW","FM","MP","MH"]; const exceptions = {"20500":51,"20501":51,"20502":51,"20503":51,"20504":51,"20505":51,"20506":51,"20507":51,"20508":51,"20509":51,"20510":51,"20511":51,"20515":51,"20520":51,"20521":51,"20522":51,"20523":51,"20524":51,"20525":51,"20526":51,"20527":51,"20528":51,"20529":51,"20530":51,"20531":51,"20532":51,"20533":51,"20534":51,"20535":51,"20536":51,"20537":51,"20538":51,"20539":51,"20540":51,"20541":51,"20542":51,"20543":51,"20544":51,"20546":51,"20547":51,"20548":51,"20549":51,"20551":51,"20552":51,"20553":51,"20554":51,"20555":51,"20557":51,"20558":51,"20559":51,"20560":51,"20565":51,"20566":51,"20570":51,"20571":51,"20572":51,"20573":51,"20575":51,"20576":51,"20577":51,"20578":51,"20579":51,"20580":51,"20581":51,"20585":51,"20586":51,"20590":51,"20591":51,"20593":51,"20594":51,"20597":51,"20598":45,"20599":51,"72643":24,"73960":43,"83414":50,"96799":58,"96939":59,"96940":59,"96941":60,"96942":60,"96943":60,"96944":60,"96950":61,"96951":61,"96952":61,"96960":62,"96970":62,"06390":34}; return function zipState (zip) { let index; zip = zip.slice(0,5); if (exceptions[zip]) { index = exceptions[zip]; } else { const prefix = parseInt(zip.slice(0,3)); index = mapping[prefix]; } return regions[index] || null; }; }));