Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

str-util

bluelovers11.4kISC3.0.2TypeScript support: included

convert full/half width, Chinese/Japanese number, 中日漢字轉換... others util helper

char, character, characters, chinese, cjk, cn, cn2tw, codepage, conv, conversion, convert, fullwidth, halfwidth, han, han zi, hanja, japanese, jp2zhs, jp2zht, kanji, node-novel, number, simplified, str, str-util, string, traditional, transform, trim, tw, tw2cn, unicode, util, words, zh, zh2jp, zhs, zht

readme

str-util

convert full/half width, Chinese/Japanese number ... others util helper

npm i str-util

Usage

import * as StrUtil from 'str-util';

See more at test / docs

FullHalf

const str = 'THE quick, BROWN\u3000fox.';

StrUtil.toFullWidth(str);
//=> 'THE quick, BROWN fox.'

StrUtil.toHalfWidth(str);
//=> 'THE quick, BROWN fox.'

console.log(StrUtil.toFullEnglish('123abcABCABC123/*-+=-0][’;/.+-*/=-09][\'";/.'));
console.log(StrUtil.toHalfEnglish('123abcABCABC123/*-+=-0][’;/.+-*/=-09][\'";/.'));
console.log(StrUtil.toFullNumber('123abcABCABC123/*-+=-0][’;/.+-*/=-09][\'";/.'));
console.log(StrUtil.toHalfNumber('123abcABCABC123/*-+=-0][’;/.+-*/=-09][\'";/.'));

default

0123456789
0123456789
ABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZ
abcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyz
 

!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~

漢字 Number

zh2num('千百十七') == 1117
num2zh(1117) == '千百十七'

中日漢字

import { zh2jp } from 'str-util';

let t = '魔物解説 ランク等話 蚀蝕蝕王で触王 冒険者ギルド解説 蚀|蝕战|戦马|馬亚|亞國預中日漢字對照表'

console.log(zh2jp(t));
import * as ZH2JP from 'str-util/lib/han/zh2jp';

// 沒有漢字存在時會直接返回原參數
console.log(ZH2JP.zhs2jp(1));

// http://ncode.syosetu.com/n1745ct/
let t = '魔物解説 ランク等話 蚀蝕蝕王で触王 冒険者ギルド解説 蚀|蝕战|戦马|馬亚|亞國預中日漢字對照表'

console.log(ZH2JP.zh2jp(t));
console.log(ZH2JP.zht2jp(t));
console.log(ZH2JP.zhs2jp(t));

console.log(ZH2JP.zht2zhs(t));
console.log(ZH2JP.zhs2zht(t));

lib

  • ascii-fullwidth-halfwidth-convert
  • string-width
  • chinese-parseint
  • japanese

changelog

Change Log

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

3.0.2 (2024-02-03)

🔖 Miscellaneous

3.0.1 (2024-01-29)

BREAKING CHANGES

  • @lazy-cjk/fullhalf
  • @lazy-cjk/zh2num

📦 Code Refactoring

🔖 Miscellaneous

2.3.41 (2023-11-24)

Note: Version bump only for package str-util

2.3.40 (2023-09-08)

Note: Version bump only for package str-util

2.3.39 (2023-04-12)

Note: Version bump only for package str-util

2.3.38 (2023-04-12)

🔖 Miscellaneous

2.3.37 (2022-11-01)

🔖 Miscellaneous

2.3.36 (2022-10-15)

🔖 Miscellaneous

2.3.35 (2022-09-26)

🔖 Miscellaneous

2.3.34 (2022-09-16)

🔖 Miscellaneous

2.3.33 (2022-08-27)

🔖 Miscellaneous

2.3.31 (2022-08-26)

♻️ Chores

🔖 Miscellaneous

2.3.30 (2022-08-26)

🔖 Miscellaneous

2.3.30 (2022-08-26)

🔖 Miscellaneous

2.3.29 (2022-08-26)

📦 Code Refactoring

🚨 Tests

🔖 Miscellaneous

2.3.28 (2022-01-17)

🔖 Miscellaneous

2.3.27 (2021-07-05)

🛠 Build System

  • typescript: importHelpers (0716543)

♻️ Chores

2.3.26 (2020-07-19)

♻️ Chores

2.3.25 (2020-06-21)

🛠 Build System

♻️ Chores

2.3.24 (2020-06-20)

Note: Version bump only for package str-util

2.3.23 (2020-06-10)

Note: Version bump only for package str-util

2.3.22 (2020-06-07)

Features