Files
e-tib.com/node_modules/.pnpm/prepend-http@3.0.1/node_modules/prepend-http/index.js
Marc Mintel d14122005d Initial commit: E-TIB production hardening & E2E foundation
Former-commit-id: ef04fca3d76375630c05aac117bf586953f3b657
2026-04-28 19:11:38 +02:00

20 lines
394 B
JavaScript

'use strict';
module.exports = (url, options) => {
if (typeof url !== 'string') {
throw new TypeError(`Expected \`url\` to be of type \`string\`, got \`${typeof url}\``);
}
url = url.trim();
options = {
https: true,
...options
};
if (/^\.*\/|^(?!localhost)\w+:/.test(url)) {
return url;
}
return url.replace(/^(?!(?:\w+:)?\/\/)/, options.https ? 'https://' : 'http://');
};