@@ -1013,17 +1013,18 @@ This function ensures the correct decodings of percent-encoded characters as
1013
1013
well as ensuring a cross-platform valid absolute path string.
1014
1014
1015
1015
``` js
1016
- new URL (' file:///C:/path/' ).pathname ; // Incorrect: /C:/path/
1017
- fileURLToPath (' file:///C:/path/' ); // Correct: C:\path\ (Windows)
1016
+ const url = require (' url' );
1017
+ new URL (' file:///C:/path/' ).pathname ; // Incorrect: /C:/path/
1018
+ url .fileURLToPath (' file:///C:/path/' ); // Correct: C:\path\ (Windows)
1018
1019
1019
- new URL (' file://nas/foo.txt' ).pathname ; // Incorrect: /foo.txt
1020
- fileURLToPath (' file://nas/foo.txt' ); // Correct: \\nas\foo.txt (Windows)
1020
+ new URL (' file://nas/foo.txt' ).pathname ; // Incorrect: /foo.txt
1021
+ url . fileURLToPath (' file://nas/foo.txt' ); // Correct: \\nas\foo.txt (Windows)
1021
1022
1022
- new URL (' file:///你好.txt' ).pathname ; // Incorrect: /%E4%BD%A0%E5%A5%BD.txt
1023
- fileURLToPath (' file:///你好.txt' ); // Correct: /你好.txt (POSIX)
1023
+ new URL (' file:///你好.txt' ).pathname ; // Incorrect: /%E4%BD%A0%E5%A5%BD.txt
1024
+ url . fileURLToPath (' file:///你好.txt' ); // Correct: /你好.txt (POSIX)
1024
1025
1025
- new URL (' file:///hello world' ).pathname ; // Incorrect: /hello%20world
1026
- fileURLToPath (' file:///hello world' ); // Correct: /hello world (POSIX)
1026
+ new URL (' file:///hello world' ).pathname ; // Incorrect: /hello%20world
1027
+ url . fileURLToPath (' file:///hello world' ); // Correct: /hello world (POSIX)
1027
1028
```
1028
1029
1029
1030
### ` url.format(URL[, options]) `
@@ -1053,6 +1054,7 @@ any way. The `url.format(URL[, options])` method allows for basic customization
1053
1054
of the output.
1054
1055
1055
1056
``` js
1057
+ const url = require (' url' );
1056
1058
const myURL = new URL (' https://a:b@測試?abc#foo' );
1057
1059
1058
1060
console .log (myURL .href );
@@ -1077,16 +1079,17 @@ This function ensures that `path` is resolved absolutely, and that the URL
1077
1079
control characters are correctly encoded when converting into a File URL.
1078
1080
1079
1081
``` js
1080
- new URL (__filename ); // Incorrect: throws (POSIX)
1081
- new URL (__filename ); // Incorrect: C:\... (Windows)
1082
- pathToFileURL (__filename ); // Correct: file:///... (POSIX)
1083
- pathToFileURL (__filename ); // Correct: file:///C:/... (Windows)
1082
+ const url = require (' url' );
1083
+ new URL (__filename ); // Incorrect: throws (POSIX)
1084
+ new URL (__filename ); // Incorrect: C:\... (Windows)
1085
+ url .pathToFileURL (__filename ); // Correct: file:///... (POSIX)
1086
+ url .pathToFileURL (__filename ); // Correct: file:///C:/... (Windows)
1084
1087
1085
- new URL (' /foo#1' , ' file:' ); // Incorrect: file:///foo#1
1086
- pathToFileURL (' /foo#1' ); // Correct: file:///foo%231 (POSIX)
1088
+ new URL (' /foo#1' , ' file:' ); // Incorrect: file:///foo#1
1089
+ url . pathToFileURL (' /foo#1' ); // Correct: file:///foo%231 (POSIX)
1087
1090
1088
- new URL (' /some/path%.c' , ' file:' ); // Incorrect: file:///some/path%.c
1089
- pathToFileURL (' /some/path%.c' ); // Correct: file:///some/path%25.c (POSIX)
1091
+ new URL (' /some/path%.c' , ' file:' ); // Incorrect: file:///some/path%.c
1092
+ url . pathToFileURL (' /some/path%.c' ); // Correct: file:///some/path%25.c (POSIX)
1090
1093
```
1091
1094
1092
1095
### ` url.urlToHttpOptions(url) `
@@ -1317,6 +1320,7 @@ The `url.format()` method returns a formatted URL string derived from
1317
1320
` urlObject ` .
1318
1321
1319
1322
``` js
1323
+ const url = require (' url' );
1320
1324
url .format ({
1321
1325
protocol: ' https' ,
1322
1326
hostname: ' example.com' ,
0 commit comments