# semver-dsl

> Tiny internal DSL which allows invocation of different functionality depending on SemVer match.

Latest version **1.0.1** (published 2017-02-19) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2017-02-19 |
| First published | 2017-02-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 11 |
| Author | Minko Gechev |
| Maintainers | mgechev |
| Keywords | semver, dsl |

## Links

- npm: https://www.npmjs.com/package/semver-dsl
- Repository: https://github.com/mgechev/semver-dsl
- Homepage: https://github.com/mgechev/semver-dsl#readme
- Issues: https://github.com/mgechev/semver-dsl/issues
- npm.io page: https://npm.io/package/semver-dsl

## Dependencies (1)

- [semver](https://npm.io/package/semver.md) ^5.3.0

## Recent versions

- 1.0.1 (latest) — 2017-02-19
- 1.0.0 — 2017-02-19

## README

[![Build Status](https://travis-ci.org/mgechev/semver-dsl.svg?branch=master)](https://travis-ci.org/mgechev/semver-dsl)

# SemVer DSL

A simple internal DSL which allows you to invoke different functionality depending on version match. Used in codelyzer for keeping the code compatible across different versions of the Angular compiler.

# Demo

```bash
$ npm i semver-dsl --save
```

```ts
import {SemVerDSL} from 'semver-dsl';

const base = () => {};
const elseIf1 = () => {};
const elseIf2 = () => {};
const else = () => console.log('I will be invoked!');

SemVerDSL('3.0.0')
  .gt('3.2.1', base)
  .elseIf.gt('3.0.1', elseIf1)
  .elseIf.between('3.0.1', '3.1.8', elseIf2)
  .else(else);
```

In the example above will be invoked `else`.

# API

- `SemDSL(version: string)` - factory which accepts a version and returns an object.
- `gte(version: string, callback?: Function): ISemContextualDSL` - returns an object with `elseIf` and `else` properties.
- `lte(version: string, callback?: Function): ISemContextualDSL` - returns an object with `elseIf` and `else` properties.
- `gt(version: string, callback?: Function): ISemContextualDSL` - returns an object with `elseIf` and `else` properties.
- `lt(version: string, callback?: Function): ISemContextualDSL` - returns an object with `elseIf` and `else` properties.
- `eq(version: string, callback?: Function): ISemContextualDSL` - returns an object with `elseIf` and `else` properties.
- `neq(version: string, callback?: Function): ISemContextualDSL` - returns an object with `elseIf` and `else` properties.
- `between(v1: string, v2: string, callback?: Function): ISemContextualDSL` - returns an object with `elseIf` properties.
- `elseIf` - returns an object of type `ISemVerDSL` bound to the previous predicate.
- `else` - invokes given callback if all of the previous conditions have failed.

```ts
export interface ISemVerDSL {
  gte(version: string, callback: Function): ISemContextualDSL;
  lte(version: string, callback: Function): ISemContextualDSL;
  gt(version: string, callback: Function): ISemContextualDSL;
  lt(version: string, callback: Function): ISemContextualDSL;
  eq(version: string, callback: Function): ISemContextualDSL;
  neq(version: string, callback: Function): ISemContextualDSL;
  between(v1: string, v2: string, callback: Function): ISemContextualDSL;
}
```

```ts
export interface ISemVerContextBoundDSL {
  elseIf: ISemVerDSL;
  else(callback: Function): void;
}
```

# License

MIT

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