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
| Parameter | Type | Description |
|---|---|---|
str | string | The string to check. |
prefix | string | The prefix to ensure. |
Returns
string
The string with the prefix ensured.
Example
ensurePrefix('User', 'I')
// "IUser"
ensurePrefix('IUser', 'I')
// "IUser"