UNPKG

henkaku

Version:

Functions to convert UTF-8 characters between full-width 全角 and half-width 半角

57 lines (53 loc) 2.14 kB
import { describe, test, expect } from "vitest"; import { toFullWidth, toHalfWidth } from ".."; const testCases = [ { description: "latin characters", half: "Helloworld", full: "Helloworld", }, { description: "whitespaces", half: " ", full: "     ", }, { description: "katakana characters", half: "ヲァィゥェォャュョッーアイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン", full: "ヲァィゥェォャュョッーアイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン", }, { description: "katakana characters with dakuden", half: "ガギグゲゴ", full: "ガギグゲゴ", }, { description: "symbols", half: "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~", full: "!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~", }, { description: "numbers", half: "0123456789", full: "0123456789", }, { description: "mixed", full: "4 Chome-2-8 Shibakoen, Minato City, Tokyo 105-0011 〒105-0011 東京都港区芝公園4丁目2-8 トウキョウトミナトクシバコウエン4チョウメ2-8", half: "4 Chome-2-8 Shibakoen, Minato City, Tokyo 105-0011 〒105-0011 東京都港区芝公園4丁目2-8 トウキョウトミナトクシバコウエン4チョウメ2-8", }, ]; describe.each(testCases)("case: %half <> %full", ({ half, full }) => { test(`toFullWidth half -> full`, () => { expect(toFullWidth(half)).toBe(full); }); test(`toFullWidth full -> full`, () => { expect(toFullWidth(full)).toBe(full); }); test(`toHalfWidth full -> half`, () => { expect(toHalfWidth(full)).toBe(half); }); test(`toFullWidth half -> half`, () => { expect(toHalfWidth(half)).toBe(half); }); });