mirror of
https://github.com/Llewellynvdm/nativefier.git
synced 2024-09-30 05:09:05 +00:00
8f78dd03af
- Add `npm run lint:fix` command - Cleanup inferIcon.js logic slightly
27 lines
673 B
JavaScript
27 lines
673 B
JavaScript
import url from 'url';
|
|
import validator from 'validator';
|
|
|
|
function appendProtocol(testUrl) {
|
|
const parsed = url.parse(testUrl);
|
|
if (!parsed.protocol) {
|
|
return `http://${testUrl}`;
|
|
}
|
|
return testUrl;
|
|
}
|
|
|
|
function normalizeUrl(testUrl) {
|
|
const urlWithProtocol = appendProtocol(testUrl);
|
|
|
|
const validatorOptions = {
|
|
require_protocol: true,
|
|
require_tld: false,
|
|
allow_trailing_dot: true, // mDNS addresses, https://github.com/jiahaog/nativefier/issues/308
|
|
};
|
|
if (!validator.isURL(urlWithProtocol, validatorOptions)) {
|
|
throw new Error(`Your Url: "${urlWithProtocol}" is invalid!`);
|
|
}
|
|
return urlWithProtocol;
|
|
}
|
|
|
|
export default normalizeUrl;
|