Skip to content

Instantly share code, notes, and snippets.

@weilu
Last active August 29, 2015 14:03
Show Gist options
  • Save weilu/878ec0357683a16da23a to your computer and use it in GitHub Desktop.
Save weilu/878ec0357683a16da23a to your computer and use it in GitHub Desktop.
Much Semver, Such Confusion

Rubygem's ~> pessimistic / eat beacon / spermy operator

Keep first n-1 digits the same, last digit is free to increment to some arbitrary value

~>1:      >=1.0.0 <2.0.0
~>1.0:    >=1.0.0 <2.0.0
~>1.2.3:  >=1.2.3 <1.3.0
~>0.1:    >=0.1.0 <1.0.0
~>0.1.3:  >=0.1.3 <0.2.0
~>0.0.2:  >=0.0.2 <0.1.0

npm's ~ "reasonably close to”

>= self < next significant digit + 1

~1:       >=1.0.0 <2.0.0
~1.0:     >=1.0.0 <1.1.0
~1.2.3:   >=1.2.3 <1.3.0
~0.1:     >=0.1.0 <0.2.0
~0.1.3:   >=0.1.3 <0.2.0
~0.0.2:   >=0.0.2 <0.1.0

npm's ^ "compatible with"

It matches any version with the same first non-zero component starting at the specified version

^1:       >=1.0.0 <2.0.0
^1.0:     >=1.0.0 <2.0.0
^1.2.3:   >=1.2.3 <2.0.0
^0.1:     >=0.1.0 <0.2.0
^0.1.3:   >=0.1.3 <0.2.0
^0.0.2:   0.0.2

tl;dr they are all bloody different!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment