A node module to list version files named with semantic version pattern.
$ yarn install --save semver-files
Given the following directory structure:
.
└── version
├── 1.0.0.js
├── 1.0.1.js
├── never-go-here
│ └── 1.0.2.js
├── test-1.0.0.js
├── test-1.0.0-RC2.js
├── test-1.0.3.js
└── test-v1.0.0-RC1.js
const SemverFiles = require('semver-files');
const semver = new SemverFiles('./version');
console.log(semver).all();
//=> [ '1.0.1', '1.0.0' ]
console.log(semver).first();
//=> [ '1.0.0' ]
console.log(semver).latest();
//=> [ '1.0.1' ]
console.log(semver.map(function formatCallback(item) {
return `${item}, latest is ${this.latest()}`;
}));
//=> [ '1.0.1, latest is 1.0.1', '1.0.0, latest is 1.0.1' ]
console.log(semver.getPath('1.0.0'));
//=> 'version/1.0.0.js'
console.log(semver.getPaths());
//=> { '1.0.0': 'version/1.0.0.js', '1.0.1': 'version/1.0.1.js' }
The SemverFiles
object.
The SemverPattern constant is a regexp string capturing a full semver version.
Constructor to search semver files into directory directory
with options options
.
directory
is a directory relative to main script.
options
is an object of options. Possible keys are:
- `extractVersionPattern` a custom regexp pattern that matches (default `SemverFiles.SemverPattern`)
- `matchIndex` is the index of the version captured from `extractVersionPattern` (default `1`)
Return an array of versions matching extractVersionPattern
option, sorted by descending version.
Return the highest version number.
Return the least version number.
Apply a callback on all version items in the context of the ServerFiles instance.
Return the relative path of the file matching the version or null.
Return an object of the relative path of al the version files. Order is not guarantee.