JSFiddle - React, Tailwind, and code Playground
JavaScript
function tokenizeZH(text) {
const segmenter = new Intl.Segmenter('zh', { granularity: 'word' });
const segments = segmenter.segment(text);
const words = [];
for (const { segment /* , index, isWordLike */ } of segments) {
words.push(segment);
}
return words;
}
console.log(tokenizeZH('我不是太清楚'));