Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@wordpress/wordcount

Package Overview
Dependencies
Maintainers
6
Versions
159
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wordpress/wordcount - npm Package Compare versions

Comparing version 1.0.3 to 1.1.0

127

build-module/defaultSettings.js

@@ -0,71 +1,62 @@

import "core-js/modules/es6.regexp.constructor";
export var defaultSettings = {
HTMLRegExp: /<\/?[a-z][^>]*?>/gi,
HTMLcommentRegExp: /<!--[\s\S]*?-->/g,
spaceRegExp: /&nbsp;|&#160;/gi,
HTMLEntityRegExp: /&\S+?;/g,
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)
"!-@[-`{-~", // Latin-1 Supplement (extract)
"\x80-\xBF\xD7\xF7",
/*
* 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,
// \u2014 = em-dash
connectorRegExp: /--|\u2014/g,
// Characters to be removed from input text.
removeRegExp: new RegExp(['[',
// Basic Latin (extract)
'!-@[-`{-~',
// Latin-1 Supplement (extract)
'\x80-\xBF\xD7\xF7',
/*
* 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: {
type: 'words'
}
/*
* 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: {
type: 'words'
}
};

@@ -0,1 +1,3 @@

import "core-js/modules/es6.regexp.match";
import "core-js/modules/es6.regexp.constructor";
import { extend, flow } from 'lodash';

@@ -12,3 +14,2 @@ import { defaultSettings } from './defaultSettings';

import transposeHTMLEntitiesToCountableChars from './transposeHTMLEntitiesToCountableChars';
/**

@@ -22,20 +23,19 @@ * Private function to manage the settings.

*/
function loadSettings(type, userSettings) {
var settings = extend(defaultSettings, userSettings);
var settings = extend(defaultSettings, userSettings);
settings.shortcodes = settings.l10n.shortcodes || {};
settings.shortcodes = settings.l10n.shortcodes || {};
if (settings.shortcodes && settings.shortcodes.length) {
settings.shortcodesRegExp = new RegExp('\\[\\/?(?:' + settings.shortcodes.join('|') + ')[^\\]]*?\\]', 'g');
}
if (settings.shortcodes && settings.shortcodes.length) {
settings.shortcodesRegExp = new RegExp('\\[\\/?(?:' + settings.shortcodes.join('|') + ')[^\\]]*?\\]', 'g');
}
settings.type = type || settings.l10n.type;
settings.type = type || settings.l10n.type;
if (settings.type !== 'characters_excluding_spaces' && settings.type !== 'characters_including_spaces') {
settings.type = 'words';
}
if (settings.type !== 'characters_excluding_spaces' && settings.type !== 'characters_including_spaces') {
settings.type = 'words';
}
return settings;
return settings;
}
/**

@@ -46,12 +46,13 @@ * Match the regex for the type 'words'

* @param {string} regex The regular expression pattern being matched
* @param {object} settings Settings object containing regular expressions for each strip function
* @param {Object} settings Settings object containing regular expressions for each strip function
*
* @return {Array|{index: number, input: string}} The matched string.
*/
function matchWords(text, regex, settings) {
text = flow(stripTags.bind(this, settings), stripHTMLComments.bind(this, settings), stripShortcodes.bind(this, settings), stripSpaces.bind(this, settings), stripHTMLEntities.bind(this, settings), stripConnectors.bind(this, settings), stripRemovables.bind(this, settings))(text);
text = text + '\n';
return text.match(regex);
text = flow(stripTags.bind(this, settings), stripHTMLComments.bind(this, settings), stripShortcodes.bind(this, settings), stripSpaces.bind(this, settings), stripHTMLEntities.bind(this, settings), stripConnectors.bind(this, settings), stripRemovables.bind(this, settings))(text);
text = text + '\n';
return text.match(regex);
}
/**

@@ -62,12 +63,13 @@ * Match the regex for either 'characters_excluding_spaces' or 'characters_including_spaces'

* @param {string} regex The regular expression pattern being matched
* @param {object} settings Settings object containing regular expressions for each strip function
* @param {Object} settings Settings object containing regular expressions for each strip function
*
* @return {Array|{index: number, input: string}} The matched string.
*/
function matchCharacters(text, regex, settings) {
text = flow(stripTags.bind(this, settings), stripHTMLComments.bind(this, settings), stripShortcodes.bind(this, settings), stripSpaces.bind(this, settings), transposeAstralsToCountableChar.bind(this, settings), transposeHTMLEntitiesToCountableChars.bind(this, settings))(text);
text = text + '\n';
return text.match(regex);
text = flow(stripTags.bind(this, settings), stripHTMLComments.bind(this, settings), stripShortcodes.bind(this, settings), stripSpaces.bind(this, settings), transposeAstralsToCountableChar.bind(this, settings), transposeHTMLEntitiesToCountableChars.bind(this, settings))(text);
text = text + '\n';
return text.match(regex);
}
/**

@@ -83,10 +85,11 @@ * Count some words.

export function count(text, type, userSettings) {
var settings = loadSettings(type, userSettings);
if (text) {
var matchRegExp = settings[type + 'RegExp'];
var results = 'words' === settings.type ? matchWords(text, matchRegExp, settings) : matchCharacters(text, matchRegExp, settings);
var settings = loadSettings(type, userSettings);
return results ? results.length : 0;
}
if (text) {
var matchRegExp = settings[type + 'RegExp'];
var results = 'words' === settings.type ? matchWords(text, matchRegExp, settings) : matchCharacters(text, matchRegExp, settings);
return results ? results.length : 0;
}
}

@@ -0,1 +1,3 @@

import "core-js/modules/es6.regexp.replace";
/**

@@ -5,3 +7,3 @@ * Replaces items matched in the regex with spaces.

* @param {Object} settings The main settings object containing regular expressions
* @param {String} text The string being counted.
* @param {string} text The string being counted.
*

@@ -14,3 +16,4 @@ * @return {string} The manipulated text.

}
return text;
}

@@ -0,1 +1,3 @@

import "core-js/modules/es6.regexp.replace";
/**

@@ -5,3 +7,3 @@ * Removes items matched in the regex.

* @param {Object} settings The main settings object containing regular expressions
* @param {String} text The string being counted.
* @param {string} text The string being counted.
*

@@ -14,3 +16,4 @@ * @return {string} The manipulated text.

}
return text;
}

@@ -0,1 +1,3 @@

import "core-js/modules/es6.regexp.replace";
/**

@@ -5,3 +7,3 @@ * Removes items matched in the regex.

* @param {Object} settings The main settings object containing regular expressions
* @param {String} text The string being counted.
* @param {string} text The string being counted.
*

@@ -14,3 +16,4 @@ * @return {string} The manipulated text.

}
return text;
}

@@ -0,1 +1,3 @@

import "core-js/modules/es6.regexp.replace";
/**

@@ -5,3 +7,3 @@ * Removes items matched in the regex.

* @param {Object} settings The main settings object containing regular expressions
* @param {String} text The string being counted.
* @param {string} text The string being counted.
*

@@ -14,3 +16,4 @@ * @return {string} The manipulated text.

}
return text;
}

@@ -0,1 +1,3 @@

import "core-js/modules/es6.regexp.replace";
/**

@@ -5,3 +7,3 @@ * Replaces items matched in the regex with a new line.

* @param {Object} settings The main settings object containing regular expressions
* @param {String} text The string being counted.
* @param {string} text The string being counted.
*

@@ -14,3 +16,4 @@ * @return {string} The manipulated text.

}
return text;
}

@@ -0,1 +1,3 @@

import "core-js/modules/es6.regexp.replace";
/**

@@ -5,3 +7,3 @@ * Replaces items matched in the regex with spaces.

* @param {Object} settings The main settings object containing regular expressions
* @param {String} text The string being counted.
* @param {string} text The string being counted.
*

@@ -8,0 +10,0 @@ * @return {string} The manipulated text.

@@ -0,1 +1,3 @@

import "core-js/modules/es6.regexp.replace";
/**

@@ -5,3 +7,3 @@ * Replaces items matched in the regex with new line

* @param {Object} settings The main settings object containing regular expressions
* @param {String} text The string being counted.
* @param {string} text The string being counted.
*

@@ -8,0 +10,0 @@ * @return {string} The manipulated text.

@@ -0,1 +1,3 @@

import "core-js/modules/es6.regexp.replace";
/**

@@ -5,3 +7,3 @@ * Replaces items matched in the regex with character.

* @param {Object} settings The main settings object containing regular expressions
* @param {String} text The string being counted.
* @param {string} text The string being counted.
*

@@ -14,3 +16,4 @@ * @return {string} The manipulated text.

}
return text;
}

@@ -0,1 +1,3 @@

import "core-js/modules/es6.regexp.replace";
/**

@@ -5,3 +7,3 @@ * Replaces items matched in the regex with a single character.

* @param {Object} settings The main settings object containing regular expressions
* @param {String} text The string being counted.
* @param {string} text The string being counted.
*

@@ -14,3 +16,4 @@ * @return {string} The manipulated text.

}
return text;
}

@@ -1,76 +0,71 @@

'use strict';
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
value: true
});
var defaultSettings = exports.defaultSettings = {
HTMLRegExp: /<\/?[a-z][^>]*?>/gi,
HTMLcommentRegExp: /<!--[\s\S]*?-->/g,
spaceRegExp: /&nbsp;|&#160;/gi,
HTMLEntityRegExp: /&\S+?;/g,
exports.defaultSettings = void 0;
// \u2014 = em-dash
connectorRegExp: /--|\u2014/g,
require("core-js/modules/es6.regexp.constructor");
// Characters to be removed from input text.
removeRegExp: new RegExp(['[',
var defaultSettings = {
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)
"!-@[-`{-~", // Latin-1 Supplement (extract)
"\x80-\xBF\xD7\xF7",
/*
* 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,
// Basic Latin (extract)
'!-@[-`{-~',
// Latin-1 Supplement (extract)
'\x80-\xBF\xD7\xF7',
/*
* 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: {
type: 'words'
}
};
/*
* 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: {
type: 'words'
}
};
exports.defaultSettings = defaultSettings;

@@ -1,50 +0,36 @@

'use strict';
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
value: true
});
exports.count = count;
var _lodash = require('lodash');
require("core-js/modules/es6.regexp.match");
var _defaultSettings = require('./defaultSettings');
require("core-js/modules/es6.regexp.constructor");
var _stripTags = require('./stripTags');
var _lodash = require("lodash");
var _stripTags2 = _interopRequireDefault(_stripTags);
var _defaultSettings = require("./defaultSettings");
var _transposeAstralsToCountableChar = require('./transposeAstralsToCountableChar');
var _stripTags = _interopRequireDefault(require("./stripTags"));
var _transposeAstralsToCountableChar2 = _interopRequireDefault(_transposeAstralsToCountableChar);
var _transposeAstralsToCountableChar = _interopRequireDefault(require("./transposeAstralsToCountableChar"));
var _stripHTMLEntities = require('./stripHTMLEntities');
var _stripHTMLEntities = _interopRequireDefault(require("./stripHTMLEntities"));
var _stripHTMLEntities2 = _interopRequireDefault(_stripHTMLEntities);
var _stripConnectors = _interopRequireDefault(require("./stripConnectors"));
var _stripConnectors = require('./stripConnectors');
var _stripRemovables = _interopRequireDefault(require("./stripRemovables"));
var _stripConnectors2 = _interopRequireDefault(_stripConnectors);
var _stripHTMLComments = _interopRequireDefault(require("./stripHTMLComments"));
var _stripRemovables = require('./stripRemovables');
var _stripShortcodes = _interopRequireDefault(require("./stripShortcodes"));
var _stripRemovables2 = _interopRequireDefault(_stripRemovables);
var _stripSpaces = _interopRequireDefault(require("./stripSpaces"));
var _stripHTMLComments = require('./stripHTMLComments');
var _transposeHTMLEntitiesToCountableChars = _interopRequireDefault(require("./transposeHTMLEntitiesToCountableChars"));
var _stripHTMLComments2 = _interopRequireDefault(_stripHTMLComments);
var _stripShortcodes = require('./stripShortcodes');
var _stripShortcodes2 = _interopRequireDefault(_stripShortcodes);
var _stripSpaces = require('./stripSpaces');
var _stripSpaces2 = _interopRequireDefault(_stripSpaces);
var _transposeHTMLEntitiesToCountableChars = require('./transposeHTMLEntitiesToCountableChars');
var _transposeHTMLEntitiesToCountableChars2 = _interopRequireDefault(_transposeHTMLEntitiesToCountableChars);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**

@@ -59,19 +45,17 @@ * Private function to manage the settings.

function loadSettings(type, userSettings) {
var settings = (0, _lodash.extend)(_defaultSettings.defaultSettings, userSettings);
var settings = (0, _lodash.extend)(_defaultSettings.defaultSettings, userSettings);
settings.shortcodes = settings.l10n.shortcodes || {};
settings.shortcodes = settings.l10n.shortcodes || {};
if (settings.shortcodes && settings.shortcodes.length) {
settings.shortcodesRegExp = new RegExp('\\[\\/?(?:' + settings.shortcodes.join('|') + ')[^\\]]*?\\]', 'g');
}
if (settings.shortcodes && settings.shortcodes.length) {
settings.shortcodesRegExp = new RegExp('\\[\\/?(?:' + settings.shortcodes.join('|') + ')[^\\]]*?\\]', 'g');
}
settings.type = type || settings.l10n.type;
settings.type = type || settings.l10n.type;
if (settings.type !== 'characters_excluding_spaces' && settings.type !== 'characters_including_spaces') {
settings.type = 'words';
}
if (settings.type !== 'characters_excluding_spaces' && settings.type !== 'characters_including_spaces') {
settings.type = 'words';
}
return settings;
return settings;
}
/**

@@ -82,12 +66,13 @@ * Match the regex for the type 'words'

* @param {string} regex The regular expression pattern being matched
* @param {object} settings Settings object containing regular expressions for each strip function
* @param {Object} settings Settings object containing regular expressions for each strip function
*
* @return {Array|{index: number, input: string}} The matched string.
*/
function matchWords(text, regex, settings) {
text = (0, _lodash.flow)(_stripTags2.default.bind(this, settings), _stripHTMLComments2.default.bind(this, settings), _stripShortcodes2.default.bind(this, settings), _stripSpaces2.default.bind(this, settings), _stripHTMLEntities2.default.bind(this, settings), _stripConnectors2.default.bind(this, settings), _stripRemovables2.default.bind(this, settings))(text);
text = text + '\n';
return text.match(regex);
text = (0, _lodash.flow)(_stripTags.default.bind(this, settings), _stripHTMLComments.default.bind(this, settings), _stripShortcodes.default.bind(this, settings), _stripSpaces.default.bind(this, settings), _stripHTMLEntities.default.bind(this, settings), _stripConnectors.default.bind(this, settings), _stripRemovables.default.bind(this, settings))(text);
text = text + '\n';
return text.match(regex);
}
/**

@@ -98,12 +83,13 @@ * Match the regex for either 'characters_excluding_spaces' or 'characters_including_spaces'

* @param {string} regex The regular expression pattern being matched
* @param {object} settings Settings object containing regular expressions for each strip function
* @param {Object} settings Settings object containing regular expressions for each strip function
*
* @return {Array|{index: number, input: string}} The matched string.
*/
function matchCharacters(text, regex, settings) {
text = (0, _lodash.flow)(_stripTags2.default.bind(this, settings), _stripHTMLComments2.default.bind(this, settings), _stripShortcodes2.default.bind(this, settings), _stripSpaces2.default.bind(this, settings), _transposeAstralsToCountableChar2.default.bind(this, settings), _transposeHTMLEntitiesToCountableChars2.default.bind(this, settings))(text);
text = text + '\n';
return text.match(regex);
text = (0, _lodash.flow)(_stripTags.default.bind(this, settings), _stripHTMLComments.default.bind(this, settings), _stripShortcodes.default.bind(this, settings), _stripSpaces.default.bind(this, settings), _transposeAstralsToCountableChar.default.bind(this, settings), _transposeHTMLEntitiesToCountableChars.default.bind(this, settings))(text);
text = text + '\n';
return text.match(regex);
}
/**

@@ -119,10 +105,11 @@ * Count some words.

function count(text, type, userSettings) {
var settings = loadSettings(type, userSettings);
if (text) {
var matchRegExp = settings[type + 'RegExp'];
var results = 'words' === settings.type ? matchWords(text, matchRegExp, settings) : matchCharacters(text, matchRegExp, settings);
var settings = loadSettings(type, userSettings);
return results ? results.length : 0;
}
if (text) {
var matchRegExp = settings[type + 'RegExp'];
var results = 'words' === settings.type ? matchWords(text, matchRegExp, settings) : matchCharacters(text, matchRegExp, settings);
return results ? results.length : 0;
}
}

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,8 +6,20 @@ Object.defineProperty(exports, "__esModule", {

});
exports.default = _default;
exports.default = function (settings, text) {
require("core-js/modules/es6.regexp.replace");
/**
* Replaces items matched in the regex with spaces.
*
* @param {Object} settings The main settings object containing regular expressions
* @param {string} text The string being counted.
*
* @return {string} The manipulated text.
*/
function _default(settings, text) {
if (settings.connectorRegExp) {
return text.replace(settings.connectorRegExp, ' ');
}
return text;
};
}

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,8 +6,20 @@ Object.defineProperty(exports, "__esModule", {

});
exports.default = _default;
exports.default = function (settings, text) {
require("core-js/modules/es6.regexp.replace");
/**
* Removes items matched in the regex.
*
* @param {Object} settings The main settings object containing regular expressions
* @param {string} text The string being counted.
*
* @return {string} The manipulated text.
*/
function _default(settings, text) {
if (settings.HTMLcommentRegExp) {
return text.replace(settings.HTMLcommentRegExp, '');
}
return text;
};
}

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,8 +6,20 @@ Object.defineProperty(exports, "__esModule", {

});
exports.default = _default;
exports.default = function (settings, text) {
require("core-js/modules/es6.regexp.replace");
/**
* Removes items matched in the regex.
*
* @param {Object} settings The main settings object containing regular expressions
* @param {string} text The string being counted.
*
* @return {string} The manipulated text.
*/
function _default(settings, text) {
if (settings.HTMLEntityRegExp) {
return text.replace(settings.HTMLEntityRegExp, '');
}
return text;
};
}

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,8 +6,20 @@ Object.defineProperty(exports, "__esModule", {

});
exports.default = _default;
exports.default = function (settings, text) {
require("core-js/modules/es6.regexp.replace");
/**
* Removes items matched in the regex.
*
* @param {Object} settings The main settings object containing regular expressions
* @param {string} text The string being counted.
*
* @return {string} The manipulated text.
*/
function _default(settings, text) {
if (settings.removeRegExp) {
return text.replace(settings.removeRegExp, '');
}
return text;
};
}

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,8 +6,20 @@ Object.defineProperty(exports, "__esModule", {

});
exports.default = _default;
exports.default = function (settings, text) {
require("core-js/modules/es6.regexp.replace");
/**
* Replaces items matched in the regex with a new line.
*
* @param {Object} settings The main settings object containing regular expressions
* @param {string} text The string being counted.
*
* @return {string} The manipulated text.
*/
function _default(settings, text) {
if (settings.shortcodesRegExp) {
return text.replace(settings.shortcodesRegExp, '\n');
}
return text;
};
}

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,7 +6,18 @@ Object.defineProperty(exports, "__esModule", {

});
exports.default = _default;
exports.default = function (settings, text) {
require("core-js/modules/es6.regexp.replace");
/**
* Replaces items matched in the regex with spaces.
*
* @param {Object} settings The main settings object containing regular expressions
* @param {string} text The string being counted.
*
* @return {string} The manipulated text.
*/
function _default(settings, text) {
if (settings.spaceRegExp) {
return text.replace(settings.spaceRegExp, ' ');
}
};
}

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,7 +6,18 @@ Object.defineProperty(exports, "__esModule", {

});
exports.default = _default;
exports.default = function (settings, text) {
require("core-js/modules/es6.regexp.replace");
/**
* Replaces items matched in the regex with new line
*
* @param {Object} settings The main settings object containing regular expressions
* @param {string} text The string being counted.
*
* @return {string} The manipulated text.
*/
function _default(settings, text) {
if (settings.HTMLRegExp) {
return text.replace(settings.HTMLRegExp, '\n');
}
};
}

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,8 +6,20 @@ Object.defineProperty(exports, "__esModule", {

});
exports.default = _default;
exports.default = function (settings, text) {
require("core-js/modules/es6.regexp.replace");
/**
* Replaces items matched in the regex with character.
*
* @param {Object} settings The main settings object containing regular expressions
* @param {string} text The string being counted.
*
* @return {string} The manipulated text.
*/
function _default(settings, text) {
if (settings.astralRegExp) {
return text.replace(settings.astralRegExp, 'a');
}
return text;
};
}

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,8 +6,20 @@ Object.defineProperty(exports, "__esModule", {

});
exports.default = _default;
exports.default = function (settings, text) {
require("core-js/modules/es6.regexp.replace");
/**
* Replaces items matched in the regex with a single character.
*
* @param {Object} settings The main settings object containing regular expressions
* @param {string} text The string being counted.
*
* @return {string} The manipulated text.
*/
function _default(settings, text) {
if (settings.HTMLEntityRegExp) {
return text.replace(settings.HTMLEntityRegExp, 'a');
}
return text;
};
}

@@ -0,1 +1,6 @@

## 1.1.0 (2018-07-12)
- Updated build to work with Babel 7 ([#7832](https://github.com/WordPress/gutenberg/pull/7832))
- Moved `@WordPress/packages` repository to `@WordPress/gutenberg` ([#7805](https://github.com/WordPress/gutenberg/pull/7805))
## 1.0.3 (2018-05-18)

@@ -2,0 +7,0 @@

{
"name": "@wordpress/wordcount",
"version": "1.0.3",
"version": "1.1.0",
"description": "WordPress Word Count Utility",
"author": "WordPress",
"author": "The WordPress Contributors",
"license": "GPL-2.0-or-later",

@@ -11,9 +11,9 @@ "keywords": [

],
"homepage": "https://github.com/WordPress/packages/tree/master/packages/wordcount/README.md",
"homepage": "https://github.com/WordPress/gutenberg/tree/master/packages/wordcount/README.md",
"repository": {
"type": "git",
"url": "git+https://github.com/WordPress/packages.git"
"url": "git+https://github.com/WordPress/gutenberg.git"
},
"bugs": {
"url": "https://github.com/WordPress/packages/issues"
"url": "https://github.com/WordPress/gutenberg/issues"
},

@@ -23,7 +23,8 @@ "main": "build/index.js",

"dependencies": {
"lodash": "^4.17.4"
"lodash": "^4.17.10"
},
"publishConfig": {
"access": "public"
}
},
"gitHead": "8827c049ec802471f51a5cb906d9096ffc1b4e48"
}

@@ -11,3 +11,3 @@ export const defaultSettings = {

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

@@ -52,4 +52,4 @@

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

@@ -74,4 +74,4 @@ // Remove UTF-16 surrogate points, see https://en.wikipedia.org/wiki/UTF-16#U.2BD800_to_U.2BDFFF

l10n: {
type: 'words'
}
type: 'words',
},
};
import { extend, flow } from 'lodash';
import { defaultSettings } from './defaultSettings'
import { defaultSettings } from './defaultSettings';
import stripTags from './stripTags';

@@ -22,3 +22,3 @@ import transposeAstralsToCountableChar from './transposeAstralsToCountableChar';

function loadSettings( type, userSettings ) {
const settings = extend( defaultSettings, userSettings );
const settings = extend( defaultSettings, userSettings );

@@ -45,3 +45,3 @@ settings.shortcodes = settings.l10n.shortcodes || {};

* @param {string} regex The regular expression pattern being matched
* @param {object} settings Settings object containing regular expressions for each strip function
* @param {Object} settings Settings object containing regular expressions for each strip function
*

@@ -69,3 +69,3 @@ * @return {Array|{index: number, input: string}} The matched string.

* @param {string} regex The regular expression pattern being matched
* @param {object} settings Settings object containing regular expressions for each strip function
* @param {Object} settings Settings object containing regular expressions for each strip function
*

@@ -100,3 +100,3 @@ * @return {Array|{index: number, input: string}} The matched string.

if ( text ) {
let matchRegExp = settings[ type + 'RegExp' ];
const matchRegExp = settings[ type + 'RegExp' ];
const results = ( 'words' === settings.type ) ?

@@ -103,0 +103,0 @@ matchWords( text, matchRegExp, settings ) :

@@ -5,7 +5,7 @@ /**

* @param {Object} settings The main settings object containing regular expressions
* @param {String} text The string being counted.
* @param {string} text The string being counted.
*
* @return {string} The manipulated text.
*/
export default function ( settings, text ) {
export default function( settings, text ) {
if ( settings.connectorRegExp ) {

@@ -12,0 +12,0 @@ return text.replace( settings.connectorRegExp, ' ' );

@@ -5,11 +5,11 @@ /**

* @param {Object} settings The main settings object containing regular expressions
* @param {String} text The string being counted.
* @param {string} text The string being counted.
*
* @return {string} The manipulated text.
*/
export default function ( settings, text ) {
export default function( settings, text ) {
if ( settings.HTMLcommentRegExp ) {
return text.replace( settings.HTMLcommentRegExp , '' );
return text.replace( settings.HTMLcommentRegExp, '' );
}
return text;
}

@@ -5,7 +5,7 @@ /**

* @param {Object} settings The main settings object containing regular expressions
* @param {String} text The string being counted.
* @param {string} text The string being counted.
*
* @return {string} The manipulated text.
*/
export default function ( settings, text ) {
export default function( settings, text ) {
if ( settings.HTMLEntityRegExp ) {

@@ -12,0 +12,0 @@ return text.replace( settings.HTMLEntityRegExp, '' );

@@ -5,7 +5,7 @@ /**

* @param {Object} settings The main settings object containing regular expressions
* @param {String} text The string being counted.
* @param {string} text The string being counted.
*
* @return {string} The manipulated text.
*/
export default function ( settings, text ) {
export default function( settings, text ) {
if ( settings.removeRegExp ) {

@@ -12,0 +12,0 @@ return text.replace( settings.removeRegExp, '' );

@@ -5,3 +5,3 @@ /**

* @param {Object} settings The main settings object containing regular expressions
* @param {String} text The string being counted.
* @param {string} text The string being counted.
*

@@ -15,2 +15,2 @@ * @return {string} The manipulated text.

return text;
}
}

@@ -5,7 +5,7 @@ /**

* @param {Object} settings The main settings object containing regular expressions
* @param {String} text The string being counted.
* @param {string} text The string being counted.
*
* @return {string} The manipulated text.
*/
export default function ( settings, text ) {
export default function( settings, text ) {
if ( settings.spaceRegExp ) {

@@ -12,0 +12,0 @@ return text.replace( settings.spaceRegExp, ' ' );

@@ -5,3 +5,3 @@ /**

* @param {Object} settings The main settings object containing regular expressions
* @param {String} text The string being counted.
* @param {string} text The string being counted.
*

@@ -8,0 +8,0 @@ * @return {string} The manipulated text.

@@ -8,89 +8,88 @@ /**

const mockData = {
'l10n': {
'shortcodes': [
'shortcode'
]
}
l10n: {
shortcodes: [
'shortcode',
],
},
};
describe( 'WordCounter', () => {
const dataProvider = [
{
message: 'Basic test.',
string: 'one two three',
words: 3,
characters_excluding_spaces: 11,
characters_including_spaces: 13
},
{
message: 'HTML tags.',
string: 'one <em class="test">two</em><br />three',
words: 3,
characters_excluding_spaces: 11,
characters_including_spaces: 12
},
{
message: 'Line breaks.',
string: 'one\ntwo\nthree',
words: 3,
characters_excluding_spaces: 11,
characters_including_spaces: 11
},
{
message: 'Encoded spaces.',
string: 'one&nbsp;two&#160;three',
words: 3,
characters_excluding_spaces: 11,
characters_including_spaces: 13
},
{
message: 'Punctuation.',
string: 'It\'s two three \u2026 4?',
words: 3,
characters_excluding_spaces: 15,
characters_including_spaces: 19
},
{
message: 'Em dash.',
string: 'one\u2014two--three',
words: 3,
characters_excluding_spaces: 14,
characters_including_spaces: 14
},
{
message: 'Shortcodes.',
string: 'one [shortcode attribute="value"]two[/shortcode]three',
words: 3,
characters_excluding_spaces: 11,
characters_including_spaces: 12
},
{
message: 'Astrals.',
string: '\uD83D\uDCA9',
words: 1,
characters_excluding_spaces: 1,
characters_including_spaces: 1
},
{
message: 'HTML comment.',
string: 'one<!-- comment -->two three',
words: 2,
characters_excluding_spaces: 11,
characters_including_spaces: 12
},
{
message: 'HTML entity.',
string: '&gt; test',
words: 1,
characters_excluding_spaces: 5,
characters_including_spaces: 6
},
{
message: "Empty Tags",
string: "<p></p>",
words: 0,
characters_excluding_spaces: 0,
characters_including_spaces: 0
}
{
message: 'Basic test.',
string: 'one two three',
words: 3,
characters_excluding_spaces: 11,
characters_including_spaces: 13,
},
{
message: 'HTML tags.',
string: 'one <em class="test">two</em><br />three',
words: 3,
characters_excluding_spaces: 11,
characters_including_spaces: 12,
},
{
message: 'Line breaks.',
string: 'one\ntwo\nthree',
words: 3,
characters_excluding_spaces: 11,
characters_including_spaces: 11,
},
{
message: 'Encoded spaces.',
string: 'one&nbsp;two&#160;three',
words: 3,
characters_excluding_spaces: 11,
characters_including_spaces: 13,
},
{
message: 'Punctuation.',
string: 'It\'s two three \u2026 4?',
words: 3,
characters_excluding_spaces: 15,
characters_including_spaces: 19,
},
{
message: 'Em dash.',
string: 'one\u2014two--three',
words: 3,
characters_excluding_spaces: 14,
characters_including_spaces: 14,
},
{
message: 'Shortcodes.',
string: 'one [shortcode attribute="value"]two[/shortcode]three',
words: 3,
characters_excluding_spaces: 11,
characters_including_spaces: 12,
},
{
message: 'Astrals.',
string: '\uD83D\uDCA9',
words: 1,
characters_excluding_spaces: 1,
characters_including_spaces: 1,
},
{
message: 'HTML comment.',
string: 'one<!-- comment -->two three',
words: 2,
characters_excluding_spaces: 11,
characters_including_spaces: 12,
},
{
message: 'HTML entity.',
string: '&gt; test',
words: 1,
characters_excluding_spaces: 5,
characters_including_spaces: 6,
},
{
message: 'Empty Tags',
string: '<p></p>',
words: 0,
characters_excluding_spaces: 0,
characters_including_spaces: 0,
},
];

@@ -100,11 +99,11 @@

dataProvider.forEach( item => {
types.forEach( type => {
dataProvider.forEach( ( item ) => {
types.forEach( ( type ) => {
const result = count( item.string, type, mockData );
test( item.message + ' (' + type + ')', () => {
expect( result ).toBe( item[ type ] );
});
});
});
});
} );
} );
} );
} );

@@ -5,7 +5,7 @@ /**

* @param {Object} settings The main settings object containing regular expressions
* @param {String} text The string being counted.
* @param {string} text The string being counted.
*
* @return {string} The manipulated text.
*/
export default function ( settings, text ) {
export default function( settings, text ) {
if ( settings.astralRegExp ) {

@@ -12,0 +12,0 @@ return text.replace( settings.astralRegExp, 'a' );

@@ -5,11 +5,11 @@ /**

* @param {Object} settings The main settings object containing regular expressions
* @param {String} text The string being counted.
* @param {string} text The string being counted.
*
* @return {string} The manipulated text.
*/
export default function ( settings, text ) {
export default function( settings, text ) {
if ( settings.HTMLEntityRegExp ) {
return text.replace(settings.HTMLEntityRegExp, 'a');
return text.replace( settings.HTMLEntityRegExp, 'a' );
}
return text;
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc