Skip to content

Function.ensurePrefix

github-actions[bot] edited this page Jul 8, 2026 · 22 revisions

umt / ensurePrefix

Function: ensurePrefix()

ensurePrefix(string_, prefix): string

Defined in: String/ensurePrefix.ts:11

Ensures a string starts with the given prefix, prepending it only when it is not already present.

Parameters

string_

string

Input string

prefix

string

Prefix to ensure

Returns

string

String guaranteed to start with the prefix

Example

ensurePrefix("example.com", "https://"); // "https://example.com"
ensurePrefix("https://example.com", "https://"); // "https://example.com"

API

Classes

Interfaces

Type Aliases

Variables

Functions

Clone this wiki locally