Skip to content
JsDevLife
Menu
  • Home
  • Leetcode in JS
  • About me
  • Contact Us
Menu

tilde (~) and a caret (^) in a npm package.json file

Posted on October 20, 2019 by Vikas Kad

What is tilde (~) and a caret (^) in an npm package.json file?

If you are using npm to manage your app, then you know that we will use package.json for managing dependencies.
tilde (~) and a caret (^) in a npm package.json file
sample package.json file
So as we can see in the above sample package.json file we have some dependencies & dev dependencies as well, now let’s go close to dependencies and try to understand the meaning of tilde & caret symbols.
{
  "devDependencies": {
    "@angular/common": "5.0.0",
    "cordova-plugin-splashscreen": "^5.0.3",
  },
  "devDependencies": {
    "@ionic/app-scripts": "3.2.4",
    "@types/chart.js": "^2.7.37",
    "typescript": "~2.6.2"
  }
}
As we can see above JSON from the package.json file,  key is the name of the package and the value is the version of the package to be used.
The version number is in semver syntax which designates each section with a different meaning. It is broken into three sections separated by a dot.
  1. MAJOR version when you make incompatible API changes,
  2. MINOR version when you add functionality in a backwards-compatible manner, and
  3. PATCH version when you make backwards-compatible bug fixes.
"@angular/common": "5.0.0",
 5.0.0
 major.minor.patch
Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format.

npm uses the tilde (~) and caret (^) to select which patch and minor versions to use respectively.

So you can see in the above example: “typescript”: “~2.6.2”
it means to install version 2.6.2 or the latest patch version such as 2.6.4. 
as same with for another example:   “cordova-plugin-splashscreen”: “^5.0.3” 
it means to install version 5.0.3 or the latest minor or patch version such as 5.1.0.

Understanding tilde(~) and caret(^):

  • ~1.2.3 means it should be greater than or equal to 1.2.3 and less than 1.3.0
  • ^1.2.3 means it should be greater than or equal to 1.2.3 and less than 2.0.0
If you still have any queries you can comment it out I will try to help you.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • Solving LeetCode Problem 79 – Word Search in JavaScript
  • Solving LeetCode Problem 48: Rotate Image using JavaScript
  • Solving the “Container With Most Water” LeetCode Problem in JavaScript – A Comprehensive Guide
  • LeetCode Solution: 54: Spiral Matrix in JavaScript
  • Solution to LeetCode Problem 31. Next Permutation in JavaScript

Archives

  • 2023 (5)
  • 2022 (20)
  • 2021 (2)
  • 2020 (4)
  • 2019 (14)
  • 2018 (17)

Categories

  • blockchain development
  • Blog
  • crystal
  • flutter
  • flutter.io
  • GitHub
  • Installation
  • Ionic Framework
  • javascript
  • leetcode-in-js
  • masteringInJavasript
  • mcqs
  • MongoDB
  • nodejs
  • Object Oriented Javacript
  • python
  • smart contracts
  • visual studio

Quick Links

  • Home
  • Leetcode in JS
  • About me
  • Contact Us

Terms of service

  • Terms Of Service
  • Disclaimer
©2023 JsDevLife | Design: Newspaperly WordPress Theme