Skip to content

Instantly share code, notes, and snippets.

@barbietunnie
Created November 10, 2022 11:03
Show Gist options
  • Select an option

  • Save barbietunnie/bad7e0bf2eab4694d35e41acc6ebc599 to your computer and use it in GitHub Desktop.

Select an option

Save barbietunnie/bad7e0bf2eab4694d35e41acc6ebc599 to your computer and use it in GitHub Desktop.
Difference between tilde(~) and caret(^) in package.json

Difference between tilde(~) and caret(^) in package.json

According the NPM and semver docs,

  • ~version - "Approximately equivalent to version", see semver.

    It does not increment the minor version

    For example,

    Pattern Range Outcome
    ~1.2.3 >=1.2.3 <1.(2+1).0 >=1.2.3 <1.3.0-0
    ~1.2 >=1.2.0 <1.(2+1).0 >=1.2.0 <1.3.0 (Same as 1.2.x)
  • ^version - “Compatible with version”, see semver.

    Allows for patch and minor updates for versions 1.0.0 and above, patch updates for versions 0.X >=0.1.0, and no updates for versions 0.0.X

    Pattern Range
    ^1.2.x >=1.2.0 <2.0.0
    ^0.0.x >=0.0.0 <0.1.0
    ^0.0 >=0.0.0 <0.1.0
    ^1.2.3 >=1.2.3 <2.0.0-0
    ^0.2.3 >=0.2.3 <0.3.0-0
    ^0.0.3 >=0.0.3 <0.0.4-0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment