cmd-ts
Version:
> 💻 A type-driven command line argument parser, with awesome error reporting 🤤
34 lines • 964 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.HttpUrl = exports.Url = void 0;
const url_1 = require("url");
const __1 = require("..");
/**
* Decodes a string into the `URL` type
*/
exports.Url = (0, __1.extendType)(__1.string, {
displayName: 'url',
description: 'A valid URL',
async from(str) {
const url = new url_1.URL(str);
if (!url.protocol || !url.host) {
throw new Error('Malformed URL');
}
if (!['http:', 'https:'].includes(url.protocol)) {
throw new Error('Only allowed http and https URLs');
}
return url;
},
});
/**
* Decodes an http/https only URL
*/
exports.HttpUrl = (0, __1.extendType)(exports.Url, {
async from(url) {
if (!['http:', 'https:'].includes(url.protocol)) {
throw new Error('Only allowed http and https URLs');
}
return url;
},
});
//# sourceMappingURL=url.js.map