Comparing version 1.0.1 to 1.0.2
10
index.js
var cjk = require('unicode-6.3.0/blocks/CJK Unified Ideographs/regex'); | ||
var re = new RegExp(cjk.source, 'g'); | ||
var re_char = new RegExp(cjk.source, 'g'); | ||
var re_word = new RegExp(cjk.source + '+', 'g'); | ||
module.exports = function(str) { | ||
function count (str, word) { | ||
word = word || false; | ||
if (typeof str === 'string') { | ||
return str.match(re); | ||
return str.match(word ? re_word : re_char); | ||
@@ -13,1 +15,3 @@ } else{ | ||
}; | ||
module.exports = count; |
{ | ||
"name": "cjk-count", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "cjk word count", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "node test.js" | ||
"test": "jasmine" | ||
}, | ||
@@ -26,3 +26,6 @@ "repository": { | ||
"unicode-6.3.0": "^0.1.5" | ||
}, | ||
"devDependencies": { | ||
"jasmine": "^2.3.1" | ||
} | ||
} |
@@ -17,4 +17,14 @@ # cjk-count | ||
var str = 'I am a 香港人'; | ||
console.log(cjkCount(str)); | ||
var str3 = ' No results found.人口家庭教育就業收I am a 香港人'; | ||
console.log(cjkCount(str)); // count char | ||
console.log(cjkCount(str3, true)); // count words | ||
``` | ||
## Test | ||
``` | ||
npm test | ||
``` |
3287
8
67
30
1