# semver-files

> A node module to list version files named with semantic version pattern

Latest version **0.0.1** (published 2017-11-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install semver-files
pnpm add semver-files
yarn add semver-files
bun add semver-files
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2017-11-15 |
| First published | 2017-11-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Francisek |
| Maintainers | francisek |
| Keywords | semver, version, file, filesystem, pattern, regexp |

## Links

- npm: https://www.npmjs.com/package/semver-files
- Repository: https://github.com/francisek/semver-files
- Issues: https://github.com/francisek/semver-files/issues
- npm.io page: https://npm.io/package/semver-files

## Dependencies (3)

- [glob-fs](https://npm.io/package/glob-fs.md) ^0.1.7
- [semver-sort](https://npm.io/package/semver-sort.md) ^0.0.4
- [compare-semver](https://npm.io/package/compare-semver.md) ^1.1.0

## Alternatives

- [unionfs](https://npm.io/package/unionfs.md) — 2.2M weekly downloads
- [path-starts-with](https://npm.io/package/path-starts-with.md) — 35.9K weekly downloads
- [redzip](https://npm.io/package/redzip.md) — 1.2K weekly downloads
- [vscode-anymatch](https://npm.io/package/vscode-anymatch.md) — 848 weekly downloads
- [@ledgerhq/coin-filecoin](https://npm.io/package/@ledgerhq/coin-filecoin.md) — 793 weekly downloads

## Recent versions

- 0.0.1 (latest) — 2017-11-15

## README

# semver-files

A node module to list version files named with semantic version pattern.

## Installation

```bash
$ yarn install --save semver-files
```

## Usage

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
```

```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' }
```

## API

The `SemverFiles` object.

### Constants

#### SemverPattern

The SemverPattern constant is a regexp string capturing a full semver version.

### Methods

#### SemverFiles.__construct(string directory, Object options)

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`)

#### all(): String[]

Return an array of versions matching `extractVersionPattern` option, sorted by descending version.

#### latest(): String|null

Return the highest version number.

#### first(): String|null

Return the least version number.

#### map(callback): Array

Apply a callback on all version items in the context of the ServerFiles instance.

#### getPath(version): String|null

Return the relative path of the file matching the version or null.

#### getPaths(): String|null

Return an object of the relative path of al the version files. Order is not guarantee.

---
_Source: https://npm.io/package/semver-files · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
