VDL Plugin SDK

snakeCase

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

function snakeCase(str, upperCase?): string;

Converts a string to snake_case.

The input is tokenized with words, each token is lowercased, and the final string is joined with underscores. This keeps the behavior aligned with the shared SDK word-splitting rules.

When upperCase is true, the same tokenization and joining behavior is preserved but the final tokens are uppercased instead. This is useful for environment variable names and constant-like identifiers.

Empty or separator-only inputs return an empty string.

Parameters

ParameterTypeDefault valueDescription
strstringundefinedString to normalize.
upperCase?booleanfalseWhen true, uppercases each token before joining.

Returns

string

The snake_case representation of str.

Examples

snakeCase("UserProfileName")
// "user_profile_name"
snakeCase("UserProfileName", true)
// "USER_PROFILE_NAME"