Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alsotang/is-chinese
Determine if a string is all Chinese(based on unicode range)
https://github.com/alsotang/is-chinese
Last synced: 1 day ago
JSON representation
Determine if a string is all Chinese(based on unicode range)
- Host: GitHub
- URL: https://github.com/alsotang/is-chinese
- Owner: alsotang
- License: mit
- Created: 2015-11-30T14:23:05.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2023-11-17T15:21:46.000Z (about 1 year ago)
- Last Synced: 2024-12-25T16:07:24.222Z (9 days ago)
- Language: TypeScript
- Homepage:
- Size: 39.1 KB
- Stars: 120
- Watchers: 5
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
JS 中文字符串判断(根据 unicode 编码区间判断)
Determine whether a string is all Chinese(based on unicode range)
## install
`$ npm install is-chinese`
## description
Chinese range is based on: https://en.wikipedia.org/wiki/CJK_Unified_Ideographs
## usage
```typescript
const isChinese: (str: string, { includePunctuation }?: {
includePunctuation?: boolean | undefined;
}) => boolean
```## example
```js
import isChinese from 'is-chinese'
isChinese('中国').should.true();
isChinese('中国ss').should.false();
isChinese('ss').should.false();
isChinese("\uD842\uDFB7").should.true();
```## benchmark
```
isChinese("扁担宽,板凳长,扁担想绑在板凳上。") x 15,813,552 ops/sec ±1.28% (98 runs sampled)
isChinese("ss扁担宽,板凳长,扁担想绑在板凳上。") x 74,815,821 ops/sec ±0.72% (96 runs sampled)
isChinese("扁担宽,板凳长,扁担想绑在板凳上。ss") x 53,410,698 ops/sec ±0.47% (92 runs sampled)
isChinese(chars1000) true x 453,971 ops/sec ±0.57% (100 runs sampled)
isChinese(chars1000WithAscii) false x 2,817,982 ops/sec ±0.36% (90 runs sampled)
Fastest is isChinese("ss扁担宽,板凳长,扁担想绑在板凳上。")
```## license
MIT