PHP 8.1.33
Preview: word-count.js Size: 7.52 KB
/home/jambtst2015/public_html/cccng.org/wp-admin/js/word-count.js

/**
 * Word or character counting functionality. Count words or characters in a
 * provided text string.
 *
 * @namespace wp.utils
 *
 * @since 2.6.0
 * @output wp-admin/js/word-count.js
 */

( function() {
	/**
	 * Word counting utility
	 *
	 * @namespace wp.utils.wordcounter
	 * @memberof  wp.utils
	 *
	 * @class
	 *
	 * @param {Object} settings                                   Optional. Key-value object containing overrides for
	 *                                                            settings.
	 * @param {RegExp} settings.HTMLRegExp                        Optional. Regular expression to find HTML elements.
	 * @param {RegExp} settings.HTMLcommentRegExp                 Optional. Regular expression to find HTML comments.
	 * @param {RegExp} settings.spaceRegExp                       Optional. Regular expression to find irregular space
	 *                                                            characters.
	 * @param {RegExp} settings.HTMLEntityRegExp                  Optional. Regular expression to find HTML entities.
	 * @param {RegExp} settings.connectorRegExp                   Optional. Regular expression to find connectors that
	 *                                                            split words.
	 * @param {RegExp} settings.removeRegExp                      Optional. Regular expression to find remove unwanted
	 *                                                            characters to reduce false-positives.
	 * @param {RegExp} settings.astralRegExp                      Optional. Regular expression to find unwanted
	 *                                                            characters when searching for non-words.
	 * @param {RegExp} settings.wordsRegExp                       Optional. Regular expression to find words by spaces.
	 * @param {RegExp} settings.characters_excluding_spacesRegExp Optional. Regular expression to find characters which
	 *                                                            are non-spaces.
	 * @param {RegExp} settings.characters_including_spacesRegExp Optional. Regular expression to find characters
	 *                                                            including spaces.
	 * @param {RegExp} settings.shortcodesRegExp                  Optional. Regular expression to find shortcodes.
	 * @param {Object} settings.l10n                              Optional. Localization object containing specific
	 *                                                            configuration for the current localization.
	 * @param {string} settings.l10n.type                         Optional. Method of finding words to count.
	 * @param {Array}  settings.l10n.shortcodes                   Optional. Array of shortcodes that should be removed
	 *                                                            from the text.
	 *
	 * @return {void}
	 */
	function WordCounter( settings ) {
		var key,
			shortcodes;

		// Apply provided settings to object settings.
		if ( settings ) {
			for ( key in settings ) {

				// Only apply valid settings.
				if ( settings.hasOwnProperty( key ) ) {
					this.settings[ key ] = settings[ key ];
				}
			}
		}

		shortcodes = this.settings.l10n.shortcodes;

		// If there are any localization shortcodes, add this as type in the settings.
		if ( shortcodes && shortcodes.length ) {
			this.settings.shortcodesRegExp = new RegExp( '\\[\\/?(?:' + shortcodes.join( '|' ) + ')[^\\]]*?\\]', 'g' );
		}
	}

	// Default settings.
	WordCounter.prototype.settings = {
		HTMLRegExp: /<\/?[a-z][^>]*?>/gi,
		HTMLcommentRegExp: /<!--[\s\S]*?-->/g,
		spaceRegExp: /&nbsp;|&#160;/gi,
		HTMLEntityRegExp: /&\S+?;/g,

		// \u2014 = em-dash.
		connectorRegExp: /--|\u2014/g,

		// Characters to be removed from input text.
		removeRegExp: new RegExp( [
			'[',

				// Basic Latin (extract).
				'\u0021-\u0040\u005B-\u0060\u007B-\u007E',

				// Latin-1 Supplement (extract).
				'\u0080-\u00BF\u00D7\u00F7',

				/*
				 * The following range consists of:
				 * General Punctuation
				 * Superscripts and Subscripts
				 * Currency Symbols
				 * Combining Diacritical Marks for Symbols
				 * Letterlike Symbols
				 * Number Forms
				 * Arrows
				 * Mathematical Operators
				 * Miscellaneous Technical
				 * Control Pictures
				 * Optical Character Recognition
				 * Enclosed Alphanumerics
				 * Box Drawing
				 * Block Elements
				 * Geometric Shapes
				 * Miscellaneous Symbols
				 * Dingbats
				 * Miscellaneous Mathematical Symbols-A
				 * Supplemental Arrows-A
				 * Braille Patterns
				 * Supplemental Arrows-B
				 * Miscellaneous Mathematical Symbols-B
				 * Supplemental Mathematical Operators
				 * Miscellaneous Symbols and Arrows
				 */
				'\u2000-\u2BFF',

				// Supplemental Punctuation.
				'\u2E00-\u2E7F',
			']'
		].join( '' ), 'g' ),

		// Remove UTF-16 surrogate points, see https://en.wikipedia.org/wiki/UTF-16#U.2BD800_to_U.2BDFFF
		astralRegExp: /[\uD800-\uDBFF][\uDC00-\uDFFF]/g,
		wordsRegExp: /\S\s+/g,
		characters_excluding_spacesRegExp: /\S/g,

		/*
		 * Match anything that is not a formatting character, excluding:
		 * \f = form feed
		 * \n = new line
		 * \r = carriage return
		 * \t = tab
		 * \v = vertical tab
		 * \u00AD = soft hyphen
		 * \u2028 = line separator
		 * \u2029 = paragraph separator
		 */
		characters_including_spacesRegExp: /[^\f\n\r\t\v\u00AD\u2028\u2029]/g,
		l10n: window.wordCountL10n || {}
	};

	/**
	 * Counts the number of words (or other specified type) in the specified text.
	 *
	 * @since 2.6.0
	 *
	 * @memberof wp.utils.wordcounter
	 *
	 * @param {string}  text Text to count elements in.
	 * @param {string}  type Optional. Specify type to use.
	 *
	 * @return {number} The number of items counted.
	 */
	WordCounter.prototype.count = function( text, type ) {
		var count = 0;

		// Use default type if none was provided.
		type = type || this.settings.l10n.type;

		// Sanitize type to one of three possibilities: 'words', 'characters_excluding_spaces' or 'characters_including_spaces'.
		if ( type !== 'characters_excluding_spaces' && type !== 'characters_including_spaces' ) {
			type = 'words';
		}

		// If we have any text at all.
		if ( text ) {
			text = text + '\n';

			// Replace all HTML with a new-line.
			text = text.replace( this.settings.HTMLRegExp, '\n' );

			// Remove all HTML comments.
			text = text.replace( this.settings.HTMLcommentRegExp, '' );

			// If a shortcode regular expression has been provided use it to remove shortcodes.
			if ( this.settings.shortcodesRegExp ) {
				text = text.replace( this.settings.shortcodesRegExp, '\n' );
			}

			// Normalize non-breaking space to a normal space.
			text = text.replace( this.settings.spaceRegExp, ' ' );

			if ( type === 'words' ) {

				// Remove HTML Entities.
				text = text.replace( this.settings.HTMLEntityRegExp, '' );

				// Convert connectors to spaces to count attached text as words.
				text = text.replace( this.settings.connectorRegExp, ' ' );

				// Remove unwanted characters.
				text = text.replace( this.settings.removeRegExp, '' );
			} else {

				// Convert HTML Entities to "a".
				text = text.replace( this.settings.HTMLEntityRegExp, 'a' );

				// Remove surrogate points.
				text = text.replace( this.settings.astralRegExp, 'a' );
			}

			// Match with the selected type regular expression to count the items.
			text = text.match( this.settings[ type + 'RegExp' ] );

			// If we have any matches, set the count to the number of items found.
			if ( text ) {
				count = text.length;
			}
		}

		return count;
	};

	// Add the WordCounter to the WP Utils.
	window.wp = window.wp || {};
	window.wp.utils = window.wp.utils || {};
	window.wp.utils.WordCounter = WordCounter;
} )();

Directory Contents

Dirs: 1 × Files: 97

Name Size Perms Modified Actions
widgets DIR
- drwxr-xr-x 2024-12-30 07:14:41
Edit Download
2.86 KB lrw-r--r-- 2024-12-17 21:37:28
Edit Download
758 B lrw-r--r-- 2024-12-17 21:37:28
Edit Download
6.24 KB lrw-r--r-- 2023-09-18 08:21:24
Edit Download
2.95 KB lrw-r--r-- 2023-09-18 08:21:24
Edit Download
5.66 KB lrw-r--r-- 2021-02-24 06:15:04
Edit Download
2.04 KB lrw-r--r-- 2022-04-09 05:37:18
Edit Download
11.32 KB lrw-r--r-- 2020-07-28 09:05:02
Edit Download
3.01 KB lrw-r--r-- 2024-06-27 23:21:44
Edit Download
9.54 KB lrw-r--r-- 2021-03-19 04:31:04
Edit Download
3.40 KB lrw-r--r-- 2022-04-09 05:37:18
Edit Download
2.85 KB lrw-r--r-- 2024-02-12 05:44:20
Edit Download
1.28 KB lrw-r--r-- 2022-04-09 05:37:18
Edit Download
61.15 KB lrw-r--r-- 2025-10-08 17:06:31
Edit Download
23.12 KB lrw-r--r-- 2025-10-08 17:06:31
Edit Download
3.35 KB lrw-r--r-- 2021-03-19 04:31:04
Edit Download
1.18 KB lrw-r--r-- 2021-03-19 04:31:04
Edit Download
1.98 KB lrw-r--r-- 2021-02-24 06:15:04
Edit Download
287.36 KB lrw-r--r-- 2025-10-08 17:06:31
Edit Download
109.14 KB lrw-r--r-- 2025-10-08 17:06:31
Edit Download
111.13 KB lrw-r--r-- 2025-10-08 17:06:31
Edit Download
46.93 KB lrw-r--r-- 2025-10-08 17:06:31
Edit Download
70.05 KB lrw-r--r-- 2024-06-22 03:47:14
Edit Download
27.41 KB lrw-r--r-- 2025-10-08 17:06:31
Edit Download
27.02 KB lrw-r--r-- 2025-10-08 17:06:31
Edit Download
8.65 KB lrw-r--r-- 2025-10-08 17:06:31
Edit Download
37.12 KB lrw-r--r-- 2025-10-08 17:06:31
Edit Download
15.13 KB lrw-r--r-- 2025-10-08 17:06:31
Edit Download
41.61 KB lrw-r--r-- 2024-04-13 03:17:14
Edit Download
13.14 KB lrw-r--r-- 2024-06-27 23:21:44
Edit Download
43.98 KB lrw-r--r-- 2025-10-08 17:06:31
Edit Download
12.76 KB lrw-r--r-- 2025-10-08 17:06:31
Edit Download
7.67 KB lrw-r--r-- 2023-07-18 07:33:26
Edit Download
5.41 KB lrw-r--r-- 2023-10-10 07:01:28
Edit Download
3.65 KB lrw-r--r-- 2023-10-10 07:01:28
Edit Download
39.98 KB lrw-r--r-- 2024-12-17 21:37:28
Edit Download
15.15 KB lrw-r--r-- 2024-12-17 21:37:28
Edit Download
20.17 KB lrw-r--r-- 2024-12-17 21:37:28
Edit Download
9.41 KB lrw-r--r-- 2024-12-17 21:37:28
Edit Download
7.61 KB lrw-r--r-- 2021-03-19 04:31:04
Edit Download
2.93 KB lrw-r--r-- 2021-03-19 04:31:04
Edit Download
23.09 KB lrw-r--r-- 2021-11-04 05:10:00
Edit Download
890 B lrw-r--r-- 2021-02-24 06:15:04
Edit Download
423 B lrw-r--r-- 2021-02-24 06:15:04
Edit Download
3.89 KB lrw-r--r-- 2021-03-19 04:31:04
Edit Download
1.70 KB lrw-r--r-- 2021-03-19 04:31:04
Edit Download
1.27 KB lrw-r--r-- 2021-02-24 06:15:04
Edit Download
611 B lrw-r--r-- 2022-04-09 05:37:18
Edit Download
3.38 KB lrw-r--r-- 2021-01-22 23:02:04
Edit Download
1.13 KB lrw-r--r-- 2023-02-03 03:06:32
Edit Download
6.61 KB lrw-r--r-- 2024-12-17 21:37:28
Edit Download
2.38 KB lrw-r--r-- 2024-12-17 21:37:28
Edit Download
60.72 KB lrw-r--r-- 2025-10-08 17:06:31
Edit Download
29.85 KB lrw-r--r-- 2025-10-08 17:06:31
Edit Download
4.14 KB lrw-r--r-- 2021-01-22 23:02:04
Edit Download
1.10 KB lrw-r--r-- 2021-01-22 23:02:04
Edit Download
1.31 KB lrw-r--r-- 2023-06-24 08:39:30
Edit Download
847 B lrw-r--r-- 2023-06-24 08:39:30
Edit Download
6.92 KB lrw-r--r-- 2021-03-19 04:31:04
Edit Download
2.35 KB lrw-r--r-- 2023-02-03 03:06:32
Edit Download
38.68 KB lrw-r--r-- 2025-10-08 17:06:31
Edit Download
18.40 KB lrw-r--r-- 2025-10-08 17:06:31
Edit Download
18.49 KB lrw-r--r-- 2025-10-08 17:06:31
Edit Download
6.60 KB lrw-r--r-- 2025-10-08 17:06:31
Edit Download
10.67 KB lrw-r--r-- 2024-06-22 03:47:14
Edit Download
5.03 KB lrw-r--r-- 2024-06-22 03:47:14
Edit Download
33.92 KB lrw-r--r-- 2024-12-17 21:37:28
Edit Download
17.97 KB lrw-r--r-- 2024-12-17 21:37:28
Edit Download
876 B lrw-r--r-- 2020-07-08 04:25:04
Edit Download
620 B lrw-r--r-- 2020-07-08 04:25:04
Edit Download
13.15 KB lrw-r--r-- 2023-12-29 01:57:16
Edit Download
6.13 KB lrw-r--r-- 2023-12-29 01:57:16
Edit Download
6.10 KB lrw-r--r-- 2024-12-17 21:37:28
Edit Download
2.20 KB lrw-r--r-- 2024-12-17 21:37:28
Edit Download
3.20 KB lrw-r--r-- 2024-12-17 21:37:28
Edit Download
1.53 KB lrw-r--r-- 2024-12-17 21:37:28
Edit Download
10.88 KB lrw-r--r-- 2021-03-19 04:31:04
Edit Download
3.00 KB lrw-r--r-- 2023-02-03 03:06:32
Edit Download
5.64 KB lrw-r--r-- 2024-02-19 08:46:14
Edit Download
2.22 KB lrw-r--r-- 2024-02-19 08:46:14
Edit Download
4.85 KB lrw-r--r-- 2025-10-08 17:06:31
Edit Download
2.04 KB lrw-r--r-- 2025-10-08 17:06:31
Edit Download
24.77 KB lrw-r--r-- 2025-10-08 17:06:31
Edit Download
11.43 KB lrw-r--r-- 2025-10-08 17:06:31
Edit Download
54.67 KB lrw-r--r-- 2025-10-08 17:06:31
Edit Download
26.42 KB lrw-r--r-- 2025-10-08 17:06:31
Edit Download
109.33 KB lrw-r--r-- 2025-10-08 17:06:31
Edit Download
47.27 KB lrw-r--r-- 2025-10-08 17:06:31
Edit Download
15.00 KB lrw-r--r-- 2024-12-17 21:37:28
Edit Download
6.70 KB lrw-r--r-- 2024-12-17 21:37:28
Edit Download
2.25 KB lrw-r--r-- 2021-03-19 04:31:04
Edit Download
676 B lrw-r--r-- 2021-03-19 04:31:04
Edit Download
22.56 KB lrw-r--r-- 2021-03-19 04:31:04
Edit Download
12.31 KB lrw-r--r-- 2023-02-03 03:06:32
Edit Download
7.52 KB lrw-r--r-- 2020-07-28 09:05:02
Edit Download
1.49 KB lrw-r--r-- 2023-02-03 03:06:32
Edit Download
740 B lrw-r--r-- 2021-03-19 04:31:04
Edit Download
458 B lrw-r--r-- 2021-03-19 04:31:04
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).