url.js 26 KB

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