Semver icon

Semver

Semantic Versioning utilities for version management

Overview

This node validates semantic version strings using the "semver" library. It checks if a given version string conforms to the semantic versioning specification and can also clean version strings by normalizing them.

Common scenarios where this node is useful include:

  • Ensuring that version inputs in workflows are valid semantic versions before proceeding with deployment or release automation.
  • Cleaning up user input or external data to produce normalized version strings.
  • Validating version strings in CI/CD pipelines or package management workflows.

Practical example:

  • Input a version string like 1.2.3-alpha and check if it is valid.
  • Clean a messy version string like v1.2.3+build to a normalized form 1.2.3.

Properties

Name Meaning
Version The semantic version string to validate or clean (e.g., "1.2.3", "2.0.0-beta").
Options Collection of options:
- Loose: Whether to use loose parsing for version strings (boolean).
- Include Prerelease: Whether to include prerelease versions in range matching (boolean).

Output

The output JSON contains the original input fields plus a result field with details depending on the operation:

  • For the Valid operation:

    • operation: "valid"
    • version: The input version string.
    • isValid: Boolean indicating if the version string is valid.
    • parsedVersion: The normalized valid version string or null if invalid.
  • For the Clean operation:

    • operation: "clean"
    • version: The input version string.
    • cleanedVersion: The cleaned and normalized version string or null if cleaning failed.

No binary data is produced by this node.

Dependencies

  • Uses the external semver npm package for semantic version parsing, validation, and cleaning.
  • No external API keys or services are required.
  • No special environment variables or n8n credentials needed.

Troubleshooting

  • Invalid version strings: If the input version string is not a valid semantic version, the isValid field will be false and parsedVersion will be null. Ensure the input follows semantic versioning format (e.g., MAJOR.MINOR.PATCH).
  • Cleaning returns null: If cleaning fails, the cleanedVersion will be null. This usually means the input cannot be normalized into a valid semver string.
  • Loose parsing option: Enabling the "Loose" option allows more permissive parsing but may lead to unexpected results if the input is malformed.
  • Error handling: If an error occurs during execution, the node will either throw an error or continue on fail based on configuration, returning the error message in the output JSON.

Links and References

Discussion