Dependency-free tiny utility

日本語フォーム入力の
表記ゆれを安全に正規化。

全角数字、全角英字、全角スペース、ハイフン類をフォーム入力向けに扱いやすく整える TypeScript utility です。

import { normalizeJaInput } from "normalize-ja-input"

normalizeJaInput(" TEL:090ー1234ー5678 ")
// "TEL:090-1234-5678"

Live demo

日本語入力で混ざりがちな文字をその場で正規化します。

Try examples

Form focused

電話番号、氏名、住所、IDなどの入力前処理に使いやすい小さな設計。

Configurable

数字間のハイフンだけをそろえる設定や、改行を残す空白圧縮を選べます。

Zero dependencies

Node.js、ブラウザ、フロントエンドフォームで扱いやすい依存ゼロ構成。

Install

npmでインストールして、TypeScript/JavaScriptから利用できます。

npm install normalize-ja-input
import { normalizeJaInput } from "normalize-ja-input"

const value = normalizeJaInput(" ABCー123 ")
// "ABC-123"

API

import { jaInputPresets, normalizeJaInput } from "normalize-ja-input"

normalizeJaInput("スーパー ヤマダ", jaInputPresets.furigana)
// "スーパー ヤマダ"

normalizeJaInput(input: string, options?: {
  trim?: boolean
  collapseSpaces?: boolean | "horizontal"
  spaces?: "preserve" | "halfwidth"
  digits?: "preserve" | "halfwidth"
  alphabets?: "preserve" | "halfwidth"
  katakana?: "preserve" | "fullwidth"
  hyphens?: "preserve" | "ascii" | "between-digits"
  punctuation?: "preserve" | "ascii"
}): string

CDN

npmで公開されたパッケージを、ブラウザからESモジュールとして読み込めます。

<script type="module">
  import { normalizeJaInput } from "https://unpkg.com/normalize-ja-input/dist/index.js"

  console.log(normalizeJaInput(" ABCー123 "))
</script>