subpath-is-present.ts 443 字节
Newer Older
P
Peter Pan 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13
import {parse as parseUrl} from 'url';

export const subpathIsPresent = (url: string | undefined, subpath: string | null) => {
    if (typeof url !== 'string' || typeof subpath !== 'string') {
        return false;
    }

    const {pathname} = parseUrl(url);
    return (
        typeof pathname === 'string' &&
        ((pathname.length === subpath.length + 1 && pathname === `/${subpath}`) || pathname.startsWith(`/${subpath}/`))
    );
};