Skip to content

ensureSuffix

Import from @varavel/vdl-plugin-sdk/utils/strings.

function ensureSuffix(str, suffix): string;

Ensures that a string ends with a specific suffix.

If the string already ends with the suffix, it is returned as is. Otherwise, the suffix is appended to the string.

Parameters

Parameter Type Description
str string The string to check.
suffix string The suffix to ensure.

Returns

string

The string with the suffix ensured.

Example

ensureSuffix('User', 'Error')
// "UserError"

ensureSuffix('UserError', 'Error')
// "UserError"