UNPKG

2.47 kBMarkdownView Raw
1[![Build Status](https://travis-ci.org/mgechev/semver-dsl.svg?branch=master)](https://travis-ci.org/mgechev/semver-dsl)
2
3# SemVer DSL
4
5A 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.
6
7# Demo
8
9```bash
10$ npm i semver-dsl --save
11```
12
13```ts
14import {SemVerDSL} from 'semver-dsl';
15
16const base = () => {};
17const elseIf1 = () => {};
18const elseIf2 = () => {};
19const else = () => console.log('I will be invoked!');
20
21SemVerDSL('3.0.0')
22 .gt('3.2.1', base)
23 .elseIf.gt('3.0.1', elseIf1)
24 .elseIf.between('3.0.1', '3.1.8', elseIf2)
25 .else(else);
26```
27
28In the example above will be invoked `else`.
29
30# API
31
32- `SemDSL(version: string)` - factory which accepts a version and returns an object.
33- `gte(version: string, callback?: Function): ISemContextualDSL` - returns an object with `elseIf` and `else` properties.
34- `lte(version: string, callback?: Function): ISemContextualDSL` - returns an object with `elseIf` and `else` properties.
35- `gt(version: string, callback?: Function): ISemContextualDSL` - returns an object with `elseIf` and `else` properties.
36- `lt(version: string, callback?: Function): ISemContextualDSL` - returns an object with `elseIf` and `else` properties.
37- `eq(version: string, callback?: Function): ISemContextualDSL` - returns an object with `elseIf` and `else` properties.
38- `neq(version: string, callback?: Function): ISemContextualDSL` - returns an object with `elseIf` and `else` properties.
39- `between(v1: string, v2: string, callback?: Function): ISemContextualDSL` - returns an object with `elseIf` properties.
40- `elseIf` - returns an object of type `ISemVerDSL` bound to the previous predicate.
41- `else` - invokes given callback if all of the previous conditions have failed.
42
43```ts
44export interface ISemVerDSL {
45 gte(version: string, callback: Function): ISemContextualDSL;
46 lte(version: string, callback: Function): ISemContextualDSL;
47 gt(version: string, callback: Function): ISemContextualDSL;
48 lt(version: string, callback: Function): ISemContextualDSL;
49 eq(version: string, callback: Function): ISemContextualDSL;
50 neq(version: string, callback: Function): ISemContextualDSL;
51 between(v1: string, v2: string, callback: Function): ISemContextualDSL;
52}
53```
54
55```ts
56export interface ISemVerContextBoundDSL {
57 elseIf: ISemVerDSL;
58 else(callback: Function): void;
59}
60```
61
62# License
63
64MIT