WordPress 字数统计实用工具。
安装
安装模块
npm install @wordpress/wordcount --save
此软件包假设你的代码将在 ES2015+ 环境中运行。如果你使用的环境对此类语言特性和 API 的支持有限或完全不支持,你应该在代码中包含 @wordpress/babel-preset-default 附带的 polyfill。
API
count
统计一些文本的字数。
用法
import { count } from '@wordpress/wordcount';
const numberOfWords = count( 'Words to count', 'words', {} );
参数
- text
string:正在处理的文本 - type
Strategy:统计类型。接受 ‘words’、‘characters_excluding_spaces’ 或 ‘characters_including_spaces’。 - userSettings
UserSettings:自定义设置对象。
返回值
number:单词或字符数量。
为这个软件包做贡献
这是一个独立软件包,是 Gutenberg 项目的一部分。该项目以 monorepo 形式组织。它由多个自包含的软件包组成,每个软件包都有特定用途。此 monorepo 中的软件包发布到 npm,并被 WordPress 以及其他软件项目使用。
要了解有关为此软件包或整个 Gutenberg 项目做贡献的更多信息,请阅读项目主要的 贡献者指南。