Value Transformers
Value transformers allow you to transform prompt and variable values before theyβre used in your configurations. This enables powerful data manipulation and validation workflows.
Table of Contents
- Overview
- Built-in Transformers
- Transformer Types
- Using Transformers
- Transformer Chains
- Custom Transformers
- Examples
Overview
Transformers are applied to:
- Prompts: Transform user input before storing in variables
- Variables: Transform computed values before using in configurations
- Global Transformers: Define custom transformers for reuse across your configuration
Key Features
- Built-in transformers for common string operations (case conversion, formatting, cleaning)
- Regex transformers for pattern-based replacements
- Computed transformers for JavaScript expressions
- Chain transformers to apply multiple transformations sequentially
- Custom transformers defined globally and reused throughout your configuration
Built-in Transformers
Scaffoldfy provides these built-in transformers:
lowercase
Converts the value to lowercase.
{
"id": "email",
"message": "Enter your email",
"type": "input",
"transformers": ["lowercase"]
}
uppercase
Converts the value to uppercase.
{
"id": "constantName",
"message": "Enter constant name",
"type": "input",
"transformers": ["uppercase"]
}
trim
Removes leading and trailing whitespace.
{
"id": "username",
"message": "Enter username",
"type": "input",
"transformers": ["trim"]
}
slugify
Converts a string to a URL-friendly slug (lowercase, spaces to hyphens, special chars removed).
{
"id": "projectName",
"message": "Enter project name",
"type": "input",
"transformers": ["slugify"]
}
Example:
- Input:
"My Awesome Project!" - Output:
"my-awesome-project"
capitalize
Capitalizes the first letter of the string.
{
"id": "title",
"message": "Enter title",
"type": "input",
"transformers": ["capitalize"]
}
Example:
- Input:
"hello world" - Output:
"Hello world"
titlecase
Converts the string to title case (capitalizes the first letter of each word with spaces). This transformer properly handles all input formats (camelCase, kebab-case, snake_case, etc.) and converts them to a properly formatted title.
{
"id": "headline",
"message": "Enter headline",
"type": "input",
"transformers": ["titlecase"]
}
Examples:
- Input:
"hello world example"β Output:"Hello World Example" - Input:
"fooBar"β Output:"Foo Bar" - Input:
"foo-bar-baz"β Output:"Foo Bar Baz" - Input:
"foo_bar"β Output:"Foo Bar" - Input:
"FooBarBaz"β Output:"Foo Bar Baz"
This is the recommended transformer when you want to convert any format to a human-readable title with proper capitalization and spacing.
capitalCase
Converts the string to capital case (capitalizes the first letter of each word).
{
"id": "headline",
"message": "Enter headline",
"type": "input",
"transformers": ["capitalCase"]
}
Example:
- Input:
"hello world example" - Output:
"Hello World Example"
camelcase
Converts the string to camelCase.
{
"id": "variableName",
"message": "Enter variable name",
"type": "input",
"transformers": ["camelcase"]
}
Example:
- Input:
"hello world example" - Output:
"helloWorldExample"
pascalcase
Converts the string to PascalCase.
{
"id": "className",
"message": "Enter class name",
"type": "input",
"transformers": ["pascalcase"]
}
Example:
- Input:
"hello world example" - Output:
"HelloWorldExample"
snakecase
Converts the string to snake_case.
{
"id": "fileName",
"message": "Enter file name",
"type": "input",
"transformers": ["snakecase"]
}
Example:
- Input:
"Hello World Example" - Output:
"hello_world_example"
kebabcase
Converts the string to kebab-case.
{
"id": "cssClass",
"message": "Enter CSS class",
"type": "input",
"transformers": ["kebabcase"]
}
Example:
- Input:
"Hello World Example" - Output:
"hello-world-example"
constantcase
Converts the string to CONSTANT_CASE.
{
"id": "envVar",
"message": "Enter environment variable",
"type": "input",
"transformers": ["constantcase"]
}
Example:
- Input:
"hello world example" - Output:
"HELLO_WORLD_EXAMPLE"
alphanumeric
Removes all non-alphanumeric characters from the string.
{
"id": "cleanId",
"message": "Enter identifier",
"type": "input",
"transformers": ["alphanumeric"]
}
Example:
- Input:
"Hello@World#123!" - Output:
"HelloWorld123"
collapse-spaces
Collapses multiple consecutive spaces into a single space.
{
"id": "description",
"message": "Enter description",
"type": "input",
"transformers": ["collapse-spaces"]
}
Example:
- Input:
"Hello World Example" - Output:
"Hello World Example"
remove-spaces
Removes all spaces from the string.
{
"id": "compactName",
"message": "Enter compact name",
"type": "input",
"transformers": ["remove-spaces"]
}
Example:
- Input:
"Hello World Example" - Output:
"HelloWorldExample"
urlencode
URL-encodes the string.
{
"id": "encodedUrl",
"message": "Enter URL",
"type": "input",
"transformers": ["urlencode"]
}
Example:
- Input:
"Hello World" - Output:
"Hello%20World"
dasherize
Converts the string to dash-separated format (similar to kebab-case but may handle special cases).
{
"id": "dashedName",
"message": "Enter dashed name",
"type": "input",
"transformers": ["dasherize"]
}
Example:
- Input:
"HelloWorldExample" - Output:
"hello-world-example"
underscore
Converts the string to underscore-separated format (similar to snake_case but may handle special cases).
{
"id": "underscoredName",
"message": "Enter underscored name",
"type": "input",
"transformers": ["underscore"]
}
Example:
- Input:
"HelloWorldExample" - Output:
"hello_world_example"
adaCase
Converts the string to Ada_Case format (capitalized words separated by underscores).
{
"id": "adaName",
"message": "Enter Ada-style name",
"type": "input",
"transformers": ["adaCase"]
}
Example:
- Input:
"helloWorldExample" - Output:
"Hello_World_Example"
cobolCase
Converts the string to COBOL-CASE format (uppercase words separated by hyphens).
{
"id": "cobolName",
"message": "Enter COBOL-style name",
"type": "input",
"transformers": ["cobolCase"]
}
Example:
- Input:
"helloWorldExample" - Output:
"HELLO-WORLD-EXAMPLE"
dotNotation
Converts the string to dot.notation format (lowercase words separated by dots).
{
"id": "propertyPath",
"message": "Enter property path",
"type": "input",
"transformers": ["dotNotation"]
}
Example:
- Input:
"helloWorldExample" - Output:
"hello.World.Example"(note: preserves original casing within segments)
pathCase
Converts the string to path/case format (words separated by forward slashes).
{
"id": "filePath",
"message": "Enter file path",
"type": "input",
"transformers": ["pathCase"]
}
Example:
- Input:
"helloWorldExample" - Output:
"hello/World/Example"(note: preserves original casing within segments)
spaceCase
Converts the string to space case format (words separated by spaces, lowercase).
{
"id": "displayName",
"message": "Enter display name",
"type": "input",
"transformers": ["spaceCase"]
}
Example:
- Input:
"helloWorldExample" - Output:
"hello World Example"(note: may preserve some original casing)
trainCase
Converts the string to Train-Case format (capitalized words separated by hyphens).
{
"id": "trainName",
"message": "Enter Train-Case name",
"type": "input",
"transformers": ["trainCase"]
}
Example:
- Input:
"helloWorldExample" - Output:
"Hello-World-Example"
upperCamelCase
Converts the string to UpperCamelCase format (same as PascalCase).
{
"id": "componentName",
"message": "Enter component name",
"type": "input",
"transformers": ["upperCamelCase"]
}
Example:
- Input:
"hello-world-example" - Output:
"HelloWorldExample"
Transformer Types
Regex Transformer
Apply regular expression find-and-replace operations.
{
"type": "regex",
"pattern": "-",
"replacement": "_",
"flags": "g"
}
Properties:
pattern(string, required): The regex pattern to matchreplacement(string, required): The replacement stringflags(string, optional): Regex flags (e.g., βgβ for global, βiβ for case-insensitive)
Example:
{
"id": "snakeCaseName",
"value": "",
"transformers": [
{
"type": "regex",
"pattern": "-",
"replacement": "_",
"flags": "g"
}
]
}
Computed Transformer
Evaluate a JavaScript expression with access to all context variables.
{
"type": "computed",
"expression": "projectName.length"
}
Properties:
expression(string, required): JavaScript expression to evaluate
Example:
{
"id": "nameLength",
"value": "computed",
"transformers": [
{
"type": "computed",
"expression": "projectName.length"
}
]
}
Available Context: All prompts, variables, and environment variables are available in the expression:
{
"type": "computed",
"expression": "projectName.toUpperCase() + '_' + version"
}
Using Transformers
On Prompts
Transform user input before storing:
{
"prompts": [
{
"id": "projectName",
"message": "What is the project name?",
"type": "input",
"transformers": ["slugify"]
},
{
"id": "description",
"message": "Project description",
"type": "input",
"transformers": ["trim"]
}
]
}
On Variables
Transform computed variable values:
{
"variables": [
{
"id": "upperProjectName",
"value": "",
"transformers": ["uppercase"]
},
{
"id": "packageName",
"value": "",
"transformers": [
"lowercase",
{
"type": "regex",
"pattern": "\\s+",
"replacement": "-",
"flags": "g"
}
]
}
]
}
Transformer Chains
Apply multiple transformers in sequence by using an array:
{
"id": "cleanedName",
"value": " My Project ",
"transformers": ["trim", "lowercase", "slugify"]
}
Execution Order:
trimβ"My Project"lowercaseβ"my project"slugifyβ"my-project"
Complex Chain Example
{
"id": "formattedName",
"value": "",
"transformers": [
"trim",
{
"type": "regex",
"pattern": "[^a-zA-Z0-9\\s-]",
"replacement": "",
"flags": "g"
},
"lowercase",
{
"type": "regex",
"pattern": "\\s+",
"replacement": "-",
"flags": "g"
}
]
}
Custom Transformers
Define custom transformers globally and reference them by ID throughout your configuration.
Defining Custom Transformers
{
"transformers": [
{
"id": "reverse",
"type": "custom",
"handler": "value => value.split('').reverse().join('')"
},
{
"id": "capitalize",
"type": "custom",
"handler": "value => value.charAt(0).toUpperCase() + value.slice(1)"
}
]
}
Using Custom Transformers
Reference custom transformers by their ID:
{
"id": "reversedName",
"value": "",
"transformers": ["reverse"]
}
Or combine with other transformers:
{
"id": "processedName",
"value": "",
"transformers": ["trim", "lowercase", "capitalize"]
}
Examples
Complete Configuration with Transformers
{
"$schema": "https://unpkg.com/@pixpilot/scaffoldfy/schema",
"name": "transformers-example",
"description": "Example configuration demonstrating value transformers",
"prompts": [
{
"id": "projectName",
"message": "What is the project name?",
"type": "input",
"required": true,
"transformers": ["slugify"]
},
{
"id": "description",
"message": "Project description",
"type": "input",
"transformers": ["trim"]
},
{
"id": "authorEmail",
"message": "Author email",
"type": "input",
"transformers": ["lowercase"]
}
],
"variables": [
{
"id": "upperProjectName",
"value": "",
"transformers": ["uppercase"]
},
{
"id": "packageName",
"value": "",
"transformers": [
"lowercase",
{
"type": "regex",
"pattern": "-",
"replacement": "_",
"flags": "g"
}
]
},
{
"id": "nameLength",
"value": "computed",
"transformers": [
{
"type": "computed",
"expression": "projectName.length"
}
]
}
],
"tasks": [
{
"id": "create-readme",
"name": "Create README",
"type": "write",
"config": {
"file": "README.md",
"template": "# \n\n\n\nPackage: \nAuthor: \nName Length: \n"
}
}
]
}
Real-World Use Cases
1. NPM Package Name from Project Name
{
"prompts": [
{
"id": "projectName",
"message": "Project name",
"type": "input",
"transformers": [
"trim",
"lowercase",
{
"type": "regex",
"pattern": "[^a-z0-9-]",
"replacement": "",
"flags": "g"
}
]
}
]
}
2. Generate Multiple Name Variants
{
"prompts": [
{
"id": "componentName",
"message": "Component name",
"type": "input"
}
],
"variables": [
{
"id": "componentKebab",
"value": "",
"transformers": ["slugify"]
},
{
"id": "componentPascal",
"value": "",
"transformers": [
{
"type": "regex",
"pattern": "[-_\\s]+(.)?",
"replacement": "$1",
"flags": "g"
},
{
"type": "computed",
"expression": "componentName.charAt(0).toUpperCase() + componentName.slice(1)"
}
]
}
]
}
3. Clean and Validate Email
{
"prompts": [
{
"id": "email",
"message": "Email address",
"type": "input",
"transformers": ["trim", "lowercase"]
}
]
}
Best Practices
- Chain Order Matters: Apply transformers in logical order (e.g., trim before lowercase)
- Use Built-ins First: Leverage built-in transformers for common operations
- Keep Custom Simple: Complex logic is better in computed transformers
- Test Expressions: Verify computed transformer expressions work with your data
- Document Custom Transformers: Add descriptions for reusable custom transformers
Limitations
- Custom transformer handlers must be valid JavaScript arrow function expressions
- Computed expressions have access to configuration context but not Node.js modules
- Transformers run synchronously - async operations are not supported
- Regex transformers use JavaScript RegExp - some advanced features may not be available