npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@simoko/tw-zip

v0.1.4

Published

taiwan zip code

Downloads

9

Readme

@simoko/tw-zip

NPM version

台灣 縣市行政區郵遞區號(3碼)資料

Installation

Install using npm or your favourite package manager:

npm i @simoko/tw-zip

Import:

import { getCityArray, getDistrictArray, getZipCode } from '@simoko/tw-zip'

React

stackblitz | codesandbox

import { useTwZip } from '@simoko/tw-zip/react';

export function App() {
  const { cities, districts, setCity, setDistrict, city, district, zipCode } =
    useTwZip();

  return (
    <div>
      <select onChange={(e) => setCity(e.target.value)}>
        {cities.map((c, i) => {
          return <option key={i}>{c}</option>;
        })}
      </select>

      <select onChange={(e) => setDistrict(e.target.value)}>
        {districts.map((d, i) => {
          return <option key={i}>{d['label']}</option>;
        })}
      </select>

      <div>
        {city}, {district}, {zipCode}
      </div>
    </div>
  );
}

Vue

stackblitz | codesandbox

<script setup lang="ts">
import useTwZip from '@simoko/tw-zip/vue';
const { cities, districts, city, district, zipCode } = useTwZip();
</script>

<template>
  <div>
    <select v-model="city">
      <option v-for="(c, i) in cities" :key="i">
        {{ c }}
      </option>
    </select>

    <select v-model="zipCode">
      <option v-for="(d, i) in districts" :key="i" :value="d.value">
        {{ d.label }}
      </option>
    </select>

    <div>{{ city }}, {{ district }}, {{ zipCode }}</div>
  </div>
</template>

Functions

getCityArray

getCityArray(): string[]

回傳縣市陣列

Returns

string[]

Example

getCityArray()
// [ "台北市", "基隆市", "新北市", ... ]

getData

getData(): ICity

回傳所有資料

Returns

ICity

Example

getData()
// { "台北市": { "中正區": "100", "大同區": "103", "中山區": "104", "松山區": "105", ... }, "基隆市": { "仁愛區": "200", "信義區": "201", "中正區": "202", ... }, ... }

getDistrictArray

getDistrictArray(city?, «destructured»?): Object[]

回傳行政區資料 - array

Parameters

| Name | Type | Default value | Description | | :------ | :------ | :------ | :------ | | city | null | string | null | 縣市名稱 | | «destructured» | Object | {} | - | | › label | undefined | string | undefined | - | | › value | undefined | string | undefined | - |

Returns

Object[]

Example

getDistrictArray('台北市', { label: 'key' })
// [ { key: "中正區", value: "100" }, { key: "大同區", value: "103" }, ... ]

getDistricts

getDistricts(city?): IDistrict

回傳行政區資料 - dist

Parameters

| Name | Type | Description | | :------ | :------ | :------ | | city? | string | 縣市名稱 |

Returns

IDistrict

Example

getDistricts('台北市')
// { "中正區": "100", "大同區": "103", ... }

getFlatArray

getFlatArray(«destructured»?): string[]

回傳扁平化陣列資訊

Parameters

| Name | Type | | :------ | :------ | | «destructured» | Object | | › city | undefined | string | | › symbol | undefined | string |

Returns

string[]

Example

getFlatArray('台北市')
// [ "100 台北市 中正區", "103 台北市 大同區", ... ]

getFlatArray({ city: '嘉義市', symbol: '#' })
// [ "600#嘉義市#東區", "600#嘉義市#西區" ]

getZipCode

getZipCode(district): undefined | string[]

根據行政區回傳郵遞區號

Parameters

| Name | Type | Description | | :------ | :------ | :------ | | district | string | 行政區名稱 |

Returns

undefined | string[]

Example

getZipCode('中正區')
// [ "100", "台北市", "中正區" ]

getZipCode('100')
// [ "100", "台北市", "中正區" ]