Skip to content

Transforms

Transforms are pure functions that modify variable values during pattern rendering. They can be chained and accept arguments.

Syntax

{variable:transform}
{variable:transform:arg}
{variable:transform1;transform2}
{variable:transform1;transform2:arg}
  • Transforms are separated by ;
  • Arguments follow the transform name with :
  • Transforms run left-to-right — the output of one is the input of the next

Available Transforms

Text Case

lower

Converts the value to lowercase.

{title:lower}
InputOutput
My Featuremy feature
UPPERCASEuppercase

upper

Converts the value to uppercase.

{title:upper}
InputOutput
my featureMY FEATURE

camel

Converts to camelCase.

{title:camel}
InputOutput
my feature titlemyFeatureTitle
some-kebab-textsomeKebabText

kebab

Converts to kebab-case.

{title:kebab}
InputOutput
My Feature Titlemy-feature-title
camelCasecamel-case

snake

Converts to snake_case.

{title:snake}
InputOutput
My Feature Titlemy_feature_title

title

Converts to Title Case.

{title:title}
InputOutput
my feature titleMy Feature Title

Formatting

slugify

Converts to a URL-safe, git-friendly slug. Removes accents, lowercases, and replaces non-alphanumeric characters with hyphens.

{title:slugify}
InputOutput
My Feature — Title!my-feature-title
Café au laitcafe-au-lait

stripAccents

Removes diacritics/accents from characters without changing case or spacing.

{title:stripAccents}
InputOutput
José GarcíaJose Garcia
crème brûléecreme brulee

Truncation

max:n

Truncates the value to at most n characters.

{title:max:25}
InputOutput
a-very-long-branch-name-herea-very-long-branch-name-

TIP

Use max after slugify to keep branch names short:

{title:slugify;max:30}

words:n

Keeps at most n words (space-separated).

{title:words:3}
InputOutput
add user authentication moduleadd user authentication

String Manipulation

replace:search:replacement

Replaces the first occurrence of a substring.

{title:replace:foo:bar}
InputOutput
foo is foobar is foo

replaceAll:search:replacement

Replaces all occurrences of a substring.

{title:replaceAll:foo:bar}
InputOutput
foo is foobar is bar

remove:substring

Removes all occurrences of a substring.

{title:remove:temp}
InputOutput
temp-feature-temp-feature-

Conditional

ifEmpty:fallback

Uses a fallback value if the input is empty.

{id:ifEmpty:no-id}
InputOutput
PROJ-123PROJ-123
(empty)no-id

before:prefix

Adds a prefix, but only if the value is not empty.

{id:before:ticket-}
InputOutput
123ticket-123
(empty)(empty)

after:suffix

Adds a suffix, but only if the value is not empty.

{id:after:-wip}
InputOutput
123123-wip
(empty)(empty)

Chaining Transforms

Transforms run left-to-right. Order matters:

{title:stripAccents;slugify;max:25}
  1. stripAccentsJose Garcia Login Page
  2. slugifyjose-garcia-login-page
  3. max:25jose-garcia-login-page

WARNING

Order can affect the result. For example:

  • {title:max:5;slugify} — truncates first, then slugifies
  • {title:slugify;max:5} — slugifies first, then truncates

The second form is usually what you want.

Listing Transforms

Use --list-transforms to see all available transforms in your terminal:

bash
npx new-branch --list-transforms

Released under the MIT License.