Initial commit (from f5274cbdce4ae7c9e4b937dcdf95ac70ae436d5f)
This commit is contained in:
commit
28ccc3db2d
13974 changed files with 2618436 additions and 0 deletions
30
node_modules/file-url/index.js
generated
vendored
Normal file
30
node_modules/file-url/index.js
generated
vendored
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
'use strict';
|
||||
const path = require('path');
|
||||
|
||||
module.exports = (filePath, options) => {
|
||||
if (typeof filePath !== 'string') {
|
||||
throw new TypeError(`Expected a string, got ${typeof filePath}`);
|
||||
}
|
||||
|
||||
options = {
|
||||
resolve: true,
|
||||
...options
|
||||
};
|
||||
|
||||
let pathName = filePath;
|
||||
|
||||
if (options.resolve) {
|
||||
pathName = path.resolve(filePath);
|
||||
}
|
||||
|
||||
pathName = pathName.replace(/\\/g, '/');
|
||||
|
||||
// Windows drive letter must be prefixed with a slash
|
||||
if (pathName[0] !== '/') {
|
||||
pathName = `/${pathName}`;
|
||||
}
|
||||
|
||||
// Escape required characters for path components
|
||||
// See: https://tools.ietf.org/html/rfc3986#section-3.3
|
||||
return encodeURI(`file://${pathName}`).replace(/[?#]/g, encodeURIComponent);
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue