PluginProbe
Gutenberg / 19.6.0
Gutenberg v19.6.0
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 19.6.0, at build/url/index.js

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