Rematch: Basic Usage

node v4.9.1
version: master
endpointsharetweet
const Rematch = require("rematch").default; class Mutant { constructor(name) { this.name = name; } } class SuperHero extends Mutant { } class Villain extends Mutant { } const Mutants = { Batman: new SuperHero('batman'), Flash: new SuperHero('flash'), Joker: new Villain('joker'), Superman: new SuperHero('superman') } function dangerLevel(mutant) { return Rematch(mutant, [ Rematch.Type(Villain, () => 5), Rematch.Value(Mutants.Flash, () => 0), Rematch.Value(Mutants.Superman, () => 2) ]); }; console.log([ dangerLevel(Mutants.Flash), // 0 dangerLevel(Mutants.Superman), // 2 dangerLevel(Mutants.Joker) // 5 ]) console.log(dangerLevel(Mutants.Batman)) // Error: Rematch.MatchError
Created from: https://runkit.com/npm/rematch
Loading…

no comments

    sign in to comment