[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-includes/js/dist/ -> wordcount.js (source)

   1  this["wp"] = this["wp"] || {}; this["wp"]["wordcount"] =
   2  /******/ (function(modules) { // webpackBootstrap
   3  /******/     // The module cache
   4  /******/     var installedModules = {};
   5  /******/
   6  /******/     // The require function
   7  /******/ 	function __webpack_require__(moduleId) {
   8  /******/
   9  /******/         // Check if module is in cache
  10  /******/         if(installedModules[moduleId]) {
  11  /******/             return installedModules[moduleId].exports;
  12  /******/         }
  13  /******/         // Create a new module (and put it into the cache)
  14  /******/         var module = installedModules[moduleId] = {
  15  /******/             i: moduleId,
  16  /******/             l: false,
  17  /******/             exports: {}
  18  /******/         };
  19  /******/
  20  /******/         // Execute the module function
  21  /******/         modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  22  /******/
  23  /******/         // Flag the module as loaded
  24  /******/         module.l = true;
  25  /******/
  26  /******/         // Return the exports of the module
  27  /******/         return module.exports;
  28  /******/     }
  29  /******/
  30  /******/
  31  /******/     // expose the modules object (__webpack_modules__)
  32  /******/     __webpack_require__.m = modules;
  33  /******/
  34  /******/     // expose the module cache
  35  /******/     __webpack_require__.c = installedModules;
  36  /******/
  37  /******/     // define getter function for harmony exports
  38  /******/     __webpack_require__.d = function(exports, name, getter) {
  39  /******/         if(!__webpack_require__.o(exports, name)) {
  40  /******/             Object.defineProperty(exports, name, { enumerable: true, get: getter });
  41  /******/         }
  42  /******/     };
  43  /******/
  44  /******/     // define __esModule on exports
  45  /******/     __webpack_require__.r = function(exports) {
  46  /******/         if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  47  /******/             Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  48  /******/         }
  49  /******/         Object.defineProperty(exports, '__esModule', { value: true });
  50  /******/     };
  51  /******/
  52  /******/     // create a fake namespace object
  53  /******/     // mode & 1: value is a module id, require it
  54  /******/     // mode & 2: merge all properties of value into the ns
  55  /******/     // mode & 4: return value when already ns object
  56  /******/     // mode & 8|1: behave like require
  57  /******/     __webpack_require__.t = function(value, mode) {
  58  /******/         if(mode & 1) value = __webpack_require__(value);
  59  /******/         if(mode & 8) return value;
  60  /******/         if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  61  /******/         var ns = Object.create(null);
  62  /******/         __webpack_require__.r(ns);
  63  /******/         Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  64  /******/         if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  65  /******/         return ns;
  66  /******/     };
  67  /******/
  68  /******/     // getDefaultExport function for compatibility with non-harmony modules
  69  /******/     __webpack_require__.n = function(module) {
  70  /******/         var getter = module && module.__esModule ?
  71  /******/ 			function getDefault() { return module['default']; } :
  72  /******/ 			function getModuleExports() { return module; };
  73  /******/         __webpack_require__.d(getter, 'a', getter);
  74  /******/         return getter;
  75  /******/     };
  76  /******/
  77  /******/     // Object.prototype.hasOwnProperty.call
  78  /******/     __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  79  /******/
  80  /******/     // __webpack_public_path__
  81  /******/     __webpack_require__.p = "";
  82  /******/
  83  /******/
  84  /******/     // Load entry module and return exports
  85  /******/     return __webpack_require__(__webpack_require__.s = 432);
  86  /******/ })
  87  /************************************************************************/
  88  /******/ ({
  89  
  90  /***/ 2:
  91  /***/ (function(module, exports) {
  92  
  93  (function() { module.exports = this["lodash"]; }());
  94  
  95  /***/ }),
  96  
  97  /***/ 432:
  98  /***/ (function(module, __webpack_exports__, __webpack_require__) {
  99  
 100  "use strict";
 101  __webpack_require__.r(__webpack_exports__);
 102  
 103  // EXTERNAL MODULE: external {"this":"lodash"}
 104  var external_this_lodash_ = __webpack_require__(2);
 105  
 106  // CONCATENATED MODULE: ./node_modules/@wordpress/wordcount/build-module/defaultSettings.js
 107  var defaultSettings = {
 108    HTMLRegExp: /<\/?[a-z][^>]*?>/gi,
 109    HTMLcommentRegExp: /<!--[\s\S]*?-->/g,
 110    spaceRegExp: /&nbsp;|&#160;/gi,
 111    HTMLEntityRegExp: /&\S+?;/g,
 112    // \u2014 = em-dash
 113    connectorRegExp: /--|\u2014/g,
 114    // Characters to be removed from input text.
 115    removeRegExp: new RegExp(['[', // Basic Latin (extract)
 116    "!-@[-`{-~", // Latin-1 Supplement (extract)
 117    "\x80-\xBF\xD7\xF7",
 118    /*
 119     * The following range consists of:
 120     * General Punctuation
 121     * Superscripts and Subscripts
 122     * Currency Symbols
 123     * Combining Diacritical Marks for Symbols
 124     * Letterlike Symbols
 125     * Number Forms
 126     * Arrows
 127     * Mathematical Operators
 128     * Miscellaneous Technical
 129     * Control Pictures
 130     * Optical Character Recognition
 131     * Enclosed Alphanumerics
 132     * Box Drawing
 133     * Block Elements
 134     * Geometric Shapes
 135     * Miscellaneous Symbols
 136     * Dingbats
 137     * Miscellaneous Mathematical Symbols-A
 138     * Supplemental Arrows-A
 139     * Braille Patterns
 140     * Supplemental Arrows-B
 141     * Miscellaneous Mathematical Symbols-B
 142     * Supplemental Mathematical Operators
 143     * Miscellaneous Symbols and Arrows
 144     */
 145    "\u2000-\u2BFF", // Supplemental Punctuation
 146    "\u2E00-\u2E7F", ']'].join(''), 'g'),
 147    // Remove UTF-16 surrogate points, see https://en.wikipedia.org/wiki/UTF-16#U.2BD800_to_U.2BDFFF
 148    astralRegExp: /[\uD800-\uDBFF][\uDC00-\uDFFF]/g,
 149    wordsRegExp: /\S\s+/g,
 150    characters_excluding_spacesRegExp: /\S/g,
 151  
 152    /*
 153     * Match anything that is not a formatting character, excluding:
 154     * \f = form feed
 155     * \n = new line
 156     * \r = carriage return
 157     * \t = tab
 158     * \v = vertical tab
 159     * \u00AD = soft hyphen
 160     * \u2028 = line separator
 161     * \u2029 = paragraph separator
 162     */
 163    characters_including_spacesRegExp: /[^\f\n\r\t\v\u00AD\u2028\u2029]/g,
 164    l10n: {
 165      type: 'words'
 166    }
 167  };
 168  
 169  // CONCATENATED MODULE: ./node_modules/@wordpress/wordcount/build-module/stripTags.js
 170  /**
 171   * Replaces items matched in the regex with new line
 172   *
 173   * @param {Object} settings The main settings object containing regular expressions
 174   * @param {string} text     The string being counted.
 175   *
 176   * @return {string} The manipulated text.
 177   */
 178  /* harmony default export */ var stripTags = (function (settings, text) {
 179    if (settings.HTMLRegExp) {
 180      return text.replace(settings.HTMLRegExp, '\n');
 181    }
 182  });
 183  
 184  // CONCATENATED MODULE: ./node_modules/@wordpress/wordcount/build-module/transposeAstralsToCountableChar.js
 185  /**
 186   * Replaces items matched in the regex with character.
 187   *
 188   * @param {Object} settings The main settings object containing regular expressions
 189   * @param {string} text     The string being counted.
 190   *
 191   * @return {string} The manipulated text.
 192   */
 193  /* harmony default export */ var transposeAstralsToCountableChar = (function (settings, text) {
 194    if (settings.astralRegExp) {
 195      return text.replace(settings.astralRegExp, 'a');
 196    }
 197  
 198    return text;
 199  });
 200  
 201  // CONCATENATED MODULE: ./node_modules/@wordpress/wordcount/build-module/stripHTMLEntities.js
 202  /**
 203   * Removes items matched in the regex.
 204   *
 205   * @param {Object} settings The main settings object containing regular expressions
 206   * @param {string} text     The string being counted.
 207   *
 208   * @return {string} The manipulated text.
 209   */
 210  /* harmony default export */ var stripHTMLEntities = (function (settings, text) {
 211    if (settings.HTMLEntityRegExp) {
 212      return text.replace(settings.HTMLEntityRegExp, '');
 213    }
 214  
 215    return text;
 216  });
 217  
 218  // CONCATENATED MODULE: ./node_modules/@wordpress/wordcount/build-module/stripConnectors.js
 219  /**
 220   * Replaces items matched in the regex with spaces.
 221   *
 222   * @param {Object} settings The main settings object containing regular expressions
 223   * @param {string} text     The string being counted.
 224   *
 225   * @return {string} The manipulated text.
 226   */
 227  /* harmony default export */ var stripConnectors = (function (settings, text) {
 228    if (settings.connectorRegExp) {
 229      return text.replace(settings.connectorRegExp, ' ');
 230    }
 231  
 232    return text;
 233  });
 234  
 235  // CONCATENATED MODULE: ./node_modules/@wordpress/wordcount/build-module/stripRemovables.js
 236  /**
 237   * Removes items matched in the regex.
 238   *
 239   * @param {Object} settings The main settings object containing regular expressions
 240   * @param {string} text     The string being counted.
 241   *
 242   * @return {string} The manipulated text.
 243   */
 244  /* harmony default export */ var stripRemovables = (function (settings, text) {
 245    if (settings.removeRegExp) {
 246      return text.replace(settings.removeRegExp, '');
 247    }
 248  
 249    return text;
 250  });
 251  
 252  // CONCATENATED MODULE: ./node_modules/@wordpress/wordcount/build-module/stripHTMLComments.js
 253  /**
 254   * Removes items matched in the regex.
 255   *
 256   * @param {Object} settings The main settings object containing regular expressions
 257   * @param {string} text     The string being counted.
 258   *
 259   * @return {string} The manipulated text.
 260   */
 261  /* harmony default export */ var stripHTMLComments = (function (settings, text) {
 262    if (settings.HTMLcommentRegExp) {
 263      return text.replace(settings.HTMLcommentRegExp, '');
 264    }
 265  
 266    return text;
 267  });
 268  
 269  // CONCATENATED MODULE: ./node_modules/@wordpress/wordcount/build-module/stripShortcodes.js
 270  /**
 271   * Replaces items matched in the regex with a new line.
 272   *
 273   * @param {Object} settings The main settings object containing regular expressions
 274   * @param {string} text     The string being counted.
 275   *
 276   * @return {string} The manipulated text.
 277   */
 278  /* harmony default export */ var stripShortcodes = (function (settings, text) {
 279    if (settings.shortcodesRegExp) {
 280      return text.replace(settings.shortcodesRegExp, '\n');
 281    }
 282  
 283    return text;
 284  });
 285  
 286  // CONCATENATED MODULE: ./node_modules/@wordpress/wordcount/build-module/stripSpaces.js
 287  /**
 288   * Replaces items matched in the regex with spaces.
 289   *
 290   * @param {Object} settings The main settings object containing regular expressions
 291   * @param {string} text     The string being counted.
 292   *
 293   * @return {string} The manipulated text.
 294   */
 295  /* harmony default export */ var stripSpaces = (function (settings, text) {
 296    if (settings.spaceRegExp) {
 297      return text.replace(settings.spaceRegExp, ' ');
 298    }
 299  });
 300  
 301  // CONCATENATED MODULE: ./node_modules/@wordpress/wordcount/build-module/transposeHTMLEntitiesToCountableChars.js
 302  /**
 303   * Replaces items matched in the regex with a single character.
 304   *
 305   * @param {Object} settings The main settings object containing regular expressions
 306   * @param {string} text     The string being counted.
 307   *
 308   * @return {string} The manipulated text.
 309   */
 310  /* harmony default export */ var transposeHTMLEntitiesToCountableChars = (function (settings, text) {
 311    if (settings.HTMLEntityRegExp) {
 312      return text.replace(settings.HTMLEntityRegExp, 'a');
 313    }
 314  
 315    return text;
 316  });
 317  
 318  // CONCATENATED MODULE: ./node_modules/@wordpress/wordcount/build-module/index.js
 319  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "count", function() { return count; });
 320  /**
 321   * External dependencies
 322   */
 323  
 324  /**
 325   * Internal dependencies
 326   */
 327  
 328  
 329  
 330  
 331  
 332  
 333  
 334  
 335  
 336  
 337  
 338  /**
 339   * Private function to manage the settings.
 340   *
 341   * @param {string} type         The type of count to be done.
 342   * @param {Object} userSettings Custom settings for the count.
 343   *
 344   * @return {void|Object|*} The combined settings object to be used.
 345   */
 346  
 347  function loadSettings(type, userSettings) {
 348    var settings = Object(external_this_lodash_["extend"])(defaultSettings, userSettings);
 349    settings.shortcodes = settings.l10n.shortcodes || {};
 350  
 351    if (settings.shortcodes && settings.shortcodes.length) {
 352      settings.shortcodesRegExp = new RegExp('\\[\\/?(?:' + settings.shortcodes.join('|') + ')[^\\]]*?\\]', 'g');
 353    }
 354  
 355    settings.type = type || settings.l10n.type;
 356  
 357    if (settings.type !== 'characters_excluding_spaces' && settings.type !== 'characters_including_spaces') {
 358      settings.type = 'words';
 359    }
 360  
 361    return settings;
 362  }
 363  /**
 364   * Match the regex for the type 'words'
 365   *
 366   * @param {string} text     The text being processed
 367   * @param {string} regex    The regular expression pattern being matched
 368   * @param {Object} settings Settings object containing regular expressions for each strip function
 369   *
 370   * @return {Array|{index: number, input: string}} The matched string.
 371   */
 372  
 373  
 374  function matchWords(text, regex, settings) {
 375    text = Object(external_this_lodash_["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);
 376    text = text + '\n';
 377    return text.match(regex);
 378  }
 379  /**
 380   * Match the regex for either 'characters_excluding_spaces' or 'characters_including_spaces'
 381   *
 382   * @param {string} text     The text being processed
 383   * @param {string} regex    The regular expression pattern being matched
 384   * @param {Object} settings Settings object containing regular expressions for each strip function
 385   *
 386   * @return {Array|{index: number, input: string}} The matched string.
 387   */
 388  
 389  
 390  function matchCharacters(text, regex, settings) {
 391    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';
 393    return text.match(regex);
 394  }
 395  /**
 396   * Count some words.
 397   *
 398   * @param {string} text         The text being processed
 399   * @param {string} type         The type of count. Accepts ;words', 'characters_excluding_spaces', or 'characters_including_spaces'.
 400   * @param {Object} userSettings Custom settings object.
 401   *
 402   * @example
 403   * ```js
 404   * import { count } from '@wordpress/wordcount';
 405   * const numberOfWords = count( 'Words to count', 'words', {} )
 406   * ```
 407   *
 408   * @return {number} The word or character count.
 409   */
 410  
 411  
 412  function count(text, type, userSettings) {
 413    if ('' === text) {
 414      return 0;
 415    }
 416  
 417    if (text) {
 418      var settings = loadSettings(type, userSettings);
 419      var matchRegExp = settings[type + 'RegExp'];
 420      var results = 'words' === settings.type ? matchWords(text, matchRegExp, settings) : matchCharacters(text, matchRegExp, settings);
 421      return results ? results.length : 0;
 422    }
 423  }
 424  
 425  
 426  /***/ })
 427  
 428  /******/ });


Generated: Wed Apr 8 01:00:03 2020 Cross-referenced by PHPXref 0.7.1