@ian_sinn/string-is-chinese
TypeScript icon, indicating that this package has built-in type declarations

1.0.6 • Public • Published

Is Chinese?

A simple helper to check if a string of characters matches the known Unicode range for Chinese.

Usage

const { isChinese, RE } = require("@ian_sinn/string-is-chinese");

// Test if a string "is chinese"
isChinese("你好嗎?還有誰要來?  我放幾個空格看看。"); // => true
isChinese("Just an english sentence"); // => false

// You can also use `hasChinese` if you just want to see if _any_ characters match.
isChinese("Just an english sentence... 不是!"); // => false
hasChinese("Just an english sentence... 不是!"); // => true

// You can configure the percentage of a string that must be Chinese in order
// to pass the test.
isChinese("Just an english sentence... 不是!", { threshold: 0.05 }); // => true

Copy Paste

This library is basically a wrapper around a regex. Feel free to copy and paste directly if it makes things easier:

const RE = /[\u4E00-\u9FA5\uF900-\uFA2D]/;

RE.test("加油!");

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.6
    3
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.6
    3
  • 1.0.4
    0
  • 1.0.3
    0

Package Sidebar

Install

npm i @ian_sinn/string-is-chinese

Weekly Downloads

3

Version

1.0.6

License

MIT

Unpacked Size

3.22 kB

Total Files

6

Last publish

Collaborators

  • ian_sinn