Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/ayonli_jsext/path/index.ts>endsWith

A JavaScript extension package for building strong and modern applications.
Latest
function endsWith
Re-export
import { endsWith } from "https://deno.land/x/ayonli_jsext@v0.9.72/path/index.ts";

Checks if the path ends 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

import { endsWith } from "@ayonli/jsext/path";

console.assert(endsWith("/usr/bin", "bin"));
console.assert(endsWith("C:\\Windows\\System32", "System32"));
console.assert(endsWith("http://example.com/foo/bar", "bar"));
console.assert(endsWith("file:///C:/Windows/System32", "System32"));

// To be noted, an absolute sub path has its own root.
console.assert(!endsWith("/usr/bin", "/bin"));

Parameters

path: string
sub: string
optional
options: PathCompareOptions = [UNSUPPORTED]

Returns

boolean