VDL Plugin SDK

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

ParameterTypeDescription
strstringThe string to check.
suffixstringThe suffix to ensure.

Returns

string

The string with the suffix ensured.

Example

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

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