Skip to content

Function.ensureSuffix

github-actions[bot] edited this page Jun 11, 2026 · 22 revisions

umt / ensureSuffix

Function: ensureSuffix()

ensureSuffix(string_, suffix): string

Defined in: String/ensureSuffix.ts:11

Ensures a string ends with the given suffix, appending it only when it is not already present.

Parameters

string_

string

Input string

suffix

string

Suffix to ensure

Returns

string

String guaranteed to end with the suffix

Example

ensureSuffix("file", ".txt"); // "file.txt"
ensureSuffix("file.txt", ".txt"); // "file.txt"

API

Classes

Interfaces

Type Aliases

Variables

Functions

Clone this wiki locally