Skip to content

feat: add default values for {{VALUE:variable}} syntax #821

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 18, 2025

Conversation

chhoumann
Copy link
Owner

@chhoumann chhoumann commented May 29, 2025

Summary

Added support for default values in the {{VALUE:variable}} syntax, allowing users to specify fallback values that will be used when they leave input prompts empty.

New Syntax

{{VALUE:variableName|defaultValue}}

Examples

  • {{VALUE:name|Anonymous}} - Uses "Anonymous" if no input provided
  • {{VALUE:status|draft}} - Uses "draft" as default status
  • {{VALUE:Yes,No,Maybe|Maybe}} - Works with suggesters too

Changes

  • Modified replaceVariableInString() in formatter.ts to parse and handle default values
  • Added new syntax constant VARIABLE_DEFAULT_SYNTAX
  • Updated format syntax arrays in constants
  • Added comprehensive test suite with 16 test cases
  • Updated FormatSyntax.md documentation with examples

Implementation Details

  • Uses pipe character (|) as separator (similar to JavaScript's OR operator)
  • Only first pipe is treated as separator (allows pipes in default values)
  • Whitespace is trimmed from both variable name and default value
  • Backwards compatible - existing templates without defaults continue to work
  • Works seamlessly with suggester functionality

Testing

  • All 16 new tests pass
  • All existing formatter tests pass
  • TypeScript compilation successful
  • Manual testing with various templates

Benefits

  1. Better UX: Users can create templates with sensible defaults
  2. Faster workflows: Skip prompts by accepting defaults
  3. Flexible: Works with all variable types including suggesters
  4. Requested feature: Highly requested by the community (12 reactions)

Related Issues

Fixes #264
Closes #569 (this implementation supersedes PR #569 with more complete test coverage and documentation)

🤖 Generated with Claude Code

- Added support for default values using pipe syntax: {{VALUE:name|default}}
- Default value is used when user provides empty input
- Works seamlessly with suggesters and variable reuse
- Backwards compatible - existing templates continue to work
- Added comprehensive test coverage (16 test cases)
- Updated documentation in FormatSyntax.md
- Updated constants to include new syntax format

This implementation follows the approach from PR #569 but with improved
test coverage, documentation, and edge case handling.

Fixes #264
Closes #569

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link

vercel bot commented May 29, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
quickadd ✅ Ready (Inspect) Visit Preview May 29, 2025 9:16pm

@chhoumann chhoumann merged commit 382294e into master Jun 18, 2025
2 checks passed
@chhoumann chhoumann deleted the feat/issue-264-default-values branch June 18, 2025 18:42
github-actions bot pushed a commit that referenced this pull request Jun 19, 2025
# [1.14.0](1.13.3...1.14.0) (2025-06-19)

### Bug Fixes

* handle undefined variables by returning empty string instead of 'undefined' ([#820](#820)) ([6048ef7](6048ef7)), closes [#209](#209)
* prevent crash when typing comma in VDATE syntax ([2e8939c](2e8939c)), closes [#455](#455)
* replaceLinebreakInString bug with double newlines ([#752](#752)) ([1a02543](1a02543))

### Features

* add canvas template support ([#831](#831)) ([ccfd936](ccfd936)), closes [#663](#663)
* add comma support in VDATE date formats ([6c65266](6c65266))
* add default values for {{VALUE:variable}} syntax ([#821](#821)) ([382294e](382294e)), closes [#569](#569) [#264](#264) [#569](#569)
* **docs:** enhance documentation with improved content, modern design, and framework upgrade ([ae003f8](ae003f8))
* enable VDATE reuse with different formats ([#822](#822)) ([fe1dcac](fe1dcac)), closes [#69](#69)
* enhance field suggestions with advanced filtering and smart defaults ([#826](#826)) ([7b09254](7b09254)), closes [#337](#337) [#337](#337)
Copy link

🎉 This PR is included in version 1.14.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE REQUEST] Default values for {{VALUE:variable}} variables.
1 participant