@wordpress/url 4.48.0 → 4.48.2-next.v.202606191442.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 +3 -1
- package/build/filter-url-for-display.cjs +2 -2
- package/build/filter-url-for-display.cjs.map +2 -2
- package/build-module/filter-url-for-display.mjs +2 -2
- package/build-module/filter-url-for-display.mjs.map +2 -2
- package/package.json +2 -3
- package/src/test/index.native.js +0 -53
- package/src/test/is-url.native.js +0 -22
package/CHANGELOG.md
CHANGED
|
@@ -39,7 +39,7 @@ function filterURLForDisplay(url, maxLength = null) {
|
|
|
39
39
|
const urlPieces = filteredURL.split("/");
|
|
40
40
|
const file = urlPieces[urlPieces.length - 1];
|
|
41
41
|
if (file.length <= maxLength) {
|
|
42
|
-
return "
|
|
42
|
+
return "…" + filteredURL.slice(-maxLength);
|
|
43
43
|
}
|
|
44
44
|
const index = file.lastIndexOf(".");
|
|
45
45
|
const [fileName, extension] = [
|
|
@@ -47,7 +47,7 @@ function filterURLForDisplay(url, maxLength = null) {
|
|
|
47
47
|
file.slice(index + 1)
|
|
48
48
|
];
|
|
49
49
|
const truncatedFile = fileName.slice(-3) + "." + extension;
|
|
50
|
-
return file.slice(0, maxLength - truncatedFile.length - 1) + "
|
|
50
|
+
return file.slice(0, maxLength - truncatedFile.length - 1) + "…" + truncatedFile;
|
|
51
51
|
}
|
|
52
52
|
// Annotate the CommonJS export names for ESM import in node:
|
|
53
53
|
0 && (module.exports = {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/filter-url-for-display.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Returns a URL for display.\n *\n * @param url Original URL.\n * @param 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 ); //
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAcO,SAAS,oBACf,KACA,YAA2B,MAClB;AACT,MAAK,CAAE,KAAM;AACZ,WAAO;AAAA,EACR;AAGA,MAAI,cAAc,IAChB,QAAS,+BAA+B,EAAG,EAC3C,QAAS,WAAW,EAAG;AAGzB,MAAK,YAAY,MAAO,YAAa,GAAI;AACxC,kBAAc,YAAY,QAAS,KAAK,EAAG;AAAA,EAC5C;AAGA,QAAM,aAAa;AAEnB,MACC,CAAE,aACF,YAAY,UAAU,aACtB,CAAE,YAAY,MAAO,UAAW,GAC/B;AACD,WAAO;AAAA,EACR;AAGA,gBAAc,YAAY,MAAO,GAAI,EAAG,CAAE;AAC1C,QAAM,YAAY,YAAY,MAAO,GAAI;AACzC,QAAM,OAAO,UAAW,UAAU,SAAS,CAAE;AAC7C,MAAK,KAAK,UAAU,WAAY;AAC/B,WAAO,
|
|
4
|
+
"sourcesContent": ["/**\n * Returns a URL for display.\n *\n * @param url Original URL.\n * @param 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 Displayed URL.\n */\nexport function filterURLForDisplay(\n\turl: string,\n\tmaxLength: number | null = null\n): string {\n\tif ( ! url ) {\n\t\treturn '';\n\t}\n\n\t// Remove protocol and www prefixes.\n\tlet filteredURL = url\n\t\t.replace( /^[a-z\\-.\\+]+[0-9]*:(\\/\\/)?/i, '' )\n\t\t.replace( /^www\\./i, '' );\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\t// capture file name from URL\n\tconst fileRegexp = /\\/([^\\/?]+)\\.(?:[\\w]+)(?=\\?|$)/;\n\n\tif (\n\t\t! maxLength ||\n\t\tfilteredURL.length <= maxLength ||\n\t\t! filteredURL.match( fileRegexp )\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"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAcO,SAAS,oBACf,KACA,YAA2B,MAClB;AACT,MAAK,CAAE,KAAM;AACZ,WAAO;AAAA,EACR;AAGA,MAAI,cAAc,IAChB,QAAS,+BAA+B,EAAG,EAC3C,QAAS,WAAW,EAAG;AAGzB,MAAK,YAAY,MAAO,YAAa,GAAI;AACxC,kBAAc,YAAY,QAAS,KAAK,EAAG;AAAA,EAC5C;AAGA,QAAM,aAAa;AAEnB,MACC,CAAE,aACF,YAAY,UAAU,aACtB,CAAE,YAAY,MAAO,UAAW,GAC/B;AACD,WAAO;AAAA,EACR;AAGA,gBAAc,YAAY,MAAO,GAAI,EAAG,CAAE;AAC1C,QAAM,YAAY,YAAY,MAAO,GAAI;AACzC,QAAM,OAAO,UAAW,UAAU,SAAS,CAAE;AAC7C,MAAK,KAAK,UAAU,WAAY;AAC/B,WAAO,MAAM,YAAY,MAAO,CAAC,SAAU;AAAA,EAC5C;AAGA,QAAM,QAAQ,KAAK,YAAa,GAAI;AACpC,QAAM,CAAE,UAAU,SAAU,IAAI;AAAA,IAC/B,KAAK,MAAO,GAAG,KAAM;AAAA,IACrB,KAAK,MAAO,QAAQ,CAAE;AAAA,EACvB;AACA,QAAM,gBAAgB,SAAS,MAAO,EAAG,IAAI,MAAM;AACnD,SACC,KAAK,MAAO,GAAG,YAAY,cAAc,SAAS,CAAE,IACpD,MACA;AAEF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -15,7 +15,7 @@ function filterURLForDisplay(url, maxLength = null) {
|
|
|
15
15
|
const urlPieces = filteredURL.split("/");
|
|
16
16
|
const file = urlPieces[urlPieces.length - 1];
|
|
17
17
|
if (file.length <= maxLength) {
|
|
18
|
-
return "
|
|
18
|
+
return "…" + filteredURL.slice(-maxLength);
|
|
19
19
|
}
|
|
20
20
|
const index = file.lastIndexOf(".");
|
|
21
21
|
const [fileName, extension] = [
|
|
@@ -23,7 +23,7 @@ function filterURLForDisplay(url, maxLength = null) {
|
|
|
23
23
|
file.slice(index + 1)
|
|
24
24
|
];
|
|
25
25
|
const truncatedFile = fileName.slice(-3) + "." + extension;
|
|
26
|
-
return file.slice(0, maxLength - truncatedFile.length - 1) + "
|
|
26
|
+
return file.slice(0, maxLength - truncatedFile.length - 1) + "…" + truncatedFile;
|
|
27
27
|
}
|
|
28
28
|
export {
|
|
29
29
|
filterURLForDisplay
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/filter-url-for-display.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Returns a URL for display.\n *\n * @param url Original URL.\n * @param 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 ); //
|
|
5
|
-
"mappings": ";AAcO,SAAS,oBACf,KACA,YAA2B,MAClB;AACT,MAAK,CAAE,KAAM;AACZ,WAAO;AAAA,EACR;AAGA,MAAI,cAAc,IAChB,QAAS,+BAA+B,EAAG,EAC3C,QAAS,WAAW,EAAG;AAGzB,MAAK,YAAY,MAAO,YAAa,GAAI;AACxC,kBAAc,YAAY,QAAS,KAAK,EAAG;AAAA,EAC5C;AAGA,QAAM,aAAa;AAEnB,MACC,CAAE,aACF,YAAY,UAAU,aACtB,CAAE,YAAY,MAAO,UAAW,GAC/B;AACD,WAAO;AAAA,EACR;AAGA,gBAAc,YAAY,MAAO,GAAI,EAAG,CAAE;AAC1C,QAAM,YAAY,YAAY,MAAO,GAAI;AACzC,QAAM,OAAO,UAAW,UAAU,SAAS,CAAE;AAC7C,MAAK,KAAK,UAAU,WAAY;AAC/B,WAAO,
|
|
4
|
+
"sourcesContent": ["/**\n * Returns a URL for display.\n *\n * @param url Original URL.\n * @param 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 Displayed URL.\n */\nexport function filterURLForDisplay(\n\turl: string,\n\tmaxLength: number | null = null\n): string {\n\tif ( ! url ) {\n\t\treturn '';\n\t}\n\n\t// Remove protocol and www prefixes.\n\tlet filteredURL = url\n\t\t.replace( /^[a-z\\-.\\+]+[0-9]*:(\\/\\/)?/i, '' )\n\t\t.replace( /^www\\./i, '' );\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\t// capture file name from URL\n\tconst fileRegexp = /\\/([^\\/?]+)\\.(?:[\\w]+)(?=\\?|$)/;\n\n\tif (\n\t\t! maxLength ||\n\t\tfilteredURL.length <= maxLength ||\n\t\t! filteredURL.match( fileRegexp )\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"],
|
|
5
|
+
"mappings": ";AAcO,SAAS,oBACf,KACA,YAA2B,MAClB;AACT,MAAK,CAAE,KAAM;AACZ,WAAO;AAAA,EACR;AAGA,MAAI,cAAc,IAChB,QAAS,+BAA+B,EAAG,EAC3C,QAAS,WAAW,EAAG;AAGzB,MAAK,YAAY,MAAO,YAAa,GAAI;AACxC,kBAAc,YAAY,QAAS,KAAK,EAAG;AAAA,EAC5C;AAGA,QAAM,aAAa;AAEnB,MACC,CAAE,aACF,YAAY,UAAU,aACtB,CAAE,YAAY,MAAO,UAAW,GAC/B;AACD,WAAO;AAAA,EACR;AAGA,gBAAc,YAAY,MAAO,GAAI,EAAG,CAAE;AAC1C,QAAM,YAAY,YAAY,MAAO,GAAI;AACzC,QAAM,OAAO,UAAW,UAAU,SAAS,CAAE;AAC7C,MAAK,KAAK,UAAU,WAAY;AAC/B,WAAO,MAAM,YAAY,MAAO,CAAC,SAAU;AAAA,EAC5C;AAGA,QAAM,QAAQ,KAAK,YAAa,GAAI;AACpC,QAAM,CAAE,UAAU,SAAU,IAAI;AAAA,IAC/B,KAAK,MAAO,GAAG,KAAM;AAAA,IACrB,KAAK,MAAO,QAAQ,CAAE;AAAA,EACvB;AACA,QAAM,gBAAgB,SAAS,MAAO,EAAG,IAAI,MAAM;AACnD,SACC,KAAK,MAAO,GAAG,YAAY,cAAc,SAAS,CAAE,IACpD,MACA;AAEF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/url",
|
|
3
|
-
"version": "4.48.0",
|
|
3
|
+
"version": "4.48.2-next.v.202606191442.0+17fe7db8a",
|
|
4
4
|
"description": "WordPress URL utilities.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -39,7 +39,6 @@
|
|
|
39
39
|
},
|
|
40
40
|
"./package.json": "./package.json"
|
|
41
41
|
},
|
|
42
|
-
"react-native": "src/index",
|
|
43
42
|
"wpScript": true,
|
|
44
43
|
"types": "build-types",
|
|
45
44
|
"sideEffects": false,
|
|
@@ -49,5 +48,5 @@
|
|
|
49
48
|
"publishConfig": {
|
|
50
49
|
"access": "public"
|
|
51
50
|
},
|
|
52
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "1b6a19222df5a88f161880b5789efb3171d8f425"
|
|
53
52
|
}
|
package/src/test/index.native.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Internal dependencies
|
|
3
|
-
*/
|
|
4
|
-
import './index.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* External dependencies
|
|
8
|
-
*/
|
|
9
|
-
import 'react-native-url-polyfill/auto';
|
|
10
|
-
|
|
11
|
-
jest.mock( './fixtures/wpt-data.json', () => {
|
|
12
|
-
const data = jest.requireActual( './fixtures/wpt-data.json' );
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Test items to exclude by input. Ideally this should be empty, but are
|
|
16
|
-
* necessary by non-spec-conformance of the Native implementations.
|
|
17
|
-
* Specifically, the React Native implementation uses an implementation of
|
|
18
|
-
* WHATWG URL without full Unicode support.
|
|
19
|
-
*
|
|
20
|
-
* @type {string[]}
|
|
21
|
-
*/
|
|
22
|
-
const URL_EXCEPTIONS = [
|
|
23
|
-
'https://�',
|
|
24
|
-
'https://%EF%BF%BD',
|
|
25
|
-
'http://a<b',
|
|
26
|
-
'http://a>b',
|
|
27
|
-
'http://a^b',
|
|
28
|
-
'non-special://a<b',
|
|
29
|
-
'non-special://a>b',
|
|
30
|
-
'non-special://a^b',
|
|
31
|
-
'ftp://example.com%80/',
|
|
32
|
-
'ftp://example.com%A0/',
|
|
33
|
-
'https://example.com%80/',
|
|
34
|
-
'https://example.com%A0/',
|
|
35
|
-
'file:///p',
|
|
36
|
-
'file://%C2%AD/p',
|
|
37
|
-
'file://xn--/p',
|
|
38
|
-
'http://a.b.c.xn--pokxncvks',
|
|
39
|
-
'http://10.0.0.xn--pokxncvks',
|
|
40
|
-
'foo://ho|st/',
|
|
41
|
-
'http://ho%3Cst/',
|
|
42
|
-
'http://ho%3Est/',
|
|
43
|
-
'http://ho%7Cst/',
|
|
44
|
-
'file://%43%7C',
|
|
45
|
-
'file://%43|',
|
|
46
|
-
'file://C%7C',
|
|
47
|
-
'file://%43%7C/',
|
|
48
|
-
'https://%43%7C/',
|
|
49
|
-
'asdf://%43|/',
|
|
50
|
-
];
|
|
51
|
-
|
|
52
|
-
return data.filter( ( { input } ) => ! URL_EXCEPTIONS.includes( input ) );
|
|
53
|
-
} );
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Internal dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { isURL } from '../is-url';
|
|
5
|
-
|
|
6
|
-
describe( 'isURL valid', () => {
|
|
7
|
-
it.each( [
|
|
8
|
-
[ 'http://wordpress.org' ],
|
|
9
|
-
[ 'https://wordpress.org/path?query#fragment' ],
|
|
10
|
-
] )( '%s', ( input ) => {
|
|
11
|
-
expect( isURL( input ) ).toBe( true );
|
|
12
|
-
} );
|
|
13
|
-
} );
|
|
14
|
-
|
|
15
|
-
describe( 'isURL invalid', () => {
|
|
16
|
-
it.each( [
|
|
17
|
-
[ 'http://wordpress.org:port' ],
|
|
18
|
-
[ 'HTTP: HyperText Transfer Protocol' ],
|
|
19
|
-
] )( '%s', ( input ) => {
|
|
20
|
-
expect( isURL( input ) ).toBe( false );
|
|
21
|
-
} );
|
|
22
|
-
} );
|