@wordpress/url 3.40.0 → 3.41.1
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/src/test/fixtures/wpt-data.json +1 -1
- package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
package/build/add-query-args.js
CHANGED
|
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.addQueryArgs = addQueryArgs;
|
|
7
|
-
|
|
8
7
|
var _getQueryArgs = require("./get-query-args");
|
|
9
|
-
|
|
10
8
|
var _buildQueryString = require("./build-query-string");
|
|
11
|
-
|
|
12
9
|
/**
|
|
13
10
|
* Internal dependencies
|
|
14
11
|
*/
|
|
@@ -34,18 +31,17 @@ function addQueryArgs(url = '', args) {
|
|
|
34
31
|
if (!args || !Object.keys(args).length) {
|
|
35
32
|
return url;
|
|
36
33
|
}
|
|
34
|
+
let baseUrl = url;
|
|
37
35
|
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
// Determine whether URL already had query arguments.
|
|
40
37
|
const queryStringIndex = url.indexOf('?');
|
|
41
|
-
|
|
42
38
|
if (queryStringIndex !== -1) {
|
|
43
39
|
// Merge into existing query arguments.
|
|
44
|
-
args = Object.assign((0, _getQueryArgs.getQueryArgs)(url), args);
|
|
40
|
+
args = Object.assign((0, _getQueryArgs.getQueryArgs)(url), args);
|
|
45
41
|
|
|
42
|
+
// Change working base URL to omit previous query arguments.
|
|
46
43
|
baseUrl = baseUrl.substr(0, queryStringIndex);
|
|
47
44
|
}
|
|
48
|
-
|
|
49
45
|
return baseUrl + '?' + (0, _buildQueryString.buildQueryString)(args);
|
|
50
46
|
}
|
|
51
47
|
//# sourceMappingURL=add-query-args.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["_getQueryArgs","require","_buildQueryString","addQueryArgs","url","args","Object","keys","length","baseUrl","queryStringIndex","indexOf","assign","getQueryArgs","substr","buildQueryString"],"sources":["@wordpress/url/src/add-query-args.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { getQueryArgs } from './get-query-args';\nimport { buildQueryString } from './build-query-string';\n\n/**\n * Appends arguments as querystring to the provided URL. If the URL already\n * includes query arguments, the arguments are merged with (and take precedent\n * over) the existing set.\n *\n * @param {string} [url=''] URL to which arguments should be appended. If omitted,\n * only the resulting querystring is returned.\n * @param {Object} [args] Query arguments to apply to URL.\n *\n * @example\n * ```js\n * const newURL = addQueryArgs( 'https://google.com', { q: 'test' } ); // https://google.com/?q=test\n * ```\n *\n * @return {string} URL with arguments applied.\n */\nexport function addQueryArgs( url = '', args ) {\n\t// If no arguments are to be appended, return original URL.\n\tif ( ! args || ! Object.keys( args ).length ) {\n\t\treturn url;\n\t}\n\n\tlet baseUrl = url;\n\n\t// Determine whether URL already had query arguments.\n\tconst queryStringIndex = url.indexOf( '?' );\n\tif ( queryStringIndex !== -1 ) {\n\t\t// Merge into existing query arguments.\n\t\targs = Object.assign( getQueryArgs( url ), args );\n\n\t\t// Change working base URL to omit previous query arguments.\n\t\tbaseUrl = baseUrl.substr( 0, queryStringIndex );\n\t}\n\n\treturn baseUrl + '?' + buildQueryString( args );\n}\n"],"mappings":";;;;;;AAGA,IAAAA,aAAA,GAAAC,OAAA;AACA,IAAAC,iBAAA,GAAAD,OAAA;AAJA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,YAAYA,CAAEC,GAAG,GAAG,EAAE,EAAEC,IAAI,EAAG;EAC9C;EACA,IAAK,CAAEA,IAAI,IAAI,CAAEC,MAAM,CAACC,IAAI,CAAEF,IAAK,CAAC,CAACG,MAAM,EAAG;IAC7C,OAAOJ,GAAG;EACX;EAEA,IAAIK,OAAO,GAAGL,GAAG;;EAEjB;EACA,MAAMM,gBAAgB,GAAGN,GAAG,CAACO,OAAO,CAAE,GAAI,CAAC;EAC3C,IAAKD,gBAAgB,KAAK,CAAC,CAAC,EAAG;IAC9B;IACAL,IAAI,GAAGC,MAAM,CAACM,MAAM,CAAE,IAAAC,0BAAY,EAAET,GAAI,CAAC,EAAEC,IAAK,CAAC;;IAEjD;IACAI,OAAO,GAAGA,OAAO,CAACK,MAAM,CAAE,CAAC,EAAEJ,gBAAiB,CAAC;EAChD;EAEA,OAAOD,OAAO,GAAG,GAAG,GAAG,IAAAM,kCAAgB,EAAEV,IAAK,CAAC;AAChD"}
|
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.buildQueryString = buildQueryString;
|
|
7
|
-
|
|
8
7
|
/**
|
|
9
8
|
* Generates URL-encoded query string using input query data.
|
|
10
9
|
*
|
|
@@ -33,18 +32,16 @@ function buildQueryString(data) {
|
|
|
33
32
|
let string = '';
|
|
34
33
|
const stack = Object.entries(data);
|
|
35
34
|
let pair;
|
|
36
|
-
|
|
37
35
|
while (pair = stack.shift()) {
|
|
38
|
-
let [key, value] = pair;
|
|
36
|
+
let [key, value] = pair;
|
|
39
37
|
|
|
38
|
+
// Support building deeply nested data, from array or object values.
|
|
40
39
|
const hasNestedData = Array.isArray(value) || value && value.constructor === Object;
|
|
41
|
-
|
|
42
40
|
if (hasNestedData) {
|
|
43
41
|
// Push array or object values onto the stack as composed of their
|
|
44
42
|
// original key and nested index or key, retaining order by a
|
|
45
43
|
// combination of Array#reverse and Array#unshift onto the stack.
|
|
46
44
|
const valuePairs = Object.entries(value).reverse();
|
|
47
|
-
|
|
48
45
|
for (const [member, memberValue] of valuePairs) {
|
|
49
46
|
stack.unshift([`${key}[${member}]`, memberValue]);
|
|
50
47
|
}
|
|
@@ -53,14 +50,13 @@ function buildQueryString(data) {
|
|
|
53
50
|
if (value === null) {
|
|
54
51
|
value = '';
|
|
55
52
|
}
|
|
56
|
-
|
|
57
53
|
string += '&' + [key, value].map(encodeURIComponent).join('=');
|
|
58
54
|
}
|
|
59
|
-
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Loop will concatenate with leading `&`, but it's only expected for all
|
|
60
58
|
// but the first query parameter. This strips the leading `&`, while still
|
|
61
59
|
// accounting for the case that the string may in-fact be empty.
|
|
62
|
-
|
|
63
|
-
|
|
64
60
|
return string.substr(1);
|
|
65
61
|
}
|
|
66
62
|
//# sourceMappingURL=build-query-string.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["buildQueryString","data","string","stack","Object","entries","pair","shift","key","value","hasNestedData","Array","isArray","constructor","valuePairs","reverse","member","memberValue","unshift","undefined","map","encodeURIComponent","join","substr"],"sources":["@wordpress/url/src/build-query-string.js"],"sourcesContent":["/**\n * Generates URL-encoded query string using input query data.\n *\n * It is intended to behave equivalent as PHP's `http_build_query`, configured\n * with encoding type PHP_QUERY_RFC3986 (spaces as `%20`).\n *\n * @example\n * ```js\n * const queryString = buildQueryString( {\n * simple: 'is ok',\n * arrays: [ 'are', 'fine', 'too' ],\n * objects: {\n * evenNested: {\n * ok: 'yes',\n * },\n * },\n * } );\n * // \"simple=is%20ok&arrays%5B0%5D=are&arrays%5B1%5D=fine&arrays%5B2%5D=too&objects%5BevenNested%5D%5Bok%5D=yes\"\n * ```\n *\n * @param {Record<string,*>} data Data to encode.\n *\n * @return {string} Query string.\n */\nexport function buildQueryString( data ) {\n\tlet string = '';\n\n\tconst stack = Object.entries( data );\n\n\tlet pair;\n\twhile ( ( pair = stack.shift() ) ) {\n\t\tlet [ key, value ] = pair;\n\n\t\t// Support building deeply nested data, from array or object values.\n\t\tconst hasNestedData =\n\t\t\tArray.isArray( value ) || ( value && value.constructor === Object );\n\n\t\tif ( hasNestedData ) {\n\t\t\t// Push array or object values onto the stack as composed of their\n\t\t\t// original key and nested index or key, retaining order by a\n\t\t\t// combination of Array#reverse and Array#unshift onto the stack.\n\t\t\tconst valuePairs = Object.entries( value ).reverse();\n\t\t\tfor ( const [ member, memberValue ] of valuePairs ) {\n\t\t\t\tstack.unshift( [ `${ key }[${ member }]`, memberValue ] );\n\t\t\t}\n\t\t} else if ( value !== undefined ) {\n\t\t\t// Null is treated as special case, equivalent to empty string.\n\t\t\tif ( value === null ) {\n\t\t\t\tvalue = '';\n\t\t\t}\n\n\t\t\tstring +=\n\t\t\t\t'&' + [ key, value ].map( encodeURIComponent ).join( '=' );\n\t\t}\n\t}\n\n\t// Loop will concatenate with leading `&`, but it's only expected for all\n\t// but the first query parameter. This strips the leading `&`, while still\n\t// accounting for the case that the string may in-fact be empty.\n\treturn string.substr( 1 );\n}\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,gBAAgBA,CAAEC,IAAI,EAAG;EACxC,IAAIC,MAAM,GAAG,EAAE;EAEf,MAAMC,KAAK,GAAGC,MAAM,CAACC,OAAO,CAAEJ,IAAK,CAAC;EAEpC,IAAIK,IAAI;EACR,OAAUA,IAAI,GAAGH,KAAK,CAACI,KAAK,CAAC,CAAC,EAAK;IAClC,IAAI,CAAEC,GAAG,EAAEC,KAAK,CAAE,GAAGH,IAAI;;IAEzB;IACA,MAAMI,aAAa,GAClBC,KAAK,CAACC,OAAO,CAAEH,KAAM,CAAC,IAAMA,KAAK,IAAIA,KAAK,CAACI,WAAW,KAAKT,MAAQ;IAEpE,IAAKM,aAAa,EAAG;MACpB;MACA;MACA;MACA,MAAMI,UAAU,GAAGV,MAAM,CAACC,OAAO,CAAEI,KAAM,CAAC,CAACM,OAAO,CAAC,CAAC;MACpD,KAAM,MAAM,CAAEC,MAAM,EAAEC,WAAW,CAAE,IAAIH,UAAU,EAAG;QACnDX,KAAK,CAACe,OAAO,CAAE,CAAG,GAAGV,GAAK,IAAIQ,MAAQ,GAAE,EAAEC,WAAW,CAAG,CAAC;MAC1D;IACD,CAAC,MAAM,IAAKR,KAAK,KAAKU,SAAS,EAAG;MACjC;MACA,IAAKV,KAAK,KAAK,IAAI,EAAG;QACrBA,KAAK,GAAG,EAAE;MACX;MAEAP,MAAM,IACL,GAAG,GAAG,CAAEM,GAAG,EAAEC,KAAK,CAAE,CAACW,GAAG,CAAEC,kBAAmB,CAAC,CAACC,IAAI,CAAE,GAAI,CAAC;IAC5D;EACD;;EAEA;EACA;EACA;EACA,OAAOpB,MAAM,CAACqB,MAAM,CAAE,CAAE,CAAC;AAC1B"}
|
package/build/clean-for-slug.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.cleanForSlug = cleanForSlug;
|
|
9
|
-
|
|
10
8
|
var _removeAccents = _interopRequireDefault(require("remove-accents"));
|
|
11
|
-
|
|
12
9
|
/**
|
|
13
10
|
* External dependencies
|
|
14
11
|
*/
|
|
@@ -33,12 +30,16 @@ function cleanForSlug(string) {
|
|
|
33
30
|
if (!string) {
|
|
34
31
|
return '';
|
|
35
32
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
.replace(/[\s\./]+/g, '-')
|
|
39
|
-
|
|
40
|
-
.
|
|
41
|
-
|
|
33
|
+
return (0, _removeAccents.default)(string)
|
|
34
|
+
// Convert each group of whitespace, periods, and forward slashes to a hyphen.
|
|
35
|
+
.replace(/[\s\./]+/g, '-')
|
|
36
|
+
// Remove anything that's not a letter, number, underscore or hyphen.
|
|
37
|
+
.replace(/[^\p{L}\p{N}_-]+/gu, '')
|
|
38
|
+
// Convert to lowercase
|
|
39
|
+
.toLowerCase()
|
|
40
|
+
// Replace multiple hyphens with a single one.
|
|
41
|
+
.replace(/-+/g, '-')
|
|
42
|
+
// Remove any remaining leading or trailing hyphens.
|
|
42
43
|
.replace(/(^-+)|(-+$)/g, '');
|
|
43
44
|
}
|
|
44
45
|
//# sourceMappingURL=clean-for-slug.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["_removeAccents","_interopRequireDefault","require","cleanForSlug","string","removeAccents","replace","toLowerCase"],"sources":["@wordpress/url/src/clean-for-slug.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport removeAccents from 'remove-accents';\n\n/**\n * Performs some basic cleanup of a string for use as a post slug.\n *\n * This replicates some of what `sanitize_title()` does in WordPress core, but\n * is only designed to approximate what the slug will be.\n *\n * Converts Latin-1 Supplement and Latin Extended-A letters to basic Latin\n * letters. Removes combining diacritical marks. Converts whitespace, periods,\n * and forward slashes to hyphens. Removes any remaining non-word characters\n * except hyphens. Converts remaining string to lowercase. It does not account\n * for octets, HTML entities, or other encoded characters.\n *\n * @param {string} string Title or slug to be processed.\n *\n * @return {string} Processed string.\n */\nexport function cleanForSlug( string ) {\n\tif ( ! string ) {\n\t\treturn '';\n\t}\n\treturn (\n\t\tremoveAccents( string )\n\t\t\t// Convert each group of whitespace, periods, and forward slashes to a hyphen.\n\t\t\t.replace( /[\\s\\./]+/g, '-' )\n\t\t\t// Remove anything that's not a letter, number, underscore or hyphen.\n\t\t\t.replace( /[^\\p{L}\\p{N}_-]+/gu, '' )\n\t\t\t// Convert to lowercase\n\t\t\t.toLowerCase()\n\t\t\t// Replace multiple hyphens with a single one.\n\t\t\t.replace( /-+/g, '-' )\n\t\t\t// Remove any remaining leading or trailing hyphens.\n\t\t\t.replace( /(^-+)|(-+$)/g, '' )\n\t);\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,cAAA,GAAAC,sBAAA,CAAAC,OAAA;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,YAAYA,CAAEC,MAAM,EAAG;EACtC,IAAK,CAAEA,MAAM,EAAG;IACf,OAAO,EAAE;EACV;EACA,OACC,IAAAC,sBAAa,EAAED,MAAO;EACrB;EAAA,CACCE,OAAO,CAAE,WAAW,EAAE,GAAI;EAC3B;EAAA,CACCA,OAAO,CAAE,oBAAoB,EAAE,EAAG;EACnC;EAAA,CACCC,WAAW,CAAC;EACb;EAAA,CACCD,OAAO,CAAE,KAAK,EAAE,GAAI;EACrB;EAAA,CACCA,OAAO,CAAE,cAAc,EAAE,EAAG,CAAC;AAEjC"}
|
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.filterURLForDisplay = filterURLForDisplay;
|
|
7
|
-
|
|
8
7
|
/**
|
|
9
8
|
* Returns a URL for display.
|
|
10
9
|
*
|
|
@@ -21,28 +20,26 @@ exports.filterURLForDisplay = filterURLForDisplay;
|
|
|
21
20
|
*/
|
|
22
21
|
function filterURLForDisplay(url, maxLength = null) {
|
|
23
22
|
// Remove protocol and www prefixes.
|
|
24
|
-
let filteredURL = url.replace(/^(?:https?:)\/\/(?:www\.)?/, '');
|
|
23
|
+
let filteredURL = url.replace(/^(?:https?:)\/\/(?:www\.)?/, '');
|
|
25
24
|
|
|
25
|
+
// Ends with / and only has that single slash, strip it.
|
|
26
26
|
if (filteredURL.match(/^[^\/]+\/$/)) {
|
|
27
27
|
filteredURL = filteredURL.replace('/', '');
|
|
28
28
|
}
|
|
29
|
-
|
|
30
29
|
const mediaRegexp = /([\w|:])*\.(?:jpg|jpeg|gif|png|svg)/;
|
|
31
|
-
|
|
32
30
|
if (!maxLength || filteredURL.length <= maxLength || !filteredURL.match(mediaRegexp)) {
|
|
33
31
|
return filteredURL;
|
|
34
|
-
}
|
|
35
|
-
|
|
32
|
+
}
|
|
36
33
|
|
|
34
|
+
// If the file is not greater than max length, return last portion of URL.
|
|
37
35
|
filteredURL = filteredURL.split('?')[0];
|
|
38
36
|
const urlPieces = filteredURL.split('/');
|
|
39
37
|
const file = urlPieces[urlPieces.length - 1];
|
|
40
|
-
|
|
41
38
|
if (file.length <= maxLength) {
|
|
42
39
|
return '…' + filteredURL.slice(-maxLength);
|
|
43
|
-
}
|
|
44
|
-
|
|
40
|
+
}
|
|
45
41
|
|
|
42
|
+
// If the file is greater than max length, truncate the file.
|
|
46
43
|
const index = file.lastIndexOf('.');
|
|
47
44
|
const [fileName, extension] = [file.slice(0, index), file.slice(index + 1)];
|
|
48
45
|
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;AACO,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"}
|
package/build/get-authority.js
CHANGED
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getAuthority = getAuthority;
|
|
7
|
-
|
|
8
7
|
/**
|
|
9
8
|
* Returns the authority part of the URL.
|
|
10
9
|
*
|
|
@@ -20,7 +19,6 @@ exports.getAuthority = getAuthority;
|
|
|
20
19
|
*/
|
|
21
20
|
function getAuthority(url) {
|
|
22
21
|
const matches = /^[^\/\s:]+:(?:\/\/)?\/?([^\/\s#?]+)[\/#?]{0,1}\S*$/.exec(url);
|
|
23
|
-
|
|
24
22
|
if (matches) {
|
|
25
23
|
return matches[1];
|
|
26
24
|
}
|
|
@@ -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;AACO,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"}
|
package/build/get-filename.js
CHANGED
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getFilename = getFilename;
|
|
7
|
-
|
|
8
7
|
/**
|
|
9
8
|
* Returns the filename part of the URL.
|
|
10
9
|
*
|
|
@@ -20,11 +19,9 @@ exports.getFilename = getFilename;
|
|
|
20
19
|
*/
|
|
21
20
|
function getFilename(url) {
|
|
22
21
|
let filename;
|
|
23
|
-
|
|
24
22
|
try {
|
|
25
23
|
filename = new URL(url, 'http://example.com').pathname.split('/').pop();
|
|
26
24
|
} catch (error) {}
|
|
27
|
-
|
|
28
25
|
if (filename) {
|
|
29
26
|
return filename;
|
|
30
27
|
}
|
|
@@ -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;AACO,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"}
|
package/build/get-fragment.js
CHANGED
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getFragment = getFragment;
|
|
7
|
-
|
|
8
7
|
/**
|
|
9
8
|
* Returns the fragment part of the URL.
|
|
10
9
|
*
|
|
@@ -20,7 +19,6 @@ exports.getFragment = getFragment;
|
|
|
20
19
|
*/
|
|
21
20
|
function getFragment(url) {
|
|
22
21
|
const matches = /^\S+?(#[^\s\?]*)/.exec(url);
|
|
23
|
-
|
|
24
22
|
if (matches) {
|
|
25
23
|
return matches[1];
|
|
26
24
|
}
|
|
@@ -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;AACO,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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["_","require","getPathAndQueryString","url","path","getPath","queryString","getQueryString","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":";;;;;;AAGA,IAAAA,CAAA,GAAAC,OAAA;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,qBAAqBA,CAAEC,GAAG,EAAG;EAC5C,MAAMC,IAAI,GAAG,IAAAC,SAAO,EAAEF,GAAI,CAAC;EAC3B,MAAMG,WAAW,GAAG,IAAAC,gBAAc,EAAEJ,GAAI,CAAC;EACzC,IAAIK,KAAK,GAAG,GAAG;EACf,IAAKJ,IAAI,EAAGI,KAAK,IAAIJ,IAAI;EACzB,IAAKE,WAAW,EAAGE,KAAK,IAAK,IAAIF,WAAa,EAAC;EAC/C,OAAOE,KAAK;AACb"}
|
package/build/get-path.js
CHANGED
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getPath = getPath;
|
|
7
|
-
|
|
8
7
|
/**
|
|
9
8
|
* Returns the path part of the URL.
|
|
10
9
|
*
|
|
@@ -20,7 +19,6 @@ exports.getPath = getPath;
|
|
|
20
19
|
*/
|
|
21
20
|
function getPath(url) {
|
|
22
21
|
const matches = /^[^\/\s:]+:(?:\/\/)?[^\/\s#?]+[\/]([^\s#?]+)[#?]{0,1}\S*$/.exec(url);
|
|
23
|
-
|
|
24
22
|
if (matches) {
|
|
25
23
|
return matches[1];
|
|
26
24
|
}
|
package/build/get-path.js.map
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;AACO,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"}
|
package/build/get-protocol.js
CHANGED
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getProtocol = getProtocol;
|
|
7
|
-
|
|
8
7
|
/**
|
|
9
8
|
* Returns the protocol part of the URL.
|
|
10
9
|
*
|
|
@@ -20,7 +19,6 @@ exports.getProtocol = getProtocol;
|
|
|
20
19
|
*/
|
|
21
20
|
function getProtocol(url) {
|
|
22
21
|
const matches = /^([^\s:]+:)/.exec(url);
|
|
23
|
-
|
|
24
22
|
if (matches) {
|
|
25
23
|
return matches[1];
|
|
26
24
|
}
|
|
@@ -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;AACO,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"}
|
package/build/get-query-arg.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["_getQueryArgs","require","getQueryArg","url","arg","getQueryArgs"],"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":";;;;;;AAGA,IAAAA,aAAA,GAAAC,OAAA;AAHA;AACA;AACA;;AAGA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,WAAWA,CAAEC,GAAG,EAAEC,GAAG,EAAG;EACvC,OAAO,IAAAC,0BAAY,EAAEF,GAAI,CAAC,CAAEC,GAAG,CAAE;AAClC"}
|
package/build/get-query-args.js
CHANGED
|
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getQueryArgs = getQueryArgs;
|
|
7
|
-
|
|
8
7
|
var _safeDecodeUriComponent = require("./safe-decode-uri-component");
|
|
9
|
-
|
|
10
8
|
var _getQueryString = require("./get-query-string");
|
|
11
|
-
|
|
12
9
|
/**
|
|
13
10
|
* Internal dependencies
|
|
14
11
|
*/
|
|
@@ -30,36 +27,37 @@ var _getQueryString = require("./get-query-string");
|
|
|
30
27
|
function setPath(object, path, value) {
|
|
31
28
|
const length = path.length;
|
|
32
29
|
const lastIndex = length - 1;
|
|
33
|
-
|
|
34
30
|
for (let i = 0; i < length; i++) {
|
|
35
31
|
let key = path[i];
|
|
36
|
-
|
|
37
32
|
if (!key && Array.isArray(object)) {
|
|
38
33
|
// If key is empty string and next value is array, derive key from
|
|
39
34
|
// the current length of the array.
|
|
40
35
|
key = object.length.toString();
|
|
41
36
|
}
|
|
37
|
+
key = ['__proto__', 'constructor', 'prototype'].includes(key) ? key.toUpperCase() : key;
|
|
42
38
|
|
|
43
|
-
|
|
39
|
+
// If the next key in the path is numeric (or empty string), it will be
|
|
44
40
|
// created as an array. Otherwise, it will be created as an object.
|
|
45
|
-
|
|
46
41
|
const isNextKeyArrayIndex = !isNaN(Number(path[i + 1]));
|
|
47
|
-
object[key] = i === lastIndex ?
|
|
48
|
-
|
|
42
|
+
object[key] = i === lastIndex ?
|
|
43
|
+
// If at end of path, assign the intended value.
|
|
44
|
+
value :
|
|
45
|
+
// Otherwise, advance to the next object in the path, creating
|
|
49
46
|
// it if it does not yet exist.
|
|
50
47
|
object[key] || (isNextKeyArrayIndex ? [] : {});
|
|
51
|
-
|
|
52
48
|
if (Array.isArray(object[key]) && !isNextKeyArrayIndex) {
|
|
53
49
|
// If we current key is non-numeric, but the next value is an
|
|
54
50
|
// array, coerce the value to an object.
|
|
55
|
-
object[key] = {
|
|
51
|
+
object[key] = {
|
|
52
|
+
...object[key]
|
|
56
53
|
};
|
|
57
|
-
}
|
|
58
|
-
|
|
54
|
+
}
|
|
59
55
|
|
|
56
|
+
// Update working reference object to the next in the path.
|
|
60
57
|
object = object[key];
|
|
61
58
|
}
|
|
62
59
|
}
|
|
60
|
+
|
|
63
61
|
/**
|
|
64
62
|
* Returns an object of query arguments of the given URL. If the given URL is
|
|
65
63
|
* invalid or has no querystring, an empty object is returned.
|
|
@@ -74,23 +72,21 @@ function setPath(object, path, value) {
|
|
|
74
72
|
*
|
|
75
73
|
* @return {QueryArgs} Query args object.
|
|
76
74
|
*/
|
|
77
|
-
|
|
78
|
-
|
|
79
75
|
function getQueryArgs(url) {
|
|
80
|
-
return ((0, _getQueryString.getQueryString)(url) || ''
|
|
76
|
+
return ((0, _getQueryString.getQueryString)(url) || ''
|
|
77
|
+
// Normalize space encoding, accounting for PHP URL encoding
|
|
81
78
|
// corresponding to `application/x-www-form-urlencoded`.
|
|
82
79
|
//
|
|
83
80
|
// See: https://tools.ietf.org/html/rfc1866#section-8.2.1
|
|
84
81
|
).replace(/\+/g, '%20').split('&').reduce((accumulator, keyValue) => {
|
|
85
|
-
const [key, value = ''] = keyValue.split('=')
|
|
82
|
+
const [key, value = ''] = keyValue.split('=')
|
|
83
|
+
// Filtering avoids decoding as `undefined` for value, where
|
|
86
84
|
// default is restored in destructuring assignment.
|
|
87
85
|
.filter(Boolean).map(_safeDecodeUriComponent.safeDecodeURIComponent);
|
|
88
|
-
|
|
89
86
|
if (key) {
|
|
90
87
|
const segments = key.replace(/\]/g, '').split('[');
|
|
91
88
|
setPath(accumulator, segments, value);
|
|
92
89
|
}
|
|
93
|
-
|
|
94
90
|
return accumulator;
|
|
95
91
|
}, Object.create(null));
|
|
96
92
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["_safeDecodeUriComponent","require","_getQueryString","setPath","object","path","value","length","lastIndex","i","key","Array","isArray","toString","includes","toUpperCase","isNextKeyArrayIndex","isNaN","Number","getQueryArgs","url","getQueryString","replace","split","reduce","accumulator","keyValue","filter","Boolean","map","safeDecodeURIComponent","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":";;;;;;AAGA,IAAAA,uBAAA,GAAAC,OAAA;AACA,IAAAC,eAAA,GAAAD,OAAA;AAJA;AACA;AACA;;AAIA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASE,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;AACO,SAASS,YAAYA,CAAEC,GAAG,EAAG;EACnC,OACC,CAAE,IAAAC,8BAAc,EAAED,GAAI,CAAC,IAAI;EAC1B;EACA;EACA;EACA;EAAA,EACCE,OAAO,CAAE,KAAK,EAAE,KAAM,CAAC,CACvBC,KAAK,CAAE,GAAI,CAAC,CACZC,MAAM,CAAE,CAAEC,WAAW,EAAEC,QAAQ,KAAM;IACrC,MAAM,CAAEhB,GAAG,EAAEJ,KAAK,GAAG,EAAE,CAAE,GAAGoB,QAAQ,CAClCH,KAAK,CAAE,GAAI;IACZ;IACA;IAAA,CACCI,MAAM,CAAEC,OAAQ,CAAC,CACjBC,GAAG,CAAEC,8CAAuB,CAAC;IAE/B,IAAKpB,GAAG,EAAG;MACV,MAAMqB,QAAQ,GAAGrB,GAAG,CAACY,OAAO,CAAE,KAAK,EAAE,EAAG,CAAC,CAACC,KAAK,CAAE,GAAI,CAAC;MACtDpB,OAAO,CAAEsB,WAAW,EAAEM,QAAQ,EAAEzB,KAAM,CAAC;IACxC;IAEA,OAAOmB,WAAW;EACnB,CAAC,EAAEO,MAAM,CAACC,MAAM,CAAE,IAAK,CAAE,CAAC;AAE7B"}
|
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getQueryString = getQueryString;
|
|
7
|
-
|
|
8
7
|
/**
|
|
9
8
|
* Returns the query string part of the URL.
|
|
10
9
|
*
|
|
@@ -19,11 +18,9 @@ exports.getQueryString = getQueryString;
|
|
|
19
18
|
*/
|
|
20
19
|
function getQueryString(url) {
|
|
21
20
|
let query;
|
|
22
|
-
|
|
23
21
|
try {
|
|
24
22
|
query = new URL(url, 'http://example.com').search.substring(1);
|
|
25
23
|
} catch (error) {}
|
|
26
|
-
|
|
27
24
|
if (query) {
|
|
28
25
|
return query;
|
|
29
26
|
}
|
|
@@ -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;AACO,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"}
|
package/build/has-query-arg.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["_getQueryArg","require","hasQueryArg","url","arg","getQueryArg","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":";;;;;;AAGA,IAAAA,YAAA,GAAAC,OAAA;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,WAAWA,CAAEC,GAAG,EAAEC,GAAG,EAAG;EACvC,OAAO,IAAAC,wBAAW,EAAEF,GAAG,EAAEC,GAAI,CAAC,KAAKE,SAAS;AAC7C"}
|