https://github.com/bluelovers/node-str-util
convert full/half width, Chinese/Japanese number ... others util helper
https://github.com/bluelovers/node-str-util
characters chinese codepage japanese l10n language localization string
Last synced: 11 months ago
JSON representation
convert full/half width, Chinese/Japanese number ... others util helper
- Host: GitHub
- URL: https://github.com/bluelovers/node-str-util
- Owner: bluelovers
- Created: 2017-12-08T09:24:32.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2019-05-27T11:56:25.000Z (over 6 years ago)
- Last Synced: 2025-02-07T09:29:13.648Z (11 months ago)
- Topics: characters, chinese, codepage, japanese, l10n, language, localization, string
- Language: TypeScript
- Homepage: https://bluelovers.github.io/node-str-util/
- Size: 352 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# str-util
> convert full/half width, Chinese/Japanese number ... others util helper
`npm i str-util`
## Usage
```javascript
import * as StrUtil from 'str-util';
```
See more at [test](https://github.com/bluelovers/node-str-util/tree/master/test) / [docs](https://bluelovers.github.io/node-str-util/)
### FullHalf
```javascript
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
```javascript
zh2num('千百十七') == 1117
num2zh(1117) == '千百十七'
```
### 中日漢字
```javascript
import { zh2jp } from 'str-util';
let t = '魔物解説 ランク等話 蚀蝕蝕王で触王 冒険者ギルド解説 蚀|蝕战|戦马|馬亚|亞國預中日漢字對照表'
console.log(zh2jp(t));
```
```javascript
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`