FunctionSelect: Select a function that passes a condition. A functional alternative to switch-case.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
2.5 KiB

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Home</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Home</h1>
<h3> </h3>
<section>
<article><h1>select-return</h1><p>Return a function based on a condition. Functional alternative to switch-case.</p>
<h2>Usage</h2><pre class="prettyprint source lang-JavaScript"><code>const a = 100;
const result = new Select(a)
.for(x => x>10,
a => `${a} is greater than 10.`)
.for(x => x&lt;10,
a => `${a} is lesser than 10.`)
.for(x => x===10,
a => `${a} is 10.`)
console.log(result.resolve()); // -> &quot;100 is greater than 10.&quot;</code></pre><h2>Docs</h2><p>Docs exist in <code>/docs</code> directory. Will be served soon.</p>
<h2>Development</h2><blockquote>
<p>If you find any mistakes in code/documentation, or if you feel something could be done better, do PR :)</p>
</blockquote>
<blockquote>
<p>I appreciate it.</p>
</blockquote>
<ul>
<li>Always write test spec for any code you add. Make sure they run as intended.</li>
<li>Add/update JSDoc comments as needed.</li>
<li>Use npm scripts for linting, debugging, building docs.</li>
</ul>
<p>Place your test file as <code>testscript.js</code> in root.</p>
<p>The following npm scripts are available: <code>npm run lint</code>, <code>npm run debug</code>, <code>npm run docs</code>.</p>
<h2>Credits</h2><p><a href="https://github.com/Floofies">@Floofies</a> was of huge help during development of this module.</p>
<p>Also, <a href="https://github.com/trgwii">@TRGWII</a> was a source of inspiration and guidance.</p></article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Select.html">Select</a></li><li><a href="SelectIterable.html">SelectIterable</a></li><li><a href="SelectValue.html">SelectValue</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Apr 10 2018 04:36:07 GMT+0530 (IST)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>