@wordpress/url 3.2.2-next.253d9b6e21.0 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/README.md +34 -1
- package/build/get-filename.js +32 -0
- package/build/get-filename.js.map +1 -0
- package/build/index.js +16 -0
- package/build/index.js.map +1 -1
- package/build/normalize-path.js +34 -0
- package/build/normalize-path.js.map +1 -0
- package/build-module/get-filename.js +25 -0
- package/build-module/get-filename.js.map +1 -0
- 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-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 +3 -4
- 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.
|
|
@@ -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/index.js
CHANGED
|
@@ -147,6 +147,18 @@ Object.defineProperty(exports, "cleanForSlug", {
|
|
|
147
147
|
return _cleanForSlug.cleanForSlug;
|
|
148
148
|
}
|
|
149
149
|
});
|
|
150
|
+
Object.defineProperty(exports, "getFilename", {
|
|
151
|
+
enumerable: true,
|
|
152
|
+
get: function () {
|
|
153
|
+
return _getFilename.getFilename;
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
Object.defineProperty(exports, "normalizePath", {
|
|
157
|
+
enumerable: true,
|
|
158
|
+
get: function () {
|
|
159
|
+
return _normalizePath.normalizePath;
|
|
160
|
+
}
|
|
161
|
+
});
|
|
150
162
|
|
|
151
163
|
var _isUrl = require("./is-url");
|
|
152
164
|
|
|
@@ -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"]}
|
|
@@ -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"]}
|
package/build-module/index.js
CHANGED
|
@@ -22,4 +22,6 @@ export { safeDecodeURI } from './safe-decode-uri';
|
|
|
22
22
|
export { safeDecodeURIComponent } from './safe-decode-uri-component';
|
|
23
23
|
export { filterURLForDisplay } from './filter-url-for-display';
|
|
24
24
|
export { cleanForSlug } from './clean-for-slug';
|
|
25
|
+
export { getFilename } from './get-filename';
|
|
26
|
+
export { normalizePath } from './normalize-path';
|
|
25
27
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/url/src/index.js"],"names":["isURL","isEmail","getProtocol","isValidProtocol","getAuthority","isValidAuthority","getPath","isValidPath","getQueryString","buildQueryString","isValidQueryString","getPathAndQueryString","getFragment","isValidFragment","addQueryArgs","getQueryArg","getQueryArgs","hasQueryArg","removeQueryArgs","prependHTTP","safeDecodeURI","safeDecodeURIComponent","filterURLForDisplay","cleanForSlug"],"mappings":"AAAA,SAASA,KAAT,QAAsB,UAAtB;AACA,SAASC,OAAT,QAAwB,YAAxB;AACA,SAASC,WAAT,QAA4B,gBAA5B;AACA,SAASC,eAAT,QAAgC,qBAAhC;AACA,SAASC,YAAT,QAA6B,iBAA7B;AACA,SAASC,gBAAT,QAAiC,sBAAjC;AACA,SAASC,OAAT,QAAwB,YAAxB;AACA,SAASC,WAAT,QAA4B,iBAA5B;AACA,SAASC,cAAT,QAA+B,oBAA/B;AACA,SAASC,gBAAT,QAAiC,sBAAjC;AACA,SAASC,kBAAT,QAAmC,yBAAnC;AACA,SAASC,qBAAT,QAAsC,6BAAtC;AACA,SAASC,WAAT,QAA4B,gBAA5B;AACA,SAASC,eAAT,QAAgC,qBAAhC;AACA,SAASC,YAAT,QAA6B,kBAA7B;AACA,SAASC,WAAT,QAA4B,iBAA5B;AACA,SAASC,YAAT,QAA6B,kBAA7B;AACA,SAASC,WAAT,QAA4B,iBAA5B;AACA,SAASC,eAAT,QAAgC,qBAAhC;AACA,SAASC,WAAT,QAA4B,gBAA5B;AACA,SAASC,aAAT,QAA8B,mBAA9B;AACA,SAASC,sBAAT,QAAuC,6BAAvC;AACA,SAASC,mBAAT,QAAoC,0BAApC;AACA,SAASC,YAAT,QAA6B,kBAA7B","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';\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/url/src/index.js"],"names":["isURL","isEmail","getProtocol","isValidProtocol","getAuthority","isValidAuthority","getPath","isValidPath","getQueryString","buildQueryString","isValidQueryString","getPathAndQueryString","getFragment","isValidFragment","addQueryArgs","getQueryArg","getQueryArgs","hasQueryArg","removeQueryArgs","prependHTTP","safeDecodeURI","safeDecodeURIComponent","filterURLForDisplay","cleanForSlug","getFilename","normalizePath"],"mappings":"AAAA,SAASA,KAAT,QAAsB,UAAtB;AACA,SAASC,OAAT,QAAwB,YAAxB;AACA,SAASC,WAAT,QAA4B,gBAA5B;AACA,SAASC,eAAT,QAAgC,qBAAhC;AACA,SAASC,YAAT,QAA6B,iBAA7B;AACA,SAASC,gBAAT,QAAiC,sBAAjC;AACA,SAASC,OAAT,QAAwB,YAAxB;AACA,SAASC,WAAT,QAA4B,iBAA5B;AACA,SAASC,cAAT,QAA+B,oBAA/B;AACA,SAASC,gBAAT,QAAiC,sBAAjC;AACA,SAASC,kBAAT,QAAmC,yBAAnC;AACA,SAASC,qBAAT,QAAsC,6BAAtC;AACA,SAASC,WAAT,QAA4B,gBAA5B;AACA,SAASC,eAAT,QAAgC,qBAAhC;AACA,SAASC,YAAT,QAA6B,kBAA7B;AACA,SAASC,WAAT,QAA4B,iBAA5B;AACA,SAASC,YAAT,QAA6B,kBAA7B;AACA,SAASC,WAAT,QAA4B,iBAA5B;AACA,SAASC,eAAT,QAAgC,qBAAhC;AACA,SAASC,WAAT,QAA4B,gBAA5B;AACA,SAASC,aAAT,QAA8B,mBAA9B;AACA,SAASC,sBAAT,QAAuC,6BAAvC;AACA,SAASC,mBAAT,QAAoC,0BAApC;AACA,SAASC,YAAT,QAA6B,kBAA7B;AACA,SAASC,WAAT,QAA4B,gBAA5B;AACA,SAASC,aAAT,QAA8B,kBAA9B","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,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Given a path, returns a normalized path where equal query parameter values
|
|
3
|
+
* will be treated as identical, regardless of order they appear in the original
|
|
4
|
+
* text.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} path Original path.
|
|
7
|
+
*
|
|
8
|
+
* @return {string} Normalized path.
|
|
9
|
+
*/
|
|
10
|
+
export function normalizePath(path) {
|
|
11
|
+
const splitted = path.split('?');
|
|
12
|
+
const query = splitted[1];
|
|
13
|
+
const base = splitted[0];
|
|
14
|
+
|
|
15
|
+
if (!query) {
|
|
16
|
+
return base;
|
|
17
|
+
} // 'b=1&c=2&a=5'
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
return base + '?' + query // [ 'b=1', 'c=2', 'a=5' ]
|
|
21
|
+
.split('&') // [ [ 'b, '1' ], [ 'c', '2' ], [ 'a', '5' ] ]
|
|
22
|
+
.map(entry => entry.split('=')) // [ [ 'a', '5' ], [ 'b, '1' ], [ 'c', '2' ] ]
|
|
23
|
+
.sort((a, b) => a[0].localeCompare(b[0])) // [ 'a=5', 'b=1', 'c=2' ]
|
|
24
|
+
.map(pair => pair.join('=')) // 'a=5&b=1&c=2'
|
|
25
|
+
.join('&');
|
|
26
|
+
}
|
|
27
|
+
//# 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;AACA,OAAO,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"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
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: string): string | void;
|
|
15
|
+
//# sourceMappingURL=get-filename.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-filename.d.ts","sourceRoot":"","sources":["../src/get-filename.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,iCAVW,MAAM,GAQL,MAAM,GAAC,IAAI,CAatB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-query-arg.d.ts","sourceRoot":"","sources":["../src/get-query-arg.js"],"names":[],"mappings":"AAKA;;GAEG;AAEH;;GAEG;AAEH;;;;;;;;;;;;GAYG;AACH,iCAVW,MAAM,OACN,MAAM,GAOL,cAAc,GAAC,IAAI,CAI9B"}
|
|
1
|
+
{"version":3,"file":"get-query-arg.d.ts","sourceRoot":"","sources":["../src/get-query-arg.js"],"names":[],"mappings":"AAKA;;GAEG;AAEH;;GAEG;AAEH;;;;;;;;;;;;GAYG;AACH,iCAVW,MAAM,OACN,MAAM,GAOL,cAAc,GAAC,IAAI,CAI9B;;;;6BAlBY,MAAM,GAAC,MAAM,EAAE,GAAC,cAAc"}
|
|
@@ -13,8 +13,6 @@
|
|
|
13
13
|
* @return {QueryArgs} Query args object.
|
|
14
14
|
*/
|
|
15
15
|
export function getQueryArgs(url: string): QueryArgs;
|
|
16
|
-
export type QueryArgParsed =
|
|
17
|
-
export type QueryArgs =
|
|
18
|
-
[x: string]: import("./get-query-arg").QueryArgParsed;
|
|
19
|
-
};
|
|
16
|
+
export type QueryArgParsed = import('./get-query-arg').QueryArgParsed;
|
|
17
|
+
export type QueryArgs = Record<string, QueryArgParsed>;
|
|
20
18
|
//# sourceMappingURL=get-query-args.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-query-args.d.ts","sourceRoot":"","sources":["../src/get-query-args.js"],"names":[],"mappings":"AAsDA;;;;;;;;;;;;;GAaG;AACH,kCAVW,MAAM,GAQL,SAAS,CA2BpB"}
|
|
1
|
+
{"version":3,"file":"get-query-args.d.ts","sourceRoot":"","sources":["../src/get-query-args.js"],"names":[],"mappings":"AAsDA;;;;;;;;;;;;;GAaG;AACH,kCAVW,MAAM,GAQL,SAAS,CA2BpB;6BAxFa,OAAO,iBAAiB,EAAE,cAAc;wBAGzC,OAAO,MAAM,EAAC,cAAc,CAAC"}
|
package/build-types/index.d.ts
CHANGED
|
@@ -22,4 +22,6 @@ export { safeDecodeURI } from "./safe-decode-uri";
|
|
|
22
22
|
export { safeDecodeURIComponent } from "./safe-decode-uri-component";
|
|
23
23
|
export { filterURLForDisplay } from "./filter-url-for-display";
|
|
24
24
|
export { cleanForSlug } from "./clean-for-slug";
|
|
25
|
+
export { getFilename } from "./get-filename";
|
|
26
|
+
export { normalizePath } from "./normalize-path";
|
|
25
27
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Given a path, returns a normalized path where equal query parameter values
|
|
3
|
+
* will be treated as identical, regardless of order they appear in the original
|
|
4
|
+
* text.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} path Original path.
|
|
7
|
+
*
|
|
8
|
+
* @return {string} Normalized path.
|
|
9
|
+
*/
|
|
10
|
+
export function normalizePath(path: string): string;
|
|
11
|
+
//# sourceMappingURL=normalize-path.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize-path.d.ts","sourceRoot":"","sources":["../src/normalize-path.js"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,oCAJW,MAAM,GAEL,MAAM,CA0BjB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/url",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"description": "WordPress URL utilities.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -28,11 +28,10 @@
|
|
|
28
28
|
"sideEffects": false,
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@babel/runtime": "^7.13.10",
|
|
31
|
-
"lodash": "^4.17.21"
|
|
32
|
-
"react-native-url-polyfill": "^1.1.2"
|
|
31
|
+
"lodash": "^4.17.21"
|
|
33
32
|
},
|
|
34
33
|
"publishConfig": {
|
|
35
34
|
"access": "public"
|
|
36
35
|
},
|
|
37
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "393c2b5533837fd637e998d23f0124c081a10df0"
|
|
38
37
|
}
|
|
@@ -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
|
+
try {
|
|
17
|
+
filename = new URL( url, 'http://example.com' ).pathname
|
|
18
|
+
.split( '/' )
|
|
19
|
+
.pop();
|
|
20
|
+
} catch ( error ) {}
|
|
21
|
+
|
|
22
|
+
if ( filename ) {
|
|
23
|
+
return filename;
|
|
24
|
+
}
|
|
25
|
+
}
|
package/src/index.js
CHANGED
|
@@ -22,3 +22,5 @@ export { safeDecodeURI } from './safe-decode-uri';
|
|
|
22
22
|
export { safeDecodeURIComponent } from './safe-decode-uri-component';
|
|
23
23
|
export { filterURLForDisplay } from './filter-url-for-display';
|
|
24
24
|
export { cleanForSlug } from './clean-for-slug';
|
|
25
|
+
export { getFilename } from './get-filename';
|
|
26
|
+
export { normalizePath } from './normalize-path';
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Given a path, returns a normalized path where equal query parameter values
|
|
3
|
+
* will be treated as identical, regardless of order they appear in the original
|
|
4
|
+
* text.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} path Original path.
|
|
7
|
+
*
|
|
8
|
+
* @return {string} Normalized path.
|
|
9
|
+
*/
|
|
10
|
+
export function normalizePath( path ) {
|
|
11
|
+
const splitted = path.split( '?' );
|
|
12
|
+
const query = splitted[ 1 ];
|
|
13
|
+
const base = splitted[ 0 ];
|
|
14
|
+
if ( ! query ) {
|
|
15
|
+
return base;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// 'b=1&c=2&a=5'
|
|
19
|
+
return (
|
|
20
|
+
base +
|
|
21
|
+
'?' +
|
|
22
|
+
query
|
|
23
|
+
// [ 'b=1', 'c=2', 'a=5' ]
|
|
24
|
+
.split( '&' )
|
|
25
|
+
// [ [ 'b, '1' ], [ 'c', '2' ], [ 'a', '5' ] ]
|
|
26
|
+
.map( ( entry ) => entry.split( '=' ) )
|
|
27
|
+
// [ [ 'a', '5' ], [ 'b, '1' ], [ 'c', '2' ] ]
|
|
28
|
+
.sort( ( a, b ) => a[ 0 ].localeCompare( b[ 0 ] ) )
|
|
29
|
+
// [ 'a=5', 'b=1', 'c=2' ]
|
|
30
|
+
.map( ( pair ) => pair.join( '=' ) )
|
|
31
|
+
// 'a=5&b=1&c=2'
|
|
32
|
+
.join( '&' )
|
|
33
|
+
);
|
|
34
|
+
}
|
package/src/test/index.js
CHANGED
|
@@ -29,6 +29,8 @@ import {
|
|
|
29
29
|
filterURLForDisplay,
|
|
30
30
|
cleanForSlug,
|
|
31
31
|
getQueryArgs,
|
|
32
|
+
getFilename,
|
|
33
|
+
normalizePath,
|
|
32
34
|
} from '../';
|
|
33
35
|
import wptData from './fixtures/wpt-data';
|
|
34
36
|
|
|
@@ -240,6 +242,7 @@ describe( 'isValidPath', () => {
|
|
|
240
242
|
expect( isValidPath( 'relative/path' ) ).toBe( true );
|
|
241
243
|
expect( isValidPath( 'slightly/longer/path/' ) ).toBe( true );
|
|
242
244
|
expect( isValidPath( 'path/with/percent%20encoding' ) ).toBe( true );
|
|
245
|
+
expect( isValidPath( '/' ) ).toBe( true );
|
|
243
246
|
} );
|
|
244
247
|
|
|
245
248
|
it( 'returns false if the path is invalid', () => {
|
|
@@ -252,6 +255,42 @@ describe( 'isValidPath', () => {
|
|
|
252
255
|
} );
|
|
253
256
|
} );
|
|
254
257
|
|
|
258
|
+
describe( 'getFilename', () => {
|
|
259
|
+
it( 'returns the filename part of the URL', () => {
|
|
260
|
+
expect( getFilename( 'https://wordpress.org/image.jpg' ) ).toBe(
|
|
261
|
+
'image.jpg'
|
|
262
|
+
);
|
|
263
|
+
expect(
|
|
264
|
+
getFilename( 'https://wordpress.org/image.jpg?query=test' )
|
|
265
|
+
).toBe( 'image.jpg' );
|
|
266
|
+
expect( getFilename( 'https://wordpress.org/image.jpg#anchor' ) ).toBe(
|
|
267
|
+
'image.jpg'
|
|
268
|
+
);
|
|
269
|
+
expect(
|
|
270
|
+
getFilename( 'http://localhost:8080/a/path/to/an/image.jpg' )
|
|
271
|
+
).toBe( 'image.jpg' );
|
|
272
|
+
expect( getFilename( '/path/to/an/image.jpg' ) ).toBe( 'image.jpg' );
|
|
273
|
+
expect( getFilename( 'path/to/an/image.jpg' ) ).toBe( 'image.jpg' );
|
|
274
|
+
expect( getFilename( '/image.jpg' ) ).toBe( 'image.jpg' );
|
|
275
|
+
expect( getFilename( 'image.jpg' ) ).toBe( 'image.jpg' );
|
|
276
|
+
} );
|
|
277
|
+
|
|
278
|
+
it( 'returns undefined when the provided value does not contain a filename', () => {
|
|
279
|
+
expect( getFilename( 'http://localhost:8080/' ) ).toBe( undefined );
|
|
280
|
+
expect( getFilename( 'http://localhost:8080/a/path/' ) ).toBe(
|
|
281
|
+
undefined
|
|
282
|
+
);
|
|
283
|
+
expect( getFilename( 'http://localhost:8080/?query=test' ) ).toBe(
|
|
284
|
+
undefined
|
|
285
|
+
);
|
|
286
|
+
expect( getFilename( 'http://localhost:8080/#anchor' ) ).toBe(
|
|
287
|
+
undefined
|
|
288
|
+
);
|
|
289
|
+
expect( getFilename( 'a/path/' ) ).toBe( undefined );
|
|
290
|
+
expect( getFilename( '/' ) ).toBe( undefined );
|
|
291
|
+
} );
|
|
292
|
+
} );
|
|
293
|
+
|
|
255
294
|
describe( 'getQueryString', () => {
|
|
256
295
|
it( 'returns the query string of a URL', () => {
|
|
257
296
|
expect(
|
|
@@ -947,3 +986,26 @@ describe( 'cleanForSlug', () => {
|
|
|
947
986
|
expect( cleanForSlug( null ) ).toBe( '' );
|
|
948
987
|
} );
|
|
949
988
|
} );
|
|
989
|
+
|
|
990
|
+
describe( 'normalizePath', () => {
|
|
991
|
+
it( 'returns same value if no query parameters', () => {
|
|
992
|
+
const path = '/foo/bar';
|
|
993
|
+
|
|
994
|
+
expect( normalizePath( path ) ).toBe( path );
|
|
995
|
+
} );
|
|
996
|
+
|
|
997
|
+
it( 'returns a stable path', () => {
|
|
998
|
+
const abc = normalizePath( '/foo/bar?a=5&b=1&c=2' );
|
|
999
|
+
const bca = normalizePath( '/foo/bar?b=1&c=2&a=5' );
|
|
1000
|
+
const bac = normalizePath( '/foo/bar?b=1&a=5&c=2' );
|
|
1001
|
+
const acb = normalizePath( '/foo/bar?a=5&c=2&b=1' );
|
|
1002
|
+
const cba = normalizePath( '/foo/bar?c=2&b=1&a=5' );
|
|
1003
|
+
const cab = normalizePath( '/foo/bar?c=2&a=5&b=1' );
|
|
1004
|
+
|
|
1005
|
+
expect( abc ).toBe( bca );
|
|
1006
|
+
expect( bca ).toBe( bac );
|
|
1007
|
+
expect( bac ).toBe( acb );
|
|
1008
|
+
expect( acb ).toBe( cba );
|
|
1009
|
+
expect( cba ).toBe( cab );
|
|
1010
|
+
} );
|
|
1011
|
+
} );
|