PluginProbe
Gutenberg / 13.5.1
Gutenberg v13.5.1
24.0.0 23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 All 403 releases
gutenberg / build / url / index.js

index.js in Gutenberg 13.5.1, at build/url/index.js

1,366 lines 31.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /******/ (() => { // webpackBootstrap
2 /******/ var __webpack_modules__ = ({
3
4 /***/ 4793:
5 /***/ ((module) => {
6
7 var characterMap = {
8 "À": "A",
9 "Á": "A",
10 "Â": "A",
11 "Ã": "A",
12 "Ä": "A",
13 "�
14 ": "A",
15 "": "A",
16 "": "A",
17 "": "A",
18 "": "A",
19 "": "A",
20 "Æ": "AE",
21 "": "A",
22 "": "A",
23 "Ȃ": "A",
24 "Ç": "C",
25 "": "C",
26 "È": "E",
27 "É": "E",
28 "Ê": "E",
29 "Ë": "E",
30 "": "E",
31 "": "E",
32 "": "E",
33 "": "E",
34 "": "E",
35 "Ȇ": "E",
36 "Ì": "I",
37 "Í": "I",
38 "Î": "I",
39 "Ï": "I",
40 "": "I",
41 "Ȋ": "I",
42 "Ð": "D",
43 "Ñ": "N",
44 "Ò": "O",
45 "Ó": "O",
46 "Ô": "O",
47 "Õ": "O",
48 "Ö": "O",
49 "Ø": "O",
50 "": "O",
51 "": "O",
52 "": "O",
53 "Ȏ": "O",
54 "Ù": "U",
55 "Ú": "U",
56 "Û": "U",
57 "Ü": "U",
58 "Ý": "Y",
59 "à": "a",
60 "á": "a",
61 "â": "a",
62 "ã": "a",
63 "ä": "a",
64 "å": "a",
65 "": "a",
66 "": "a",
67 "": "a",
68 "": "a",
69 "": "a",
70 "æ": "ae",
71 "": "a",
72 "": "a",
73 "ȃ": "a",
74 "ç": "c",
75 "": "c",
76 "è": "e",
77 "é": "e",
78 "ê": "e",
79 "ë": "e",
80 "ế": "e",
81 "": "e",
82 "": "e",
83 "": "e",
84 "": "e",
85 "ȇ": "e",
86 "ì": "i",
87 "í": "i",
88 "î": "i",
89 "ï": "i",
90 "": "i",
91 "ȋ": "i",
92 "ð": "d",
93 "ñ": "n",
94 "ò": "o",
95 "ó": "o",
96 "ô": "o",
97 "õ": "o",
98 "ö": "o",
99 "ø": "o",
100 "": "o",
101 "": "o",
102 "": "o",
103 "ȏ": "o",
104 "ù": "u",
105 "ú": "u",
106 "û": "u",
107 "ü": "u",
108 "ý": "y",
109 "ÿ": "y",
110 "Ā": "A",
111 "ā": "a",
112 "Ă": "A",
113 "ă": "a",
114 "Ą": "A",
115 "�
116 ": "a",
117 "Ć": "C",
118 "ć": "c",
119 "Ĉ": "C",
120 "ĉ": "c",
121 "Ċ": "C",
122 "ċ": "c",
123 "Č": "C",
124 "č": "c",
125 "": "C",
126 "": "c",
127 "Ď": "D",
128 "ď": "d",
129 "Đ": "D",
130 "đ": "d",
131 "Ē": "E",
132 "ē": "e",
133 "Ĕ": "E",
134 "ĕ": "e",
135 "Ė": "E",
136 "ė": "e",
137 "Ę": "E",
138 "ę": "e",
139 "Ě": "E",
140 "ě": "e",
141 "Ĝ": "G",
142 "Ǵ": "G",
143 "ĝ": "g",
144 "ǵ": "g",
145 "Ğ": "G",
146 "ğ": "g",
147 "Ġ": "G",
148 "ġ": "g",
149 "Ģ": "G",
150 "ģ": "g",
151 "Ĥ": "H",
152 "ĥ": "h",
153 "Ħ": "H",
154 "ħ": "h",
155 "": "H",
156 "": "h",
157 "Ĩ": "I",
158 "ĩ": "i",
159 "Ī": "I",
160 "ī": "i",
161 "Ĭ": "I",
162 "ĭ": "i",
163 "Į": "I",
164 "į": "i",
165 "İ": "I",
166 "ı": "i",
167 "IJ": "IJ",
168 "ij": "ij",
169 "Ĵ": "J",
170 "ĵ": "j",
171 "Ķ": "K",
172 "ķ": "k",
173 "": "K",
174 "": "k",
175 "": "K",
176 "": "k",
177 "Ĺ": "L",
178 "ĺ": "l",
179 "Ļ": "L",
180 "ļ": "l",
181 "Ľ": "L",
182 "ľ": "l",
183 "Ŀ": "L",
184 "ŀ": "l",
185 "Ł": "l",
186 "ł": "l",
187 "": "M",
188 "ḿ": "m",
189 "": "M",
190 "": "m",
191 "Ń": "N",
192 "ń": "n",
193 "�
194 ": "N",
195 "ņ": "n",
196 "Ň": "N",
197 "ň": "n",
198 "ʼn": "n",
199 "": "N",
200 "": "n",
201 "Ō": "O",
202 "ō": "o",
203 "Ŏ": "O",
204 "ŏ": "o",
205 "Ő": "O",
206 "ő": "o",
207 "Œ": "OE",
208 "œ": "oe",
209 "": "P",
210 "": "p",
211 "Ŕ": "R",
212 "ŕ": "r",
213 "Ŗ": "R",
214 "ŗ": "r",
215 "Ř": "R",
216 "ř": "r",
217 "": "R",
218 "": "r",
219 "Ȓ": "R",
220 "ȓ": "r",
221 "Ś": "S",
222 "ś": "s",
223 "Ŝ": "S",
224 "ŝ": "s",
225 "Ş": "S",
226 "Ș": "S",
227 "ș": "s",
228 "ş": "s",
229 "Š": "S",
230 "š": "s",
231 "Ţ": "T",
232 "ţ": "t",
233 "ț": "t",
234 "Ț": "T",
235 "Ť": "T",
236 "ť": "t",
237 "Ŧ": "T",
238 "ŧ": "t",
239 "": "T",
240 "": "t",
241 "Ũ": "U",
242 "ũ": "u",
243 "Ū": "U",
244 "ū": "u",
245 "Ŭ": "U",
246 "ŭ": "u",
247 "Ů": "U",
248 "ů": "u",
249 "Ű": "U",
250 "ű": "u",
251 "Ų": "U",
252 "ų": "u",
253 "Ȗ": "U",
254 "ȗ": "u",
255 "": "V",
256 "": "v",
257 "Ŵ": "W",
258 "ŵ": "w",
259 "": "W",
260 "": "w",
261 "": "X",
262 "": "x",
263 "Ŷ": "Y",
264 "ŷ": "y",
265 "Ÿ": "Y",
266 "": "Y",
267 "": "y",
268 "Ź": "Z",
269 "ź": "z",
270 "Ż": "Z",
271 "ż": "z",
272 "Ž": "Z",
273 "ž": "z",
274 "ſ": "s",
275 "ƒ": "f",
276 "Ơ": "O",
277 "ơ": "o",
278 "Ư": "U",
279 "ư": "u",
280 "Ǎ": "A",
281 "ǎ": "a",
282 "Ǐ": "I",
283 "ǐ": "i",
284 "Ǒ": "O",
285 "ǒ": "o",
286 "Ǔ": "U",
287 "ǔ": "u",
288 "Ǖ": "U",
289 "ǖ": "u",
290 "Ǘ": "U",
291 "ǘ": "u",
292 "Ǚ": "U",
293 "ǚ": "u",
294 "Ǜ": "U",
295 "ǜ": "u",
296 "": "U",
297 "": "u",
298 "": "U",
299 "": "u",
300 "Ǻ": "A",
301 "ǻ": "a",
302 "Ǽ": "AE",
303 "ǽ": "ae",
304 "Ǿ": "O",
305 "ǿ": "o",
306 "Þ": "TH",
307 "þ": "th",
308 "": "P",
309 "": "p",
310 "": "S",
311 "": "s",
312 "": "X",
313 "": "x",
314 "Ѓ": "Г",
315 "ѓ": "г",
316 "Ќ": "К",
317 "ќ": "к",
318 "": "A",
319 "": "a",
320 "": "E",
321 "": "e",
322 "": "I",
323 "": "i",
324 "Ǹ": "N",
325 "ǹ": "n",
326 "": "O",
327 "": "o",
328 "": "O",
329 "": "o",
330 "": "U",
331 "": "u",
332 "": "W",
333 "": "w",
334 "": "Y",
335 "": "y",
336 "Ȁ": "A",
337 "ȁ": "a",
338 "Ȅ": "E",
339 "�
340 ": "e",
341 "Ȉ": "I",
342 "ȉ": "i",
343 "Ȍ": "O",
344 "ȍ": "o",
345 "Ȑ": "R",
346 "ȑ": "r",
347 "Ȕ": "U",
348 "ȕ": "u",
349 "": "B",
350 "": "b",
351 "Č̣": "C",
352 "č̣": "c",
353 "Ê̌": "E",
354 "ê̌": "e",
355 "": "F",
356 "": "f",
357 "Ǧ": "G",
358 "ǧ": "g",
359 "Ȟ": "H",
360 "ȟ": "h",
361 "": "J",
362 "ǰ": "j",
363 "Ǩ": "K",
364 "ǩ": "k",
365 "": "M",
366 "": "m",
367 "": "P",
368 "": "p",
369 "": "Q",
370 "": "q",
371 "Ř̩": "R",
372 "ř̩": "r",
373 "": "S",
374 "": "s",
375 "": "V",
376 "": "v",
377 "": "W",
378 "": "w",
379 "": "X",
380 "": "x",
381 "": "Y",
382 "": "y",
383 "": "A",
384 "": "a",
385 "": "B",
386 "": "b",
387 "": "D",
388 "": "d",
389 "Ȩ": "E",
390 "ȩ": "e",
391 "Ɛ̧": "E",
392 "ɛ̧": "e",
393 "": "H",
394 "": "h",
395 "": "I",
396 "": "i",
397 "Ɨ̧": "I",
398 "ɨ̧": "i",
399 "": "M",
400 "": "m",
401 "": "O",
402 "": "o",
403 "": "Q",
404 "": "q",
405 "": "U",
406 "": "u",
407 "": "X",
408 "": "x",
409 "": "Z",
410 "": "z",
411 };
412
413 var chars = Object.keys(characterMap).join('|');
414 var allAccents = new RegExp(chars, 'g');
415 var firstAccent = new RegExp(chars, '');
416
417 var removeAccents = function(string) {
418 return string.replace(allAccents, function(match) {
419 return characterMap[match];
420 });
421 };
422
423 var hasAccents = function(string) {
424 return !!string.match(firstAccent);
425 };
426
427 module.exports = removeAccents;
428 module.exports.has = hasAccents;
429 module.exports.remove = removeAccents;
430
431
432 /***/ })
433
434 /******/ });
435 /************************************************************************/
436 /******/ // The module cache
437 /******/ var __webpack_module_cache__ = {};
438 /******/
439 /******/ // The require function
440 /******/ function __webpack_require__(moduleId) {
441 /******/ // Check if module is in cache
442 /******/ var cachedModule = __webpack_module_cache__[moduleId];
443 /******/ if (cachedModule !== undefined) {
444 /******/ return cachedModule.exports;
445 /******/ }
446 /******/ // Create a new module (and put it into the cache)
447 /******/ var module = __webpack_module_cache__[moduleId] = {
448 /******/ // no module.id needed
449 /******/ // no module.loaded needed
450 /******/ exports: {}
451 /******/ };
452 /******/
453 /******/ // Execute the module function
454 /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
455 /******/
456 /******/ // Return the exports of the module
457 /******/ return module.exports;
458 /******/ }
459 /******/
460 /************************************************************************/
461 /******/ /* webpack/runtime/compat get default export */
462 /******/ (() => {
463 /******/ // getDefaultExport function for compatibility with non-harmony modules
464 /******/ __webpack_require__.n = (module) => {
465 /******/ var getter = module && module.__esModule ?
466 /******/ () => (module['default']) :
467 /******/ () => (module);
468 /******/ __webpack_require__.d(getter, { a: getter });
469 /******/ return getter;
470 /******/ };
471 /******/ })();
472 /******/
473 /******/ /* webpack/runtime/define property getters */
474 /******/ (() => {
475 /******/ // define getter functions for harmony exports
476 /******/ __webpack_require__.d = (exports, definition) => {
477 /******/ for(var key in definition) {
478 /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
479 /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
480 /******/ }
481 /******/ }
482 /******/ };
483 /******/ })();
484 /******/
485 /******/ /* webpack/runtime/hasOwnProperty shorthand */
486 /******/ (() => {
487 /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
488 /******/ })();
489 /******/
490 /******/ /* webpack/runtime/make namespace object */
491 /******/ (() => {
492 /******/ // define __esModule on exports
493 /******/ __webpack_require__.r = (exports) => {
494 /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
495 /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
496 /******/ }
497 /******/ Object.defineProperty(exports, '__esModule', { value: true });
498 /******/ };
499 /******/ })();
500 /******/
501 /************************************************************************/
502 var __webpack_exports__ = {};
503 // This entry need to be wrapped in an IIFE because it need to be in strict mode.
504 (() => {
505 "use strict";
506 // ESM COMPAT FLAG
507 __webpack_require__.r(__webpack_exports__);
508
509 // EXPORTS
510 __webpack_require__.d(__webpack_exports__, {
511 "addQueryArgs": () => (/* reexport */ addQueryArgs),
512 "buildQueryString": () => (/* reexport */ buildQueryString),
513 "cleanForSlug": () => (/* reexport */ cleanForSlug),
514 "filterURLForDisplay": () => (/* reexport */ filterURLForDisplay),
515 "getAuthority": () => (/* reexport */ getAuthority),
516 "getFilename": () => (/* reexport */ getFilename),
517 "getFragment": () => (/* reexport */ getFragment),
518 "getPath": () => (/* reexport */ getPath),
519 "getPathAndQueryString": () => (/* reexport */ getPathAndQueryString),
520 "getProtocol": () => (/* reexport */ getProtocol),
521 "getQueryArg": () => (/* reexport */ getQueryArg),
522 "getQueryArgs": () => (/* reexport */ getQueryArgs),
523 "getQueryString": () => (/* reexport */ getQueryString),
524 "hasQueryArg": () => (/* reexport */ hasQueryArg),
525 "isEmail": () => (/* reexport */ isEmail),
526 "isURL": () => (/* reexport */ isURL),
527 "isValidAuthority": () => (/* reexport */ isValidAuthority),
528 "isValidFragment": () => (/* reexport */ isValidFragment),
529 "isValidPath": () => (/* reexport */ isValidPath),
530 "isValidProtocol": () => (/* reexport */ isValidProtocol),
531 "isValidQueryString": () => (/* reexport */ isValidQueryString),
532 "normalizePath": () => (/* reexport */ normalizePath),
533 "prependHTTP": () => (/* reexport */ prependHTTP),
534 "removeQueryArgs": () => (/* reexport */ removeQueryArgs),
535 "safeDecodeURI": () => (/* reexport */ safeDecodeURI),
536 "safeDecodeURIComponent": () => (/* reexport */ safeDecodeURIComponent)
537 });
538
539 ;// CONCATENATED MODULE: ./packages/url/build-module/is-url.js
540 /**
541 * Determines whether the given string looks like a URL.
542 *
543 * @param {string} url The string to scrutinise.
544 *
545 * @example
546 * ```js
547 * const isURL = isURL( 'https://wordpress.org' ); // true
548 * ```
549 *
550 * @see https://url.spec.whatwg.org/
551 * @see https://url.spec.whatwg.org/#valid-url-string
552 *
553 * @return {boolean} Whether or not it looks like a URL.
554 */
555 function isURL(url) {
556 // A URL can be considered value if the `URL` constructor is able to parse
557 // it. The constructor throws an error for an invalid URL.
558 try {
559 new URL(url);
560 return true;
561 } catch {
562 return false;
563 }
564 }
565
566 ;// CONCATENATED MODULE: ./packages/url/build-module/is-email.js
567 const EMAIL_REGEXP = /^(mailto:)?[a-z0-9._%+-]+@[a-z0-9][a-z0-9.-]*\.[a-z]{2,63}$/i;
568 /**
569 * Determines whether the given string looks like an email.
570 *
571 * @param {string} email The string to scrutinise.
572 *
573 * @example
574 * ```js
575 * const isEmail = isEmail( 'hello@wordpress.org' ); // true
576 * ```
577 *
578 * @return {boolean} Whether or not it looks like an email.
579 */
580
581 function isEmail(email) {
582 return EMAIL_REGEXP.test(email);
583 }
584
585 ;// CONCATENATED MODULE: ./packages/url/build-module/get-protocol.js
586 /**
587 * Returns the protocol part of the URL.
588 *
589 * @param {string} url The full URL.
590 *
591 * @example
592 * ```js
593 * const protocol1 = getProtocol( 'tel:012345678' ); // 'tel:'
594 * const protocol2 = getProtocol( 'https://wordpress.org' ); // 'https:'
595 * ```
596 *
597 * @return {string|void} The protocol part of the URL.
598 */
599 function getProtocol(url) {
600 const matches = /^([^\s:]+:)/.exec(url);
601
602 if (matches) {
603 return matches[1];
604 }
605 }
606
607 ;// CONCATENATED MODULE: ./packages/url/build-module/is-valid-protocol.js
608 /**
609 * Tests if a url protocol is valid.
610 *
611 * @param {string} protocol The url protocol.
612 *
613 * @example
614 * ```js
615 * const isValid = isValidProtocol( 'https:' ); // true
616 * const isNotValid = isValidProtocol( 'https :' ); // false
617 * ```
618 *
619 * @return {boolean} True if the argument is a valid protocol (e.g. http:, tel:).
620 */
621 function isValidProtocol(protocol) {
622 if (!protocol) {
623 return false;
624 }
625
626 return /^[a-z\-.\+]+[0-9]*:$/i.test(protocol);
627 }
628
629 ;// CONCATENATED MODULE: ./packages/url/build-module/get-authority.js
630 /**
631 * Returns the authority part of the URL.
632 *
633 * @param {string} url The full URL.
634 *
635 * @example
636 * ```js
637 * const authority1 = getAuthority( 'https://wordpress.org/help/' ); // 'wordpress.org'
638 * const authority2 = getAuthority( 'https://localhost:8080/test/' ); // 'localhost:8080'
639 * ```
640 *
641 * @return {string|void} The authority part of the URL.
642 */
643 function getAuthority(url) {
644 const matches = /^[^\/\s:]+:(?:\/\/)?\/?([^\/\s#?]+)[\/#?]{0,1}\S*$/.exec(url);
645
646 if (matches) {
647 return matches[1];
648 }
649 }
650
651 ;// CONCATENATED MODULE: ./packages/url/build-module/is-valid-authority.js
652 /**
653 * Checks for invalid characters within the provided authority.
654 *
655 * @param {string} authority A string containing the URL authority.
656 *
657 * @example
658 * ```js
659 * const isValid = isValidAuthority( 'wordpress.org' ); // true
660 * const isNotValid = isValidAuthority( 'wordpress#org' ); // false
661 * ```
662 *
663 * @return {boolean} True if the argument contains a valid authority.
664 */
665 function isValidAuthority(authority) {
666 if (!authority) {
667 return false;
668 }
669
670 return /^[^\s#?]+$/.test(authority);
671 }
672
673 ;// CONCATENATED MODULE: ./packages/url/build-module/get-path.js
674 /**
675 * Returns the path part of the URL.
676 *
677 * @param {string} url The full URL.
678 *
679 * @example
680 * ```js
681 * const path1 = getPath( 'http://localhost:8080/this/is/a/test?query=true' ); // 'this/is/a/test'
682 * const path2 = getPath( 'https://wordpress.org/help/faq/' ); // 'help/faq'
683 * ```
684 *
685 * @return {string|void} The path part of the URL.
686 */
687 function getPath(url) {
688 const matches = /^[^\/\s:]+:(?:\/\/)?[^\/\s#?]+[\/]([^\s#?]+)[#?]{0,1}\S*$/.exec(url);
689
690 if (matches) {
691 return matches[1];
692 }
693 }
694
695 ;// CONCATENATED MODULE: ./packages/url/build-module/is-valid-path.js
696 /**
697 * Checks for invalid characters within the provided path.
698 *
699 * @param {string} path The URL path.
700 *
701 * @example
702 * ```js
703 * const isValid = isValidPath( 'test/path/' ); // true
704 * const isNotValid = isValidPath( '/invalid?test/path/' ); // false
705 * ```
706 *
707 * @return {boolean} True if the argument contains a valid path
708 */
709 function isValidPath(path) {
710 if (!path) {
711 return false;
712 }
713
714 return /^[^\s#?]+$/.test(path);
715 }
716
717 ;// CONCATENATED MODULE: ./packages/url/build-module/get-query-string.js
718 /**
719 * Returns the query string part of the URL.
720 *
721 * @param {string} url The full URL.
722 *
723 * @example
724 * ```js
725 * const queryString = getQueryString( 'http://localhost:8080/this/is/a/test?query=true#fragment' ); // 'query=true'
726 * ```
727 *
728 * @return {string|void} The query string part of the URL.
729 */
730 function getQueryString(url) {
731 let query;
732
733 try {
734 query = new URL(url, 'http://example.com').search.substring(1);
735 } catch (error) {}
736
737 if (query) {
738 return query;
739 }
740 }
741
742 ;// CONCATENATED MODULE: ./packages/url/build-module/build-query-string.js
743 /**
744 * Generates URL-encoded query string using input query data.
745 *
746 * It is intended to behave equivalent as PHP's `http_build_query`, configured
747 * with encoding type PHP_QUERY_RFC3986 (spaces as `%20`).
748 *
749 * @example
750 * ```js
751 * const queryString = buildQueryString( {
752 * simple: 'is ok',
753 * arrays: [ 'are', 'fine', 'too' ],
754 * objects: {
755 * evenNested: {
756 * ok: 'yes',
757 * },
758 * },
759 * } );
760 * // "simple=is%20ok&arrays%5B0%5D=are&arrays%5B1%5D=fine&arrays%5B2%5D=too&objects%5BevenNested%5D%5Bok%5D=yes"
761 * ```
762 *
763 * @param {Record<string,*>} data Data to encode.
764 *
765 * @return {string} Query string.
766 */
767 function buildQueryString(data) {
768 let string = '';
769 const stack = Object.entries(data);
770 let pair;
771
772 while (pair = stack.shift()) {
773 let [key, value] = pair; // Support building deeply nested data, from array or object values.
774
775 const hasNestedData = Array.isArray(value) || value && value.constructor === Object;
776
777 if (hasNestedData) {
778 // Push array or object values onto the stack as composed of their
779 // original key and nested index or key, retaining order by a
780 // combination of Array#reverse and Array#unshift onto the stack.
781 const valuePairs = Object.entries(value).reverse();
782
783 for (const [member, memberValue] of valuePairs) {
784 stack.unshift([`${key}[${member}]`, memberValue]);
785 }
786 } else if (value !== undefined) {
787 // Null is treated as special case, equivalent to empty string.
788 if (value === null) {
789 value = '';
790 }
791
792 string += '&' + [key, value].map(encodeURIComponent).join('=');
793 }
794 } // Loop will concatenate with leading `&`, but it's only expected for all
795 // but the first query parameter. This strips the leading `&`, while still
796 // accounting for the case that the string may in-fact be empty.
797
798
799 return string.substr(1);
800 }
801
802 ;// CONCATENATED MODULE: ./packages/url/build-module/is-valid-query-string.js
803 /**
804 * Checks for invalid characters within the provided query string.
805 *
806 * @param {string} queryString The query string.
807 *
808 * @example
809 * ```js
810 * const isValid = isValidQueryString( 'query=true&another=false' ); // true
811 * const isNotValid = isValidQueryString( 'query=true?another=false' ); // false
812 * ```
813 *
814 * @return {boolean} True if the argument contains a valid query string.
815 */
816 function isValidQueryString(queryString) {
817 if (!queryString) {
818 return false;
819 }
820
821 return /^[^\s#?\/]+$/.test(queryString);
822 }
823
824 ;// CONCATENATED MODULE: ./packages/url/build-module/get-path-and-query-string.js
825 /**
826 * Internal dependencies
827 */
828
829 /**
830 * Returns the path part and query string part of the URL.
831 *
832 * @param {string} url The full URL.
833 *
834 * @example
835 * ```js
836 * const pathAndQueryString1 = getPathAndQueryString( 'http://localhost:8080/this/is/a/test?query=true' ); // '/this/is/a/test?query=true'
837 * const pathAndQueryString2 = getPathAndQueryString( 'https://wordpress.org/help/faq/' ); // '/help/faq'
838 * ```
839 *
840 * @return {string} The path part and query string part of the URL.
841 */
842
843 function getPathAndQueryString(url) {
844 const path = getPath(url);
845 const queryString = getQueryString(url);
846 let value = '/';
847 if (path) value += path;
848 if (queryString) value += `?${queryString}`;
849 return value;
850 }
851
852 ;// CONCATENATED MODULE: ./packages/url/build-module/get-fragment.js
853 /**
854 * Returns the fragment part of the URL.
855 *
856 * @param {string} url The full URL
857 *
858 * @example
859 * ```js
860 * const fragment1 = getFragment( 'http://localhost:8080/this/is/a/test?query=true#fragment' ); // '#fragment'
861 * const fragment2 = getFragment( 'https://wordpress.org#another-fragment?query=true' ); // '#another-fragment'
862 * ```
863 *
864 * @return {string|void} The fragment part of the URL.
865 */
866 function getFragment(url) {
867 const matches = /^\S+?(#[^\s\?]*)/.exec(url);
868
869 if (matches) {
870 return matches[1];
871 }
872 }
873
874 ;// CONCATENATED MODULE: ./packages/url/build-module/is-valid-fragment.js
875 /**
876 * Checks for invalid characters within the provided fragment.
877 *
878 * @param {string} fragment The url fragment.
879 *
880 * @example
881 * ```js
882 * const isValid = isValidFragment( '#valid-fragment' ); // true
883 * const isNotValid = isValidFragment( '#invalid-#fragment' ); // false
884 * ```
885 *
886 * @return {boolean} True if the argument contains a valid fragment.
887 */
888 function isValidFragment(fragment) {
889 if (!fragment) {
890 return false;
891 }
892
893 return /^#[^\s#?\/]*$/.test(fragment);
894 }
895
896 ;// CONCATENATED MODULE: ./packages/url/build-module/get-query-args.js
897 /**
898 * Internal dependencies
899 */
900
901 /** @typedef {import('./get-query-arg').QueryArgParsed} QueryArgParsed */
902
903 /**
904 * @typedef {Record<string,QueryArgParsed>} QueryArgs
905 */
906
907 /**
908 * Sets a value in object deeply by a given array of path segments. Mutates the
909 * object reference.
910 *
911 * @param {Record<string,*>} object Object in which to assign.
912 * @param {string[]} path Path segment at which to set value.
913 * @param {*} value Value to set.
914 */
915
916 function setPath(object, path, value) {
917 const length = path.length;
918 const lastIndex = length - 1;
919
920 for (let i = 0; i < length; i++) {
921 let key = path[i];
922
923 if (!key && Array.isArray(object)) {
924 // If key is empty string and next value is array, derive key from
925 // the current length of the array.
926 key = object.length.toString();
927 }
928
929 key = ['__proto__', 'constructor', 'prototype'].includes(key) ? key.toUpperCase() : key; // If the next key in the path is numeric (or empty string), it will be
930 // created as an array. Otherwise, it will be created as an object.
931
932 const isNextKeyArrayIndex = !isNaN(Number(path[i + 1]));
933 object[key] = i === lastIndex ? // If at end of path, assign the intended value.
934 value : // Otherwise, advance to the next object in the path, creating
935 // it if it does not yet exist.
936 object[key] || (isNextKeyArrayIndex ? [] : {});
937
938 if (Array.isArray(object[key]) && !isNextKeyArrayIndex) {
939 // If we current key is non-numeric, but the next value is an
940 // array, coerce the value to an object.
941 object[key] = { ...object[key]
942 };
943 } // Update working reference object to the next in the path.
944
945
946 object = object[key];
947 }
948 }
949 /**
950 * Returns an object of query arguments of the given URL. If the given URL is
951 * invalid or has no querystring, an empty object is returned.
952 *
953 * @param {string} url URL.
954 *
955 * @example
956 * ```js
957 * const foo = getQueryArgs( 'https://wordpress.org?foo=bar&bar=baz' );
958 * // { "foo": "bar", "bar": "baz" }
959 * ```
960 *
961 * @return {QueryArgs} Query args object.
962 */
963
964
965 function getQueryArgs(url) {
966 return (getQueryString(url) || '' // Normalize space encoding, accounting for PHP URL encoding
967 // corresponding to `application/x-www-form-urlencoded`.
968 //
969 // See: https://tools.ietf.org/html/rfc1866#section-8.2.1
970 ).replace(/\+/g, '%20').split('&').reduce((accumulator, keyValue) => {
971 const [key, value = ''] = keyValue.split('=') // Filtering avoids decoding as `undefined` for value, where
972 // default is restored in destructuring assignment.
973 .filter(Boolean).map(decodeURIComponent);
974
975 if (key) {
976 const segments = key.replace(/\]/g, '').split('[');
977 setPath(accumulator, segments, value);
978 }
979
980 return accumulator;
981 }, Object.create(null));
982 }
983
984 ;// CONCATENATED MODULE: ./packages/url/build-module/add-query-args.js
985 /**
986 * Internal dependencies
987 */
988
989
990 /**
991 * Appends arguments as querystring to the provided URL. If the URL already
992 * includes query arguments, the arguments are merged with (and take precedent
993 * over) the existing set.
994 *
995 * @param {string} [url=''] URL to which arguments should be appended. If omitted,
996 * only the resulting querystring is returned.
997 * @param {Object} [args] Query arguments to apply to URL.
998 *
999 * @example
1000 * ```js
1001 * const newURL = addQueryArgs( 'https://google.com', { q: 'test' } ); // https://google.com/?q=test
1002 * ```
1003 *
1004 * @return {string} URL with arguments applied.
1005 */
1006
1007 function addQueryArgs() {
1008 let url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
1009 let args = arguments.length > 1 ? arguments[1] : undefined;
1010
1011 // If no arguments are to be appended, return original URL.
1012 if (!args || !Object.keys(args).length) {
1013 return url;
1014 }
1015
1016 let baseUrl = url; // Determine whether URL already had query arguments.
1017
1018 const queryStringIndex = url.indexOf('?');
1019
1020 if (queryStringIndex !== -1) {
1021 // Merge into existing query arguments.
1022 args = Object.assign(getQueryArgs(url), args); // Change working base URL to omit previous query arguments.
1023
1024 baseUrl = baseUrl.substr(0, queryStringIndex);
1025 }
1026
1027 return baseUrl + '?' + buildQueryString(args);
1028 }
1029
1030 ;// CONCATENATED MODULE: ./packages/url/build-module/get-query-arg.js
1031 /**
1032 * Internal dependencies
1033 */
1034
1035 /**
1036 * @typedef {{[key: string]: QueryArgParsed}} QueryArgObject
1037 */
1038
1039 /**
1040 * @typedef {string|string[]|QueryArgObject} QueryArgParsed
1041 */
1042
1043 /**
1044 * Returns a single query argument of the url
1045 *
1046 * @param {string} url URL.
1047 * @param {string} arg Query arg name.
1048 *
1049 * @example
1050 * ```js
1051 * const foo = getQueryArg( 'https://wordpress.org?foo=bar&bar=baz', 'foo' ); // bar
1052 * ```
1053 *
1054 * @return {QueryArgParsed|void} Query arg value.
1055 */
1056
1057 function getQueryArg(url, arg) {
1058 return getQueryArgs(url)[arg];
1059 }
1060
1061 ;// CONCATENATED MODULE: ./packages/url/build-module/has-query-arg.js
1062 /**
1063 * Internal dependencies
1064 */
1065
1066 /**
1067 * Determines whether the URL contains a given query arg.
1068 *
1069 * @param {string} url URL.
1070 * @param {string} arg Query arg name.
1071 *
1072 * @example
1073 * ```js
1074 * const hasBar = hasQueryArg( 'https://wordpress.org?foo=bar&bar=baz', 'bar' ); // true
1075 * ```
1076 *
1077 * @return {boolean} Whether or not the URL contains the query arg.
1078 */
1079
1080 function hasQueryArg(url, arg) {
1081 return getQueryArg(url, arg) !== undefined;
1082 }
1083
1084 ;// CONCATENATED MODULE: ./packages/url/build-module/remove-query-args.js
1085 /**
1086 * Internal dependencies
1087 */
1088
1089
1090 /**
1091 * Removes arguments from the query string of the url
1092 *
1093 * @param {string} url URL.
1094 * @param {...string} args Query Args.
1095 *
1096 * @example
1097 * ```js
1098 * const newUrl = removeQueryArgs( 'https://wordpress.org?foo=bar&bar=baz&baz=foobar', 'foo', 'bar' ); // https://wordpress.org?baz=foobar
1099 * ```
1100 *
1101 * @return {string} Updated URL.
1102 */
1103
1104 function removeQueryArgs(url) {
1105 const queryStringIndex = url.indexOf('?');
1106
1107 if (queryStringIndex === -1) {
1108 return url;
1109 }
1110
1111 const query = getQueryArgs(url);
1112 const baseURL = url.substr(0, queryStringIndex);
1113
1114 for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
1115 args[_key - 1] = arguments[_key];
1116 }
1117
1118 args.forEach(arg => delete query[arg]);
1119 const queryString = buildQueryString(query);
1120 return queryString ? baseURL + '?' + queryString : baseURL;
1121 }
1122
1123 ;// CONCATENATED MODULE: ./packages/url/build-module/prepend-http.js
1124 /**
1125 * Internal dependencies
1126 */
1127
1128 const USABLE_HREF_REGEXP = /^(?:[a-z]+:|#|\?|\.|\/)/i;
1129 /**
1130 * Prepends "http://" to a url, if it looks like something that is meant to be a TLD.
1131 *
1132 * @param {string} url The URL to test.
1133 *
1134 * @example
1135 * ```js
1136 * const actualURL = prependHTTP( 'wordpress.org' ); // http://wordpress.org
1137 * ```
1138 *
1139 * @return {string} The updated URL.
1140 */
1141
1142 function prependHTTP(url) {
1143 if (!url) {
1144 return url;
1145 }
1146
1147 url = url.trim();
1148
1149 if (!USABLE_HREF_REGEXP.test(url) && !isEmail(url)) {
1150 return 'http://' + url;
1151 }
1152
1153 return url;
1154 }
1155
1156 ;// CONCATENATED MODULE: ./packages/url/build-module/safe-decode-uri.js
1157 /**
1158 * Safely decodes a URI with `decodeURI`. Returns the URI unmodified if
1159 * `decodeURI` throws an error.
1160 *
1161 * @param {string} uri URI to decode.
1162 *
1163 * @example
1164 * ```js
1165 * const badUri = safeDecodeURI( '%z' ); // does not throw an Error, simply returns '%z'
1166 * ```
1167 *
1168 * @return {string} Decoded URI if possible.
1169 */
1170 function safeDecodeURI(uri) {
1171 try {
1172 return decodeURI(uri);
1173 } catch (uriError) {
1174 return uri;
1175 }
1176 }
1177
1178 ;// CONCATENATED MODULE: ./packages/url/build-module/safe-decode-uri-component.js
1179 /**
1180 * Safely decodes a URI component with `decodeURIComponent`. Returns the URI component unmodified if
1181 * `decodeURIComponent` throws an error.
1182 *
1183 * @param {string} uriComponent URI component to decode.
1184 *
1185 * @return {string} Decoded URI component if possible.
1186 */
1187 function safeDecodeURIComponent(uriComponent) {
1188 try {
1189 return decodeURIComponent(uriComponent);
1190 } catch (uriComponentError) {
1191 return uriComponent;
1192 }
1193 }
1194
1195 ;// CONCATENATED MODULE: ./packages/url/build-module/filter-url-for-display.js
1196 /**
1197 * Returns a URL for display.
1198 *
1199 * @param {string} url Original URL.
1200 * @param {number|null} maxLength URL length.
1201 *
1202 * @example
1203 * ```js
1204 * const displayUrl = filterURLForDisplay( 'https://www.wordpress.org/gutenberg/' ); // wordpress.org/gutenberg
1205 * const imageUrl = filterURLForDisplay( 'https://www.wordpress.org/wp-content/uploads/img.png', 20 ); // …ent/uploads/img.png
1206 * ```
1207 *
1208 * @return {string} Displayed URL.
1209 */
1210 function filterURLForDisplay(url) {
1211 let maxLength = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
1212 // Remove protocol and www prefixes.
1213 let filteredURL = url.replace(/^(?:https?:)\/\/(?:www\.)?/, ''); // Ends with / and only has that single slash, strip it.
1214
1215 if (filteredURL.match(/^[^\/]+\/$/)) {
1216 filteredURL = filteredURL.replace('/', '');
1217 }
1218
1219 const mediaRegexp = /([\w|:])*\.(?:jpg|jpeg|gif|png|svg)/;
1220
1221 if (!maxLength || filteredURL.length <= maxLength || !filteredURL.match(mediaRegexp)) {
1222 return filteredURL;
1223 } // If the file is not greater than max length, return last portion of URL.
1224
1225
1226 filteredURL = filteredURL.split('?')[0];
1227 const urlPieces = filteredURL.split('/');
1228 const file = urlPieces[urlPieces.length - 1];
1229
1230 if (file.length <= maxLength) {
1231 return '' + filteredURL.slice(-maxLength);
1232 } // If the file is greater than max length, truncate the file.
1233
1234
1235 const index = file.lastIndexOf('.');
1236 const [fileName, extension] = [file.slice(0, index), file.slice(index + 1)];
1237 const truncatedFile = fileName.slice(-3) + '.' + extension;
1238 return file.slice(0, maxLength - truncatedFile.length - 1) + '' + truncatedFile;
1239 }
1240
1241 // EXTERNAL MODULE: ./node_modules/remove-accents/index.js
1242 var remove_accents = __webpack_require__(4793);
1243 var remove_accents_default = /*#__PURE__*/__webpack_require__.n(remove_accents);
1244 ;// CONCATENATED MODULE: ./packages/url/build-module/clean-for-slug.js
1245 /**
1246 * External dependencies
1247 */
1248
1249 /**
1250 * Performs some basic cleanup of a string for use as a post slug.
1251 *
1252 * This replicates some of what `sanitize_title()` does in WordPress core, but
1253 * is only designed to approximate what the slug will be.
1254 *
1255 * Converts Latin-1 Supplement and Latin Extended-A letters to basic Latin
1256 * letters. Removes combining diacritical marks. Converts whitespace, periods,
1257 * and forward slashes to hyphens. Removes any remaining non-word characters
1258 * except hyphens. Converts remaining string to lowercase. It does not account
1259 * for octets, HTML entities, or other encoded characters.
1260 *
1261 * @param {string} string Title or slug to be processed.
1262 *
1263 * @return {string} Processed string.
1264 */
1265
1266 function cleanForSlug(string) {
1267 if (!string) {
1268 return '';
1269 }
1270
1271 return remove_accents_default()(string) // Convert each group of whitespace, periods, and forward slashes to a hyphen.
1272 .replace(/[\s\./]+/g, '-') // Remove anything that's not a letter, number, underscore or hyphen.
1273 .replace(/[^\p{L}\p{N}_-]+/gu, '') // Convert to lowercase
1274 .toLowerCase() // Remove any remaining leading or trailing hyphens.
1275 .replace(/(^-+)|(-+$)/g, '');
1276 }
1277
1278 ;// CONCATENATED MODULE: ./packages/url/build-module/get-filename.js
1279 /**
1280 * Returns the filename part of the URL.
1281 *
1282 * @param {string} url The full URL.
1283 *
1284 * @example
1285 * ```js
1286 * const filename1 = getFilename( 'http://localhost:8080/this/is/a/test.jpg' ); // 'test.jpg'
1287 * const filename2 = getFilename( '/this/is/a/test.png' ); // 'test.png'
1288 * ```
1289 *
1290 * @return {string|void} The filename part of the URL.
1291 */
1292 function getFilename(url) {
1293 let filename;
1294
1295 try {
1296 filename = new URL(url, 'http://example.com').pathname.split('/').pop();
1297 } catch (error) {}
1298
1299 if (filename) {
1300 return filename;
1301 }
1302 }
1303
1304 ;// CONCATENATED MODULE: ./packages/url/build-module/normalize-path.js
1305 /**
1306 * Given a path, returns a normalized path where equal query parameter values
1307 * will be treated as identical, regardless of order they appear in the original
1308 * text.
1309 *
1310 * @param {string} path Original path.
1311 *
1312 * @return {string} Normalized path.
1313 */
1314 function normalizePath(path) {
1315 const splitted = path.split('?');
1316 const query = splitted[1];
1317 const base = splitted[0];
1318
1319 if (!query) {
1320 return base;
1321 } // 'b=1%2C2&c=2&a=5'
1322
1323
1324 return base + '?' + query // [ 'b=1%2C2', 'c=2', 'a=5' ]
1325 .split('&') // [ [ 'b, '1%2C2' ], [ 'c', '2' ], [ 'a', '5' ] ]
1326 .map(entry => entry.split('=')) // [ [ 'b', '1,2' ], [ 'c', '2' ], [ 'a', '5' ] ]
1327 .map(pair => pair.map(decodeURIComponent)) // [ [ 'a', '5' ], [ 'b, '1,2' ], [ 'c', '2' ] ]
1328 .sort((a, b) => a[0].localeCompare(b[0])) // [ [ 'a', '5' ], [ 'b, '1%2C2' ], [ 'c', '2' ] ]
1329 .map(pair => pair.map(encodeURIComponent)) // [ 'a=5', 'b=1%2C2', 'c=2' ]
1330 .map(pair => pair.join('=')) // 'a=5&b=1%2C2&c=2'
1331 .join('&');
1332 }
1333
1334 ;// CONCATENATED MODULE: ./packages/url/build-module/index.js
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362 })();
1363
1364 (window.wp = window.wp || {}).url = __webpack_exports__;
1365 /******/ })()
1366 ;