173 * @param {Object} settings The main settings object containing regular expressions |
177 * @param {Object} settings The main settings object containing regular expressions |
174 * @param {string} text The string being counted. |
178 * @param {string} text The string being counted. |
175 * |
179 * |
176 * @return {string} The manipulated text. |
180 * @return {string} The manipulated text. |
177 */ |
181 */ |
178 /* harmony default export */ var stripTags = (function (settings, text) { |
182 function stripTags(settings, text) { |
179 if (settings.HTMLRegExp) { |
183 if (settings.HTMLRegExp) { |
180 return text.replace(settings.HTMLRegExp, '\n'); |
184 return text.replace(settings.HTMLRegExp, '\n'); |
181 } |
185 } |
182 }); |
186 } |
183 |
187 |
184 // CONCATENATED MODULE: ./node_modules/@wordpress/wordcount/build-module/transposeAstralsToCountableChar.js |
188 // CONCATENATED MODULE: ./node_modules/@wordpress/wordcount/build-module/transposeAstralsToCountableChar.js |
185 /** |
189 /** |
186 * Replaces items matched in the regex with character. |
190 * Replaces items matched in the regex with character. |
187 * |
191 * |
188 * @param {Object} settings The main settings object containing regular expressions |
192 * @param {Object} settings The main settings object containing regular expressions |
189 * @param {string} text The string being counted. |
193 * @param {string} text The string being counted. |
190 * |
194 * |
191 * @return {string} The manipulated text. |
195 * @return {string} The manipulated text. |
192 */ |
196 */ |
193 /* harmony default export */ var transposeAstralsToCountableChar = (function (settings, text) { |
197 function transposeAstralsToCountableChar(settings, text) { |
194 if (settings.astralRegExp) { |
198 if (settings.astralRegExp) { |
195 return text.replace(settings.astralRegExp, 'a'); |
199 return text.replace(settings.astralRegExp, 'a'); |
196 } |
200 } |
197 |
201 |
198 return text; |
202 return text; |
199 }); |
203 } |
200 |
204 |
201 // CONCATENATED MODULE: ./node_modules/@wordpress/wordcount/build-module/stripHTMLEntities.js |
205 // CONCATENATED MODULE: ./node_modules/@wordpress/wordcount/build-module/stripHTMLEntities.js |
202 /** |
206 /** |
203 * Removes items matched in the regex. |
207 * Removes items matched in the regex. |
204 * |
208 * |
205 * @param {Object} settings The main settings object containing regular expressions |
209 * @param {Object} settings The main settings object containing regular expressions |
206 * @param {string} text The string being counted. |
210 * @param {string} text The string being counted. |
207 * |
211 * |
208 * @return {string} The manipulated text. |
212 * @return {string} The manipulated text. |
209 */ |
213 */ |
210 /* harmony default export */ var stripHTMLEntities = (function (settings, text) { |
214 function stripHTMLEntities(settings, text) { |
211 if (settings.HTMLEntityRegExp) { |
215 if (settings.HTMLEntityRegExp) { |
212 return text.replace(settings.HTMLEntityRegExp, ''); |
216 return text.replace(settings.HTMLEntityRegExp, ''); |
213 } |
217 } |
214 |
218 |
215 return text; |
219 return text; |
216 }); |
220 } |
217 |
221 |
218 // CONCATENATED MODULE: ./node_modules/@wordpress/wordcount/build-module/stripConnectors.js |
222 // CONCATENATED MODULE: ./node_modules/@wordpress/wordcount/build-module/stripConnectors.js |
219 /** |
223 /** |
220 * Replaces items matched in the regex with spaces. |
224 * Replaces items matched in the regex with spaces. |
221 * |
225 * |
222 * @param {Object} settings The main settings object containing regular expressions |
226 * @param {Object} settings The main settings object containing regular expressions |
223 * @param {string} text The string being counted. |
227 * @param {string} text The string being counted. |
224 * |
228 * |
225 * @return {string} The manipulated text. |
229 * @return {string} The manipulated text. |
226 */ |
230 */ |
227 /* harmony default export */ var stripConnectors = (function (settings, text) { |
231 function stripConnectors(settings, text) { |
228 if (settings.connectorRegExp) { |
232 if (settings.connectorRegExp) { |
229 return text.replace(settings.connectorRegExp, ' '); |
233 return text.replace(settings.connectorRegExp, ' '); |
230 } |
234 } |
231 |
235 |
232 return text; |
236 return text; |
233 }); |
237 } |
234 |
238 |
235 // CONCATENATED MODULE: ./node_modules/@wordpress/wordcount/build-module/stripRemovables.js |
239 // CONCATENATED MODULE: ./node_modules/@wordpress/wordcount/build-module/stripRemovables.js |
236 /** |
240 /** |
237 * Removes items matched in the regex. |
241 * Removes items matched in the regex. |
238 * |
242 * |
239 * @param {Object} settings The main settings object containing regular expressions |
243 * @param {Object} settings The main settings object containing regular expressions |
240 * @param {string} text The string being counted. |
244 * @param {string} text The string being counted. |
241 * |
245 * |
242 * @return {string} The manipulated text. |
246 * @return {string} The manipulated text. |
243 */ |
247 */ |
244 /* harmony default export */ var stripRemovables = (function (settings, text) { |
248 function stripRemovables(settings, text) { |
245 if (settings.removeRegExp) { |
249 if (settings.removeRegExp) { |
246 return text.replace(settings.removeRegExp, ''); |
250 return text.replace(settings.removeRegExp, ''); |
247 } |
251 } |
248 |
252 |
249 return text; |
253 return text; |
250 }); |
254 } |
251 |
255 |
252 // CONCATENATED MODULE: ./node_modules/@wordpress/wordcount/build-module/stripHTMLComments.js |
256 // CONCATENATED MODULE: ./node_modules/@wordpress/wordcount/build-module/stripHTMLComments.js |
253 /** |
257 /** |
254 * Removes items matched in the regex. |
258 * Removes items matched in the regex. |
255 * |
259 * |
256 * @param {Object} settings The main settings object containing regular expressions |
260 * @param {Object} settings The main settings object containing regular expressions |
257 * @param {string} text The string being counted. |
261 * @param {string} text The string being counted. |
258 * |
262 * |
259 * @return {string} The manipulated text. |
263 * @return {string} The manipulated text. |
260 */ |
264 */ |
261 /* harmony default export */ var stripHTMLComments = (function (settings, text) { |
265 function stripHTMLComments(settings, text) { |
262 if (settings.HTMLcommentRegExp) { |
266 if (settings.HTMLcommentRegExp) { |
263 return text.replace(settings.HTMLcommentRegExp, ''); |
267 return text.replace(settings.HTMLcommentRegExp, ''); |
264 } |
268 } |
265 |
269 |
266 return text; |
270 return text; |
267 }); |
271 } |
268 |
272 |
269 // CONCATENATED MODULE: ./node_modules/@wordpress/wordcount/build-module/stripShortcodes.js |
273 // CONCATENATED MODULE: ./node_modules/@wordpress/wordcount/build-module/stripShortcodes.js |
270 /** |
274 /** |
271 * Replaces items matched in the regex with a new line. |
275 * Replaces items matched in the regex with a new line. |
272 * |
276 * |
273 * @param {Object} settings The main settings object containing regular expressions |
277 * @param {Object} settings The main settings object containing regular expressions |
274 * @param {string} text The string being counted. |
278 * @param {string} text The string being counted. |
275 * |
279 * |
276 * @return {string} The manipulated text. |
280 * @return {string} The manipulated text. |
277 */ |
281 */ |
278 /* harmony default export */ var stripShortcodes = (function (settings, text) { |
282 function stripShortcodes(settings, text) { |
279 if (settings.shortcodesRegExp) { |
283 if (settings.shortcodesRegExp) { |
280 return text.replace(settings.shortcodesRegExp, '\n'); |
284 return text.replace(settings.shortcodesRegExp, '\n'); |
281 } |
285 } |
282 |
286 |
283 return text; |
287 return text; |
284 }); |
288 } |
285 |
289 |
286 // CONCATENATED MODULE: ./node_modules/@wordpress/wordcount/build-module/stripSpaces.js |
290 // CONCATENATED MODULE: ./node_modules/@wordpress/wordcount/build-module/stripSpaces.js |
287 /** |
291 /** |
288 * Replaces items matched in the regex with spaces. |
292 * Replaces items matched in the regex with spaces. |
289 * |
293 * |
290 * @param {Object} settings The main settings object containing regular expressions |
294 * @param {Object} settings The main settings object containing regular expressions |
291 * @param {string} text The string being counted. |
295 * @param {string} text The string being counted. |
292 * |
296 * |
293 * @return {string} The manipulated text. |
297 * @return {string} The manipulated text. |
294 */ |
298 */ |
295 /* harmony default export */ var stripSpaces = (function (settings, text) { |
299 function stripSpaces(settings, text) { |
296 if (settings.spaceRegExp) { |
300 if (settings.spaceRegExp) { |
297 return text.replace(settings.spaceRegExp, ' '); |
301 return text.replace(settings.spaceRegExp, ' '); |
298 } |
302 } |
299 }); |
303 } |
300 |
304 |
301 // CONCATENATED MODULE: ./node_modules/@wordpress/wordcount/build-module/transposeHTMLEntitiesToCountableChars.js |
305 // CONCATENATED MODULE: ./node_modules/@wordpress/wordcount/build-module/transposeHTMLEntitiesToCountableChars.js |
302 /** |
306 /** |
303 * Replaces items matched in the regex with a single character. |
307 * Replaces items matched in the regex with a single character. |
304 * |
308 * |
305 * @param {Object} settings The main settings object containing regular expressions |
309 * @param {Object} settings The main settings object containing regular expressions |
306 * @param {string} text The string being counted. |
310 * @param {string} text The string being counted. |
307 * |
311 * |
308 * @return {string} The manipulated text. |
312 * @return {string} The manipulated text. |
309 */ |
313 */ |
310 /* harmony default export */ var transposeHTMLEntitiesToCountableChars = (function (settings, text) { |
314 function transposeHTMLEntitiesToCountableChars(settings, text) { |
311 if (settings.HTMLEntityRegExp) { |
315 if (settings.HTMLEntityRegExp) { |
312 return text.replace(settings.HTMLEntityRegExp, 'a'); |
316 return text.replace(settings.HTMLEntityRegExp, 'a'); |
313 } |
317 } |
314 |
318 |
315 return text; |
319 return text; |
316 }); |
320 } |
317 |
321 |
318 // CONCATENATED MODULE: ./node_modules/@wordpress/wordcount/build-module/index.js |
322 // CONCATENATED MODULE: ./node_modules/@wordpress/wordcount/build-module/index.js |
319 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "count", function() { return count; }); |
|
320 /** |
323 /** |
321 * External dependencies |
324 * External dependencies |
322 */ |
325 */ |
323 |
326 |
324 /** |
327 /** |
386 * @return {Array|{index: number, input: string}} The matched string. |
389 * @return {Array|{index: number, input: string}} The matched string. |
387 */ |
390 */ |
388 |
391 |
389 |
392 |
390 function matchCharacters(text, regex, settings) { |
393 function matchCharacters(text, regex, settings) { |
391 text = Object(external_lodash_["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); |
394 text = Object(external_this_lodash_["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); |
392 text = text + '\n'; |
395 text = text + '\n'; |
393 return text.match(regex); |
396 return text.match(regex); |
394 } |
397 } |
395 /** |
398 /** |
396 * Count some words. |
399 * Count some words. |
397 * |
400 * |
398 * @param {String} text The text being processed |
401 * @param {string} text The text being processed |
399 * @param {String} type The type of count. Accepts ;words', 'characters_excluding_spaces', or 'characters_including_spaces'. |
402 * @param {string} type The type of count. Accepts ;words', 'characters_excluding_spaces', or 'characters_including_spaces'. |
400 * @param {Object} userSettings Custom settings object. |
403 * @param {Object} userSettings Custom settings object. |
401 * |
404 * |
402 * @example |
405 * @example |
403 * ```js |
406 * ```js |
404 * import { count } from '@wordpress/wordcount'; |
407 * import { count } from '@wordpress/wordcount'; |
405 * const numberOfWords = count( 'Words to count', 'words', {} ) |
408 * const numberOfWords = count( 'Words to count', 'words', {} ) |
406 * ``` |
409 * ``` |
407 * |
410 * |
408 * @return {Number} The word or character count. |
411 * @return {number} The word or character count. |
409 */ |
412 */ |
410 |
413 |
411 |
414 |
412 function count(text, type, userSettings) { |
415 function count(text, type, userSettings) { |
413 if ('' === text) { |
416 if ('' === text) { |