2017 © Pedro Peláez
 

library semver-converter

Converts SemVer version (like Composer packages) into integer version with operators. Helps managing versions: store, compare, sort and retrive by conditions.

image

requtize/semver-converter

Converts SemVer version (like Composer packages) into integer version with operators. Helps managing versions: store, compare, sort and retrive by conditions.

  • Tuesday, January 30, 2018
  • by requtize
  • Repository
  • 1 Watchers
  • 0 Stars
  • 1,218 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 118 % Grown

The README.md

SemVer Converter

Converts SemVer version (like Composer packages) into integer version with operators. Helps managing versions: store, compare, sort and retrive by conditions., (*1)

Converter accepts the same versions as Composer, so You can use it with any package manager that accepts Semantic Versioning., (*2)

How it works?

For each version it uses Composer SemVer parser to parse version and normalize it. And then, for each version, converter creates array exploded by dot values. Each value pads with zeros and create from it long string which is converted to integer. And for each version we have big integer., (*3)

Sample:

  1. Version 1.0.5
  2. Normalize with SemVer: 1.0.5
  3. Explode: [ 1, 0, 5 ]
  4. Converts to strings and pad zeros: [ '100', '000', '500' ]
  5. Concatenate all strings: '100' + '000' + '500'
  6. Converts to integer: (int) '100000500'

Result: '1.0.5' == 100000500, (*4)

Examples

Simple version

$result = (new SemVerConverter)->convert('0.1.0');

// Result
array (size=1)
  0 => 
    array (size=2)
      'from' => 
        array (size=2)
          0 => int 100000000
          1 => string '==' (length=2)
      'to' => 
        array (size=2)
          0 => int 100000000
          1 => string '==' (length=2)

Version between

$result = (new SemVerConverter)->convert('>= 1.3.0 < 1.7.0');

// Result
array (size=1)
  0 => 
    array (size=2)
      'from' => 
        array (size=2)
          0 => int 100300000
          1 => string '>=' (length=2)
      'to' => 
        array (size=2)
          0 => int 100700000
          1 => string '<' (length=1)

Tilde operator

$result = (new SemVerConverter)->convert('~1.3');

// Result
array (size=1)
  0 => 
    array (size=2)
      'from' => 
        array (size=2)
          0 => int 100300000
          1 => string '>=' (length=2)
      'to' => 
        array (size=2)
          0 => int 200000000
          1 => string '<' (length=1)

Version or

$result = (new SemVerConverter)->convert('^1.9 || 3.0.*');

// Result
array (size=2)
  0 => 
    array (size=2)
      'from' => 
        array (size=2)
          0 => int 100900000
          1 => string '>=' (length=2)
      'to' => 
        array (size=2)
          0 => int 200000000
          1 => string '<' (length=1)
  1 => 
    array (size=2)
      'from' => 
        array (size=2)
          0 => int 300000000
          1 => string '>=' (length=2)
      'to' => 
        array (size=2)
          0 => int 300100000
          1 => string '<' (length=1)

Settings

new SemVerConverter($zeros, $sections);

$zeros

Defines how meny zeros need to pad for each section of versions. It allows to define how long should be result., (*5)

$sections

Defines how many sections need to be generated from input. Default is 3, Composer SemVer generates 4. This also have an impact for result., (*6)

Licence

This code is licensed under MIT License., (*7)

The Versions

30/01 2018

dev-master

9999999-dev

Converts SemVer version (like Composer packages) into integer version with operators. Helps managing versions: store, compare, sort and retrive by conditions.

  Sources   Download

MIT

The Requires

 

The Development Requires

php converter semver semantic version semver converter semver to int semver to integer

30/01 2018

0.3.1

0.3.1.0

Converts SemVer version (like Composer packages) into integer version with operators. Helps managing versions: store, compare, sort and retrive by conditions.

  Sources   Download

MIT

The Requires

 

php converter semver semantic version semver converter semver to int semver to integer

08/05 2017

0.3.0

0.3.0.0

Converts SemVer version (like Composer packages) into integer version with operators. Helps managing versions: store, compare, sort and retrive by conditions.

  Sources   Download

MIT

The Requires

 

The Development Requires

php converter semver semantic version semver converter semver to int semver to integer

26/10 2016

0.2.1

0.2.1.0

Converts SemVer version (like Composer packages) into integer version with operators. Helps managing versions: store, compare, sort and retrive by conditions.

  Sources   Download

MIT

The Requires

 

The Development Requires

php converter semver semantic version semver converter semver to int semver to integer

25/10 2016

0.1.1

0.1.1.0

Converts SemVer version (like Composer packages) into integer version with operators. Helps managing versions: store, compare, sort and retrive by conditions.

  Sources   Download

The Requires

 

The Development Requires

php converter semver semantic version semver converter semver to int semver to integer

25/10 2016

0.1.0

0.1.0.0

Converts SemVer version (like Composer packages) into integer version with operators. Helps managing versions: store, compare, sort and retrive by conditions.

  Sources   Download

The Requires

 

The Development Requires

converter semver semantic version semver converter semver to int semver to integer