| English | 日本語 |
|---|
deno-zhconv is a library that supports character conversion in Deno. It performs mutual conversion between full-width and half-width characters and kana.
-
deno.land: https://deno.land/x/zhconv
-
jsr.io: https://jsr.io/@suwakei/zhconv
import {h2z, z2h, h2zAt, z2hAt} from "https://deno.land/x/[email protected]/mod.ts"or
import {h2z, z2h, h2zAt, z2hAt} from "https://jsr.io/@suwakei/zhconv";/**
* h2z converts half-width characters (hankaku) in a string to full-width characters (zenkaku).
* It handles ASCII, Katakana, digits, and Katakana with dakuten/handakuten.
* @param "str" The input string.
* @returns The converted string.
*/
function h2z(str: string): string
/**
* h2zAt returns string that converted from half width to full width.
* Conversion string can be selected with the second argument.
* @param "str" The input string.
* @param "at" Indices of characters to convert.
* @returns The converted string.
*/
function h2zAt(str: string, ...at: number[]): string
/**
* z2h converts full-width characters (zenkaku) in a string to half-width characters (hankaku).
* It handles ASCII, Katakana, digits, and Katakana with dakuten/handakuten.
* @param "str" The input string.
* @returns The converted string.
*/
function z2h(str: string): string
/**
* z2hAt returns string that converted from full-width to half-width.
* Conversion string can be selected with the second argument.
* @param "str" The input string.
* @param "at" Indices of characters to convert.
* @returns The converted string.
*/
function Z2hAt(str: tring, at: number[]): string
/**
* Reverses the width of characters in a string.
* Full-width characters are converted to half-width, and half-width characters are converted to full-width.
* Characters that are neither full-width nor half-width, or for which no direct reverse mapping exists, remain unchanged.
*
* @param str The input string.
* @returns The string with character widths reversed.
*/
function reverse (str: string): stringimport { h2z } from "https://deno.land/x/[email protected]/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 ガギグパピプ!?.import { z2h } from "https://deno.land/x/[email protected]/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) // ①②③㈱㈲import { h2zAt } from "https://deno.land/x/[email protected]/mod.ts";
let result = h2zAt("Hello, world!", 0, 7)
console.log(result) // Hello, world!.
let result = h2zAt("", 0) // Empty string.
console.log(result) // "".
let result = h2zAt("ABC123アイウガパ", 0, 5) // No conversion needed (Zenkaku).
console.log(result) // ABC123アイウガパ.
let result = h2zAt("ABCdef XYZ!#$%&'()*+,-./:;<=>?@[¥]^_`{|}~ \\", 3, 17)
console.log(result) // ABCdef XYZ!#$%&'()*+,-./:;<=>?@[¥]^_`{|}~ \\.
let result = h2zAt("0123456789",0, 5) // Hankaku Digits to Zenkaku.
console.log(result) // 0123456789.
let result = h2zAt("アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲン", 0) // Hankaku Katakana to Zenkaku.
console.log(result) // アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲン.
let result = h2zAt("ァィゥェォッャュョ", 0) // Hankaku Katakana (Small) to Zenkaku.
console.log(result) // ァィゥェォッャュョ.import { z2hAt } from "https://deno.land/x/[email protected]/mod.ts";
let result = z2hAt("Hello, world!", 0, 7)
console.log(result) // Hello, world!.
let result = z2hAt("ABCdef XYZ!#$%&’()*+,-./:;<=>?@[¥]^_‘{|}~", 3, 17)
console.log(result) // ABCdef XYZ!#$%&’()*+,-./:;<=>?@[¥]^_‘{|}~.
let result = z2hAt("0123456789", 0, 5)
console.log(result) // 0123456789.
let result = z2hAt("アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲン", 0, 6, 9, 10)
console.log(result) // アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲン.
let result = z2hAt("ァィゥェォッャュョ", 4)
console.log(result) // ァィゥェォッャュョ.import { reverse } from "https://deno.land/x/[email protected]/mod.ts";
let result = reverse("abc xyz!")
console.log(result) // abc xyz!
let result = reverse("012345")
console.log(result) // 012345
let result = reverse("Hello World! 123 アイウガパ")
console.log(result) // Hello World! 123 アイウガパ
let result = reverse("AbcDEFgh 123XYz アイウエオ カギクゲコ サジスゼソ タチヅテド")
console.log(result) //AbcDEFgh 123XYz アイウエオ カギクゲコ サジスゼソ タチヅテド
let result = reverse("1st「PRICE」is ¥1,000- (TAX IN) ガンバレ!")
console.log(result) // 1st「PRICE」is \\1,000- (TAX IN) ガンバレ!
let result = reverse("テストガ")
console.log(result) // テストガ