UNPKG

304 BJavaScriptView Raw
1"use strict";
2
3const path = require('path');
4
5module.exports = function fileUrl(str) {
6
7 var pathName = path.resolve(str).replace(/\\/g, '/');
8
9 // Windows drive letter must be prefixed with a slash
10 if(pathName[0] !== '/')
11 pathName = '/' + pathName;
12
13 return encodeURI('file://' + pathName);
14};