1.0.4 • Published 1 year ago

count-text-words v1.0.4

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

计算文本字数(规则类word字数统计)

Installation

npm i count-text-words

import {calculateTextCount} from 'count-text-words';
calculateTextCount('አሜሪው ዛሬ መልካም ነው።');

html 直接使用

<script src="https://unpkg.com/count-text-words" />
<script>
    countTextWords.calculateTextCount('hello world!');
</script>

属性说明

calculateTextCount(text: string, config?): number

config: {type?: 'Word' | 'Char', includeSpace?: boolean, includeWrap?: boolean}

textSlice(text: string, start: number, end: number, config?): string

config: {type?: 'Word' | 'Char', includeSpace?: boolean, includeWrap?: boolean}

getTextChunks(text: string, config?): string

config: {type?: 'Word' | 'Char', includeSpace?: boolean, includeWrap?: boolean}

getCharString(text: string, start: number, end: number, config?): string

config: {type?: 'Word' | 'Char', includeSpace?: boolean, includeWrap?: boolean}

other
    isEmoji(str: string): boolean // 是否是个emoji
    isCnMark(str: string): boolean // 是否是个中文标点符号
    isCJKWord(str: string): boolean // 是否是个中文类字符
    isBlankString(str: string): boolean // 是否是个空白符
    isWrap(str: string): boolean // 是否是个换行符
    isSpace(str: string): boolean // 是否是个空格

实例

import {calculateTextCount, textSlice, getTextChunks, getCharString} from 'count-text-words';

const text  = `
    hello, happy!
    你好!Olá
    🐶👈🏻
`;
const textLength = calculateTextLength(text); // 7
const str = textSlice(text, 0, 5);
    // `
    // hello, happy!
    // 你好!
    // `
const chunks = getTextChunks(text); // ['\nhello, ', 'happy!\n', '你', '好', '!', 'Olá\n', '🐶👈🏻']
const charStr = getCharString(text, 0, 20); // 'hello, happy!\n    🐶'
1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago