UNPKG

cjk-count

Version:
17 lines (12 loc) 391 B
var cjk = require('unicode-6.3.0/blocks/CJK Unified Ideographs/regex'); var re_char = new RegExp(cjk.source, 'g'); var re_word = new RegExp(cjk.source + '+', 'g'); function count (str, word) { word = word || false; if (typeof str === 'string') { return str.match(word ? re_word : re_char); } else{ throw new Error('arguments str is not a string'); }; }; module.exports = count;