import { startsWith } from "https://deno.land/x/ayonli_jsext@v0.9.72/esm/path/index.js";
Checks if the path
starts with the given sub
path.
This function doesn't check the path string directly, instead, it checks the path segments.
This function is ignorant about the path separator, the query string and the hash string (if present). And is case-insensitive on Windows volume symbol by default.
Examples
Example 1
Example 1
import { startsWith } from "@ayonli/jsext/path";
console.assert(startsWith("/usr/bin", "/usr"));
console.assert(startsWith("C:\\Windows\\System32", "c:/Windows"));
console.assert(startsWith("http://example.com/foo/bar", "http://example.com"));
console.assert(startsWith("file:///C:/Windows/System32", "file:///c:/Windows"));
// To be noted, the origin portion of a URL is considered as a whole segment.
console.assert(!startsWith("http://example.com/foo/bar", "example.com"));
console.assert(startsWith("http://example.com/foo/b", "http://example.com"));
// ignore file protocol
console.assert(startsWith("file:///C:/Windows/System32", "C:/Windows/System32", {
ignoreFileProtocol: true,
}));