trimStartBy

import { trimStartBy } from "jsr:@ende/text/unstable-trim-by";

function ยท experimental

function trimStartBy(str: string, pattern: TrimPattern): string

Trims all instances of the specified pattern at the start of the string.

str: string

The input string

pattern: TrimPattern

The pattern to trim

Returns

The trimmed input string

Example: Remove leading byte-order marks

import { trimStartBy } from "@ende/text/unstable-trim-by";
import { assertEquals } from "@ende/assert";

const result = trimStartBy("\ufeffhello world", "\ufeff");
assertEquals(result, "hello world");

Example: Remove leading "http://" or "https://" from a URL

import { trimStartBy } from "@ende/text/unstable-trim-by";
import { assertEquals } from "@ende/assert";

const result = trimStartBy("https://example.com", ["http://", "https://"]);
assertEquals(result, "example.com");

Example: Remove leading numbers from a string

import { trimStartBy } from "@ende/text/unstable-trim-by";
import { assertEquals } from "@ende/assert";

const result = trimStartBy("123abc456", /[0-9]+/);
assertEquals(result, "abc456");

Source