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 |
|
5 | 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.
|
6 |
|
7 | # Demo
|
8 |
|
9 | ```bash
|
10 | $ npm i semver-dsl --save
|
11 | ```
|
12 |
|
13 | ```ts
|
14 | import {SemVerDSL} from 'semver-dsl';
|
15 |
|
16 | const base = () => {};
|
17 | const elseIf1 = () => {};
|
18 | const elseIf2 = () => {};
|
19 | const else = () => console.log('I will be invoked!');
|
20 |
|
21 | SemVerDSL('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 |
|
28 | In 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
|
44 | export 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
|
56 | export interface ISemVerContextBoundDSL {
|
57 | elseIf: ISemVerDSL;
|
58 | else(callback: Function): void;
|
59 | }
|
60 | ```
|
61 |
|
62 | # License
|
63 |
|
64 | MIT
|