1. semver-dsl
Tiny internal DSL which allows invocation of different functionality depending on SemVer match.
semver-dsl
Package: semver-dsl
Created by: mgechev
Last modified: Sun, 26 Jun 2022 17:33:10 GMT
Version: 1.0.1
License: MIT
Downloads: 2,749,884
Repository: https://github.com/mgechev/semver-dsl

Install

npm install semver-dsl
yarn add semver-dsl

Build Status

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

 $ npm i semver-dsl --save
 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.
 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;
}
 export interface ISemVerContextBoundDSL {
  elseIf: ISemVerDSL;
  else(callback: Function): void;
}

License

MIT

Dependencies

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code