No Description

url.js 26KB

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