Skip to content

MarvNC/is-cjk-hanzi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

is-cjk-hanzi

npm

A handy utility to determine if a character or string contains CJK (Chinese, Japanese, Korean) Hanzi/Kanji characters.

Installation

npm install is-cjk-hanzi

Purpose

Some characters are tricky to work with because they are surrogate pairs and have a length of 2.

console.log('𧓈'.length); // 2
isSingleCJKHanzi('𧓈'); // true

Usage

const isCJKHanzi = require('is-cjk-hanzi');

isCJKHanzi('我'); // true
isCJKHanzi('詠む'); // true
isCJKHanzi('hello'); // false

// Check for single CJK Hanzi characters
const isSingleCJKHanzi = require('is-cjk-hanzi/isSingleCJKHanzi');

isSingleCJKHanzi('我'); // true
isSingleCJKHanzi('我的'); // false

Functions

  • isCJKHanzi(inputString)

    • Returns true if the input string contains at least one CJK Hanzi character; false otherwise.
  • isSingleCJKHanzi(inputCharacter)

    • Returns true if the input is a single CJK Hanzi character; false otherwise.