Merge branches 'develop' and 'develop' of https://github.com/syuilo/misskey into develop

This commit is contained in:
syuilo
2019-02-06 13:56:21 +09:00
18 changed files with 100 additions and 3 deletions

View File

@ -47,14 +47,21 @@ export default function load() {
return Object.assign(config, mixin);
}
function validateUrl(url: string) {
function tryCreateUrl(url: string) {
try {
return new URL(url);
} catch (e) {
throw `url="${url}" is not a valid URL`;
throw `url="${url}" is not a valid URL.`;
}
}
function validateUrl(url: string) {
const result = tryCreateUrl(url);
if (result.pathname.replace('/', '').length) throw `url="${url}" is not a valid URL, has a pathname.`;
if (!url.includes(result.host)) throw `url="${url}" is not a valid URL, has an invalid hostname.`;
return result;
}
function normalizeUrl(url: string) {
return url.endsWith('/') ? url.substr(0, url.length - 1) : url;
}

View File

@ -45,7 +45,7 @@ export default class Logger {
this.log(important ? chalk.bgGreen.white('DONE') : chalk.green('DONE'), chalk.green(message), important);
}
public debug(message: string, important = false): void { // デバッグ用に使う(開発者にとっては必要だが利用者にとっては不要な情報)
public debug(message: string, important = false): void { // デバッグ用に使う(開発者に必要だが利用者に不要な情報)
if (process.env.NODE_ENV != 'production' || program.verbose) {
this.log(chalk.gray('VERB'), chalk.gray(message), important);
}

20
src/prelude/maybe.ts Normal file
View File

@ -0,0 +1,20 @@
export interface Maybe<T> {
isJust(): this is Just<T>;
}
export type Just<T> = Maybe<T> & {
get(): T
};
export function just<T>(value: T): Just<T> {
return {
isJust: () => true,
get: () => value
};
}
export function nothing<T>(): Maybe<T> {
return {
isJust: () => false,
};
}