Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 188 Vote(s) - 3.45 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What's the difference between tilde(~) and caret(^) in package.json?

#1
After I upgraded to the latest stable `node` and `npm`, I tried `npm install moment --save`. It saves the entry in the `package.json` with the caret `^` prefix. Previously, it was a tilde `~` prefix.

1. Why are these changes made in `npm`?
2. What is the difference between tilde `~` and caret `^`?
3. What are the advantages over others?
Reply

#2
`^` is 1.[any].[any] (latest minor version)<br/>
`~` is 1.2.[any] (latest patch)

A great read is [this blog post][1] on how semver applies to npm<br/>
and what they're doing to make it match [the semver standard][2]<br/>

[To see links please register here]



[1]:

[To see links please register here]

[2]:

[To see links please register here]

Reply

#3
`~` : Reasonably **close** to

~1.1.5: 1.1.0 <= accepted < 1.2.0

`^`: **Compatible** with

^1.1.5: 1.1.5 <= accepted < 2.0.0

^0.1.3: 0.1.3 <= accepted < 0.2.0

^0.0.4: 0.0.4 <= accepted < 0.1.0
Reply

#4
Hat matching may be considered "broken" because it wont update `^0.1.2` to `0.2.0`. When the software is emerging use `0.x.y` versions and hat matching will only match the last varying digit (`y`). This is done on purpose. The reason is that while the software is evolving the API changes rapidly: one day you have these methods and the other day you have those methods and the old ones are gone. If you don't want to break the code for people who already are using your library you go and increment the major version: e.g. `1.0.0` -> `2.0.0` -> `3.0.0`. So, by the time your software is finally 100% done and full-featured it will be like version `11.0.0` and that doesn't look very meaningful, and actually looks confusing. If you were, on the other hand, using `0.1.x` -> `0.2.x` -> `0.3.x` versions then by the time the software is finally 100% done and full-featured it is released as version `1.0.0` and it means "This release is a long-term service one, you can proceed and use this version of the library in your production code, and the author won't change everything tomorrow, or next month, and he won't abandon the package".

The rule is: use `0.x.y` versioning when your software hasn't yet matured and release it with incrementing the middle digit when your public API changes (therefore people having `^0.1.0` won't get `0.2.0` update and it won't break their code). Then, when the software matures, release it under `1.0.0` and increment the leftmost digit each time your public API changes (therefore people having `^1.0.0` won't get `2.0.0` update and it won't break their code).

Given a version number MAJOR.MINOR.PATCH, increment the:

MAJOR version when you make incompatible API changes,
MINOR version when you add functionality in a backwards-compatible manner, and
PATCH version when you make backwards-compatible bug fixes.
Reply

#5
**One liner explanation**

The standard versioning system is major.minor.build (e.g. 2.4.1)

npm checks and fixes the version of a particular package based on these characters

> **~** : major version is fixed, minor version is fixed, matches any build number

*e.g. : ~2.4.1 means it will check for 2.4.x where x is anything*

> **^** : major version is fixed, matches any minor version, matches any build number

*e.g. : ^2.4.1 means it will check for 2.x.x where x is anything*

Reply

#6
You probably have seen the tilde (~) and caret (^) in the package.json. What is the difference between them?

When you do npm install moment --save, It saves the entry in the package.json with the caret (^) prefix.

### The tilde (~)

In the simplest terms, the tilde (~) matches the most recent minor version (the middle number). ~1.2.3 will match all 1.2.x versions but will miss 1.3.0.

### The caret (^)

The caret (^), on the other hand, is more relaxed. It will update you to the most recent major version (the first number). ^1.2.3 will match any 1.x.x release including 1.3.0, but will hold off on 2.0.0.

Reference:

[To see links please register here]

Reply

#7
The version number is in syntax which designates each section with different meaning. syntax is broken into three sections separated by a dot.

major.minor.patch
1.0.2

Major, minor and patch represent the different releases of a package.

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

So if you see ~1.0.2 it means to install version 1.0.2 or the latest patch version such as 1.0.4. If you see ^1.0.2 it means to install version 1.0.2 or the latest minor or patch version such as 1.1.0.
Reply

#8
**~ Tilde:**

- `~` freezes **major and minor numbers.**
- It is used when you're ready to accept bug-fixes in your dependency,
but don't want any potentially incompatible changes.
- The tilde matches the **most recent minor version** (the middle number).
- ~1.2.3 will match all 1.2.x versions, but it will miss 1.3.0.
- Tilde (~) gives you bug fix releases


**^ Caret:**

- `^` freezes the major number only.
- It is used when you're closely watching your dependencies and are ready to quickly change your code if minor release will be incompatible.
- It will update you to the **most recent major version** (the first number).
- ^1.2.3 will match any 1.x.x release including 1.3.0, but it will hold off on 2.0.0.
- Caret (^) gives you backwards-compatible new functionality as well.
Reply

#9
**Tilde ~** matches minor version, if you have installed a package that has 1.4.2 and after your installation, versions 1.4.3 and 1.4.4 are also available if in your package.json it is used as ~1.4.2 then npm install in your project after upgrade will install 1.4.4 in your project. But there is 1.5.0 available for that package then it will not be installed by ~. It is called minor version.

**Caret ^** matches major version, if 1.4.2 package is installed in your project and after your installation 1.5.0 is released then ^ will install major version. It will not allow to install 2.1.0 if you have **^1.4.2**.

**Fixed version** if you don't want to change version of package on each installation then used fixed version with out any special character e.g **"1.4.2"**

**Latest Version *** If you want to install latest version then only use * in front of package name.
Reply

#10
semver is separate in to 3 major sections which is broken by dots.

major.minor.patch
1.0.0
These different major, minor and patch are using to identify different releases.
tide (~) and caret (^) are using to identify which minor and patch version to be used in package versioning.

~1.0.1
Install 1.0.1 or **latest patch versions** such as 1.0.2 ,1.0.5
^1.0.1
Install 1.0.1 or **latest patch and minor versions** such as 1.0.2 ,1.1.0 ,1.1.1

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through