[GH-ISSUE #564] Mnemotechnic : remember ^ versus ~ #1277

Closed
opened 2026-04-16 10:38:28 -05:00 by GiteaMirror · 5 comments
Owner

Originally created by @cyrilchapon on GitHub (Apr 28, 2020).
Original GitHub issue: https://github.com/semver/semver/issues/564

Hey !

While I strongly understand ~ versus ^ behavior; I always struggle at remembering which one does what I think it does.

Roughly, I always re-read the doc; find the information, and tell myself "Ok, caret equals patch; tild equals minor + patch", and always forget it.

Does anyone knows some Mnemotechnic to learn it for good a single time ? 😄

Originally created by @cyrilchapon on GitHub (Apr 28, 2020). Original GitHub issue: https://github.com/semver/semver/issues/564 Hey ! While I strongly understand `~` versus `^` behavior; I always struggle at remembering which one does what I think it does. Roughly, I always re-read the doc; find the information, and tell myself "Ok, caret equals patch; tild equals minor + patch", and always forget it. Does anyone knows some Mnemotechnic to learn it for good a single time ? 😄
Author
Owner

@klehelley commented on GitHub (Apr 28, 2020):

This repository is about the Semantic Versioning specification, that does not use nor define the ~ and ^ prefixes. Maybe you meant to post your question at https://github.com/npm/cli or https://github.com/npm/node-semver?

<!-- gh-comment-id:620623284 --> @klehelley commented on GitHub (Apr 28, 2020): This repository is about the Semantic Versioning specification, that does not use nor define the `~` and `^` prefixes. Maybe you meant to post your question at https://github.com/npm/cli or https://github.com/npm/node-semver?
Author
Owner

@cyrilchapon commented on GitHub (Apr 28, 2020):

I'm using Node.js but that's not really a Nodejs specific question (composer, https://devhints.io/semver).

Though, I was sure the semver ranges was defined in the spec; and I'm very surprised to discover it's not the case !

<!-- gh-comment-id:620627583 --> @cyrilchapon commented on GitHub (Apr 28, 2020): I'm using Node.js but that's not really a Nodejs specific question (composer, https://devhints.io/semver). Though, I was sure the semver **ranges** was defined in the spec; and I'm very surprised to discover it's not the case !
Author
Owner

@cyrilchapon commented on GitHub (Apr 28, 2020):

Well; additional question. What spec / standard defines "semver ranges" ? Is that a commonly-used format without being backed by a spec ?

<!-- gh-comment-id:620627922 --> @cyrilchapon commented on GitHub (Apr 28, 2020): Well; additional question. What spec / standard defines "semver ranges" ? Is that a commonly-used format without being backed by a spec ?
Author
Owner

@ljharb commented on GitHub (Apr 28, 2020):

The caret points up, because it means “this one, up to the next major”. The tilde looks like a hand waggling in place, meaning “kind of like this one, the same minor”.

npm defined ranges for itself with https://npmjs.com/semver, whose implementation is effectively the spec.

<!-- gh-comment-id:620647071 --> @ljharb commented on GitHub (Apr 28, 2020): The caret points up, because it means “this one, up to the next major”. The tilde looks like a hand waggling in place, meaning “kind of like this one, the same minor”. npm defined ranges for itself with https://npmjs.com/semver, whose implementation is effectively the spec.
Author
Owner

@Seldaek commented on GitHub (Apr 29, 2020):

Composer implemented mostly-node-compatible range constraints to help with "mental" interoperability as most PHP devs using Composer also use npm to some extent. But indeed the semver spec defines none of this. This spec is only describing how to choose a version number when publishing a new release.

The bottom line though IMO is that if a given dependency strictly follows semver, you should only ever use ^. ~ seems to be confusing people and I would thus not recommend using it. 1.2.* is usually clearer if you just want patches within one minor version.

<!-- gh-comment-id:621140400 --> @Seldaek commented on GitHub (Apr 29, 2020): Composer implemented mostly-node-compatible [range constraints](https://getcomposer.org/doc/articles/versions.md#writing-version-constraints) to help with "mental" interoperability as most PHP devs using Composer also use npm to some extent. But indeed the semver spec defines none of this. This spec is only describing how to choose a version number when publishing a new release. The bottom line though IMO is that if a given dependency strictly follows semver, you should only ever use `^`. `~` seems to be confusing people and I would thus not recommend using it. `1.2.*` is usually clearer if you just want patches within one minor version.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/semver#1277