All files url.ts

100% Statements 17/17
100% Branches 3/3
100% Functions 7/7
100% Lines 15/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47    24x   12x 23x 2x       10x     1x 12x                         1x 15x 21x       21x   75x         15x 15x     21x    
 
function isSchemeUrl(url: string, protocols: ReadonlyArray<string>): boolean {
	const starts = protocols.map(i => i + '://');
 
	for (const start of starts) {
		if (url.startsWith(start) && start.length < url.length) {
			return true;
		}
	}
 
	return false;
}
 
export function isHttpUrl(s: string): boolean {
	return isSchemeUrl(s, [
		'https',
		'http',
	]);
}
 
/**
 * パス文字列の結合。
 *
 * @param base 基点となるパス
 * @param path1 結合するパス
 * @param pathN 結合するパス
 */
export function joinPath(base: string, path1: string, ...pathN: ReadonlyArray<string>): string {
	while (base.endsWith('/')) {
		base = base.substring(0, base.length - 1);
	}
 
	function chomp(s: string): string {
		return s
			.split('/')
			.filter(i => i)
			.join('/')
			;
	}
 
	const paths = [path1];
	paths.push(...pathN);
 
	//console.debug(base);
	return base + '/' + paths.map(i => chomp(i)).join('/');
}