UNPKG

enum-fp

Version:

Functional enum type for javascript with simple pattern matching

162 lines (161 loc) 4.82 kB
<!doctype html> <html lang="en"> <head> <title>Code coverage report for EnumTag.js</title> <meta charset="utf-8" /> <link rel="stylesheet" href="prettify.css" /> <link rel="stylesheet" href="base.css" /> <meta name="viewport" content="width=device-width, initial-scale=1"> <style type='text/css'> .coverage-summary .sorter { background-image: url(sort-arrow-sprite.png); } </style> </head> <body> <div class='wrapper'> <div class='pad1'> <h1> <a href="index.html">All files</a> EnumTag.js </h1> <div class='clearfix'> <div class='fl pad1y space-right2'> <span class="strong">100% </span> <span class="quiet">Statements</span> <span class='fraction'>11/11</span> </div> <div class='fl pad1y space-right2'> <span class="strong">100% </span> <span class="quiet">Branches</span> <span class='fraction'>4/4</span> </div> <div class='fl pad1y space-right2'> <span class="strong">100% </span> <span class="quiet">Functions</span> <span class='fraction'>5/5</span> </div> <div class='fl pad1y space-right2'> <span class="strong">100% </span> <span class="quiet">Lines</span> <span class='fraction'>9/9</span> </div> </div> </div> <div class='status-line high'></div> <pre><table class="coverage"> <tr><td class="line-count quiet">1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33</td><td class="line-coverage quiet"><span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">3x</span> <span class="cline-any cline-yes">26x</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">48x</span> <span class="cline-any cline-yes">26x</span> <span class="cline-any cline-yes">3x</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">23x</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">2x</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">23x</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">23x</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">&nbsp; // type TypeConstructor = ...a -&gt; EnumTagType &nbsp; &nbsp; // validateArguments :: (?Array String, [a]) -&gt; Boolean const validateArguments = (props, args) =&gt; !props? true : props.length === args.length; &nbsp; // (constructor) // EnumTag :: (String, EnumType, ?Array String) -&gt; TypeConstructor export const EnumTag = (name, Type, props) =&gt; (...args) =&gt; { if(!validateArguments(props, args)) throw new TypeError(`Invalid number of arguments passed to constructor ${name}`); &nbsp; const self = { // args :: Array * args, // name :: String name, // props :: ?Array String props, // is :: String | EnumTagType | ConstructorDescription ~&gt; Boolean is: otherType =&gt; [otherType, otherType.name].indexOf(name) !== -1, }; &nbsp; // match :: Object (* -&gt; b) ~&gt; b self.match = pattern =&gt; Type.match(self, pattern); &nbsp; return self; }; &nbsp; export default EnumTag; &nbsp;</pre></td></tr> </table></pre> <div class='push'></div><!-- for sticky footer --> </div><!-- /wrapper --> <div class='footer quiet pad2 space-top1 center small'> Code coverage generated by <a href="https://istanbul.js.org/" target="_blank">istanbul</a> at Thu Nov 01 2018 16:43:32 GMT+0530 (IST) </div> </div> <script src="prettify.js"></script> <script> window.onload = function () { if (typeof prettyPrint === 'function') { prettyPrint(); } }; </script> <script src="sorter.js"></script> </body> </html>