bare-url 0.3.3 → 0.3.5

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.
Files changed (3) hide show
  1. package/index.js +24 -0
  2. package/lib/parse.js +1 -1
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -221,3 +221,27 @@ exports.fileURLToPath = function fileURLToPath (url) {
221
221
 
222
222
  return pathname
223
223
  }
224
+
225
+ exports.pathToFileURL = function pathToFileURL (pathname) {
226
+ let resolved = path.resolve(pathname)
227
+
228
+ if (pathname[pathname.length - 1] === '/') {
229
+ resolved += '/'
230
+ } else if (os.platform() === 'win32' && pathname[pathname.length - 1 === '\\']) {
231
+ resolved += '/'
232
+ }
233
+
234
+ resolved = resolved
235
+ .replaceAll('%', '%25') // Must be first
236
+ .replaceAll('#', '%23')
237
+ .replaceAll('?', '%3f')
238
+ .replaceAll('\n', '%0a')
239
+ .replaceAll('\r', '%0d')
240
+ .replaceAll('\t', '%09')
241
+
242
+ if (os.platform() !== 'win32') {
243
+ resolved = resolved.replaceAll('\\', '%5c')
244
+ }
245
+
246
+ return new URL('file:' + resolved)
247
+ }
package/lib/parse.js CHANGED
@@ -183,7 +183,7 @@ module.exports = function parse (
183
183
  } else {
184
184
  url.username = base.username
185
185
  url.password = base.password
186
- url.host = base.url
186
+ url.host = base.host
187
187
  url.port = base.port
188
188
  state = constants.STATE_PATH
189
189
  pointer--
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-url",
3
- "version": "0.3.3",
3
+ "version": "0.3.5",
4
4
  "description": "URL parser for JavaScript",
5
5
  "main": "index.js",
6
6
  "files": [