resolve-runtime
Version:
This package create server with resolve.
49 lines (40 loc) • 952 B
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _url = _interopRequireDefault(require("url"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const validatePath = (url, {
allowEmptyPath,
allowAbsolutePath
} = {}) => {
if (url === '' && !allowEmptyPath) {
return false;
}
try {
const {
protocol,
slashes,
auth,
host,
port,
hostname,
hash,
search,
query
} = _url.default.parse(url);
if (!allowAbsolutePath && (protocol || slashes || host || port || hostname)) {
return false;
}
if (auth || hash || search || query || /^\//.test(url) || /\/$/.test(url)) {
return false;
}
return true;
} catch (error) {
return false;
}
};
var _default = validatePath;
exports.default = _default;
//# sourceMappingURL=validate_path.js.map
;