Actions35
- Cleaning Actions
- Coercion Actions
- Comparison Actions
- Increment Actions
- Parsing Actions
- Range Actions
- Sorting Actions
- Validation Actions
Overview
This node provides utilities for semantic versioning (semver) operations, focusing on comparing two version strings in the "Comparison" resource with the "Compare" operation. It allows users to compare versions using various comparison methods such as greater than, less than, equality, difference, and more.
Common scenarios include:
- Determining if a software version is newer or older than another.
- Checking if two versions are equal or different.
- Finding the difference type between two versions (major, minor, patch).
- Sorting or ordering versions based on semver rules.
Practical example:
- A CI/CD pipeline can use this node to decide whether to deploy a new build by comparing the current deployed version with the new build version.
- A package manager workflow can verify if a dependency version satisfies certain constraints by comparing versions.
Properties
| Name | Meaning |
|---|---|
| Version 1 | The first version string to compare (e.g., "1.2.3"). |
| Version 2 | The second version string to compare (e.g., "1.2.4"). |
| Options | Collection of optional flags: • Loose: Use loose parsing for version strings (boolean). • Include Prerelease: Include prerelease versions in range matching (boolean). • RTL (Right to Left): Only shown for coercion resource, ignored here. |
The "Options" allow tweaking how version strings are parsed and compared, e.g., enabling loose parsing to accept non-strict semver formats.
Output
The output JSON contains the original input data merged with a result object describing the comparison outcome. For the "Compare" operation under "Comparison" resource, the output includes:
operation: The performed comparison operation name (e.g., "gt", "eq", "diff").version1: The first version string.version2: The second version string.result: The result of the comparison, which varies by operation:- For relational comparisons (
gt,lt, etc.): a boolean indicating the comparison result. - For
compareandrcompare: an integer (-1, 0, 1) indicating order. - For
diff: a string indicating the difference type ("major", "minor", "patch", etc.).
- For relational comparisons (
Example output snippet for a "greater than" check:
{
"operation": "gt",
"version1": "1.2.3",
"version2": "1.2.4",
"result": false
}
Dependencies
- Uses the external
semverlibrary for all semantic version parsing and comparison logic. - No external API keys or services are required.
- No special environment variables or n8n credentials needed.
Troubleshooting
- Invalid version strings: If either version string is not a valid semver format, the comparison may fail or return unexpected results. Ensure inputs conform to semver standards or enable the "Loose" option if necessary.
- Unsupported operations: Using an operation not supported by the "Comparison" resource will throw an error.
- Empty inputs: Providing empty or missing version strings will likely cause errors or invalid results.
- To resolve errors, verify input correctness and consult semver documentation for valid version formats.
Links and References
- Semantic Versioning Specification
- semver npm package
- n8n Documentation (for general node usage)