GuobaGuoba Utils

ensureSuffix

@guoba-ai/utils / string / ensureSuffix

Function: ensureSuffix()

function ensureSuffix(str, suffix): string;

Defined in: string.ts:55

Ensure a string ends with a given suffix.

Parameters

str

string

The input string

suffix

string

The suffix to ensure

Returns

string

The string with the suffix appended if it was missing

Example

ensureSuffix('file.ts', '.ts') // 'file.ts'

ensureSuffix('file', '.ts') // 'file.ts'

ensureSuffix('/api/users', '/') // '/api/users/'

On this page