How to use @wordpress/wordcount - 3 common examples

To help you get started, we’ve selected a few @wordpress/wordcount examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github WordPress / gutenberg / packages / block-editor / src / components / multi-selection-inspector / index.js View on Github external
function MultiSelectionInspector( { blocks } ) {
	const words = wordCount( serialize( blocks ), 'words' );

	return (
		<div>
			</div>
github phpbits / block-options / src / extensions / components / reading-time / components / controls.js View on Github external
calculateReadingTime() {
		const { content, blocks } = this.props;
		const words = wordcount( content, 'words', {} );

		let estimated = ( words / 275 ) * 60; //get time on seconds
		if ( blocks ) {
			let i = 12;
			map( blocks, ( block ) => {
				if ( mediaBlocks.includes( block.name ) || hasBlockSupport( block.name, 'editorsKitWordCount' ) ) {
					estimated = estimated + i;
					if ( i > 3 ) {
						i--;
					}
				}
			} );
		}
		estimated = estimated / 60; //convert to minutes

		//do not show zero
github WordPress / gutenberg / packages / editor / src / components / word-count / index.js View on Github external
function WordCount( { content } ) {
	/*
	 * translators: If your word count is based on single characters (e.g. East Asian characters),
	 * enter 'characters_excluding_spaces' or 'characters_including_spaces'. Otherwise, enter 'words'.
	 * Do not translate into your own language.
	 */
	const wordCountType = _x( 'words', 'Word count type. Do not translate!' );

	return (
		<span>{ wordCount( content, wordCountType ) }</span>
	);
}

@wordpress/wordcount

WordPress word count utility.

GPL-2.0-or-later
Latest version published 2 days ago

Package Health Score

95 / 100
Full package analysis

Popular @wordpress/wordcount functions