silverwolf-x's picture
download
raw
880 Bytes
import type { Normalizer } from '../normalizer'
export class PrefixPathnameNormalizer implements Normalizer {
constructor(private readonly prefix: string) {
if (prefix.endsWith('/')) {
throw new Error(
`PrefixPathnameNormalizer: prefix "${prefix}" should not end with a slash`
)
}
}
public match(pathname: string) {
// If the pathname doesn't start with the prefix, we don't match.
if (pathname !== this.prefix && !pathname.startsWith(this.prefix + '/')) {
return false
}
return true
}
public normalize(pathname: string, matched?: boolean): string {
// If we're not matched and we don't match, we don't need to normalize.
if (!matched && !this.match(pathname)) return pathname
if (pathname.length === this.prefix.length) {
return '/'
}
return pathname.substring(this.prefix.length)
}
}

Xet Storage Details

Size:
880 Bytes
·
Xet hash:
23be130562c8ab661db8866c006f81af2fe441d24f1ec0d0e2910f07de090936

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.