Files
e-tib.com/node_modules/.pnpm/file-url@3.0.0/node_modules/file-url/index.js
T
mmintel d14122005d Initial commit: E-TIB production hardening & E2E foundation
Former-commit-id: ef04fca3d76375630c05aac117bf586953f3b657
2026-04-28 19:11:38 +02:00

31 lines
684 B
JavaScript

'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);
};