Skip to content

grncdr/semver-intersection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

semver-intersection

Find the intersection of 2 semver ranges.

Synopsis

var assert = require('assert');
var intersect = require('./'); // [Function intersect]

This module exports a single function intersect that takes an array of semver ranges and returns a single range that represents the intersection.

assert.equal(intersect(['2.5.x', '^2.3.1']), '>=2.5.0-0 <2.6.0-0');

A useful property of the intersection is that it's a semver range that will satisfy all of the input ranges.

Of course, a specific version also represents a valid range:

assert.equal(intersect(['1.2.1']), '>=1.2.1 <1.2.2-0');

You can include as many ranges as you like:

assert.equal(intersect(['^2.1.4', '^2.3.1', '<4.0.0']), '>=2.3.1-0 <3.0.0-0');

If there is no intersection between the two ranges, intersect will return false:

assert.equal(intersect(['^2.1.4', '^3.0.0']), false);

License

MIT

About

No description, website, or topics provided.

Resources

Stars

2 stars

Watchers

1 watching

Forks

Packages

 
 
 

Contributors