Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] add methods to update a range, including operator #314

Open
bnb opened this issue Jan 30, 2020 · 5 comments
Open

[FEATURE] add methods to update a range, including operator #314

bnb opened this issue Jan 30, 2020 · 5 comments
Labels
Enhancement new feature or improvement

Comments

@bnb
Copy link

bnb commented Jan 30, 2020

What / Why

There doesn't seem to currently be a way to get the operator of a passed semver range. Adding something like semver.operator() to get the operator would be helpful.

Current Behavior

There does not seem to be a way to get an operator of a passed version easily.

Expected Behavior

Have an easy way to get the operator of the passed semver range.

@isaacs
Copy link
Contributor

isaacs commented Apr 14, 2020

I'm not sure exactly what you're looking for. Can you share some example code of how you might expect this to work and/or a description of what you'd use it for?

If you have a range like 1.x || >=2.0.3 <3, you can get the operators of all the comparators in the range like so:

const semver = require('semver')
const range = new semver.Range('1.x || >=2.0.3 <3')
for (const set of range.set) {
  console.log('set:')
  for (const comparator of set) {
    console.log(comparator.operator, comparator.semver.version)
  }
}
// outputs
/*
set:
>= 1.0.0
< 2.0.0
set:
>= 2.0.3
< 3.0.0
*/

@isaacs
Copy link
Contributor

isaacs commented Apr 18, 2020

Note that some comparators will have their .semver member set to an internal Symbol('ANY'), which is used for stars, empty strings, and >=0.0.0.

@lukekarrys
Copy link
Contributor

Reopening after some research into other issues. I think providing a supported way to do this without reaching into range.set[][].operator would be nice, similar to what was discussed for getting the bounds of a range in #323.

@lukekarrys lukekarrys reopened this Apr 10, 2022
@darcyclarke darcyclarke added the Enhancement new feature or improvement label Jul 28, 2022
@lukekarrys
Copy link
Contributor

One area this would be useful is when getting a range and attempting to increase the range somehow. Maybe there is less use of an .operator() method if that existed?

Digging up #10 as an old issue asking for something like this. Some other prior art here:

@lukekarrys lukekarrys changed the title [FEATURE] add semver.operator() [FEATURE] add methods to update a range, including operator Oct 27, 2022
@lukekarrys
Copy link
Contributor

Updated the title of the issue to increase its scope.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement new feature or improvement
Projects
None yet
Development

No branches or pull requests

4 participants