[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

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

   1  this["wp"] = this["wp"] || {}; this["wp"]["url"] =
   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 = "lbya");
  86  /******/ })
  87  /************************************************************************/
  88  /******/ ({
  89  
  90  /***/ "YLtl":
  91  /***/ (function(module, exports) {
  92  
  93  (function() { module.exports = window["lodash"]; }());
  94  
  95  /***/ }),
  96  
  97  /***/ "lbya":
  98  /***/ (function(module, __webpack_exports__, __webpack_require__) {
  99  
 100  "use strict";
 101  // ESM COMPAT FLAG
 102  __webpack_require__.r(__webpack_exports__);
 103  
 104  // EXPORTS
 105  __webpack_require__.d(__webpack_exports__, "isURL", function() { return /* reexport */ isURL; });
 106  __webpack_require__.d(__webpack_exports__, "isEmail", function() { return /* reexport */ isEmail; });
 107  __webpack_require__.d(__webpack_exports__, "getProtocol", function() { return /* reexport */ getProtocol; });
 108  __webpack_require__.d(__webpack_exports__, "isValidProtocol", function() { return /* reexport */ isValidProtocol; });
 109  __webpack_require__.d(__webpack_exports__, "getAuthority", function() { return /* reexport */ getAuthority; });
 110  __webpack_require__.d(__webpack_exports__, "isValidAuthority", function() { return /* reexport */ isValidAuthority; });
 111  __webpack_require__.d(__webpack_exports__, "getPath", function() { return /* reexport */ getPath; });
 112  __webpack_require__.d(__webpack_exports__, "isValidPath", function() { return /* reexport */ isValidPath; });
 113  __webpack_require__.d(__webpack_exports__, "getQueryString", function() { return /* reexport */ getQueryString; });
 114  __webpack_require__.d(__webpack_exports__, "buildQueryString", function() { return /* reexport */ buildQueryString; });
 115  __webpack_require__.d(__webpack_exports__, "isValidQueryString", function() { return /* reexport */ isValidQueryString; });
 116  __webpack_require__.d(__webpack_exports__, "getPathAndQueryString", function() { return /* reexport */ getPathAndQueryString; });
 117  __webpack_require__.d(__webpack_exports__, "getFragment", function() { return /* reexport */ getFragment; });
 118  __webpack_require__.d(__webpack_exports__, "isValidFragment", function() { return /* reexport */ isValidFragment; });
 119  __webpack_require__.d(__webpack_exports__, "addQueryArgs", function() { return /* reexport */ addQueryArgs; });
 120  __webpack_require__.d(__webpack_exports__, "getQueryArg", function() { return /* reexport */ getQueryArg; });
 121  __webpack_require__.d(__webpack_exports__, "getQueryArgs", function() { return /* reexport */ getQueryArgs; });
 122  __webpack_require__.d(__webpack_exports__, "hasQueryArg", function() { return /* reexport */ hasQueryArg; });
 123  __webpack_require__.d(__webpack_exports__, "removeQueryArgs", function() { return /* reexport */ removeQueryArgs; });
 124  __webpack_require__.d(__webpack_exports__, "prependHTTP", function() { return /* reexport */ prependHTTP; });
 125  __webpack_require__.d(__webpack_exports__, "safeDecodeURI", function() { return /* reexport */ safeDecodeURI; });
 126  __webpack_require__.d(__webpack_exports__, "safeDecodeURIComponent", function() { return /* reexport */ safeDecodeURIComponent; });
 127  __webpack_require__.d(__webpack_exports__, "filterURLForDisplay", function() { return /* reexport */ filterURLForDisplay; });
 128  __webpack_require__.d(__webpack_exports__, "cleanForSlug", function() { return /* reexport */ cleanForSlug; });
 129  
 130  // CONCATENATED MODULE: ./node_modules/@wordpress/url/build-module/is-url.js
 131  /**
 132   * Determines whether the given string looks like a URL.
 133   *
 134   * @param {string} url The string to scrutinise.
 135   *
 136   * @example
 137   * ```js
 138   * const isURL = isURL( 'https://wordpress.org' ); // true
 139   * ```
 140   *
 141   * @see https://url.spec.whatwg.org/
 142   * @see https://url.spec.whatwg.org/#valid-url-string
 143   *
 144   * @return {boolean} Whether or not it looks like a URL.
 145   */
 146  function isURL(url) {
 147    // A URL can be considered value if the `URL` constructor is able to parse
 148    // it. The constructor throws an error for an invalid URL.
 149    try {
 150      new URL(url);
 151      return true;
 152    } catch {
 153      return false;
 154    }
 155  }
 156  
 157  // CONCATENATED MODULE: ./node_modules/@wordpress/url/build-module/is-email.js
 158  const EMAIL_REGEXP = /^(mailto:)?[a-z0-9._%+-]+@[a-z0-9][a-z0-9.-]*\.[a-z]{2,63}$/i;
 159  /**
 160   * Determines whether the given string looks like an email.
 161   *
 162   * @param {string} email The string to scrutinise.
 163   *
 164   * @example
 165   * ```js
 166   * const isEmail = isEmail( 'hello@wordpress.org' ); // true
 167   * ```
 168   *
 169   * @return {boolean} Whether or not it looks like an email.
 170   */
 171  
 172  function isEmail(email) {
 173    return EMAIL_REGEXP.test(email);
 174  }
 175  
 176  // CONCATENATED MODULE: ./node_modules/@wordpress/url/build-module/get-protocol.js
 177  /**
 178   * Returns the protocol part of the URL.
 179   *
 180   * @param {string} url The full URL.
 181   *
 182   * @example
 183   * ```js
 184   * const protocol1 = getProtocol( 'tel:012345678' ); // 'tel:'
 185   * const protocol2 = getProtocol( 'https://wordpress.org' ); // 'https:'
 186   * ```
 187   *
 188   * @return {string|void} The protocol part of the URL.
 189   */
 190  function getProtocol(url) {
 191    const matches = /^([^\s:]+:)/.exec(url);
 192  
 193    if (matches) {
 194      return matches[1];
 195    }
 196  }
 197  
 198  // CONCATENATED MODULE: ./node_modules/@wordpress/url/build-module/is-valid-protocol.js
 199  /**
 200   * Tests if a url protocol is valid.
 201   *
 202   * @param {string} protocol The url protocol.
 203   *
 204   * @example
 205   * ```js
 206   * const isValid = isValidProtocol( 'https:' ); // true
 207   * const isNotValid = isValidProtocol( 'https :' ); // false
 208   * ```
 209   *
 210   * @return {boolean} True if the argument is a valid protocol (e.g. http:, tel:).
 211   */
 212  function isValidProtocol(protocol) {
 213    if (!protocol) {
 214      return false;
 215    }
 216  
 217    return /^[a-z\-.\+]+[0-9]*:$/i.test(protocol);
 218  }
 219  
 220  // CONCATENATED MODULE: ./node_modules/@wordpress/url/build-module/get-authority.js
 221  /**
 222   * Returns the authority part of the URL.
 223   *
 224   * @param {string} url The full URL.
 225   *
 226   * @example
 227   * ```js
 228   * const authority1 = getAuthority( 'https://wordpress.org/help/' ); // 'wordpress.org'
 229   * const authority2 = getAuthority( 'https://localhost:8080/test/' ); // 'localhost:8080'
 230   * ```
 231   *
 232   * @return {string|void} The authority part of the URL.
 233   */
 234  function getAuthority(url) {
 235    const matches = /^[^\/\s:]+:(?:\/\/)?\/?([^\/\s#?]+)[\/#?]{0,1}\S*$/.exec(url);
 236  
 237    if (matches) {
 238      return matches[1];
 239    }
 240  }
 241  
 242  // CONCATENATED MODULE: ./node_modules/@wordpress/url/build-module/is-valid-authority.js
 243  /**
 244   * Checks for invalid characters within the provided authority.
 245   *
 246   * @param {string} authority A string containing the URL authority.
 247   *
 248   * @example
 249   * ```js
 250   * const isValid = isValidAuthority( 'wordpress.org' ); // true
 251   * const isNotValid = isValidAuthority( 'wordpress#org' ); // false
 252   * ```
 253   *
 254   * @return {boolean} True if the argument contains a valid authority.
 255   */
 256  function isValidAuthority(authority) {
 257    if (!authority) {
 258      return false;
 259    }
 260  
 261    return /^[^\s#?]+$/.test(authority);
 262  }
 263  
 264  // CONCATENATED MODULE: ./node_modules/@wordpress/url/build-module/get-path.js
 265  /**
 266   * Returns the path part of the URL.
 267   *
 268   * @param {string} url The full URL.
 269   *
 270   * @example
 271   * ```js
 272   * const path1 = getPath( 'http://localhost:8080/this/is/a/test?query=true' ); // 'this/is/a/test'
 273   * const path2 = getPath( 'https://wordpress.org/help/faq/' ); // 'help/faq'
 274   * ```
 275   *
 276   * @return {string|void} The path part of the URL.
 277   */
 278  function getPath(url) {
 279    const matches = /^[^\/\s:]+:(?:\/\/)?[^\/\s#?]+[\/]([^\s#?]+)[#?]{0,1}\S*$/.exec(url);
 280  
 281    if (matches) {
 282      return matches[1];
 283    }
 284  }
 285  
 286  // CONCATENATED MODULE: ./node_modules/@wordpress/url/build-module/is-valid-path.js
 287  /**
 288   * Checks for invalid characters within the provided path.
 289   *
 290   * @param {string} path The URL path.
 291   *
 292   * @example
 293   * ```js
 294   * const isValid = isValidPath( 'test/path/' ); // true
 295   * const isNotValid = isValidPath( '/invalid?test/path/' ); // false
 296   * ```
 297   *
 298   * @return {boolean} True if the argument contains a valid path
 299   */
 300  function isValidPath(path) {
 301    if (!path) {
 302      return false;
 303    }
 304  
 305    return /^[^\s#?]+$/.test(path);
 306  }
 307  
 308  // CONCATENATED MODULE: ./node_modules/@wordpress/url/build-module/get-query-string.js
 309  /**
 310   * Returns the query string part of the URL.
 311   *
 312   * @param {string} url The full URL.
 313   *
 314   * @example
 315   * ```js
 316   * const queryString = getQueryString( 'http://localhost:8080/this/is/a/test?query=true#fragment' ); // 'query=true'
 317   * ```
 318   *
 319   * @return {string|void} The query string part of the URL.
 320   */
 321  function getQueryString(url) {
 322    let query;
 323  
 324    try {
 325      query = new URL(url, 'http://example.com').search.substring(1);
 326    } catch (error) {}
 327  
 328    if (query) {
 329      return query;
 330    }
 331  }
 332  
 333  // CONCATENATED MODULE: ./node_modules/@wordpress/url/build-module/build-query-string.js
 334  /**
 335   * Generates URL-encoded query string using input query data.
 336   *
 337   * It is intended to behave equivalent as PHP's `http_build_query`, configured
 338   * with encoding type PHP_QUERY_RFC3986 (spaces as `%20`).
 339   *
 340   * @example
 341   * ```js
 342   * const queryString = buildQueryString( {
 343   *    simple: 'is ok',
 344   *    arrays: [ 'are', 'fine', 'too' ],
 345   *    objects: {
 346   *       evenNested: {
 347   *          ok: 'yes',
 348   *       },
 349   *    },
 350   * } );
 351   * // "simple=is%20ok&arrays%5B0%5D=are&arrays%5B1%5D=fine&arrays%5B2%5D=too&objects%5BevenNested%5D%5Bok%5D=yes"
 352   * ```
 353   *
 354   * @param {Record<string,*>} data Data to encode.
 355   *
 356   * @return {string} Query string.
 357   */
 358  function buildQueryString(data) {
 359    let string = '';
 360    const stack = Object.entries(data);
 361    let pair;
 362  
 363    while (pair = stack.shift()) {
 364      let [key, value] = pair; // Support building deeply nested data, from array or object values.
 365  
 366      const hasNestedData = Array.isArray(value) || value && value.constructor === Object;
 367  
 368      if (hasNestedData) {
 369        // Push array or object values onto the stack as composed of their
 370        // original key and nested index or key, retaining order by a
 371        // combination of Array#reverse and Array#unshift onto the stack.
 372        const valuePairs = Object.entries(value).reverse();
 373  
 374        for (const [member, memberValue] of valuePairs) {
 375          stack.unshift([`$key}[$member}]`, memberValue]);
 376        }
 377      } else if (value !== undefined) {
 378        // Null is treated as special case, equivalent to empty string.
 379        if (value === null) {
 380          value = '';
 381        }
 382  
 383        string += '&' + [key, value].map(encodeURIComponent).join('=');
 384      }
 385    } // Loop will concatenate with leading `&`, but it's only expected for all
 386    // but the first query parameter. This strips the leading `&`, while still
 387    // accounting for the case that the string may in-fact be empty.
 388  
 389  
 390    return string.substr(1);
 391  }
 392  
 393  // CONCATENATED MODULE: ./node_modules/@wordpress/url/build-module/is-valid-query-string.js
 394  /**
 395   * Checks for invalid characters within the provided query string.
 396   *
 397   * @param {string} queryString The query string.
 398   *
 399   * @example
 400   * ```js
 401   * const isValid = isValidQueryString( 'query=true&another=false' ); // true
 402   * const isNotValid = isValidQueryString( 'query=true?another=false' ); // false
 403   * ```
 404   *
 405   * @return {boolean} True if the argument contains a valid query string.
 406   */
 407  function isValidQueryString(queryString) {
 408    if (!queryString) {
 409      return false;
 410    }
 411  
 412    return /^[^\s#?\/]+$/.test(queryString);
 413  }
 414  
 415  // CONCATENATED MODULE: ./node_modules/@wordpress/url/build-module/get-path-and-query-string.js
 416  /**
 417   * Internal dependencies
 418   */
 419  
 420  /**
 421   * Returns the path part and query string part of the URL.
 422   *
 423   * @param {string} url The full URL.
 424   *
 425   * @example
 426   * ```js
 427   * const pathAndQueryString1 = getPathAndQueryString( 'http://localhost:8080/this/is/a/test?query=true' ); // '/this/is/a/test?query=true'
 428   * const pathAndQueryString2 = getPathAndQueryString( 'https://wordpress.org/help/faq/' ); // '/help/faq'
 429   * ```
 430   *
 431   * @return {string} The path part and query string part of the URL.
 432   */
 433  
 434  function getPathAndQueryString(url) {
 435    const path = getPath(url);
 436    const queryString = getQueryString(url);
 437    let value = '/';
 438    if (path) value += path;
 439    if (queryString) value += `?$queryString}`;
 440    return value;
 441  }
 442  
 443  // CONCATENATED MODULE: ./node_modules/@wordpress/url/build-module/get-fragment.js
 444  /**
 445   * Returns the fragment part of the URL.
 446   *
 447   * @param {string} url The full URL
 448   *
 449   * @example
 450   * ```js
 451   * const fragment1 = getFragment( 'http://localhost:8080/this/is/a/test?query=true#fragment' ); // '#fragment'
 452   * const fragment2 = getFragment( 'https://wordpress.org#another-fragment?query=true' ); // '#another-fragment'
 453   * ```
 454   *
 455   * @return {string|void} The fragment part of the URL.
 456   */
 457  function getFragment(url) {
 458    const matches = /^\S+?(#[^\s\?]*)/.exec(url);
 459  
 460    if (matches) {
 461      return matches[1];
 462    }
 463  }
 464  
 465  // CONCATENATED MODULE: ./node_modules/@wordpress/url/build-module/is-valid-fragment.js
 466  /**
 467   * Checks for invalid characters within the provided fragment.
 468   *
 469   * @param {string} fragment The url fragment.
 470   *
 471   * @example
 472   * ```js
 473   * const isValid = isValidFragment( '#valid-fragment' ); // true
 474   * const isNotValid = isValidFragment( '#invalid-#fragment' ); // false
 475   * ```
 476   *
 477   * @return {boolean} True if the argument contains a valid fragment.
 478   */
 479  function isValidFragment(fragment) {
 480    if (!fragment) {
 481      return false;
 482    }
 483  
 484    return /^#[^\s#?\/]*$/.test(fragment);
 485  }
 486  
 487  // CONCATENATED MODULE: ./node_modules/@wordpress/url/build-module/get-query-args.js
 488  /**
 489   * Internal dependencies
 490   */
 491  
 492  /** @typedef {import('./get-query-arg').QueryArgParsed} QueryArgParsed */
 493  
 494  /**
 495   * @typedef {Record<string,QueryArgParsed>} QueryArgs
 496   */
 497  
 498  /**
 499   * Sets a value in object deeply by a given array of path segments. Mutates the
 500   * object reference.
 501   *
 502   * @param {Record<string,*>} object Object in which to assign.
 503   * @param {string[]}         path   Path segment at which to set value.
 504   * @param {*}                value  Value to set.
 505   */
 506  
 507  function setPath(object, path, value) {
 508    const length = path.length;
 509    const lastIndex = length - 1;
 510  
 511    for (let i = 0; i < length; i++) {
 512      let key = path[i];
 513  
 514      if (!key && Array.isArray(object)) {
 515        // If key is empty string and next value is array, derive key from
 516        // the current length of the array.
 517        key = object.length.toString();
 518      } // If the next key in the path is numeric (or empty string), it will be
 519      // created as an array. Otherwise, it will be created as an object.
 520  
 521  
 522      const isNextKeyArrayIndex = !isNaN(Number(path[i + 1]));
 523      object[key] = i === lastIndex ? // If at end of path, assign the intended value.
 524      value : // Otherwise, advance to the next object in the path, creating
 525      // it if it does not yet exist.
 526      object[key] || (isNextKeyArrayIndex ? [] : {});
 527  
 528      if (Array.isArray(object[key]) && !isNextKeyArrayIndex) {
 529        // If we current key is non-numeric, but the next value is an
 530        // array, coerce the value to an object.
 531        object[key] = { ...object[key]
 532        };
 533      } // Update working reference object to the next in the path.
 534  
 535  
 536      object = object[key];
 537    }
 538  }
 539  /**
 540   * Returns an object of query arguments of the given URL. If the given URL is
 541   * invalid or has no querystring, an empty object is returned.
 542   *
 543   * @param {string} url URL.
 544   *
 545   * @example
 546   * ```js
 547   * const foo = getQueryArgs( 'https://wordpress.org?foo=bar&bar=baz' );
 548   * // { "foo": "bar", "bar": "baz" }
 549   * ```
 550   *
 551   * @return {QueryArgs} Query args object.
 552   */
 553  
 554  
 555  function getQueryArgs(url) {
 556    return (getQueryString(url) || ''). // Normalize space encoding, accounting for PHP URL encoding
 557    // corresponding to `application/x-www-form-urlencoded`.
 558    //
 559    // See: https://tools.ietf.org/html/rfc1866#section-8.2.1
 560    replace(/\+/g, '%20').split('&').reduce((accumulator, keyValue) => {
 561      const [key, value = ''] = keyValue.split('=') // Filtering avoids decoding as `undefined` for value, where
 562      // default is restored in destructuring assignment.
 563      .filter(Boolean).map(decodeURIComponent);
 564  
 565      if (key) {
 566        const segments = key.replace(/\]/g, '').split('[');
 567        setPath(accumulator, segments, value);
 568      }
 569  
 570      return accumulator;
 571    }, {});
 572  }
 573  
 574  // CONCATENATED MODULE: ./node_modules/@wordpress/url/build-module/add-query-args.js
 575  /**
 576   * Internal dependencies
 577   */
 578  
 579  
 580  /**
 581   * Appends arguments as querystring to the provided URL. If the URL already
 582   * includes query arguments, the arguments are merged with (and take precedent
 583   * over) the existing set.
 584   *
 585   * @param {string} [url='']  URL to which arguments should be appended. If omitted,
 586   *                           only the resulting querystring is returned.
 587   * @param {Object} [args]    Query arguments to apply to URL.
 588   *
 589   * @example
 590   * ```js
 591   * const newURL = addQueryArgs( 'https://google.com', { q: 'test' } ); // https://google.com/?q=test
 592   * ```
 593   *
 594   * @return {string} URL with arguments applied.
 595   */
 596  
 597  function addQueryArgs(url = '', args) {
 598    // If no arguments are to be appended, return original URL.
 599    if (!args || !Object.keys(args).length) {
 600      return url;
 601    }
 602  
 603    let baseUrl = url; // Determine whether URL already had query arguments.
 604  
 605    const queryStringIndex = url.indexOf('?');
 606  
 607    if (queryStringIndex !== -1) {
 608      // Merge into existing query arguments.
 609      args = Object.assign(getQueryArgs(url), args); // Change working base URL to omit previous query arguments.
 610  
 611      baseUrl = baseUrl.substr(0, queryStringIndex);
 612    }
 613  
 614    return baseUrl + '?' + buildQueryString(args);
 615  }
 616  
 617  // CONCATENATED MODULE: ./node_modules/@wordpress/url/build-module/get-query-arg.js
 618  /**
 619   * Internal dependencies
 620   */
 621  
 622  /**
 623   * @typedef {{[key: string]: QueryArgParsed}} QueryArgObject
 624   */
 625  
 626  /**
 627   * @typedef {string|string[]|QueryArgObject} QueryArgParsed
 628   */
 629  
 630  /**
 631   * Returns a single query argument of the url
 632   *
 633   * @param {string} url URL.
 634   * @param {string} arg Query arg name.
 635   *
 636   * @example
 637   * ```js
 638   * const foo = getQueryArg( 'https://wordpress.org?foo=bar&bar=baz', 'foo' ); // bar
 639   * ```
 640   *
 641   * @return {QueryArgParsed|void} Query arg value.
 642   */
 643  
 644  function getQueryArg(url, arg) {
 645    return getQueryArgs(url)[arg];
 646  }
 647  
 648  // CONCATENATED MODULE: ./node_modules/@wordpress/url/build-module/has-query-arg.js
 649  /**
 650   * Internal dependencies
 651   */
 652  
 653  /**
 654   * Determines whether the URL contains a given query arg.
 655   *
 656   * @param {string} url URL.
 657   * @param {string} arg Query arg name.
 658   *
 659   * @example
 660   * ```js
 661   * const hasBar = hasQueryArg( 'https://wordpress.org?foo=bar&bar=baz', 'bar' ); // true
 662   * ```
 663   *
 664   * @return {boolean} Whether or not the URL contains the query arg.
 665   */
 666  
 667  function hasQueryArg(url, arg) {
 668    return getQueryArg(url, arg) !== undefined;
 669  }
 670  
 671  // CONCATENATED MODULE: ./node_modules/@wordpress/url/build-module/remove-query-args.js
 672  /**
 673   * Internal dependencies
 674   */
 675  
 676  
 677  /**
 678   * Removes arguments from the query string of the url
 679   *
 680   * @param {string}    url  URL.
 681   * @param {...string} args Query Args.
 682   *
 683   * @example
 684   * ```js
 685   * const newUrl = removeQueryArgs( 'https://wordpress.org?foo=bar&bar=baz&baz=foobar', 'foo', 'bar' ); // https://wordpress.org?baz=foobar
 686   * ```
 687   *
 688   * @return {string} Updated URL.
 689   */
 690  
 691  function removeQueryArgs(url, ...args) {
 692    const queryStringIndex = url.indexOf('?');
 693  
 694    if (queryStringIndex === -1) {
 695      return url;
 696    }
 697  
 698    const query = getQueryArgs(url);
 699    const baseURL = url.substr(0, queryStringIndex);
 700    args.forEach(arg => delete query[arg]);
 701    const queryString = buildQueryString(query);
 702    return queryString ? baseURL + '?' + queryString : baseURL;
 703  }
 704  
 705  // CONCATENATED MODULE: ./node_modules/@wordpress/url/build-module/prepend-http.js
 706  /**
 707   * Internal dependencies
 708   */
 709  
 710  const USABLE_HREF_REGEXP = /^(?:[a-z]+:|#|\?|\.|\/)/i;
 711  /**
 712   * Prepends "http://" to a url, if it looks like something that is meant to be a TLD.
 713   *
 714   * @param {string} url The URL to test.
 715   *
 716   * @example
 717   * ```js
 718   * const actualURL = prependHTTP( 'wordpress.org' ); // http://wordpress.org
 719   * ```
 720   *
 721   * @return {string} The updated URL.
 722   */
 723  
 724  function prependHTTP(url) {
 725    if (!url) {
 726      return url;
 727    }
 728  
 729    url = url.trim();
 730  
 731    if (!USABLE_HREF_REGEXP.test(url) && !isEmail(url)) {
 732      return 'http://' + url;
 733    }
 734  
 735    return url;
 736  }
 737  
 738  // CONCATENATED MODULE: ./node_modules/@wordpress/url/build-module/safe-decode-uri.js
 739  /**
 740   * Safely decodes a URI with `decodeURI`. Returns the URI unmodified if
 741   * `decodeURI` throws an error.
 742   *
 743   * @param {string} uri URI to decode.
 744   *
 745   * @example
 746   * ```js
 747   * const badUri = safeDecodeURI( '%z' ); // does not throw an Error, simply returns '%z'
 748   * ```
 749   *
 750   * @return {string} Decoded URI if possible.
 751   */
 752  function safeDecodeURI(uri) {
 753    try {
 754      return decodeURI(uri);
 755    } catch (uriError) {
 756      return uri;
 757    }
 758  }
 759  
 760  // CONCATENATED MODULE: ./node_modules/@wordpress/url/build-module/safe-decode-uri-component.js
 761  /**
 762   * Safely decodes a URI component with `decodeURIComponent`. Returns the URI component unmodified if
 763   * `decodeURIComponent` throws an error.
 764   *
 765   * @param {string} uriComponent URI component to decode.
 766   *
 767   * @return {string} Decoded URI component if possible.
 768   */
 769  function safeDecodeURIComponent(uriComponent) {
 770    try {
 771      return decodeURIComponent(uriComponent);
 772    } catch (uriComponentError) {
 773      return uriComponent;
 774    }
 775  }
 776  
 777  // CONCATENATED MODULE: ./node_modules/@wordpress/url/build-module/filter-url-for-display.js
 778  /**
 779   * Returns a URL for display.
 780   *
 781   * @param {string} url Original URL.
 782   * @param {number|null} maxLength URL length.
 783   *
 784   * @example
 785   * ```js
 786   * const displayUrl = filterURLForDisplay( 'https://www.wordpress.org/gutenberg/' ); // wordpress.org/gutenberg
 787   * const imageUrl = filterURLForDisplay( 'https://www.wordpress.org/wp-content/uploads/img.png', 20 ); // …ent/uploads/img.png
 788   * ```
 789   *
 790   * @return {string} Displayed URL.
 791   */
 792  function filterURLForDisplay(url, maxLength = null) {
 793    // Remove protocol and www prefixes.
 794    let filteredURL = url.replace(/^(?:https?:)\/\/(?:www\.)?/, ''); // Ends with / and only has that single slash, strip it.
 795  
 796    if (filteredURL.match(/^[^\/]+\/$/)) {
 797      filteredURL = filteredURL.replace('/', '');
 798    }
 799  
 800    const mediaRegexp = /([\w|:])*\.(?:jpg|jpeg|gif|png|svg)/;
 801  
 802    if (!maxLength || filteredURL.length <= maxLength || !filteredURL.match(mediaRegexp)) {
 803      return filteredURL;
 804    } // If the file is not greater than max length, return last portion of URL.
 805  
 806  
 807    filteredURL = filteredURL.split('?')[0];
 808    const urlPieces = filteredURL.split('/');
 809    const file = urlPieces[urlPieces.length - 1];
 810  
 811    if (file.length <= maxLength) {
 812      return '…' + filteredURL.slice(-maxLength);
 813    } // If the file is greater than max length, truncate the file.
 814  
 815  
 816    const index = file.lastIndexOf('.');
 817    const [fileName, extension] = [file.slice(0, index), file.slice(index + 1)];
 818    const truncatedFile = fileName.slice(-3) + '.' + extension;
 819    return file.slice(0, maxLength - truncatedFile.length - 1) + '…' + truncatedFile;
 820  }
 821  
 822  // EXTERNAL MODULE: external "lodash"
 823  var external_lodash_ = __webpack_require__("YLtl");
 824  
 825  // CONCATENATED MODULE: ./node_modules/@wordpress/url/build-module/clean-for-slug.js
 826  /**
 827   * External dependencies
 828   */
 829  
 830  /**
 831   * Performs some basic cleanup of a string for use as a post slug.
 832   *
 833   * This replicates some of what `sanitize_title()` does in WordPress core, but
 834   * is only designed to approximate what the slug will be.
 835   *
 836   * Converts Latin-1 Supplement and Latin Extended-A letters to basic Latin
 837   * letters. Removes combining diacritical marks. Converts whitespace, periods,
 838   * and forward slashes to hyphens. Removes any remaining non-word characters
 839   * except hyphens. Converts remaining string to lowercase. It does not account
 840   * for octets, HTML entities, or other encoded characters.
 841   *
 842   * @param {string} string Title or slug to be processed.
 843   *
 844   * @return {string} Processed string.
 845   */
 846  
 847  function cleanForSlug(string) {
 848    if (!string) {
 849      return '';
 850    }
 851  
 852    return Object(external_lodash_["trim"])(Object(external_lodash_["deburr"])(string).replace(/[\s\./]+/g, '-').replace(/[^\w-]+/g, '').toLowerCase(), '-');
 853  }
 854  
 855  // CONCATENATED MODULE: ./node_modules/@wordpress/url/build-module/index.js
 856  
 857  
 858  
 859  
 860  
 861  
 862  
 863  
 864  
 865  
 866  
 867  
 868  
 869  
 870  
 871  
 872  
 873  
 874  
 875  
 876  
 877  
 878  
 879  
 880  
 881  
 882  /***/ })
 883  
 884  /******/ });


Generated: Wed Jun 16 01:00:05 2021 Cross-referenced by PHPXref 0.7.1