Semver icon

Semver

Semantic Versioning utilities for version management

Overview

This node provides utilities for working with semantic versioning (semver) ranges. Specifically, the "Range" resource with the "To Comparators" operation converts a semver range string into an array of comparator sets. This is useful when you want to analyze or manipulate the individual comparators that define a version range.

Common scenarios include:

  • Breaking down complex version ranges into simpler comparator expressions.
  • Validating or transforming version constraints in package management or deployment pipelines.
  • Integrating with systems that require explicit comparator lists rather than range strings.

For example, given a range string like ^1.2.0 || >=2.0.0 <3.0.0, this operation will output the corresponding comparator sets that represent this range.

Properties

Name Meaning
Options Collection of optional flags:
• Loose: Whether to use loose parsing for version strings.
• Include Prerelease: Whether to include prerelease versions in range matching.

Output

The node outputs a JSON object containing:

  • operation: The string "toComparators" indicating the performed operation.
  • range: The input version range string.
  • result: An array representing the comparator sets derived from the range. Each element corresponds to a set of comparators that define part of the range.

Example output structure:

{
  "operation": "toComparators",
  "range": "^1.2.0",
  "result": [
    [
      { "operator": ">=", "semver": "1.2.0" },
      { "operator": "<", "semver": "2.0.0" }
    ]
  ]
}

This output can be used downstream to inspect or process individual comparators explicitly.

Dependencies

  • Uses the semver library internally for all semantic version parsing and manipulation.
  • No external API keys or services are required.
  • No special environment variables or n8n credentials needed.

Troubleshooting

  • Invalid Range String: If the provided range string is malformed or invalid, the node may throw an error or return null results. Ensure the range string follows semver range syntax.
  • Loose Parsing Issues: Enabling the "Loose" option allows more permissive parsing but may lead to unexpected results if the input is ambiguous.
  • Empty or Missing Input: Providing an empty range string will result in no comparators; ensure the input is correctly set.
  • Include Prerelease Flag: If prerelease versions are relevant, enable the "Include Prerelease" option; otherwise, they might be excluded from matching logic.

Links and References

Discussion