@wordpress/url 3.2.2-next.5df0cd52b7.0 → 3.3.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 +12 -0
- package/README.md +34 -1
- package/build/add-query-args.js +4 -1
- package/build/add-query-args.js.map +1 -1
- package/build/filter-url-for-display.js +2 -1
- package/build/filter-url-for-display.js.map +1 -1
- package/build/get-filename.js +32 -0
- package/build/get-filename.js.map +1 -0
- package/build/get-query-args.js +2 -2
- package/build/get-query-args.js.map +1 -1
- package/build/index.js +60 -44
- package/build/index.js.map +1 -1
- package/build/normalize-path.js +34 -0
- package/build/normalize-path.js.map +1 -0
- package/build/remove-query-args.js +6 -1
- package/build/remove-query-args.js.map +1 -1
- package/build-module/add-query-args.js +4 -1
- package/build-module/add-query-args.js.map +1 -1
- package/build-module/filter-url-for-display.js +2 -1
- package/build-module/filter-url-for-display.js.map +1 -1
- package/build-module/get-filename.js +25 -0
- package/build-module/get-filename.js.map +1 -0
- package/build-module/get-query-args.js +2 -2
- package/build-module/get-query-args.js.map +1 -1
- package/build-module/index.js +2 -0
- package/build-module/index.js.map +1 -1
- package/build-module/normalize-path.js +27 -0
- package/build-module/normalize-path.js.map +1 -0
- package/build-module/remove-query-args.js +6 -1
- package/build-module/remove-query-args.js.map +1 -1
- package/build-types/get-filename.d.ts +15 -0
- package/build-types/get-filename.d.ts.map +1 -0
- package/build-types/get-query-arg.d.ts.map +1 -1
- package/build-types/get-query-args.d.ts +2 -4
- package/build-types/get-query-args.d.ts.map +1 -1
- package/build-types/index.d.ts +2 -0
- package/build-types/normalize-path.d.ts +11 -0
- package/build-types/normalize-path.d.ts.map +1 -0
- package/package.json +4 -5
- package/src/get-filename.js +25 -0
- package/src/index.js +2 -0
- package/src/normalize-path.js +34 -0
- package/src/test/index.js +62 -0
- package/tsconfig.tsbuildinfo +1 -953
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 3.3.0 (2021-11-07)
|
|
6
|
+
|
|
7
|
+
### New Feature
|
|
8
|
+
|
|
9
|
+
- Added new `normalizePath` function ([#35992](https://github.com/WordPress/gutenberg/pull/35992)).
|
|
10
|
+
|
|
11
|
+
## 3.2.3 (2021-10-12)
|
|
12
|
+
|
|
13
|
+
### Bug Fix
|
|
14
|
+
|
|
15
|
+
- Removed unused `react-native-url-polyfill` dependency ([#34687](https://github.com/WordPress/gutenberg/pull/34687)).
|
|
16
|
+
|
|
5
17
|
## 3.2.0 (2021-07-21)
|
|
6
18
|
|
|
7
19
|
## 3.1.0 (2021-05-20)
|
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ Install the module
|
|
|
10
10
|
npm install @wordpress/url --save
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
_This package assumes that your code will run in an **ES2015+** environment. If you're using an environment that has limited or no support for
|
|
13
|
+
_This package assumes that your code will run in an **ES2015+** environment. If you're using an environment that has limited or no support for such language features and APIs, you should include [the polyfill shipped in `@wordpress/babel-preset-default`](https://github.com/WordPress/gutenberg/tree/HEAD/packages/babel-preset-default#polyfill) in your code._
|
|
14
14
|
|
|
15
15
|
## Usage
|
|
16
16
|
|
|
@@ -132,6 +132,25 @@ _Returns_
|
|
|
132
132
|
|
|
133
133
|
- `string|void`: The authority part of the URL.
|
|
134
134
|
|
|
135
|
+
### getFilename
|
|
136
|
+
|
|
137
|
+
Returns the filename part of the URL.
|
|
138
|
+
|
|
139
|
+
_Usage_
|
|
140
|
+
|
|
141
|
+
```js
|
|
142
|
+
const filename1 = getFilename( 'http://localhost:8080/this/is/a/test.jpg' ); // 'test.jpg'
|
|
143
|
+
const filename2 = getFilename( '/this/is/a/test.png' ); // 'test.png'
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
_Parameters_
|
|
147
|
+
|
|
148
|
+
- _url_ `string`: The full URL.
|
|
149
|
+
|
|
150
|
+
_Returns_
|
|
151
|
+
|
|
152
|
+
- `string|void`: The filename part of the URL.
|
|
153
|
+
|
|
135
154
|
### getFragment
|
|
136
155
|
|
|
137
156
|
Returns the fragment part of the URL.
|
|
@@ -430,6 +449,20 @@ _Returns_
|
|
|
430
449
|
|
|
431
450
|
- `boolean`: True if the argument contains a valid query string.
|
|
432
451
|
|
|
452
|
+
### normalizePath
|
|
453
|
+
|
|
454
|
+
Given a path, returns a normalized path where equal query parameter values
|
|
455
|
+
will be treated as identical, regardless of order they appear in the original
|
|
456
|
+
text.
|
|
457
|
+
|
|
458
|
+
_Parameters_
|
|
459
|
+
|
|
460
|
+
- _path_ `string`: Original path.
|
|
461
|
+
|
|
462
|
+
_Returns_
|
|
463
|
+
|
|
464
|
+
- `string`: Normalized path.
|
|
465
|
+
|
|
433
466
|
### prependHTTP
|
|
434
467
|
|
|
435
468
|
Prepends "http\://" to a url, if it looks like something that is meant to be a TLD.
|
package/build/add-query-args.js
CHANGED
|
@@ -29,7 +29,10 @@ var _buildQueryString = require("./build-query-string");
|
|
|
29
29
|
*
|
|
30
30
|
* @return {string} URL with arguments applied.
|
|
31
31
|
*/
|
|
32
|
-
function addQueryArgs(
|
|
32
|
+
function addQueryArgs() {
|
|
33
|
+
let url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
34
|
+
let args = arguments.length > 1 ? arguments[1] : undefined;
|
|
35
|
+
|
|
33
36
|
// If no arguments are to be appended, return original URL.
|
|
34
37
|
if (!args || !Object.keys(args).length) {
|
|
35
38
|
return url;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/url/src/add-query-args.js"],"names":["addQueryArgs","url","args","Object","keys","length","baseUrl","queryStringIndex","indexOf","assign","substr"],"mappings":";;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,YAAT,
|
|
1
|
+
{"version":3,"sources":["@wordpress/url/src/add-query-args.js"],"names":["addQueryArgs","url","args","Object","keys","length","baseUrl","queryStringIndex","indexOf","assign","substr"],"mappings":";;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,YAAT,GAAwC;AAAA,MAAjBC,GAAiB,uEAAX,EAAW;AAAA,MAAPC,IAAO;;AAC9C;AACA,MAAK,CAAEA,IAAF,IAAU,CAAEC,MAAM,CAACC,IAAP,CAAaF,IAAb,EAAoBG,MAArC,EAA8C;AAC7C,WAAOJ,GAAP;AACA;;AAED,MAAIK,OAAO,GAAGL,GAAd,CAN8C,CAQ9C;;AACA,QAAMM,gBAAgB,GAAGN,GAAG,CAACO,OAAJ,CAAa,GAAb,CAAzB;;AACA,MAAKD,gBAAgB,KAAK,CAAC,CAA3B,EAA+B;AAC9B;AACAL,IAAAA,IAAI,GAAGC,MAAM,CAACM,MAAP,CAAe,gCAAcR,GAAd,CAAf,EAAoCC,IAApC,CAAP,CAF8B,CAI9B;;AACAI,IAAAA,OAAO,GAAGA,OAAO,CAACI,MAAR,CAAgB,CAAhB,EAAmBH,gBAAnB,CAAV;AACA;;AAED,SAAOD,OAAO,GAAG,GAAV,GAAgB,wCAAkBJ,IAAlB,CAAvB;AACA","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"]}
|
|
@@ -19,7 +19,8 @@ exports.filterURLForDisplay = filterURLForDisplay;
|
|
|
19
19
|
*
|
|
20
20
|
* @return {string} Displayed URL.
|
|
21
21
|
*/
|
|
22
|
-
function filterURLForDisplay(url
|
|
22
|
+
function filterURLForDisplay(url) {
|
|
23
|
+
let maxLength = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
23
24
|
// Remove protocol and www prefixes.
|
|
24
25
|
let filteredURL = url.replace(/^(?:https?:)\/\/(?:www\.)?/, ''); // Ends with / and only has that single slash, strip it.
|
|
25
26
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/url/src/filter-url-for-display.js"],"names":["filterURLForDisplay","url","maxLength","filteredURL","replace","match","mediaRegexp","length","split","urlPieces","file","slice","index","lastIndexOf","fileName","extension","truncatedFile"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,mBAAT,CAA8BC,GAA9B,
|
|
1
|
+
{"version":3,"sources":["@wordpress/url/src/filter-url-for-display.js"],"names":["filterURLForDisplay","url","maxLength","filteredURL","replace","match","mediaRegexp","length","split","urlPieces","file","slice","index","lastIndexOf","fileName","extension","truncatedFile"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,mBAAT,CAA8BC,GAA9B,EAAsD;AAAA,MAAnBC,SAAmB,uEAAP,IAAO;AAC5D;AACA,MAAIC,WAAW,GAAGF,GAAG,CAACG,OAAJ,CAAa,4BAAb,EAA2C,EAA3C,CAAlB,CAF4D,CAI5D;;AACA,MAAKD,WAAW,CAACE,KAAZ,CAAmB,YAAnB,CAAL,EAAyC;AACxCF,IAAAA,WAAW,GAAGA,WAAW,CAACC,OAAZ,CAAqB,GAArB,EAA0B,EAA1B,CAAd;AACA;;AAED,QAAME,WAAW,GAAG,qCAApB;;AAEA,MACC,CAAEJ,SAAF,IACAC,WAAW,CAACI,MAAZ,IAAsBL,SADtB,IAEA,CAAEC,WAAW,CAACE,KAAZ,CAAmBC,WAAnB,CAHH,EAIE;AACD,WAAOH,WAAP;AACA,GAjB2D,CAmB5D;;;AACAA,EAAAA,WAAW,GAAGA,WAAW,CAACK,KAAZ,CAAmB,GAAnB,EAA0B,CAA1B,CAAd;AACA,QAAMC,SAAS,GAAGN,WAAW,CAACK,KAAZ,CAAmB,GAAnB,CAAlB;AACA,QAAME,IAAI,GAAGD,SAAS,CAAEA,SAAS,CAACF,MAAV,GAAmB,CAArB,CAAtB;;AACA,MAAKG,IAAI,CAACH,MAAL,IAAeL,SAApB,EAAgC;AAC/B,WAAO,MAAMC,WAAW,CAACQ,KAAZ,CAAmB,CAACT,SAApB,CAAb;AACA,GAzB2D,CA2B5D;;;AACA,QAAMU,KAAK,GAAGF,IAAI,CAACG,WAAL,CAAkB,GAAlB,CAAd;AACA,QAAM,CAAEC,QAAF,EAAYC,SAAZ,IAA0B,CAC/BL,IAAI,CAACC,KAAL,CAAY,CAAZ,EAAeC,KAAf,CAD+B,EAE/BF,IAAI,CAACC,KAAL,CAAYC,KAAK,GAAG,CAApB,CAF+B,CAAhC;AAIA,QAAMI,aAAa,GAAGF,QAAQ,CAACH,KAAT,CAAgB,CAAC,CAAjB,IAAuB,GAAvB,GAA6BI,SAAnD;AACA,SACCL,IAAI,CAACC,KAAL,CAAY,CAAZ,EAAeT,SAAS,GAAGc,aAAa,CAACT,MAA1B,GAAmC,CAAlD,IACA,GADA,GAEAS,aAHD;AAKA","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"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getFilename = getFilename;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Returns the filename part of the URL.
|
|
10
|
+
*
|
|
11
|
+
* @param {string} url The full URL.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```js
|
|
15
|
+
* const filename1 = getFilename( 'http://localhost:8080/this/is/a/test.jpg' ); // 'test.jpg'
|
|
16
|
+
* const filename2 = getFilename( '/this/is/a/test.png' ); // 'test.png'
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @return {string|void} The filename part of the URL.
|
|
20
|
+
*/
|
|
21
|
+
function getFilename(url) {
|
|
22
|
+
let filename;
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
filename = new URL(url, 'http://example.com').pathname.split('/').pop();
|
|
26
|
+
} catch (error) {}
|
|
27
|
+
|
|
28
|
+
if (filename) {
|
|
29
|
+
return filename;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=get-filename.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/url/src/get-filename.js"],"names":["getFilename","url","filename","URL","pathname","split","pop","error"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,WAAT,CAAsBC,GAAtB,EAA4B;AAClC,MAAIC,QAAJ;;AACA,MAAI;AACHA,IAAAA,QAAQ,GAAG,IAAIC,GAAJ,CAASF,GAAT,EAAc,oBAAd,EAAqCG,QAArC,CACTC,KADS,CACF,GADE,EAETC,GAFS,EAAX;AAGA,GAJD,CAIE,OAAQC,KAAR,EAAgB,CAAE;;AAEpB,MAAKL,QAAL,EAAgB;AACf,WAAOA,QAAP;AACA;AACD","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"]}
|
package/build/get-query-args.js
CHANGED
|
@@ -74,11 +74,11 @@ function setPath(object, path, value) {
|
|
|
74
74
|
|
|
75
75
|
|
|
76
76
|
function getQueryArgs(url) {
|
|
77
|
-
return ((0, _getQueryString.getQueryString)(url) || ''
|
|
77
|
+
return ((0, _getQueryString.getQueryString)(url) || '' // Normalize space encoding, accounting for PHP URL encoding
|
|
78
78
|
// corresponding to `application/x-www-form-urlencoded`.
|
|
79
79
|
//
|
|
80
80
|
// See: https://tools.ietf.org/html/rfc1866#section-8.2.1
|
|
81
|
-
replace(/\+/g, '%20').split('&').reduce((accumulator, keyValue) => {
|
|
81
|
+
).replace(/\+/g, '%20').split('&').reduce((accumulator, keyValue) => {
|
|
82
82
|
const [key, value = ''] = keyValue.split('=') // Filtering avoids decoding as `undefined` for value, where
|
|
83
83
|
// default is restored in destructuring assignment.
|
|
84
84
|
.filter(Boolean).map(decodeURIComponent);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/url/src/get-query-args.js"],"names":["setPath","object","path","value","length","lastIndex","i","key","Array","isArray","toString","isNextKeyArrayIndex","isNaN","Number","getQueryArgs","url","replace","split","reduce","accumulator","keyValue","filter","Boolean","map","decodeURIComponent","segments"],"mappings":";;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,OAAT,CAAkBC,MAAlB,EAA0BC,IAA1B,EAAgCC,KAAhC,EAAwC;AACvC,QAAMC,MAAM,GAAGF,IAAI,CAACE,MAApB;AACA,QAAMC,SAAS,GAAGD,MAAM,GAAG,CAA3B;;AACA,OAAM,IAAIE,CAAC,GAAG,CAAd,EAAiBA,CAAC,GAAGF,MAArB,EAA6BE,CAAC,EAA9B,EAAmC;AAClC,QAAIC,GAAG,GAAGL,IAAI,CAAEI,CAAF,CAAd;;AAEA,QAAK,CAAEC,GAAF,IAASC,KAAK,CAACC,OAAN,CAAeR,MAAf,CAAd,EAAwC;AACvC;AACA;AACAM,MAAAA,GAAG,GAAGN,MAAM,CAACG,MAAP,CAAcM,QAAd,EAAN;AACA,KAPiC,CASlC;AACA;;;AACA,UAAMC,mBAAmB,GAAG,CAAEC,KAAK,CAAEC,MAAM,CAAEX,IAAI,CAAEI,CAAC,GAAG,CAAN,CAAN,CAAR,CAAnC;AAEAL,IAAAA,MAAM,CAAEM,GAAF,CAAN,GACCD,CAAC,KAAKD,SAAN,GACG;AACAF,IAAAA,KAFH,GAGG;AACA;AACAF,IAAAA,MAAM,CAAEM,GAAF,CAAN,KAAmBI,mBAAmB,GAAG,EAAH,GAAQ,EAA9C,CANJ;;AAQA,QAAKH,KAAK,CAACC,OAAN,CAAeR,MAAM,CAAEM,GAAF,CAArB,KAAkC,CAAEI,mBAAzC,EAA+D;AAC9D;AACA;AACAV,MAAAA,MAAM,CAAEM,GAAF,CAAN,GAAgB,EAAE,GAAGN,MAAM,CAAEM,GAAF;AAAX,OAAhB;AACA,KAzBiC,CA2BlC;;;AACAN,IAAAA,MAAM,GAAGA,MAAM,CAAEM,GAAF,CAAf;AACA;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASO,YAAT,CAAuBC,GAAvB,EAA6B;AACnC,SACC,CAAE,oCAAgBA,GAAhB,KAAyB,EAA3B,
|
|
1
|
+
{"version":3,"sources":["@wordpress/url/src/get-query-args.js"],"names":["setPath","object","path","value","length","lastIndex","i","key","Array","isArray","toString","isNextKeyArrayIndex","isNaN","Number","getQueryArgs","url","replace","split","reduce","accumulator","keyValue","filter","Boolean","map","decodeURIComponent","segments"],"mappings":";;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,OAAT,CAAkBC,MAAlB,EAA0BC,IAA1B,EAAgCC,KAAhC,EAAwC;AACvC,QAAMC,MAAM,GAAGF,IAAI,CAACE,MAApB;AACA,QAAMC,SAAS,GAAGD,MAAM,GAAG,CAA3B;;AACA,OAAM,IAAIE,CAAC,GAAG,CAAd,EAAiBA,CAAC,GAAGF,MAArB,EAA6BE,CAAC,EAA9B,EAAmC;AAClC,QAAIC,GAAG,GAAGL,IAAI,CAAEI,CAAF,CAAd;;AAEA,QAAK,CAAEC,GAAF,IAASC,KAAK,CAACC,OAAN,CAAeR,MAAf,CAAd,EAAwC;AACvC;AACA;AACAM,MAAAA,GAAG,GAAGN,MAAM,CAACG,MAAP,CAAcM,QAAd,EAAN;AACA,KAPiC,CASlC;AACA;;;AACA,UAAMC,mBAAmB,GAAG,CAAEC,KAAK,CAAEC,MAAM,CAAEX,IAAI,CAAEI,CAAC,GAAG,CAAN,CAAN,CAAR,CAAnC;AAEAL,IAAAA,MAAM,CAAEM,GAAF,CAAN,GACCD,CAAC,KAAKD,SAAN,GACG;AACAF,IAAAA,KAFH,GAGG;AACA;AACAF,IAAAA,MAAM,CAAEM,GAAF,CAAN,KAAmBI,mBAAmB,GAAG,EAAH,GAAQ,EAA9C,CANJ;;AAQA,QAAKH,KAAK,CAACC,OAAN,CAAeR,MAAM,CAAEM,GAAF,CAArB,KAAkC,CAAEI,mBAAzC,EAA+D;AAC9D;AACA;AACAV,MAAAA,MAAM,CAAEM,GAAF,CAAN,GAAgB,EAAE,GAAGN,MAAM,CAAEM,GAAF;AAAX,OAAhB;AACA,KAzBiC,CA2BlC;;;AACAN,IAAAA,MAAM,GAAGA,MAAM,CAAEM,GAAF,CAAf;AACA;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASO,YAAT,CAAuBC,GAAvB,EAA6B;AACnC,SACC,CAAE,oCAAgBA,GAAhB,KAAyB,EAA3B,CACC;AACA;AACA;AACA;AAJD,IAKEC,OALF,CAKW,KALX,EAKkB,KALlB,EAMEC,KANF,CAMS,GANT,EAOEC,MAPF,CAOU,CAAEC,WAAF,EAAeC,QAAf,KAA6B;AACrC,UAAM,CAAEb,GAAF,EAAOJ,KAAK,GAAG,EAAf,IAAsBiB,QAAQ,CAClCH,KAD0B,CACnB,GADmB,EAE3B;AACA;AAH2B,KAI1BI,MAJ0B,CAIlBC,OAJkB,EAK1BC,GAL0B,CAKrBC,kBALqB,CAA5B;;AAOA,QAAKjB,GAAL,EAAW;AACV,YAAMkB,QAAQ,GAAGlB,GAAG,CAACS,OAAJ,CAAa,KAAb,EAAoB,EAApB,EAAyBC,KAAzB,CAAgC,GAAhC,CAAjB;AACAjB,MAAAA,OAAO,CAAEmB,WAAF,EAAeM,QAAf,EAAyBtB,KAAzB,CAAP;AACA;;AAED,WAAOgB,WAAP;AACA,GArBF,EAqBI,EArBJ,CADD;AAwBA","sourcesContent":["/**\n * Internal dependencies\n */\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\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( decodeURIComponent );\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}, {} )\n\t);\n}\n"]}
|
package/build/index.js
CHANGED
|
@@ -3,28 +3,28 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
Object.defineProperty(exports, "
|
|
6
|
+
Object.defineProperty(exports, "addQueryArgs", {
|
|
7
7
|
enumerable: true,
|
|
8
8
|
get: function () {
|
|
9
|
-
return
|
|
9
|
+
return _addQueryArgs.addQueryArgs;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
|
-
Object.defineProperty(exports, "
|
|
12
|
+
Object.defineProperty(exports, "buildQueryString", {
|
|
13
13
|
enumerable: true,
|
|
14
14
|
get: function () {
|
|
15
|
-
return
|
|
15
|
+
return _buildQueryString.buildQueryString;
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
|
-
Object.defineProperty(exports, "
|
|
18
|
+
Object.defineProperty(exports, "cleanForSlug", {
|
|
19
19
|
enumerable: true,
|
|
20
20
|
get: function () {
|
|
21
|
-
return
|
|
21
|
+
return _cleanForSlug.cleanForSlug;
|
|
22
22
|
}
|
|
23
23
|
});
|
|
24
|
-
Object.defineProperty(exports, "
|
|
24
|
+
Object.defineProperty(exports, "filterURLForDisplay", {
|
|
25
25
|
enumerable: true,
|
|
26
26
|
get: function () {
|
|
27
|
-
return
|
|
27
|
+
return _filterUrlForDisplay.filterURLForDisplay;
|
|
28
28
|
}
|
|
29
29
|
});
|
|
30
30
|
Object.defineProperty(exports, "getAuthority", {
|
|
@@ -33,10 +33,16 @@ Object.defineProperty(exports, "getAuthority", {
|
|
|
33
33
|
return _getAuthority.getAuthority;
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
|
-
Object.defineProperty(exports, "
|
|
36
|
+
Object.defineProperty(exports, "getFilename", {
|
|
37
37
|
enumerable: true,
|
|
38
38
|
get: function () {
|
|
39
|
-
return
|
|
39
|
+
return _getFilename.getFilename;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
Object.defineProperty(exports, "getFragment", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get: function () {
|
|
45
|
+
return _getFragment.getFragment;
|
|
40
46
|
}
|
|
41
47
|
});
|
|
42
48
|
Object.defineProperty(exports, "getPath", {
|
|
@@ -45,106 +51,112 @@ Object.defineProperty(exports, "getPath", {
|
|
|
45
51
|
return _getPath.getPath;
|
|
46
52
|
}
|
|
47
53
|
});
|
|
48
|
-
Object.defineProperty(exports, "
|
|
54
|
+
Object.defineProperty(exports, "getPathAndQueryString", {
|
|
49
55
|
enumerable: true,
|
|
50
56
|
get: function () {
|
|
51
|
-
return
|
|
57
|
+
return _getPathAndQueryString.getPathAndQueryString;
|
|
52
58
|
}
|
|
53
59
|
});
|
|
54
|
-
Object.defineProperty(exports, "
|
|
60
|
+
Object.defineProperty(exports, "getProtocol", {
|
|
55
61
|
enumerable: true,
|
|
56
62
|
get: function () {
|
|
57
|
-
return
|
|
63
|
+
return _getProtocol.getProtocol;
|
|
58
64
|
}
|
|
59
65
|
});
|
|
60
|
-
Object.defineProperty(exports, "
|
|
66
|
+
Object.defineProperty(exports, "getQueryArg", {
|
|
61
67
|
enumerable: true,
|
|
62
68
|
get: function () {
|
|
63
|
-
return
|
|
69
|
+
return _getQueryArg.getQueryArg;
|
|
64
70
|
}
|
|
65
71
|
});
|
|
66
|
-
Object.defineProperty(exports, "
|
|
72
|
+
Object.defineProperty(exports, "getQueryArgs", {
|
|
67
73
|
enumerable: true,
|
|
68
74
|
get: function () {
|
|
69
|
-
return
|
|
75
|
+
return _getQueryArgs.getQueryArgs;
|
|
70
76
|
}
|
|
71
77
|
});
|
|
72
|
-
Object.defineProperty(exports, "
|
|
78
|
+
Object.defineProperty(exports, "getQueryString", {
|
|
73
79
|
enumerable: true,
|
|
74
80
|
get: function () {
|
|
75
|
-
return
|
|
81
|
+
return _getQueryString.getQueryString;
|
|
76
82
|
}
|
|
77
83
|
});
|
|
78
|
-
Object.defineProperty(exports, "
|
|
84
|
+
Object.defineProperty(exports, "hasQueryArg", {
|
|
79
85
|
enumerable: true,
|
|
80
86
|
get: function () {
|
|
81
|
-
return
|
|
87
|
+
return _hasQueryArg.hasQueryArg;
|
|
82
88
|
}
|
|
83
89
|
});
|
|
84
|
-
Object.defineProperty(exports, "
|
|
90
|
+
Object.defineProperty(exports, "isEmail", {
|
|
85
91
|
enumerable: true,
|
|
86
92
|
get: function () {
|
|
87
|
-
return
|
|
93
|
+
return _isEmail.isEmail;
|
|
88
94
|
}
|
|
89
95
|
});
|
|
90
|
-
Object.defineProperty(exports, "
|
|
96
|
+
Object.defineProperty(exports, "isURL", {
|
|
91
97
|
enumerable: true,
|
|
92
98
|
get: function () {
|
|
93
|
-
return
|
|
99
|
+
return _isUrl.isURL;
|
|
94
100
|
}
|
|
95
101
|
});
|
|
96
|
-
Object.defineProperty(exports, "
|
|
102
|
+
Object.defineProperty(exports, "isValidAuthority", {
|
|
97
103
|
enumerable: true,
|
|
98
104
|
get: function () {
|
|
99
|
-
return
|
|
105
|
+
return _isValidAuthority.isValidAuthority;
|
|
100
106
|
}
|
|
101
107
|
});
|
|
102
|
-
Object.defineProperty(exports, "
|
|
108
|
+
Object.defineProperty(exports, "isValidFragment", {
|
|
103
109
|
enumerable: true,
|
|
104
110
|
get: function () {
|
|
105
|
-
return
|
|
111
|
+
return _isValidFragment.isValidFragment;
|
|
106
112
|
}
|
|
107
113
|
});
|
|
108
|
-
Object.defineProperty(exports, "
|
|
114
|
+
Object.defineProperty(exports, "isValidPath", {
|
|
109
115
|
enumerable: true,
|
|
110
116
|
get: function () {
|
|
111
|
-
return
|
|
117
|
+
return _isValidPath.isValidPath;
|
|
112
118
|
}
|
|
113
119
|
});
|
|
114
|
-
Object.defineProperty(exports, "
|
|
120
|
+
Object.defineProperty(exports, "isValidProtocol", {
|
|
115
121
|
enumerable: true,
|
|
116
122
|
get: function () {
|
|
117
|
-
return
|
|
123
|
+
return _isValidProtocol.isValidProtocol;
|
|
118
124
|
}
|
|
119
125
|
});
|
|
120
|
-
Object.defineProperty(exports, "
|
|
126
|
+
Object.defineProperty(exports, "isValidQueryString", {
|
|
121
127
|
enumerable: true,
|
|
122
128
|
get: function () {
|
|
123
|
-
return
|
|
129
|
+
return _isValidQueryString.isValidQueryString;
|
|
124
130
|
}
|
|
125
131
|
});
|
|
126
|
-
Object.defineProperty(exports, "
|
|
132
|
+
Object.defineProperty(exports, "normalizePath", {
|
|
127
133
|
enumerable: true,
|
|
128
134
|
get: function () {
|
|
129
|
-
return
|
|
135
|
+
return _normalizePath.normalizePath;
|
|
130
136
|
}
|
|
131
137
|
});
|
|
132
|
-
Object.defineProperty(exports, "
|
|
138
|
+
Object.defineProperty(exports, "prependHTTP", {
|
|
133
139
|
enumerable: true,
|
|
134
140
|
get: function () {
|
|
135
|
-
return
|
|
141
|
+
return _prependHttp.prependHTTP;
|
|
136
142
|
}
|
|
137
143
|
});
|
|
138
|
-
Object.defineProperty(exports, "
|
|
144
|
+
Object.defineProperty(exports, "removeQueryArgs", {
|
|
139
145
|
enumerable: true,
|
|
140
146
|
get: function () {
|
|
141
|
-
return
|
|
147
|
+
return _removeQueryArgs.removeQueryArgs;
|
|
142
148
|
}
|
|
143
149
|
});
|
|
144
|
-
Object.defineProperty(exports, "
|
|
150
|
+
Object.defineProperty(exports, "safeDecodeURI", {
|
|
145
151
|
enumerable: true,
|
|
146
152
|
get: function () {
|
|
147
|
-
return
|
|
153
|
+
return _safeDecodeUri.safeDecodeURI;
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
Object.defineProperty(exports, "safeDecodeURIComponent", {
|
|
157
|
+
enumerable: true,
|
|
158
|
+
get: function () {
|
|
159
|
+
return _safeDecodeUriComponent.safeDecodeURIComponent;
|
|
148
160
|
}
|
|
149
161
|
});
|
|
150
162
|
|
|
@@ -195,4 +207,8 @@ var _safeDecodeUriComponent = require("./safe-decode-uri-component");
|
|
|
195
207
|
var _filterUrlForDisplay = require("./filter-url-for-display");
|
|
196
208
|
|
|
197
209
|
var _cleanForSlug = require("./clean-for-slug");
|
|
210
|
+
|
|
211
|
+
var _getFilename = require("./get-filename");
|
|
212
|
+
|
|
213
|
+
var _normalizePath = require("./normalize-path");
|
|
198
214
|
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/url/src/index.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["@wordpress/url/src/index.js"],"names":[],"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;;AACA;;AACA","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';\n"]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.normalizePath = normalizePath;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Given a path, returns a normalized path where equal query parameter values
|
|
10
|
+
* will be treated as identical, regardless of order they appear in the original
|
|
11
|
+
* text.
|
|
12
|
+
*
|
|
13
|
+
* @param {string} path Original path.
|
|
14
|
+
*
|
|
15
|
+
* @return {string} Normalized path.
|
|
16
|
+
*/
|
|
17
|
+
function normalizePath(path) {
|
|
18
|
+
const splitted = path.split('?');
|
|
19
|
+
const query = splitted[1];
|
|
20
|
+
const base = splitted[0];
|
|
21
|
+
|
|
22
|
+
if (!query) {
|
|
23
|
+
return base;
|
|
24
|
+
} // 'b=1&c=2&a=5'
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
return base + '?' + query // [ 'b=1', 'c=2', 'a=5' ]
|
|
28
|
+
.split('&') // [ [ 'b, '1' ], [ 'c', '2' ], [ 'a', '5' ] ]
|
|
29
|
+
.map(entry => entry.split('=')) // [ [ 'a', '5' ], [ 'b, '1' ], [ 'c', '2' ] ]
|
|
30
|
+
.sort((a, b) => a[0].localeCompare(b[0])) // [ 'a=5', 'b=1', 'c=2' ]
|
|
31
|
+
.map(pair => pair.join('=')) // 'a=5&b=1&c=2'
|
|
32
|
+
.join('&');
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=normalize-path.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/url/src/normalize-path.js"],"names":["normalizePath","path","splitted","split","query","base","map","entry","sort","a","b","localeCompare","pair","join"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,aAAT,CAAwBC,IAAxB,EAA+B;AACrC,QAAMC,QAAQ,GAAGD,IAAI,CAACE,KAAL,CAAY,GAAZ,CAAjB;AACA,QAAMC,KAAK,GAAGF,QAAQ,CAAE,CAAF,CAAtB;AACA,QAAMG,IAAI,GAAGH,QAAQ,CAAE,CAAF,CAArB;;AACA,MAAK,CAAEE,KAAP,EAAe;AACd,WAAOC,IAAP;AACA,GANoC,CAQrC;;;AACA,SACCA,IAAI,GACJ,GADA,GAEAD,KAAK,CACJ;AADI,GAEHD,KAFF,CAES,GAFT,EAGC;AAHD,GAIEG,GAJF,CAISC,KAAF,IAAaA,KAAK,CAACJ,KAAN,CAAa,GAAb,CAJpB,EAKC;AALD,GAMEK,IANF,CAMQ,CAAEC,CAAF,EAAKC,CAAL,KAAYD,CAAC,CAAE,CAAF,CAAD,CAAOE,aAAP,CAAsBD,CAAC,CAAE,CAAF,CAAvB,CANpB,EAOC;AAPD,GAQEJ,GARF,CAQSM,IAAF,IAAYA,IAAI,CAACC,IAAL,CAAW,GAAX,CARnB,EASC;AATD,GAUEA,IAVF,CAUQ,GAVR,CAHD;AAeA","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&c=2&a=5'\n\treturn (\n\t\tbase +\n\t\t'?' +\n\t\tquery\n\t\t\t// [ 'b=1', 'c=2', 'a=5' ]\n\t\t\t.split( '&' )\n\t\t\t// [ [ 'b, '1' ], [ 'c', '2' ], [ 'a', '5' ] ]\n\t\t\t.map( ( entry ) => entry.split( '=' ) )\n\t\t\t// [ [ 'a', '5' ], [ 'b, '1' ], [ 'c', '2' ] ]\n\t\t\t.sort( ( a, b ) => a[ 0 ].localeCompare( b[ 0 ] ) )\n\t\t\t// [ 'a=5', 'b=1', 'c=2' ]\n\t\t\t.map( ( pair ) => pair.join( '=' ) )\n\t\t\t// 'a=5&b=1&c=2'\n\t\t\t.join( '&' )\n\t);\n}\n"]}
|
|
@@ -26,7 +26,7 @@ var _buildQueryString = require("./build-query-string");
|
|
|
26
26
|
*
|
|
27
27
|
* @return {string} Updated URL.
|
|
28
28
|
*/
|
|
29
|
-
function removeQueryArgs(url
|
|
29
|
+
function removeQueryArgs(url) {
|
|
30
30
|
const queryStringIndex = url.indexOf('?');
|
|
31
31
|
|
|
32
32
|
if (queryStringIndex === -1) {
|
|
@@ -35,6 +35,11 @@ function removeQueryArgs(url, ...args) {
|
|
|
35
35
|
|
|
36
36
|
const query = (0, _getQueryArgs.getQueryArgs)(url);
|
|
37
37
|
const baseURL = url.substr(0, queryStringIndex);
|
|
38
|
+
|
|
39
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
40
|
+
args[_key - 1] = arguments[_key];
|
|
41
|
+
}
|
|
42
|
+
|
|
38
43
|
args.forEach(arg => delete query[arg]);
|
|
39
44
|
const queryString = (0, _buildQueryString.buildQueryString)(query);
|
|
40
45
|
return queryString ? baseURL + '?' + queryString : baseURL;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/url/src/remove-query-args.js"],"names":["removeQueryArgs","url","
|
|
1
|
+
{"version":3,"sources":["@wordpress/url/src/remove-query-args.js"],"names":["removeQueryArgs","url","queryStringIndex","indexOf","query","baseURL","substr","args","forEach","arg","queryString"],"mappings":";;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,eAAT,CAA0BC,GAA1B,EAAyC;AAC/C,QAAMC,gBAAgB,GAAGD,GAAG,CAACE,OAAJ,CAAa,GAAb,CAAzB;;AACA,MAAKD,gBAAgB,KAAK,CAAC,CAA3B,EAA+B;AAC9B,WAAOD,GAAP;AACA;;AAED,QAAMG,KAAK,GAAG,gCAAcH,GAAd,CAAd;AACA,QAAMI,OAAO,GAAGJ,GAAG,CAACK,MAAJ,CAAY,CAAZ,EAAeJ,gBAAf,CAAhB;;AAP+C,oCAAPK,IAAO;AAAPA,IAAAA,IAAO;AAAA;;AAQ/CA,EAAAA,IAAI,CAACC,OAAL,CAAgBC,GAAF,IAAW,OAAOL,KAAK,CAAEK,GAAF,CAArC;AACA,QAAMC,WAAW,GAAG,wCAAkBN,KAAlB,CAApB;AACA,SAAOM,WAAW,GAAGL,OAAO,GAAG,GAAV,GAAgBK,WAAnB,GAAiCL,OAAnD;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport { getQueryArgs } from './get-query-args';\nimport { buildQueryString } from './build-query-string';\n\n/**\n * Removes arguments from the query string of the url\n *\n * @param {string} url URL.\n * @param {...string} args Query Args.\n *\n * @example\n * ```js\n * const newUrl = removeQueryArgs( 'https://wordpress.org?foo=bar&bar=baz&baz=foobar', 'foo', 'bar' ); // https://wordpress.org?baz=foobar\n * ```\n *\n * @return {string} Updated URL.\n */\nexport function removeQueryArgs( url, ...args ) {\n\tconst queryStringIndex = url.indexOf( '?' );\n\tif ( queryStringIndex === -1 ) {\n\t\treturn url;\n\t}\n\n\tconst query = getQueryArgs( url );\n\tconst baseURL = url.substr( 0, queryStringIndex );\n\targs.forEach( ( arg ) => delete query[ arg ] );\n\tconst queryString = buildQueryString( query );\n\treturn queryString ? baseURL + '?' + queryString : baseURL;\n}\n"]}
|
|
@@ -20,7 +20,10 @@ import { buildQueryString } from './build-query-string';
|
|
|
20
20
|
* @return {string} URL with arguments applied.
|
|
21
21
|
*/
|
|
22
22
|
|
|
23
|
-
export function addQueryArgs(
|
|
23
|
+
export function addQueryArgs() {
|
|
24
|
+
let url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
25
|
+
let args = arguments.length > 1 ? arguments[1] : undefined;
|
|
26
|
+
|
|
24
27
|
// If no arguments are to be appended, return original URL.
|
|
25
28
|
if (!args || !Object.keys(args).length) {
|
|
26
29
|
return url;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/url/src/add-query-args.js"],"names":["getQueryArgs","buildQueryString","addQueryArgs","url","args","Object","keys","length","baseUrl","queryStringIndex","indexOf","assign","substr"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,YAAT,QAA6B,kBAA7B;AACA,SAASC,gBAAT,QAAiC,sBAAjC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,YAAT,
|
|
1
|
+
{"version":3,"sources":["@wordpress/url/src/add-query-args.js"],"names":["getQueryArgs","buildQueryString","addQueryArgs","url","args","Object","keys","length","baseUrl","queryStringIndex","indexOf","assign","substr"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,YAAT,QAA6B,kBAA7B;AACA,SAASC,gBAAT,QAAiC,sBAAjC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,YAAT,GAAwC;AAAA,MAAjBC,GAAiB,uEAAX,EAAW;AAAA,MAAPC,IAAO;;AAC9C;AACA,MAAK,CAAEA,IAAF,IAAU,CAAEC,MAAM,CAACC,IAAP,CAAaF,IAAb,EAAoBG,MAArC,EAA8C;AAC7C,WAAOJ,GAAP;AACA;;AAED,MAAIK,OAAO,GAAGL,GAAd,CAN8C,CAQ9C;;AACA,QAAMM,gBAAgB,GAAGN,GAAG,CAACO,OAAJ,CAAa,GAAb,CAAzB;;AACA,MAAKD,gBAAgB,KAAK,CAAC,CAA3B,EAA+B;AAC9B;AACAL,IAAAA,IAAI,GAAGC,MAAM,CAACM,MAAP,CAAeX,YAAY,CAAEG,GAAF,CAA3B,EAAoCC,IAApC,CAAP,CAF8B,CAI9B;;AACAI,IAAAA,OAAO,GAAGA,OAAO,CAACI,MAAR,CAAgB,CAAhB,EAAmBH,gBAAnB,CAAV;AACA;;AAED,SAAOD,OAAO,GAAG,GAAV,GAAgBP,gBAAgB,CAAEG,IAAF,CAAvC;AACA","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"]}
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
*
|
|
13
13
|
* @return {string} Displayed URL.
|
|
14
14
|
*/
|
|
15
|
-
export function filterURLForDisplay(url
|
|
15
|
+
export function filterURLForDisplay(url) {
|
|
16
|
+
let maxLength = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
16
17
|
// Remove protocol and www prefixes.
|
|
17
18
|
let filteredURL = url.replace(/^(?:https?:)\/\/(?:www\.)?/, ''); // Ends with / and only has that single slash, strip it.
|
|
18
19
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/url/src/filter-url-for-display.js"],"names":["filterURLForDisplay","url","maxLength","filteredURL","replace","match","mediaRegexp","length","split","urlPieces","file","slice","index","lastIndexOf","fileName","extension","truncatedFile"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,mBAAT,CAA8BC,GAA9B,
|
|
1
|
+
{"version":3,"sources":["@wordpress/url/src/filter-url-for-display.js"],"names":["filterURLForDisplay","url","maxLength","filteredURL","replace","match","mediaRegexp","length","split","urlPieces","file","slice","index","lastIndexOf","fileName","extension","truncatedFile"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,mBAAT,CAA8BC,GAA9B,EAAsD;AAAA,MAAnBC,SAAmB,uEAAP,IAAO;AAC5D;AACA,MAAIC,WAAW,GAAGF,GAAG,CAACG,OAAJ,CAAa,4BAAb,EAA2C,EAA3C,CAAlB,CAF4D,CAI5D;;AACA,MAAKD,WAAW,CAACE,KAAZ,CAAmB,YAAnB,CAAL,EAAyC;AACxCF,IAAAA,WAAW,GAAGA,WAAW,CAACC,OAAZ,CAAqB,GAArB,EAA0B,EAA1B,CAAd;AACA;;AAED,QAAME,WAAW,GAAG,qCAApB;;AAEA,MACC,CAAEJ,SAAF,IACAC,WAAW,CAACI,MAAZ,IAAsBL,SADtB,IAEA,CAAEC,WAAW,CAACE,KAAZ,CAAmBC,WAAnB,CAHH,EAIE;AACD,WAAOH,WAAP;AACA,GAjB2D,CAmB5D;;;AACAA,EAAAA,WAAW,GAAGA,WAAW,CAACK,KAAZ,CAAmB,GAAnB,EAA0B,CAA1B,CAAd;AACA,QAAMC,SAAS,GAAGN,WAAW,CAACK,KAAZ,CAAmB,GAAnB,CAAlB;AACA,QAAME,IAAI,GAAGD,SAAS,CAAEA,SAAS,CAACF,MAAV,GAAmB,CAArB,CAAtB;;AACA,MAAKG,IAAI,CAACH,MAAL,IAAeL,SAApB,EAAgC;AAC/B,WAAO,MAAMC,WAAW,CAACQ,KAAZ,CAAmB,CAACT,SAApB,CAAb;AACA,GAzB2D,CA2B5D;;;AACA,QAAMU,KAAK,GAAGF,IAAI,CAACG,WAAL,CAAkB,GAAlB,CAAd;AACA,QAAM,CAAEC,QAAF,EAAYC,SAAZ,IAA0B,CAC/BL,IAAI,CAACC,KAAL,CAAY,CAAZ,EAAeC,KAAf,CAD+B,EAE/BF,IAAI,CAACC,KAAL,CAAYC,KAAK,GAAG,CAApB,CAF+B,CAAhC;AAIA,QAAMI,aAAa,GAAGF,QAAQ,CAACH,KAAT,CAAgB,CAAC,CAAjB,IAAuB,GAAvB,GAA6BI,SAAnD;AACA,SACCL,IAAI,CAACC,KAAL,CAAY,CAAZ,EAAeT,SAAS,GAAGc,aAAa,CAACT,MAA1B,GAAmC,CAAlD,IACA,GADA,GAEAS,aAHD;AAKA","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"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the filename part of the URL.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} url The full URL.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```js
|
|
8
|
+
* const filename1 = getFilename( 'http://localhost:8080/this/is/a/test.jpg' ); // 'test.jpg'
|
|
9
|
+
* const filename2 = getFilename( '/this/is/a/test.png' ); // 'test.png'
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* @return {string|void} The filename part of the URL.
|
|
13
|
+
*/
|
|
14
|
+
export function getFilename(url) {
|
|
15
|
+
let filename;
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
filename = new URL(url, 'http://example.com').pathname.split('/').pop();
|
|
19
|
+
} catch (error) {}
|
|
20
|
+
|
|
21
|
+
if (filename) {
|
|
22
|
+
return filename;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=get-filename.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/url/src/get-filename.js"],"names":["getFilename","url","filename","URL","pathname","split","pop","error"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,WAAT,CAAsBC,GAAtB,EAA4B;AAClC,MAAIC,QAAJ;;AACA,MAAI;AACHA,IAAAA,QAAQ,GAAG,IAAIC,GAAJ,CAASF,GAAT,EAAc,oBAAd,EAAqCG,QAArC,CACTC,KADS,CACF,GADE,EAETC,GAFS,EAAX;AAGA,GAJD,CAIE,OAAQC,KAAR,EAAgB,CAAE;;AAEpB,MAAKL,QAAL,EAAgB;AACf,WAAOA,QAAP;AACA;AACD","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"]}
|
|
@@ -66,11 +66,11 @@ function setPath(object, path, value) {
|
|
|
66
66
|
|
|
67
67
|
|
|
68
68
|
export function getQueryArgs(url) {
|
|
69
|
-
return (getQueryString(url) || ''
|
|
69
|
+
return (getQueryString(url) || '' // Normalize space encoding, accounting for PHP URL encoding
|
|
70
70
|
// corresponding to `application/x-www-form-urlencoded`.
|
|
71
71
|
//
|
|
72
72
|
// See: https://tools.ietf.org/html/rfc1866#section-8.2.1
|
|
73
|
-
replace(/\+/g, '%20').split('&').reduce((accumulator, keyValue) => {
|
|
73
|
+
).replace(/\+/g, '%20').split('&').reduce((accumulator, keyValue) => {
|
|
74
74
|
const [key, value = ''] = keyValue.split('=') // Filtering avoids decoding as `undefined` for value, where
|
|
75
75
|
// default is restored in destructuring assignment.
|
|
76
76
|
.filter(Boolean).map(decodeURIComponent);
|