1
0
mirror of https://github.com/hotomoe/hotomoe synced 2024-12-01 08:18:14 +09:00

Bye 'is-url'

This commit is contained in:
Acid Chicken (硫酸鶏) 2019-02-04 00:09:24 +09:00
parent 8f2f4b6d2d
commit 8b71006fbe
No known key found for this signature in database
GPG Key ID: 5388F56C75B677A1
3 changed files with 9 additions and 13 deletions

View File

@ -142,7 +142,6 @@
"insert-text-at-cursor": "0.1.1",
"is-root": "2.0.0",
"is-svg": "3.0.0",
"is-url": "1.2.4",
"js-yaml": "3.12.1",
"jsdom": "13.1.0",
"json5": "2.1.0",

View File

@ -1,7 +0,0 @@
declare module 'is-url' {
function isUrl(string: string): boolean;
namespace isUrl {} // Hack
export = isUrl;
}

View File

@ -6,7 +6,6 @@ import * as fs from 'fs';
import { URL } from 'url';
import * as yaml from 'js-yaml';
import { Source, Mixin } from './types';
import * as isUrl from 'is-url';
import * as pkg from '../../package.json';
/**
@ -26,10 +25,7 @@ export default function load() {
const mixin = {} as Mixin;
// Validate URLs
if (!isUrl(config.url)) throw `url="${config.url}" is not a valid URL`;
const url = new URL(config.url);
const url = validateUrl(config.url);
config.url = normalizeUrl(config.url);
mixin.host = url.host;
@ -51,6 +47,14 @@ export default function load() {
return Object.assign(config, mixin);
}
function validateUrl(url: string) {
try {
return new URL(url);
} catch (e) {
throw `url="${url}" is not a valid URL`;
}
}
function normalizeUrl(url: string) {
return url.endsWith('/') ? url.substr(0, url.length - 1) : url;
}