All Projects → h2non → Semver.c

h2non / Semver.c

Licence: mit
Semantic version library written in ANSI C

Programming Languages

c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to Semver.c

perfekt
Release, changelog and version your packages with perfe(k)t 👌 ease!
Stars: ✭ 15 (-89.8%)
Mutual labels:  semantic, semver, versioning, version
Python Semver
Python package to work with Semantic Versioning (http://semver.org/)
Stars: ✭ 264 (+79.59%)
Mutual labels:  versioning, version, semver
Grabver
Gradle Automatic Build Versioning Plugin - An easy Gradle plugin that follows semver.org rules to automatically generate the Patch version, Build number and Code version, while Major, Minor and Pre-Release suffix remain under our control.
Stars: ✭ 39 (-73.47%)
Mutual labels:  versioning, version, semver
Standard Version
🏆 Automate versioning and CHANGELOG generation, with semver.org and conventionalcommits.org
Stars: ✭ 5,806 (+3849.66%)
Mutual labels:  versioning, version, semantic
zerover
0️⃣ Minimalist versioning scheme for devs who can't be bothered.
Stars: ✭ 141 (-4.08%)
Mutual labels:  semver, versioning, version
Reckon
Infer a project's version from your Git repository.
Stars: ✭ 124 (-15.65%)
Mutual labels:  versioning, version, semver
Version
Represent and compare versions via semantic versioning (SemVer) in Swift
Stars: ✭ 160 (+8.84%)
Mutual labels:  versioning, version, semver
Shipjs
Take control of what is going to be your next release.
Stars: ✭ 668 (+354.42%)
Mutual labels:  versioning, semver, semantic
dotnet-version-cli
dotnet version cli (similar to npm version cli)
Stars: ✭ 30 (-79.59%)
Mutual labels:  versioning, version
semver
Semantic version object for Perl
Stars: ✭ 12 (-91.84%)
Mutual labels:  semver, version
Calver
📅 The web's go-to resource for Calendar Versioning info.
Stars: ✭ 271 (+84.35%)
Mutual labels:  versioning, version
Jgitver Maven Plugin
maven core extension to automatically define versions using jgitver & git tags
Stars: ✭ 117 (-20.41%)
Mutual labels:  versioning, version
McSherry.SemanticVersioning
A semantic versioning library for .NET 5, Core, FX, and Standard with version range support.
Stars: ✭ 16 (-89.12%)
Mutual labels:  semantic, versioning
Cli
🆑📍 Setup automated semver compliant package publishing
Stars: ✭ 272 (+85.03%)
Mutual labels:  version, semver
Jsemver
Java implementation of the SemVer Specification
Stars: ✭ 360 (+144.9%)
Mutual labels:  versioning, semver
React Native Version
🔢 Version your React Native or Expo app in a `npm version` fashion.
Stars: ✭ 408 (+177.55%)
Mutual labels:  versioning, semver
version-check
An action that allows you to check whether your npm package version has been updated
Stars: ✭ 65 (-55.78%)
Mutual labels:  semver, version
Git Version Bumper
Bump your git tag to the next version, easily. 👊
Stars: ✭ 87 (-40.82%)
Mutual labels:  versioning, semver
bump
A generic version tracking and update tool
Stars: ✭ 33 (-77.55%)
Mutual labels:  semver, version
terraform-module-versions
CLI tool that checks Terraform code for module updates. Single binary, no dependencies. linux, osx, windows. #golang #cli #terraform
Stars: ✭ 143 (-2.72%)
Mutual labels:  semver, versioning

semver.c Build Status GitHub release

Semantic version v2.0 parser and render written in ANSI C with zero dependencies.

Features

  • [x] Standard compliant (otherwise, open an issue)
  • [x] Version metadata parsing
  • [x] Version prerelease parsing
  • [x] Version comparison helpers
  • [x] Supports comparison operators
  • [x] Version render
  • [x] Version bump
  • [x] Version sanitizer
  • [x] 100% test coverage
  • [x] No regexp (ANSI C doesn't support it)
  • [x] Numeric conversion for sorting/filtering

Versions

  • v0 - Legacy version. Beta. Not maintained anymore.
  • v1 - Current stable version.

Usage

Basic comparison:

#include <stdio.h>
#include <semver.h>

char current[] = "1.5.10";
char compare[] = "2.3.0";

int
main(int argc, char *argv[]) {
    semver_t current_version = {};
    semver_t compare_version = {};

    if (semver_parse(current, &current_version)
      || semver_parse(compare, &compare_version)) {
      fprintf(stderr,"Invalid semver string\n");
      return -1;
    }

    int resolution = semver_compare(compare_version, current_version);

    if (resolution == 0) {
      printf("Versions %s is equal to: %s\n", compare, current);
    }
    else if (resolution == -1) {
      printf("Version %s is lower than: %s\n", compare, current);
    }
    else {
      printf("Version %s is higher than: %s\n", compare, current);
    }

    // Free allocated memory when we're done
    semver_free(&current_version);
    semver_free(&compare_version);
    return 0;
}

Satisfies version:

#include <stdio.h>
#include <semver.h>

semver_t current = {};
semver_t compare = {};

int
main(int argc, char *argv[]) {
    semver_parse("1.3.10", &current);
    semver_parse("1.5.2", &compare);

    // Use caret operator for the comparison
    char operator[] = "^";

    if (semver_satisfies(current, compare, operator)) {
      printf("Version %s can be satisfied by %s", "1.3.10", "1.5.2");
    }

    // Free allocated memory when we're done
    semver_free(&current);
    semver_free(&compare);
    return 0;
}

Installation

Clone this repository:

$ git clone https://github.com/h2non/semver.c

Or install with clib:

$ clib install h2non/semver.c

API

struct semver_t { int major, int minor, int patch, char * prerelease, char * metadata }

semver base struct.

semver_parse(const char *str, semver_t *ver) => int

Parses a string as semver expression.

Returns:

  • -1 - In case of invalid semver or parsing error.
  • 0 - All was fine!

semver_compare(semver_t a, semver_t b) => int

Compare versions a with b.

Returns:

  • -1 in case of lower version.
  • 0 in case of equal versions.
  • 1 in case of higher version.

semver_satisfies(semver_t a, semver_t b, char *operator) => int

Checks if both versions can be satisfied based on the given comparison operator.

Allowed operators:

  • = - Equality
  • >= - Higher or equal to
  • <= - Lower or equal to
  • < - Lower than
  • > - Higher than
  • ^ - Caret operator comparison (more info)
  • ~ - Tilde operator comparison (more info)

Returns:

  • 1 - Can be satisfied
  • 0 - Cannot be satisfied

semver_satisfies_caret(semver_t a, semver_t b) => int

Checks if version x can be satisfied by y performing a comparison with caret operator.

See: https://docs.npmjs.com/misc/semver#caret-ranges-1-2-3-0-2-5-0-0-4

Returns:

  • 1 - Can be satisfied
  • 0 - Cannot be satisfied

semver_satisfies_patch(semver_t a, semver_t b) => int

Checks if version x can be satisfied by y performing a comparison with tilde operator.

See: https://docs.npmjs.com/misc/semver#tilde-ranges-1-2-3-1-2-1

Returns:

  • 1 - Can be satisfied
  • 0 - Cannot be satisfied

semver_eq(semver_t a, semver_t b) => int

Equality comparison.

semver_ne(semver_t a, semver_t b) => int

Non equal comparison.

semver_gt(semver_t a, semver_t b) => int

Greater than comparison.

semver_lt(semver_t a, semver_t b) => int

Lower than comparison.

semver_gte(semver_t a, semver_t b) => int

Greater than or equal comparison.

semver_lte(semver_t a, semver_t b) => int

Lower than or equal comparison.

semver_render(semver_t *v, char *dest) => void

Render as string.

semver_numeric(semver_t *v) => int

Render as numeric value. Useful for ordering and filtering.

semver_bump(semver_t *a) => void

Bump major version.

semver_bump_minor(semver_t *a) => void

Bump minor version.

semver_bump_patch(semver_t *a) => void

Bump patch version.

semver_free(semver_t *a) => void

Helper to free allocated memory from heap.

semver_is_valid(char *str) => int

Checks if the given string is a valid semver expression.

semver_clean(char *str) => int

Removes invalid semver characters in a given string.

License

MIT - Tomas Aparicio

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].