Skip to main content
Deno 2 is finally here 🎉️
Learn more

deno-zhconv

Overview

deno-zhconv is a library that supports character conversion in Deno. It performs mutual conversion between full-width and half-width characters and kana.

URL: deno.land https://deno.land/x/zhconv@1.0.1

URL: jsr.io https://jsr.io/@suwakei/zhconv

Installation

import {h2z, z2h} from "https://deno.land/x/zhconv@1.0.1/mod.ts"

or

import {h2z, z2h} from "https://jsr.io/@suwakei/zhconv";

Usage

convert from HalfWidth to FullWidth

import { h2z } from "https://deno.land/x/zhconv@1.0.1/mod.ts"; // or import { h2z } from "https://jsr.io/@suwakei/zhconv";


let result = h2z("Hello, world!")
console.log(result) // Hello, world!.

let result = h2z("") // Empty string.
console.log(result) // "".

let result = h2z("ABC123アイウガパ") // No conversion needed (Zenkaku).
console.log(result) // ABC123アイウガパ.

let result = h2z("ABCdef XYZ!#$%&'()*+,-./:;<=>?@[¥]^_`{|}~ \\")
console.log(result) // ABCdef XYZ!#$%&’()*+,-./:;<=>?@[¥]^_‘{|}~ \.

let result = h2z("0123456789") // Hankaku Digits to Zenkaku.
console.log(result) // 0123456789.

let result = h2z("アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲン") // Hankaku Katakana to Zenkaku.
console.log(result) // アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲン.

let result = h2z("ァィゥェォッャュョ") // Hankaku Katakana (Small) to Zenkaku.
console.log(result) // ァィゥェォッャュョ.

let result = h2z("。、・ー「」")// Hankaku Katakana (Symbols) to Zenkaku.
console.log(result) // 。、・ー「」.

let result = h2z("ガギグゲゴザジズゼゾダヂヅデドバビブベボヴ") // Hankaku Katakana with Dakuten to Zenkaku".
console.log(result) // ガギグゲゴザジズゼゾダヂヅデドバビブベボヴ.

let result = h2z( "パピプペポ") // Hankaku Katakana with Handakuten to Zenkaku.
console.log(result) // パピプペポ.

let result = h2z("これはテストです。123 ABC アイウ ガギグ パピプ!") // Mixed Hankaku/Zenkaku/Other.
console.log(result) // これはテストです。123 ABC アイウ ガギグ パピプ!.

let result = h2z(" スペース ") // convert from Half width space to Full width space.
console.log(result) //   スペース .

let result = h2z("ア゙イ゚ン゙") // Dakuten/Handakuten cannot be applied.
console.log(result) // ア゛イ゜ン゛ Converted to full-width characters as separated( (ア->ア, ゙->゙).

let result = h2z("①②③㈱㈲") // Not convertible symbols.
console.log(result) // It is assumed that environment dependent characters will not be converted.

let result = h2z("1バイト文字と2バイト文字が混在するテキスト。 ABC 123 ガギグパピプ!?") // Long string with various conversions.
console.log(result) // 1バイト文字と2バイト文字が混在するテキスト。 ABC 123 ガギグパピプ!?.

convert from HalfWidth to FullWidth

import { z2h } from "https://deno.land/x/zhconv@1.0.1/mod.ts";


let result = z2h("ABCdef XYZ!#$%&’()*+,-./:;<=>?@[¥]^_‘{|}~")
console.log(result) // ABCdef XYZ!#$%&'()*+,-./:;<=>?@[¥]^_`{|}~

let result = z2h("0123456789")
console.log(result) // 0123456789

let result = z2h("アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲン")
console.log(result) // アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲン

let result = z2h("ァィゥェォッャュョ")
console.log(result) // ァィゥェォッャュョ ヮ is not converted because there is no corresponding character for half-width.

let result = z2h("。、・ー「」")
console.log(result) // 。、・ー「」

let result = z2h("ガギグゲゴザジズゼゾダヂヅデドバビブベボヴ")
console.log(result) // ガギグゲゴザジズゼゾダヂヅデドバビブベボヴ

let result = z2h("パピプペポ")
console.log(result) // パピプペポ

let result = z2h(" スペース ") // convert from Full width space to half width space
console.log(result) //  スペース 

let result = z2h("①②③㈱㈲") // It is assumed that environment dependent characters will not be converted.
console.log(result) // ①②③㈱㈲