Actions35
- Cleaning Actions
- Coercion Actions
- Comparison Actions
- Increment Actions
- Parsing Actions
- Range Actions
- Sorting Actions
- Validation Actions
Overview
This node provides semantic versioning (semver) utilities focused on comparing two version strings using loose parsing rules. It is useful when you want to compare software versions that may not strictly follow semver formatting but still need to be ordered or checked for equality, difference, or precedence.
Common scenarios include:
- Comparing two version strings from different sources where strict semver compliance is not guaranteed.
- Determining if one version is greater than, less than, or equal to another with tolerance for loosely formatted versions.
- Finding the difference between two versions even if they are not perfectly normalized.
Practical example:
- You have two version strings "1.2" and "1.2.0-beta" and want to know which one is considered newer or if they are equivalent under loose parsing rules.
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 options: |
| - Loose: Whether to use loose parsing for version strings (true/false). | |
| - Include Prerelease: Whether to include prerelease versions in range matching (true/false). | |
| - RTL (Right to Left): Whether to coerce version strings right to left (true/false). |
Note: For this operation ("Compare Loose"), only the "Loose" option is used internally in the comparison function; "Include Prerelease" and "RTL" are available generally but not applied here.
Output
The output JSON contains a result field representing the comparison result as an integer:
-1: Version 1 is less than Version 2.0: Version 1 is equal to Version 2.1: Version 1 is greater than Version 2.
Additionally, the output includes the input versions and the operation name for clarity, e.g.:
{
"operation": "compareLoose",
"version1": "1.2.3",
"version2": "1.2.4",
"result": -1
}
No binary data output is produced by this node.
Dependencies
- Uses the external
semverlibrary for version parsing and comparison. - 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 malformed beyond what loose parsing can handle, the comparison might fail or return unexpected results. Ensure version inputs are at least somewhat recognizable as version numbers.
- Unexpected comparison results: Remember that "loose" parsing allows non-strict semver formats, so some edge cases might behave differently than strict semver comparisons.
- Error messages: Errors typically arise from invalid parameters or unknown resources/operations. Verify that the resource is set to "Comparison" and operation to "Compare Loose".
- Continue On Fail: If enabled, errors will be returned in the output JSON under an
errorfield instead of stopping execution.
Links and References
- Semantic Versioning Specification
- semver npm package - The underlying library used for version operations