VDL Plugin SDK

ensurePrefix

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

function ensurePrefix(str, prefix): string;

Ensures that a string starts with a specific prefix.

If the string already starts with the prefix, it is returned as is. Otherwise, the prefix is prepended to the string.

Parameters

ParameterTypeDescription
strstringThe string to check.
prefixstringThe prefix to ensure.

Returns

string

The string with the prefix ensured.

Example

ensurePrefix('User', 'I')
// "IUser"

ensurePrefix('IUser', 'I')
// "IUser"