@simoko/tw-zip
Version:
台灣縣市、行政區、郵遞區號(3碼/6碼)查詢工具,支援 React/Vue/Svelte/SolidJS/Angular
3 lines • 1.04 kB
JavaScript
;var l="https://cdn.jsdelivr.net/npm/@simoko/tw-zip/data/zip6",r=new Map,n=null,a=null;async function u(e={}){if(n)return n;if(a)return a;let i=e.baseUrl||l;return a=fetch(`${i}/cities.json`).then(t=>{if(!t.ok)throw new Error(`Failed to load cities data: HTTP ${t.status}`);return t.json()}).then(t=>(n=t,t)).catch(t=>{throw a=null,t}),a}async function d(e,i={}){let t=e.trim();if(!t)throw new Error("City name cannot be empty");let s=r.get(t);if(s)return s;let p=i.baseUrl||l,o=await fetch(`${p}/${encodeURIComponent(t)}.json`);if(!o.ok)throw new Error(`Failed to load city data for ${t}: HTTP ${o.status}`);let c=await o.json();return r.set(t,c),c}async function C(e,i={}){await Promise.all(e.map(t=>d(t,i)));}function y(e){return r.get(e)}function D(e){return r.has(e)}function f(){r.clear(),n=null,a=null;}
exports.clearCache=f;exports.getCachedCityData=y;exports.isCityCached=D;exports.loadCitiesData=u;exports.loadCityData=d;exports.preloadCities=C;//# sourceMappingURL=loader.cjs.map
//# sourceMappingURL=loader.cjs.map