@wordpress/url 3.40.0 → 3.41.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/build/add-query-args.js +4 -8
- package/build/add-query-args.js.map +1 -1
- package/build/build-query-string.js +5 -9
- package/build/build-query-string.js.map +1 -1
- package/build/clean-for-slug.js +10 -9
- package/build/clean-for-slug.js.map +1 -1
- package/build/filter-url-for-display.js +6 -9
- package/build/filter-url-for-display.js.map +1 -1
- package/build/get-authority.js +0 -2
- package/build/get-authority.js.map +1 -1
- package/build/get-filename.js +0 -3
- package/build/get-filename.js.map +1 -1
- package/build/get-fragment.js +0 -2
- package/build/get-fragment.js.map +1 -1
- package/build/get-path-and-query-string.js +0 -2
- package/build/get-path-and-query-string.js.map +1 -1
- package/build/get-path.js +0 -2
- package/build/get-path.js.map +1 -1
- package/build/get-protocol.js +0 -2
- package/build/get-protocol.js.map +1 -1
- package/build/get-query-arg.js +0 -2
- package/build/get-query-arg.js.map +1 -1
- package/build/get-query-args.js +15 -19
- package/build/get-query-args.js.map +1 -1
- package/build/get-query-string.js +0 -3
- package/build/get-query-string.js.map +1 -1
- package/build/has-query-arg.js +0 -2
- package/build/has-query-arg.js.map +1 -1
- package/build/index.js +0 -27
- package/build/index.js.map +1 -1
- package/build/is-email.js +1 -1
- package/build/is-email.js.map +1 -1
- package/build/is-url.js +0 -1
- package/build/is-url.js.map +1 -1
- package/build/is-valid-authority.js +0 -2
- package/build/is-valid-authority.js.map +1 -1
- package/build/is-valid-fragment.js +0 -2
- package/build/is-valid-fragment.js.map +1 -1
- package/build/is-valid-path.js +0 -2
- package/build/is-valid-path.js.map +1 -1
- package/build/is-valid-protocol.js +0 -2
- package/build/is-valid-protocol.js.map +1 -1
- package/build/is-valid-query-string.js +0 -2
- package/build/is-valid-query-string.js.map +1 -1
- package/build/normalize-path.js +16 -11
- package/build/normalize-path.js.map +1 -1
- package/build/prepend-http.js +2 -6
- package/build/prepend-http.js.map +1 -1
- package/build/prepend-https.js +2 -5
- package/build/prepend-https.js.map +1 -1
- package/build/remove-query-args.js +0 -5
- package/build/remove-query-args.js.map +1 -1
- package/build/safe-decode-uri-component.js +0 -1
- package/build/safe-decode-uri-component.js.map +1 -1
- package/build/safe-decode-uri.js +0 -1
- package/build/safe-decode-uri.js.map +1 -1
- package/build-module/add-query-args.js +5 -6
- package/build-module/add-query-args.js.map +1 -1
- package/build-module/build-query-string.js +5 -8
- package/build-module/build-query-string.js.map +1 -1
- package/build-module/clean-for-slug.js +11 -7
- package/build-module/clean-for-slug.js.map +1 -1
- package/build-module/filter-url-for-display.js +6 -8
- package/build-module/filter-url-for-display.js.map +1 -1
- package/build-module/get-authority.js +0 -1
- package/build-module/get-authority.js.map +1 -1
- package/build-module/get-filename.js +0 -2
- package/build-module/get-filename.js.map +1 -1
- package/build-module/get-fragment.js +0 -1
- package/build-module/get-fragment.js.map +1 -1
- package/build-module/get-path-and-query-string.js +1 -1
- package/build-module/get-path-and-query-string.js.map +1 -1
- package/build-module/get-path.js +0 -1
- package/build-module/get-path.js.map +1 -1
- package/build-module/get-protocol.js +0 -1
- package/build-module/get-protocol.js.map +1 -1
- package/build-module/get-query-arg.js +1 -1
- package/build-module/get-query-arg.js.map +1 -1
- package/build-module/get-query-args.js +16 -17
- package/build-module/get-query-args.js.map +1 -1
- package/build-module/get-query-string.js +0 -2
- package/build-module/get-query-string.js.map +1 -1
- package/build-module/has-query-arg.js +1 -1
- package/build-module/has-query-arg.js.map +1 -1
- package/build-module/index.js.map +1 -1
- package/build-module/is-email.js +1 -1
- package/build-module/is-email.js.map +1 -1
- package/build-module/is-url.js.map +1 -1
- package/build-module/is-valid-authority.js +0 -1
- package/build-module/is-valid-authority.js.map +1 -1
- package/build-module/is-valid-fragment.js +0 -1
- package/build-module/is-valid-fragment.js.map +1 -1
- package/build-module/is-valid-path.js +0 -1
- package/build-module/is-valid-path.js.map +1 -1
- package/build-module/is-valid-protocol.js +0 -1
- package/build-module/is-valid-protocol.js.map +1 -1
- package/build-module/is-valid-query-string.js +0 -1
- package/build-module/is-valid-query-string.js.map +1 -1
- package/build-module/normalize-path.js +16 -10
- package/build-module/normalize-path.js.map +1 -1
- package/build-module/prepend-http.js +1 -4
- package/build-module/prepend-http.js.map +1 -1
- package/build-module/prepend-https.js +3 -4
- package/build-module/prepend-https.js.map +1 -1
- package/build-module/remove-query-args.js +1 -3
- package/build-module/remove-query-args.js.map +1 -1
- package/build-module/safe-decode-uri-component.js.map +1 -1
- package/build-module/safe-decode-uri.js.map +1 -1
- package/package.json +3 -3
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -14,28 +14,26 @@
|
|
|
14
14
|
*/
|
|
15
15
|
export function filterURLForDisplay(url, maxLength = null) {
|
|
16
16
|
// Remove protocol and www prefixes.
|
|
17
|
-
let filteredURL = url.replace(/^(?:https?:)\/\/(?:www\.)?/, '');
|
|
17
|
+
let filteredURL = url.replace(/^(?:https?:)\/\/(?:www\.)?/, '');
|
|
18
18
|
|
|
19
|
+
// Ends with / and only has that single slash, strip it.
|
|
19
20
|
if (filteredURL.match(/^[^\/]+\/$/)) {
|
|
20
21
|
filteredURL = filteredURL.replace('/', '');
|
|
21
22
|
}
|
|
22
|
-
|
|
23
23
|
const mediaRegexp = /([\w|:])*\.(?:jpg|jpeg|gif|png|svg)/;
|
|
24
|
-
|
|
25
24
|
if (!maxLength || filteredURL.length <= maxLength || !filteredURL.match(mediaRegexp)) {
|
|
26
25
|
return filteredURL;
|
|
27
|
-
}
|
|
28
|
-
|
|
26
|
+
}
|
|
29
27
|
|
|
28
|
+
// If the file is not greater than max length, return last portion of URL.
|
|
30
29
|
filteredURL = filteredURL.split('?')[0];
|
|
31
30
|
const urlPieces = filteredURL.split('/');
|
|
32
31
|
const file = urlPieces[urlPieces.length - 1];
|
|
33
|
-
|
|
34
32
|
if (file.length <= maxLength) {
|
|
35
33
|
return '…' + filteredURL.slice(-maxLength);
|
|
36
|
-
}
|
|
37
|
-
|
|
34
|
+
}
|
|
38
35
|
|
|
36
|
+
// If the file is greater than max length, truncate the file.
|
|
39
37
|
const index = file.lastIndexOf('.');
|
|
40
38
|
const [fileName, extension] = [file.slice(0, index), file.slice(index + 1)];
|
|
41
39
|
const truncatedFile = fileName.slice(-3) + '.' + extension;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["filterURLForDisplay","url","maxLength","filteredURL","replace","match","mediaRegexp","length","split","urlPieces","file","slice","index","lastIndexOf","fileName","extension","truncatedFile"],"sources":["@wordpress/url/src/filter-url-for-display.js"],"sourcesContent":["/**\n * Returns a URL for display.\n *\n * @param {string} url Original URL.\n * @param {number|null} maxLength URL length.\n *\n * @example\n * ```js\n * const displayUrl = filterURLForDisplay( 'https://www.wordpress.org/gutenberg/' ); // wordpress.org/gutenberg\n * const imageUrl = filterURLForDisplay( 'https://www.wordpress.org/wp-content/uploads/img.png', 20 ); // …ent/uploads/img.png\n * ```\n *\n * @return {string} Displayed URL.\n */\nexport function filterURLForDisplay( url, maxLength = null ) {\n\t// Remove protocol and www prefixes.\n\tlet filteredURL = url.replace( /^(?:https?:)\\/\\/(?:www\\.)?/, '' );\n\n\t// Ends with / and only has that single slash, strip it.\n\tif ( filteredURL.match( /^[^\\/]+\\/$/ ) ) {\n\t\tfilteredURL = filteredURL.replace( '/', '' );\n\t}\n\n\tconst mediaRegexp = /([\\w|:])*\\.(?:jpg|jpeg|gif|png|svg)/;\n\n\tif (\n\t\t! maxLength ||\n\t\tfilteredURL.length <= maxLength ||\n\t\t! filteredURL.match( mediaRegexp )\n\t) {\n\t\treturn filteredURL;\n\t}\n\n\t// If the file is not greater than max length, return last portion of URL.\n\tfilteredURL = filteredURL.split( '?' )[ 0 ];\n\tconst urlPieces = filteredURL.split( '/' );\n\tconst file = urlPieces[ urlPieces.length - 1 ];\n\tif ( file.length <= maxLength ) {\n\t\treturn '…' + filteredURL.slice( -maxLength );\n\t}\n\n\t// If the file is greater than max length, truncate the file.\n\tconst index = file.lastIndexOf( '.' );\n\tconst [ fileName, extension ] = [\n\t\tfile.slice( 0, index ),\n\t\tfile.slice( index + 1 ),\n\t];\n\tconst truncatedFile = fileName.slice( -3 ) + '.' + extension;\n\treturn (\n\t\tfile.slice( 0, maxLength - truncatedFile.length - 1 ) +\n\t\t'…' +\n\t\ttruncatedFile\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,mBAAmBA,CAAEC,GAAG,EAAEC,SAAS,GAAG,IAAI,EAAG;EAC5D;EACA,IAAIC,WAAW,GAAGF,GAAG,CAACG,OAAO,CAAE,4BAA4B,EAAE,EAAG,CAAC;;EAEjE;EACA,IAAKD,WAAW,CAACE,KAAK,CAAE,YAAa,CAAC,EAAG;IACxCF,WAAW,GAAGA,WAAW,CAACC,OAAO,CAAE,GAAG,EAAE,EAAG,CAAC;EAC7C;EAEA,MAAME,WAAW,GAAG,qCAAqC;EAEzD,IACC,CAAEJ,SAAS,IACXC,WAAW,CAACI,MAAM,IAAIL,SAAS,IAC/B,CAAEC,WAAW,CAACE,KAAK,CAAEC,WAAY,CAAC,EACjC;IACD,OAAOH,WAAW;EACnB;;EAEA;EACAA,WAAW,GAAGA,WAAW,CAACK,KAAK,CAAE,GAAI,CAAC,CAAE,CAAC,CAAE;EAC3C,MAAMC,SAAS,GAAGN,WAAW,CAACK,KAAK,CAAE,GAAI,CAAC;EAC1C,MAAME,IAAI,GAAGD,SAAS,CAAEA,SAAS,CAACF,MAAM,GAAG,CAAC,CAAE;EAC9C,IAAKG,IAAI,CAACH,MAAM,IAAIL,SAAS,EAAG;IAC/B,OAAO,GAAG,GAAGC,WAAW,CAACQ,KAAK,CAAE,CAACT,SAAU,CAAC;EAC7C;;EAEA;EACA,MAAMU,KAAK,GAAGF,IAAI,CAACG,WAAW,CAAE,GAAI,CAAC;EACrC,MAAM,CAAEC,QAAQ,EAAEC,SAAS,CAAE,GAAG,CAC/BL,IAAI,CAACC,KAAK,CAAE,CAAC,EAAEC,KAAM,CAAC,EACtBF,IAAI,CAACC,KAAK,CAAEC,KAAK,GAAG,CAAE,CAAC,CACvB;EACD,MAAMI,aAAa,GAAGF,QAAQ,CAACH,KAAK,CAAE,CAAC,CAAE,CAAC,GAAG,GAAG,GAAGI,SAAS;EAC5D,OACCL,IAAI,CAACC,KAAK,CAAE,CAAC,EAAET,SAAS,GAAGc,aAAa,CAACT,MAAM,GAAG,CAAE,CAAC,GACrD,GAAG,GACHS,aAAa;AAEf"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["getAuthority","url","matches","exec"],"sources":["@wordpress/url/src/get-authority.js"],"sourcesContent":["/**\n * Returns the authority part of the URL.\n *\n * @param {string} url The full URL.\n *\n * @example\n * ```js\n * const authority1 = getAuthority( 'https://wordpress.org/help/' ); // 'wordpress.org'\n * const authority2 = getAuthority( 'https://localhost:8080/test/' ); // 'localhost:8080'\n * ```\n *\n * @return {string|void} The authority part of the URL.\n */\nexport function getAuthority( url ) {\n\tconst matches = /^[^\\/\\s:]+:(?:\\/\\/)?\\/?([^\\/\\s#?]+)[\\/#?]{0,1}\\S*$/.exec(\n\t\turl\n\t);\n\tif ( matches ) {\n\t\treturn matches[ 1 ];\n\t}\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,YAAYA,CAAEC,GAAG,EAAG;EACnC,MAAMC,OAAO,GAAG,oDAAoD,CAACC,IAAI,CACxEF,GACD,CAAC;EACD,IAAKC,OAAO,EAAG;IACd,OAAOA,OAAO,CAAE,CAAC,CAAE;EACpB;AACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["getFilename","url","filename","URL","pathname","split","pop","error"],"sources":["@wordpress/url/src/get-filename.js"],"sourcesContent":["/**\n * Returns the filename part of the URL.\n *\n * @param {string} url The full URL.\n *\n * @example\n * ```js\n * const filename1 = getFilename( 'http://localhost:8080/this/is/a/test.jpg' ); // 'test.jpg'\n * const filename2 = getFilename( '/this/is/a/test.png' ); // 'test.png'\n * ```\n *\n * @return {string|void} The filename part of the URL.\n */\nexport function getFilename( url ) {\n\tlet filename;\n\ttry {\n\t\tfilename = new URL( url, 'http://example.com' ).pathname\n\t\t\t.split( '/' )\n\t\t\t.pop();\n\t} catch ( error ) {}\n\n\tif ( filename ) {\n\t\treturn filename;\n\t}\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,WAAWA,CAAEC,GAAG,EAAG;EAClC,IAAIC,QAAQ;EACZ,IAAI;IACHA,QAAQ,GAAG,IAAIC,GAAG,CAAEF,GAAG,EAAE,oBAAqB,CAAC,CAACG,QAAQ,CACtDC,KAAK,CAAE,GAAI,CAAC,CACZC,GAAG,CAAC,CAAC;EACR,CAAC,CAAC,OAAQC,KAAK,EAAG,CAAC;EAEnB,IAAKL,QAAQ,EAAG;IACf,OAAOA,QAAQ;EAChB;AACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["getFragment","url","matches","exec"],"sources":["@wordpress/url/src/get-fragment.js"],"sourcesContent":["/**\n * Returns the fragment part of the URL.\n *\n * @param {string} url The full URL\n *\n * @example\n * ```js\n * const fragment1 = getFragment( 'http://localhost:8080/this/is/a/test?query=true#fragment' ); // '#fragment'\n * const fragment2 = getFragment( 'https://wordpress.org#another-fragment?query=true' ); // '#another-fragment'\n * ```\n *\n * @return {string|void} The fragment part of the URL.\n */\nexport function getFragment( url ) {\n\tconst matches = /^\\S+?(#[^\\s\\?]*)/.exec( url );\n\tif ( matches ) {\n\t\treturn matches[ 1 ];\n\t}\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,WAAWA,CAAEC,GAAG,EAAG;EAClC,MAAMC,OAAO,GAAG,kBAAkB,CAACC,IAAI,CAAEF,GAAI,CAAC;EAC9C,IAAKC,OAAO,EAAG;IACd,OAAOA,OAAO,CAAE,CAAC,CAAE;EACpB;AACD"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Internal dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { getPath, getQueryString } from '.';
|
|
5
|
+
|
|
5
6
|
/**
|
|
6
7
|
* Returns the path part and query string part of the URL.
|
|
7
8
|
*
|
|
@@ -15,7 +16,6 @@ import { getPath, getQueryString } from '.';
|
|
|
15
16
|
*
|
|
16
17
|
* @return {string} The path part and query string part of the URL.
|
|
17
18
|
*/
|
|
18
|
-
|
|
19
19
|
export function getPathAndQueryString(url) {
|
|
20
20
|
const path = getPath(url);
|
|
21
21
|
const queryString = getQueryString(url);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["getPath","getQueryString","getPathAndQueryString","url","path","queryString","value"],"sources":["@wordpress/url/src/get-path-and-query-string.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { getPath, getQueryString } from '.';\n\n/**\n * Returns the path part and query string part of the URL.\n *\n * @param {string} url The full URL.\n *\n * @example\n * ```js\n * const pathAndQueryString1 = getPathAndQueryString( 'http://localhost:8080/this/is/a/test?query=true' ); // '/this/is/a/test?query=true'\n * const pathAndQueryString2 = getPathAndQueryString( 'https://wordpress.org/help/faq/' ); // '/help/faq'\n * ```\n *\n * @return {string} The path part and query string part of the URL.\n */\nexport function getPathAndQueryString( url ) {\n\tconst path = getPath( url );\n\tconst queryString = getQueryString( url );\n\tlet value = '/';\n\tif ( path ) value += path;\n\tif ( queryString ) value += `?${ queryString }`;\n\treturn value;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,OAAO,EAAEC,cAAc,QAAQ,GAAG;;AAE3C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,qBAAqBA,CAAEC,GAAG,EAAG;EAC5C,MAAMC,IAAI,GAAGJ,OAAO,CAAEG,GAAI,CAAC;EAC3B,MAAME,WAAW,GAAGJ,cAAc,CAAEE,GAAI,CAAC;EACzC,IAAIG,KAAK,GAAG,GAAG;EACf,IAAKF,IAAI,EAAGE,KAAK,IAAIF,IAAI;EACzB,IAAKC,WAAW,EAAGC,KAAK,IAAK,IAAID,WAAa,EAAC;EAC/C,OAAOC,KAAK;AACb"}
|
package/build-module/get-path.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["getPath","url","matches","exec"],"sources":["@wordpress/url/src/get-path.js"],"sourcesContent":["/**\n * Returns the path part of the URL.\n *\n * @param {string} url The full URL.\n *\n * @example\n * ```js\n * const path1 = getPath( 'http://localhost:8080/this/is/a/test?query=true' ); // 'this/is/a/test'\n * const path2 = getPath( 'https://wordpress.org/help/faq/' ); // 'help/faq'\n * ```\n *\n * @return {string|void} The path part of the URL.\n */\nexport function getPath( url ) {\n\tconst matches =\n\t\t/^[^\\/\\s:]+:(?:\\/\\/)?[^\\/\\s#?]+[\\/]([^\\s#?]+)[#?]{0,1}\\S*$/.exec( url );\n\tif ( matches ) {\n\t\treturn matches[ 1 ];\n\t}\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,OAAOA,CAAEC,GAAG,EAAG;EAC9B,MAAMC,OAAO,GACZ,2DAA2D,CAACC,IAAI,CAAEF,GAAI,CAAC;EACxE,IAAKC,OAAO,EAAG;IACd,OAAOA,OAAO,CAAE,CAAC,CAAE;EACpB;AACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["getProtocol","url","matches","exec"],"sources":["@wordpress/url/src/get-protocol.js"],"sourcesContent":["/**\n * Returns the protocol part of the URL.\n *\n * @param {string} url The full URL.\n *\n * @example\n * ```js\n * const protocol1 = getProtocol( 'tel:012345678' ); // 'tel:'\n * const protocol2 = getProtocol( 'https://wordpress.org' ); // 'https:'\n * ```\n *\n * @return {string|void} The protocol part of the URL.\n */\nexport function getProtocol( url ) {\n\tconst matches = /^([^\\s:]+:)/.exec( url );\n\tif ( matches ) {\n\t\treturn matches[ 1 ];\n\t}\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,WAAWA,CAAEC,GAAG,EAAG;EAClC,MAAMC,OAAO,GAAG,aAAa,CAACC,IAAI,CAAEF,GAAI,CAAC;EACzC,IAAKC,OAAO,EAAG;IACd,OAAOA,OAAO,CAAE,CAAC,CAAE;EACpB;AACD"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Internal dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { getQueryArgs } from './get-query-args';
|
|
5
|
+
|
|
5
6
|
/**
|
|
6
7
|
* @typedef {{[key: string]: QueryArgParsed}} QueryArgObject
|
|
7
8
|
*/
|
|
@@ -23,7 +24,6 @@ import { getQueryArgs } from './get-query-args';
|
|
|
23
24
|
*
|
|
24
25
|
* @return {QueryArgParsed|void} Query arg value.
|
|
25
26
|
*/
|
|
26
|
-
|
|
27
27
|
export function getQueryArg(url, arg) {
|
|
28
28
|
return getQueryArgs(url)[arg];
|
|
29
29
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["getQueryArgs","getQueryArg","url","arg"],"sources":["@wordpress/url/src/get-query-arg.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { getQueryArgs } from './get-query-args';\n\n/**\n * @typedef {{[key: string]: QueryArgParsed}} QueryArgObject\n */\n\n/**\n * @typedef {string|string[]|QueryArgObject} QueryArgParsed\n */\n\n/**\n * Returns a single query argument of the url\n *\n * @param {string} url URL.\n * @param {string} arg Query arg name.\n *\n * @example\n * ```js\n * const foo = getQueryArg( 'https://wordpress.org?foo=bar&bar=baz', 'foo' ); // bar\n * ```\n *\n * @return {QueryArgParsed|void} Query arg value.\n */\nexport function getQueryArg( url, arg ) {\n\treturn getQueryArgs( url )[ arg ];\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,YAAY,QAAQ,kBAAkB;;AAE/C;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,WAAWA,CAAEC,GAAG,EAAEC,GAAG,EAAG;EACvC,OAAOH,YAAY,CAAEE,GAAI,CAAC,CAAEC,GAAG,CAAE;AAClC"}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { safeDecodeURIComponent } from './safe-decode-uri-component';
|
|
5
5
|
import { getQueryString } from './get-query-string';
|
|
6
|
+
|
|
6
7
|
/** @typedef {import('./get-query-arg').QueryArgParsed} QueryArgParsed */
|
|
7
8
|
|
|
8
9
|
/**
|
|
@@ -17,40 +18,40 @@ import { getQueryString } from './get-query-string';
|
|
|
17
18
|
* @param {string[]} path Path segment at which to set value.
|
|
18
19
|
* @param {*} value Value to set.
|
|
19
20
|
*/
|
|
20
|
-
|
|
21
21
|
function setPath(object, path, value) {
|
|
22
22
|
const length = path.length;
|
|
23
23
|
const lastIndex = length - 1;
|
|
24
|
-
|
|
25
24
|
for (let i = 0; i < length; i++) {
|
|
26
25
|
let key = path[i];
|
|
27
|
-
|
|
28
26
|
if (!key && Array.isArray(object)) {
|
|
29
27
|
// If key is empty string and next value is array, derive key from
|
|
30
28
|
// the current length of the array.
|
|
31
29
|
key = object.length.toString();
|
|
32
30
|
}
|
|
31
|
+
key = ['__proto__', 'constructor', 'prototype'].includes(key) ? key.toUpperCase() : key;
|
|
33
32
|
|
|
34
|
-
|
|
33
|
+
// If the next key in the path is numeric (or empty string), it will be
|
|
35
34
|
// created as an array. Otherwise, it will be created as an object.
|
|
36
|
-
|
|
37
35
|
const isNextKeyArrayIndex = !isNaN(Number(path[i + 1]));
|
|
38
|
-
object[key] = i === lastIndex ?
|
|
39
|
-
|
|
36
|
+
object[key] = i === lastIndex ?
|
|
37
|
+
// If at end of path, assign the intended value.
|
|
38
|
+
value :
|
|
39
|
+
// Otherwise, advance to the next object in the path, creating
|
|
40
40
|
// it if it does not yet exist.
|
|
41
41
|
object[key] || (isNextKeyArrayIndex ? [] : {});
|
|
42
|
-
|
|
43
42
|
if (Array.isArray(object[key]) && !isNextKeyArrayIndex) {
|
|
44
43
|
// If we current key is non-numeric, but the next value is an
|
|
45
44
|
// array, coerce the value to an object.
|
|
46
|
-
object[key] = {
|
|
45
|
+
object[key] = {
|
|
46
|
+
...object[key]
|
|
47
47
|
};
|
|
48
|
-
}
|
|
49
|
-
|
|
48
|
+
}
|
|
50
49
|
|
|
50
|
+
// Update working reference object to the next in the path.
|
|
51
51
|
object = object[key];
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
+
|
|
54
55
|
/**
|
|
55
56
|
* Returns an object of query arguments of the given URL. If the given URL is
|
|
56
57
|
* invalid or has no querystring, an empty object is returned.
|
|
@@ -65,23 +66,21 @@ function setPath(object, path, value) {
|
|
|
65
66
|
*
|
|
66
67
|
* @return {QueryArgs} Query args object.
|
|
67
68
|
*/
|
|
68
|
-
|
|
69
|
-
|
|
70
69
|
export function getQueryArgs(url) {
|
|
71
|
-
return (getQueryString(url) || ''
|
|
70
|
+
return (getQueryString(url) || ''
|
|
71
|
+
// Normalize space encoding, accounting for PHP URL encoding
|
|
72
72
|
// corresponding to `application/x-www-form-urlencoded`.
|
|
73
73
|
//
|
|
74
74
|
// See: https://tools.ietf.org/html/rfc1866#section-8.2.1
|
|
75
75
|
).replace(/\+/g, '%20').split('&').reduce((accumulator, keyValue) => {
|
|
76
|
-
const [key, value = ''] = keyValue.split('=')
|
|
76
|
+
const [key, value = ''] = keyValue.split('=')
|
|
77
|
+
// Filtering avoids decoding as `undefined` for value, where
|
|
77
78
|
// default is restored in destructuring assignment.
|
|
78
79
|
.filter(Boolean).map(safeDecodeURIComponent);
|
|
79
|
-
|
|
80
80
|
if (key) {
|
|
81
81
|
const segments = key.replace(/\]/g, '').split('[');
|
|
82
82
|
setPath(accumulator, segments, value);
|
|
83
83
|
}
|
|
84
|
-
|
|
85
84
|
return accumulator;
|
|
86
85
|
}, Object.create(null));
|
|
87
86
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["safeDecodeURIComponent","getQueryString","setPath","object","path","value","length","lastIndex","i","key","Array","isArray","toString","includes","toUpperCase","isNextKeyArrayIndex","isNaN","Number","getQueryArgs","url","replace","split","reduce","accumulator","keyValue","filter","Boolean","map","segments","Object","create"],"sources":["@wordpress/url/src/get-query-args.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { safeDecodeURIComponent } from './safe-decode-uri-component';\nimport { getQueryString } from './get-query-string';\n\n/** @typedef {import('./get-query-arg').QueryArgParsed} QueryArgParsed */\n\n/**\n * @typedef {Record<string,QueryArgParsed>} QueryArgs\n */\n\n/**\n * Sets a value in object deeply by a given array of path segments. Mutates the\n * object reference.\n *\n * @param {Record<string,*>} object Object in which to assign.\n * @param {string[]} path Path segment at which to set value.\n * @param {*} value Value to set.\n */\nfunction setPath( object, path, value ) {\n\tconst length = path.length;\n\tconst lastIndex = length - 1;\n\tfor ( let i = 0; i < length; i++ ) {\n\t\tlet key = path[ i ];\n\n\t\tif ( ! key && Array.isArray( object ) ) {\n\t\t\t// If key is empty string and next value is array, derive key from\n\t\t\t// the current length of the array.\n\t\t\tkey = object.length.toString();\n\t\t}\n\n\t\tkey = [ '__proto__', 'constructor', 'prototype' ].includes( key )\n\t\t\t? key.toUpperCase()\n\t\t\t: key;\n\n\t\t// If the next key in the path is numeric (or empty string), it will be\n\t\t// created as an array. Otherwise, it will be created as an object.\n\t\tconst isNextKeyArrayIndex = ! isNaN( Number( path[ i + 1 ] ) );\n\n\t\tobject[ key ] =\n\t\t\ti === lastIndex\n\t\t\t\t? // If at end of path, assign the intended value.\n\t\t\t\t value\n\t\t\t\t: // Otherwise, advance to the next object in the path, creating\n\t\t\t\t // it if it does not yet exist.\n\t\t\t\t object[ key ] || ( isNextKeyArrayIndex ? [] : {} );\n\n\t\tif ( Array.isArray( object[ key ] ) && ! isNextKeyArrayIndex ) {\n\t\t\t// If we current key is non-numeric, but the next value is an\n\t\t\t// array, coerce the value to an object.\n\t\t\tobject[ key ] = { ...object[ key ] };\n\t\t}\n\n\t\t// Update working reference object to the next in the path.\n\t\tobject = object[ key ];\n\t}\n}\n\n/**\n * Returns an object of query arguments of the given URL. If the given URL is\n * invalid or has no querystring, an empty object is returned.\n *\n * @param {string} url URL.\n *\n * @example\n * ```js\n * const foo = getQueryArgs( 'https://wordpress.org?foo=bar&bar=baz' );\n * // { \"foo\": \"bar\", \"bar\": \"baz\" }\n * ```\n *\n * @return {QueryArgs} Query args object.\n */\nexport function getQueryArgs( url ) {\n\treturn (\n\t\t( getQueryString( url ) || '' )\n\t\t\t// Normalize space encoding, accounting for PHP URL encoding\n\t\t\t// corresponding to `application/x-www-form-urlencoded`.\n\t\t\t//\n\t\t\t// See: https://tools.ietf.org/html/rfc1866#section-8.2.1\n\t\t\t.replace( /\\+/g, '%20' )\n\t\t\t.split( '&' )\n\t\t\t.reduce( ( accumulator, keyValue ) => {\n\t\t\t\tconst [ key, value = '' ] = keyValue\n\t\t\t\t\t.split( '=' )\n\t\t\t\t\t// Filtering avoids decoding as `undefined` for value, where\n\t\t\t\t\t// default is restored in destructuring assignment.\n\t\t\t\t\t.filter( Boolean )\n\t\t\t\t\t.map( safeDecodeURIComponent );\n\n\t\t\t\tif ( key ) {\n\t\t\t\t\tconst segments = key.replace( /\\]/g, '' ).split( '[' );\n\t\t\t\t\tsetPath( accumulator, segments, value );\n\t\t\t\t}\n\n\t\t\t\treturn accumulator;\n\t\t\t}, Object.create( null ) )\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,sBAAsB,QAAQ,6BAA6B;AACpE,SAASC,cAAc,QAAQ,oBAAoB;;AAEnD;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,OAAOA,CAAEC,MAAM,EAAEC,IAAI,EAAEC,KAAK,EAAG;EACvC,MAAMC,MAAM,GAAGF,IAAI,CAACE,MAAM;EAC1B,MAAMC,SAAS,GAAGD,MAAM,GAAG,CAAC;EAC5B,KAAM,IAAIE,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGF,MAAM,EAAEE,CAAC,EAAE,EAAG;IAClC,IAAIC,GAAG,GAAGL,IAAI,CAAEI,CAAC,CAAE;IAEnB,IAAK,CAAEC,GAAG,IAAIC,KAAK,CAACC,OAAO,CAAER,MAAO,CAAC,EAAG;MACvC;MACA;MACAM,GAAG,GAAGN,MAAM,CAACG,MAAM,CAACM,QAAQ,CAAC,CAAC;IAC/B;IAEAH,GAAG,GAAG,CAAE,WAAW,EAAE,aAAa,EAAE,WAAW,CAAE,CAACI,QAAQ,CAAEJ,GAAI,CAAC,GAC9DA,GAAG,CAACK,WAAW,CAAC,CAAC,GACjBL,GAAG;;IAEN;IACA;IACA,MAAMM,mBAAmB,GAAG,CAAEC,KAAK,CAAEC,MAAM,CAAEb,IAAI,CAAEI,CAAC,GAAG,CAAC,CAAG,CAAE,CAAC;IAE9DL,MAAM,CAAEM,GAAG,CAAE,GACZD,CAAC,KAAKD,SAAS;IACZ;IACAF,KAAK;IACL;IACA;IACAF,MAAM,CAAEM,GAAG,CAAE,KAAMM,mBAAmB,GAAG,EAAE,GAAG,CAAC,CAAC,CAAE;IAEtD,IAAKL,KAAK,CAACC,OAAO,CAAER,MAAM,CAAEM,GAAG,CAAG,CAAC,IAAI,CAAEM,mBAAmB,EAAG;MAC9D;MACA;MACAZ,MAAM,CAAEM,GAAG,CAAE,GAAG;QAAE,GAAGN,MAAM,CAAEM,GAAG;MAAG,CAAC;IACrC;;IAEA;IACAN,MAAM,GAAGA,MAAM,CAAEM,GAAG,CAAE;EACvB;AACD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASS,YAAYA,CAAEC,GAAG,EAAG;EACnC,OACC,CAAElB,cAAc,CAAEkB,GAAI,CAAC,IAAI;EAC1B;EACA;EACA;EACA;EAAA,EACCC,OAAO,CAAE,KAAK,EAAE,KAAM,CAAC,CACvBC,KAAK,CAAE,GAAI,CAAC,CACZC,MAAM,CAAE,CAAEC,WAAW,EAAEC,QAAQ,KAAM;IACrC,MAAM,CAAEf,GAAG,EAAEJ,KAAK,GAAG,EAAE,CAAE,GAAGmB,QAAQ,CAClCH,KAAK,CAAE,GAAI;IACZ;IACA;IAAA,CACCI,MAAM,CAAEC,OAAQ,CAAC,CACjBC,GAAG,CAAE3B,sBAAuB,CAAC;IAE/B,IAAKS,GAAG,EAAG;MACV,MAAMmB,QAAQ,GAAGnB,GAAG,CAACW,OAAO,CAAE,KAAK,EAAE,EAAG,CAAC,CAACC,KAAK,CAAE,GAAI,CAAC;MACtDnB,OAAO,CAAEqB,WAAW,EAAEK,QAAQ,EAAEvB,KAAM,CAAC;IACxC;IAEA,OAAOkB,WAAW;EACnB,CAAC,EAAEM,MAAM,CAACC,MAAM,CAAE,IAAK,CAAE,CAAC;AAE7B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["getQueryString","url","query","URL","search","substring","error"],"sources":["@wordpress/url/src/get-query-string.js"],"sourcesContent":["/**\n * Returns the query string part of the URL.\n *\n * @param {string} url The full URL.\n *\n * @example\n * ```js\n * const queryString = getQueryString( 'http://localhost:8080/this/is/a/test?query=true#fragment' ); // 'query=true'\n * ```\n *\n * @return {string|void} The query string part of the URL.\n */\nexport function getQueryString( url ) {\n\tlet query;\n\ttry {\n\t\tquery = new URL( url, 'http://example.com' ).search.substring( 1 );\n\t} catch ( error ) {}\n\n\tif ( query ) {\n\t\treturn query;\n\t}\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,cAAcA,CAAEC,GAAG,EAAG;EACrC,IAAIC,KAAK;EACT,IAAI;IACHA,KAAK,GAAG,IAAIC,GAAG,CAAEF,GAAG,EAAE,oBAAqB,CAAC,CAACG,MAAM,CAACC,SAAS,CAAE,CAAE,CAAC;EACnE,CAAC,CAAC,OAAQC,KAAK,EAAG,CAAC;EAEnB,IAAKJ,KAAK,EAAG;IACZ,OAAOA,KAAK;EACb;AACD"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Internal dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { getQueryArg } from './get-query-arg';
|
|
5
|
+
|
|
5
6
|
/**
|
|
6
7
|
* Determines whether the URL contains a given query arg.
|
|
7
8
|
*
|
|
@@ -15,7 +16,6 @@ import { getQueryArg } from './get-query-arg';
|
|
|
15
16
|
*
|
|
16
17
|
* @return {boolean} Whether or not the URL contains the query arg.
|
|
17
18
|
*/
|
|
18
|
-
|
|
19
19
|
export function hasQueryArg(url, arg) {
|
|
20
20
|
return getQueryArg(url, arg) !== undefined;
|
|
21
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["getQueryArg","hasQueryArg","url","arg","undefined"],"sources":["@wordpress/url/src/has-query-arg.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { getQueryArg } from './get-query-arg';\n\n/**\n * Determines whether the URL contains a given query arg.\n *\n * @param {string} url URL.\n * @param {string} arg Query arg name.\n *\n * @example\n * ```js\n * const hasBar = hasQueryArg( 'https://wordpress.org?foo=bar&bar=baz', 'bar' ); // true\n * ```\n *\n * @return {boolean} Whether or not the URL contains the query arg.\n */\nexport function hasQueryArg( url, arg ) {\n\treturn getQueryArg( url, arg ) !== undefined;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAW,QAAQ,iBAAiB;;AAE7C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,WAAWA,CAAEC,GAAG,EAAEC,GAAG,EAAG;EACvC,OAAOH,WAAW,CAAEE,GAAG,EAAEC,GAAI,CAAC,KAAKC,SAAS;AAC7C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["isURL","isEmail","getProtocol","isValidProtocol","getAuthority","isValidAuthority","getPath","isValidPath","getQueryString","buildQueryString","isValidQueryString","getPathAndQueryString","getFragment","isValidFragment","addQueryArgs","getQueryArg","getQueryArgs","hasQueryArg","removeQueryArgs","prependHTTP","safeDecodeURI","safeDecodeURIComponent","filterURLForDisplay","cleanForSlug","getFilename","normalizePath","prependHTTPS"],"sources":["@wordpress/url/src/index.js"],"sourcesContent":["export { isURL } from './is-url';\nexport { isEmail } from './is-email';\nexport { getProtocol } from './get-protocol';\nexport { isValidProtocol } from './is-valid-protocol';\nexport { getAuthority } from './get-authority';\nexport { isValidAuthority } from './is-valid-authority';\nexport { getPath } from './get-path';\nexport { isValidPath } from './is-valid-path';\nexport { getQueryString } from './get-query-string';\nexport { buildQueryString } from './build-query-string';\nexport { isValidQueryString } from './is-valid-query-string';\nexport { getPathAndQueryString } from './get-path-and-query-string';\nexport { getFragment } from './get-fragment';\nexport { isValidFragment } from './is-valid-fragment';\nexport { addQueryArgs } from './add-query-args';\nexport { getQueryArg } from './get-query-arg';\nexport { getQueryArgs } from './get-query-args';\nexport { hasQueryArg } from './has-query-arg';\nexport { removeQueryArgs } from './remove-query-args';\nexport { prependHTTP } from './prepend-http';\nexport { safeDecodeURI } from './safe-decode-uri';\nexport { safeDecodeURIComponent } from './safe-decode-uri-component';\nexport { filterURLForDisplay } from './filter-url-for-display';\nexport { cleanForSlug } from './clean-for-slug';\nexport { getFilename } from './get-filename';\nexport { normalizePath } from './normalize-path';\nexport { prependHTTPS } from './prepend-https';\n"],"mappings":"AAAA,SAASA,KAAK,QAAQ,UAAU;AAChC,SAASC,OAAO,QAAQ,YAAY;AACpC,SAASC,WAAW,QAAQ,gBAAgB;AAC5C,SAASC,eAAe,QAAQ,qBAAqB;AACrD,SAASC,YAAY,QAAQ,iBAAiB;AAC9C,SAASC,gBAAgB,QAAQ,sBAAsB;AACvD,SAASC,OAAO,QAAQ,YAAY;AACpC,SAASC,WAAW,QAAQ,iBAAiB;AAC7C,SAASC,cAAc,QAAQ,oBAAoB;AACnD,SAASC,gBAAgB,QAAQ,sBAAsB;AACvD,SAASC,kBAAkB,QAAQ,yBAAyB;AAC5D,SAASC,qBAAqB,QAAQ,6BAA6B;AACnE,SAASC,WAAW,QAAQ,gBAAgB;AAC5C,SAASC,eAAe,QAAQ,qBAAqB;AACrD,SAASC,YAAY,QAAQ,kBAAkB;AAC/C,SAASC,WAAW,QAAQ,iBAAiB;AAC7C,SAASC,YAAY,QAAQ,kBAAkB;AAC/C,SAASC,WAAW,QAAQ,iBAAiB;AAC7C,SAASC,eAAe,QAAQ,qBAAqB;AACrD,SAASC,WAAW,QAAQ,gBAAgB;AAC5C,SAASC,aAAa,QAAQ,mBAAmB;AACjD,SAASC,sBAAsB,QAAQ,6BAA6B;AACpE,SAASC,mBAAmB,QAAQ,0BAA0B;AAC9D,SAASC,YAAY,QAAQ,kBAAkB;AAC/C,SAASC,WAAW,QAAQ,gBAAgB;AAC5C,SAASC,aAAa,QAAQ,kBAAkB;AAChD,SAASC,YAAY,QAAQ,iBAAiB"}
|
package/build-module/is-email.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const EMAIL_REGEXP = /^(mailto:)?[a-z0-9._%+-]+@[a-z0-9][a-z0-9.-]*\.[a-z]{2,63}$/i;
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* Determines whether the given string looks like an email.
|
|
4
5
|
*
|
|
@@ -11,7 +12,6 @@ const EMAIL_REGEXP = /^(mailto:)?[a-z0-9._%+-]+@[a-z0-9][a-z0-9.-]*\.[a-z]{2,63}
|
|
|
11
12
|
*
|
|
12
13
|
* @return {boolean} Whether or not it looks like an email.
|
|
13
14
|
*/
|
|
14
|
-
|
|
15
15
|
export function isEmail(email) {
|
|
16
16
|
return EMAIL_REGEXP.test(email);
|
|
17
17
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["EMAIL_REGEXP","isEmail","email","test"],"sources":["@wordpress/url/src/is-email.js"],"sourcesContent":["const EMAIL_REGEXP =\n\t/^(mailto:)?[a-z0-9._%+-]+@[a-z0-9][a-z0-9.-]*\\.[a-z]{2,63}$/i;\n\n/**\n * Determines whether the given string looks like an email.\n *\n * @param {string} email The string to scrutinise.\n *\n * @example\n * ```js\n * const isEmail = isEmail( 'hello@wordpress.org' ); // true\n * ```\n *\n * @return {boolean} Whether or not it looks like an email.\n */\nexport function isEmail( email ) {\n\treturn EMAIL_REGEXP.test( email );\n}\n"],"mappings":"AAAA,MAAMA,YAAY,GACjB,8DAA8D;;AAE/D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,OAAOA,CAAEC,KAAK,EAAG;EAChC,OAAOF,YAAY,CAACG,IAAI,CAAED,KAAM,CAAC;AAClC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["isURL","url","URL"],"sources":["@wordpress/url/src/is-url.js"],"sourcesContent":["/**\n * Determines whether the given string looks like a URL.\n *\n * @param {string} url The string to scrutinise.\n *\n * @example\n * ```js\n * const isURL = isURL( 'https://wordpress.org' ); // true\n * ```\n *\n * @see https://url.spec.whatwg.org/\n * @see https://url.spec.whatwg.org/#valid-url-string\n *\n * @return {boolean} Whether or not it looks like a URL.\n */\nexport function isURL( url ) {\n\t// A URL can be considered value if the `URL` constructor is able to parse\n\t// it. The constructor throws an error for an invalid URL.\n\ttry {\n\t\tnew URL( url );\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,KAAKA,CAAEC,GAAG,EAAG;EAC5B;EACA;EACA,IAAI;IACH,IAAIC,GAAG,CAAED,GAAI,CAAC;IACd,OAAO,IAAI;EACZ,CAAC,CAAC,MAAM;IACP,OAAO,KAAK;EACb;AACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["isValidAuthority","authority","test"],"sources":["@wordpress/url/src/is-valid-authority.js"],"sourcesContent":["/**\n * Checks for invalid characters within the provided authority.\n *\n * @param {string} authority A string containing the URL authority.\n *\n * @example\n * ```js\n * const isValid = isValidAuthority( 'wordpress.org' ); // true\n * const isNotValid = isValidAuthority( 'wordpress#org' ); // false\n * ```\n *\n * @return {boolean} True if the argument contains a valid authority.\n */\nexport function isValidAuthority( authority ) {\n\tif ( ! authority ) {\n\t\treturn false;\n\t}\n\treturn /^[^\\s#?]+$/.test( authority );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,gBAAgBA,CAAEC,SAAS,EAAG;EAC7C,IAAK,CAAEA,SAAS,EAAG;IAClB,OAAO,KAAK;EACb;EACA,OAAO,YAAY,CAACC,IAAI,CAAED,SAAU,CAAC;AACtC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["isValidFragment","fragment","test"],"sources":["@wordpress/url/src/is-valid-fragment.js"],"sourcesContent":["/**\n * Checks for invalid characters within the provided fragment.\n *\n * @param {string} fragment The url fragment.\n *\n * @example\n * ```js\n * const isValid = isValidFragment( '#valid-fragment' ); // true\n * const isNotValid = isValidFragment( '#invalid-#fragment' ); // false\n * ```\n *\n * @return {boolean} True if the argument contains a valid fragment.\n */\nexport function isValidFragment( fragment ) {\n\tif ( ! fragment ) {\n\t\treturn false;\n\t}\n\treturn /^#[^\\s#?\\/]*$/.test( fragment );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,eAAeA,CAAEC,QAAQ,EAAG;EAC3C,IAAK,CAAEA,QAAQ,EAAG;IACjB,OAAO,KAAK;EACb;EACA,OAAO,eAAe,CAACC,IAAI,CAAED,QAAS,CAAC;AACxC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["isValidPath","path","test"],"sources":["@wordpress/url/src/is-valid-path.js"],"sourcesContent":["/**\n * Checks for invalid characters within the provided path.\n *\n * @param {string} path The URL path.\n *\n * @example\n * ```js\n * const isValid = isValidPath( 'test/path/' ); // true\n * const isNotValid = isValidPath( '/invalid?test/path/' ); // false\n * ```\n *\n * @return {boolean} True if the argument contains a valid path\n */\nexport function isValidPath( path ) {\n\tif ( ! path ) {\n\t\treturn false;\n\t}\n\treturn /^[^\\s#?]+$/.test( path );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,WAAWA,CAAEC,IAAI,EAAG;EACnC,IAAK,CAAEA,IAAI,EAAG;IACb,OAAO,KAAK;EACb;EACA,OAAO,YAAY,CAACC,IAAI,CAAED,IAAK,CAAC;AACjC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["isValidProtocol","protocol","test"],"sources":["@wordpress/url/src/is-valid-protocol.js"],"sourcesContent":["/**\n * Tests if a url protocol is valid.\n *\n * @param {string} protocol The url protocol.\n *\n * @example\n * ```js\n * const isValid = isValidProtocol( 'https:' ); // true\n * const isNotValid = isValidProtocol( 'https :' ); // false\n * ```\n *\n * @return {boolean} True if the argument is a valid protocol (e.g. http:, tel:).\n */\nexport function isValidProtocol( protocol ) {\n\tif ( ! protocol ) {\n\t\treturn false;\n\t}\n\treturn /^[a-z\\-.\\+]+[0-9]*:$/i.test( protocol );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,eAAeA,CAAEC,QAAQ,EAAG;EAC3C,IAAK,CAAEA,QAAQ,EAAG;IACjB,OAAO,KAAK;EACb;EACA,OAAO,uBAAuB,CAACC,IAAI,CAAED,QAAS,CAAC;AAChD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/url/src/is-valid-query-string.js"],"
|
|
1
|
+
{"version":3,"names":["isValidQueryString","queryString","test"],"sources":["@wordpress/url/src/is-valid-query-string.js"],"sourcesContent":["/**\n * Checks for invalid characters within the provided query string.\n *\n * @param {string} queryString The query string.\n *\n * @example\n * ```js\n * const isValid = isValidQueryString( 'query=true&another=false' ); // true\n * const isNotValid = isValidQueryString( 'query=true?another=false' ); // false\n * ```\n *\n * @return {boolean} True if the argument contains a valid query string.\n */\nexport function isValidQueryString( queryString ) {\n\tif ( ! queryString ) {\n\t\treturn false;\n\t}\n\treturn /^[^\\s#?\\/]+$/.test( queryString );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,kBAAkBA,CAAEC,WAAW,EAAG;EACjD,IAAK,CAAEA,WAAW,EAAG;IACpB,OAAO,KAAK;EACb;EACA,OAAO,cAAc,CAACC,IAAI,CAAED,WAAY,CAAC;AAC1C"}
|
|
@@ -11,19 +11,25 @@ export function normalizePath(path) {
|
|
|
11
11
|
const splitted = path.split('?');
|
|
12
12
|
const query = splitted[1];
|
|
13
13
|
const base = splitted[0];
|
|
14
|
-
|
|
15
14
|
if (!query) {
|
|
16
15
|
return base;
|
|
17
|
-
}
|
|
18
|
-
|
|
16
|
+
}
|
|
19
17
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
.
|
|
24
|
-
|
|
25
|
-
.map(
|
|
26
|
-
|
|
18
|
+
// 'b=1%2C2&c=2&a=5'
|
|
19
|
+
return base + '?' + query
|
|
20
|
+
// [ 'b=1%2C2', 'c=2', 'a=5' ]
|
|
21
|
+
.split('&')
|
|
22
|
+
// [ [ 'b, '1%2C2' ], [ 'c', '2' ], [ 'a', '5' ] ]
|
|
23
|
+
.map(entry => entry.split('='))
|
|
24
|
+
// [ [ 'b', '1,2' ], [ 'c', '2' ], [ 'a', '5' ] ]
|
|
25
|
+
.map(pair => pair.map(decodeURIComponent))
|
|
26
|
+
// [ [ 'a', '5' ], [ 'b, '1,2' ], [ 'c', '2' ] ]
|
|
27
|
+
.sort((a, b) => a[0].localeCompare(b[0]))
|
|
28
|
+
// [ [ 'a', '5' ], [ 'b, '1%2C2' ], [ 'c', '2' ] ]
|
|
29
|
+
.map(pair => pair.map(encodeURIComponent))
|
|
30
|
+
// [ 'a=5', 'b=1%2C2', 'c=2' ]
|
|
31
|
+
.map(pair => pair.join('='))
|
|
32
|
+
// 'a=5&b=1%2C2&c=2'
|
|
27
33
|
.join('&');
|
|
28
34
|
}
|
|
29
35
|
//# sourceMappingURL=normalize-path.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["normalizePath","path","splitted","split","query","base","map","entry","pair","decodeURIComponent","sort","a","b","localeCompare","encodeURIComponent","join"],"sources":["@wordpress/url/src/normalize-path.js"],"sourcesContent":["/**\n * Given a path, returns a normalized path where equal query parameter values\n * will be treated as identical, regardless of order they appear in the original\n * text.\n *\n * @param {string} path Original path.\n *\n * @return {string} Normalized path.\n */\nexport function normalizePath( path ) {\n\tconst splitted = path.split( '?' );\n\tconst query = splitted[ 1 ];\n\tconst base = splitted[ 0 ];\n\tif ( ! query ) {\n\t\treturn base;\n\t}\n\n\t// 'b=1%2C2&c=2&a=5'\n\treturn (\n\t\tbase +\n\t\t'?' +\n\t\tquery\n\t\t\t// [ 'b=1%2C2', 'c=2', 'a=5' ]\n\t\t\t.split( '&' )\n\t\t\t// [ [ 'b, '1%2C2' ], [ 'c', '2' ], [ 'a', '5' ] ]\n\t\t\t.map( ( entry ) => entry.split( '=' ) )\n\t\t\t// [ [ 'b', '1,2' ], [ 'c', '2' ], [ 'a', '5' ] ]\n\t\t\t.map( ( pair ) => pair.map( decodeURIComponent ) )\n\t\t\t// [ [ 'a', '5' ], [ 'b, '1,2' ], [ 'c', '2' ] ]\n\t\t\t.sort( ( a, b ) => a[ 0 ].localeCompare( b[ 0 ] ) )\n\t\t\t// [ [ 'a', '5' ], [ 'b, '1%2C2' ], [ 'c', '2' ] ]\n\t\t\t.map( ( pair ) => pair.map( encodeURIComponent ) )\n\t\t\t// [ 'a=5', 'b=1%2C2', 'c=2' ]\n\t\t\t.map( ( pair ) => pair.join( '=' ) )\n\t\t\t// 'a=5&b=1%2C2&c=2'\n\t\t\t.join( '&' )\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,aAAaA,CAAEC,IAAI,EAAG;EACrC,MAAMC,QAAQ,GAAGD,IAAI,CAACE,KAAK,CAAE,GAAI,CAAC;EAClC,MAAMC,KAAK,GAAGF,QAAQ,CAAE,CAAC,CAAE;EAC3B,MAAMG,IAAI,GAAGH,QAAQ,CAAE,CAAC,CAAE;EAC1B,IAAK,CAAEE,KAAK,EAAG;IACd,OAAOC,IAAI;EACZ;;EAEA;EACA,OACCA,IAAI,GACJ,GAAG,GACHD;EACC;EAAA,CACCD,KAAK,CAAE,GAAI;EACZ;EAAA,CACCG,GAAG,CAAIC,KAAK,IAAMA,KAAK,CAACJ,KAAK,CAAE,GAAI,CAAE;EACtC;EAAA,CACCG,GAAG,CAAIE,IAAI,IAAMA,IAAI,CAACF,GAAG,CAAEG,kBAAmB,CAAE;EACjD;EAAA,CACCC,IAAI,CAAE,CAAEC,CAAC,EAAEC,CAAC,KAAMD,CAAC,CAAE,CAAC,CAAE,CAACE,aAAa,CAAED,CAAC,CAAE,CAAC,CAAG,CAAE;EAClD;EAAA,CACCN,GAAG,CAAIE,IAAI,IAAMA,IAAI,CAACF,GAAG,CAAEQ,kBAAmB,CAAE;EACjD;EAAA,CACCR,GAAG,CAAIE,IAAI,IAAMA,IAAI,CAACO,IAAI,CAAE,GAAI,CAAE;EACnC;EAAA,CACCA,IAAI,CAAE,GAAI,CAAC;AAEf"}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { isEmail } from './is-email';
|
|
5
5
|
const USABLE_HREF_REGEXP = /^(?:[a-z]+:|#|\?|\.|\/)/i;
|
|
6
|
+
|
|
6
7
|
/**
|
|
7
8
|
* Prepends "http://" to a url, if it looks like something that is meant to be a TLD.
|
|
8
9
|
*
|
|
@@ -15,18 +16,14 @@ const USABLE_HREF_REGEXP = /^(?:[a-z]+:|#|\?|\.|\/)/i;
|
|
|
15
16
|
*
|
|
16
17
|
* @return {string} The updated URL.
|
|
17
18
|
*/
|
|
18
|
-
|
|
19
19
|
export function prependHTTP(url) {
|
|
20
20
|
if (!url) {
|
|
21
21
|
return url;
|
|
22
22
|
}
|
|
23
|
-
|
|
24
23
|
url = url.trim();
|
|
25
|
-
|
|
26
24
|
if (!USABLE_HREF_REGEXP.test(url) && !isEmail(url)) {
|
|
27
25
|
return 'http://' + url;
|
|
28
26
|
}
|
|
29
|
-
|
|
30
27
|
return url;
|
|
31
28
|
}
|
|
32
29
|
//# sourceMappingURL=prepend-http.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["isEmail","USABLE_HREF_REGEXP","prependHTTP","url","trim","test"],"sources":["@wordpress/url/src/prepend-http.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { isEmail } from './is-email';\n\nconst USABLE_HREF_REGEXP = /^(?:[a-z]+:|#|\\?|\\.|\\/)/i;\n\n/**\n * Prepends \"http://\" to a url, if it looks like something that is meant to be a TLD.\n *\n * @param {string} url The URL to test.\n *\n * @example\n * ```js\n * const actualURL = prependHTTP( 'wordpress.org' ); // http://wordpress.org\n * ```\n *\n * @return {string} The updated URL.\n */\nexport function prependHTTP( url ) {\n\tif ( ! url ) {\n\t\treturn url;\n\t}\n\n\turl = url.trim();\n\tif ( ! USABLE_HREF_REGEXP.test( url ) && ! isEmail( url ) ) {\n\t\treturn 'http://' + url;\n\t}\n\n\treturn url;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,OAAO,QAAQ,YAAY;AAEpC,MAAMC,kBAAkB,GAAG,0BAA0B;;AAErD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,WAAWA,CAAEC,GAAG,EAAG;EAClC,IAAK,CAAEA,GAAG,EAAG;IACZ,OAAOA,GAAG;EACX;EAEAA,GAAG,GAAGA,GAAG,CAACC,IAAI,CAAC,CAAC;EAChB,IAAK,CAAEH,kBAAkB,CAACI,IAAI,CAAEF,GAAI,CAAC,IAAI,CAAEH,OAAO,CAAEG,GAAI,CAAC,EAAG;IAC3D,OAAO,SAAS,GAAGA,GAAG;EACvB;EAEA,OAAOA,GAAG;AACX"}
|