Skip to content

indexOfOrThrow

String.indexOfOrThrow(target, source)

Returns the index of the first occurrence of source string in target string, or throws an error if not found.

Example

ts
import { String } from "@monstermann/string";

String.indexOfOrThrow("hello world", "world"); // 6
String.indexOfOrThrow("hello world", "foo"); // throws FnError
ts
import { String } from "@monstermann/string";

pipe("hello world", String.indexOfOrThrow("world")); // 6
pipe("hello world", String.indexOfOrThrow("foo")); // throws FnError