Skip to content

strings

Functions

camelCase()

function camelCase(str): string;

Converts a string to camelCase.

Tokenization is delegated to words, so mixed input styles such as snake_case, kebab-case, PascalCase, camelCase, and separator-heavy strings are normalized first and then reassembled.

The first token is lowercased. Every following token is capitalized with the remainder lowercased. Empty or separator-only inputs return an empty string.

Parameters

str

string

String to normalize.

Returns

string

The camelCase representation of str.

Example

camelCase("user_profile-name")
// "userProfileName"

dedent()

function dedent(input): string;

Removes shared indentation from a multi-line string.

This helper is useful for generating readable code templates, markdown, or text fixtures inside plugins without carrying indentation from the source file into the final output.

Parameters

input

string

Multi-line string to dedent.

Returns

string

The same text with common indentation removed.

Example

dedent(`
         export interface User {
           id: string;
         }
`);
// returns "export interface User {\n  id: string;\n}"

See

Powered by dedent (MIT License): https://github.com/dmnd/dedent


kebabCase()

function kebabCase(str, upperCase?): string;

Converts a string to kebab-case.

The function tokenizes the input with words, lowercases every token, and joins the result with hyphens. This allows mixed casing conventions and noisy separators to converge into a consistent kebab-cased string.

When upperCase is true, the same tokenization and joining rules are used, but the final tokens are uppercased instead. This is useful for constants, identifiers, or file names that still need kebab separators.

Empty or separator-only inputs return an empty string.

Parameters

str

string

String to normalize.

upperCase?

boolean = false

When true, uppercases each token before joining.

Returns

string

The kebab-case representation of str.

Examples

kebabCase("UserProfileName")
// "user-profile-name"
kebabCase("UserProfileName", true)
// "USER-PROFILE-NAME"

lowerCase()

function lowerCase(str): string;

Converts a string to lowercase words separated by spaces.

The input is normalized with words, then each token is lowercased and joined using a single space. This is useful when a readable, sentence-like representation is preferred over identifier-style separators.

Empty or separator-only inputs return an empty string.

Parameters

str

string

String to normalize.

Returns

string

The lowercased space-separated representation of str.

Example

lowerCase("userProfileName")
// "user profile name"

pad()

function pad(
   str, 
   length, 
   chars?): string;

Pads both sides of a string until it reaches the requested length.

Padding is only added when the string is shorter than length. The padding pattern repeats as needed and is truncated to fit exactly. When the total number of padding characters cannot be split evenly, the right side receives one more character than the left side.

By default, spaces are used as padding. Pass chars to use a custom padding pattern. If chars is an empty string, the input is returned unchanged.

The target length is truncated with Math.trunc, so decimal lengths behave predictably. Non-finite lengths are ignored and return the original string.

Parameters

str

string

String to pad.

length

number

Final string length to target.

chars?

string

Optional padding characters to repeat.

Returns

string

str centered within the requested width.

Examples

pad("cat", 7)
// "  cat  "
pad("cat", 8, "_-")
// "_-cat_-_"

padLeft()

function padLeft(
   str, 
   length, 
   chars?): string;

Pads the left side of a string until it reaches the requested length.

Padding is added only when the string is shorter than length. The padding pattern repeats as needed and is truncated to fit exactly.

By default, spaces are used as padding. Pass chars to use a custom padding pattern. If chars is an empty string, the input is returned unchanged.

The target length is truncated with Math.trunc, and non-finite lengths are ignored by returning the original string.

Parameters

str

string

String to pad.

length

number

Final string length to target.

chars?

string

Optional padding characters to repeat.

Returns

string

str padded on the left up to length characters.

Example

padLeft("cat", 5, "0")
// "00cat"

padRight()

function padRight(
   str, 
   length, 
   chars?): string;

Pads the right side of a string until it reaches the requested length.

Padding is added only when the string is shorter than length. The padding pattern repeats as needed and is truncated to fit exactly.

By default, spaces are used as padding. Pass chars to use a custom padding pattern. If chars is an empty string, the input is returned unchanged.

The target length is truncated with Math.trunc, and non-finite lengths are ignored by returning the original string.

Parameters

str

string

String to pad.

length

number

Final string length to target.

chars?

string

Optional padding characters to repeat.

Returns

string

str padded on the right up to length characters.

Example

padRight("cat", 5, "0")
// "cat00"

pascalCase()

function pascalCase(str): string;

Converts a string to PascalCase.

The input is first tokenized with words, allowing the function to accept a wide range of source formats such as snake_case, kebab-case, spaced strings, camelCase, or acronym-heavy identifiers.

Every token is normalized to an initial uppercase letter followed by a lowercased remainder. Empty or separator-only inputs return an empty string.

Parameters

str

string

String to normalize.

Returns

string

The PascalCase representation of str.

Example

pascalCase("user_profile-name")
// "UserProfileName"

snakeCase()

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

str

string

String to normalize.

upperCase?

boolean = false

When 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"

trim()

function trim(str, chars?): string;

Removes matching characters from both ends of a string.

By default, the function trims leading and trailing whitespace using the platform's built-in whitespace semantics.

When chars is provided, only those characters are trimmed from the start and end of the string. A string value is interpreted as a set of individual characters, and an array combines all characters from all entries. For example, trim("__value--", "_-") and trim("__value--", ["_", "-"]) both return "value".

Characters are removed only at the outer edges; matching characters inside the string are preserved.

Parameters

str

string

String to trim.

chars?

Optional characters to remove instead of whitespace.

string | readonly string[]

Returns

string

A copy of str without the matching leading and trailing characters.

Examples

trim("  hello  ")
// "hello"
trim("__hello--", ["_", "-"])
// "hello"

trimEnd()

function trimEnd(str, chars?): string;

Removes matching characters from the end of a string.

By default, the function trims trailing whitespace using the platform's built-in whitespace semantics.

When chars is provided, only those characters are removed from the end. A string value is interpreted as a set of individual characters, and an array combines all characters from all entries.

Matching characters that appear earlier in the string are preserved.

Parameters

str

string

String to trim.

chars?

Optional characters to remove instead of whitespace.

string | readonly string[]

Returns

string

A copy of str without the matching trailing characters.

Examples

trimEnd("  hello  ")
// "  hello"
trimEnd("__hello__", "_")
// "__hello"

trimStart()

function trimStart(str, chars?): string;

Removes matching characters from the start of a string.

By default, the function trims leading whitespace using the platform's built-in whitespace semantics.

When chars is provided, only those characters are removed from the start. A string value is interpreted as a set of individual characters, and an array combines all characters from all entries.

Matching characters that appear later in the string are preserved.

Parameters

str

string

String to trim.

chars?

Optional characters to remove instead of whitespace.

string | readonly string[]

Returns

string

A copy of str without the matching leading characters.

Examples

trimStart("  hello  ")
// "hello  "
trimStart("__hello__", "_")
// "hello__"

upperCase()

function upperCase(str): string;

Converts a string to uppercase words separated by spaces.

The input is normalized with words, then each token is uppercased and joined using a single space. This is useful for readable labels, headings, or enum-like display values derived from mixed naming conventions.

Empty or separator-only inputs return an empty string.

Parameters

str

string

String to normalize.

Returns

string

The uppercased space-separated representation of str.

Example

upperCase("userProfileName")
// "USER PROFILE NAME"

words()

function words(str): string[];

Splits a string into normalized word tokens.

The function preserves the current tokenization rules used by the SDK: it inserts spaces at camelCase and acronym-to-word boundaries, converts any non-alphanumeric separator to a space, trims the result, and then splits on whitespace.

This makes it suitable for inputs such as camelCase, PascalCase, HTTPServer, snake_case, kebab-case, and mixed separator variants.

Empty or separator-only inputs return an empty array.

Parameters

str

string

String to tokenize.

Returns

string[]

An array of normalized word tokens.

Example

words("HTTPServer_error-code");
// returns ["HTTP", "Server", "error", "code"]