Dodi’s parts shelf: 45 versions of chalk really published on npm. Type a range (^, ~, x, prereleases), see which boxes a port of node-semver lets in, and the…
Why it matters
A range decides which updates slip in when someone else runs npm install. Misreading ^ and ~, or ^ on 0.x, means a build that breaks out of nowhere or a fix that never arrives. Knowing the prerelease rule and how npm picks explains why a beta stays out, and why two laptops can install different versions.
The key idea
A range picks a set of versions; npm picks one from the set
Common mistakes
Thinking ^ and ~ are the same^1.2.3 = >=1.2.3 <2.0.0-0 (minor and patch), ~1.2.3 = >=1.2.3 <1.3.0-0 (patch only). ^1.2.3 takes 1.9.0; ~1.2.3 does not.
A caret on 0.x taken to reach as far as on 1.x^0.2.3 = >=0.2.3 <0.3.0-0, and ^0.0.3 is 0.0.3 alone. Below 1.0, every minor (or patch on 0.0.x) counts as breaking.
Counting on a range for the same build everywhere The same range installs another version on another day (try --before) or on another Node. What is installed is pinned in package-lock.json: commit it, and use npm ci in CI.
Try it in this playground
Compare ^ with ~ Type ^4.1.0, then ~4.1.0: a caret opens the minor, a tilde only the patch.
Try a caret on 0.x^0.4.0 only lets in 0.4.x: below 1.0, a minor counts as breaking.
Let a prerelease in A prerelease only gets in when the range names one on the same version.
Switch to Node 20 The same range gives another version, because chalk 6 asks for Node 22.