protomorphism
Polymorphism via Clojure-style protocols.
Install
npm install protomorphism
Example
const protocol = // create a new protocol `Pattern`, which requires a// `matches` function to be implementedconst Pattern = // Make all strings implement pattern by exact matchingPatternimplementationString { return pattern === string } // Make all arrays implement pattern by reporting a match// when the array contains the target stringPatternimplementationArray { return arr !== -1 } // Make all regular expressions implement patternPatternimplementationRegExp { return !!regexp } // `Pattern.matches` is the polymorphic// `matches` function which you can use on// any object who implements `Pattern`.const matches = Patternmatchesconst patterns = 'README.md' 'README' 'README.md' 'readme.md' /README\./i let matched = patterns