CoreFiles by mySites.guru
word-count.js48 lines, 1,070 bytes, from wordpress-4.3-beta1.zip
Raw History Compare with 4.2-beta4
md5
7348fc0ec6b2b37ddfd3dab63436f171
sha1
f8d86e96435f23110eaacc78c22a7cb15977c439
sha256
7facb169bebe02dd4eae1e6a1b010d2e3b97028fd478877e55875a48ae8375c3
( function() {
	function WordCounter( settings ) {
		var key;

		if ( settings ) {
			for ( key in settings ) {
				if ( settings.hasOwnProperty( key ) ) {
					this.settings[ key ] = settings[ key ];
				}
			}
		}
	}

	WordCounter.prototype.settings = {
		HTMLRegExp: /<\/?[a-z][^>]*?>/gi,
		spaceRegExp: /&nbsp;|&#160;/gi,
		removeRegExp: /[0-9.(),;:!?%#$¿'"_+=\\\/-]+/g,
		wordsRegExp: /\S\s+/g,
		charactersRegExp: /\S/g,
		l10n: window.wordCountL10n || {}
	};

	WordCounter.prototype.count = function( text, type ) {
		var count = 0;

		type = type || this.settings.l10n.type || 'words';

		if ( text ) {
			text = ' ' + text + ' ';

			text = text.replace( this.settings.HTMLRegExp, ' ' );
			text = text.replace( this.settings.spaceRegExp, ' ' );
			text = text.replace( this.settings.removeRegExp, '' );

			text = text.match( this.settings[ type + 'RegExp' ] );

			if ( text ) {
				count = text.length;
			}
		}

		return count;
	};

	window.wp = window.wp || {};
	window.wp.utils = window.wp.utils || {};
	window.wp.utils.WordCounter = WordCounter;
} )();

The same content is in 3 releases, WordPress 4.3-beta1 to 4.3-beta3. See them all, or every version of this file.