UNPKG

3.92 kBHTMLView Raw
1<!doctype html>
2<html>
3
4<head>
5 <meta name="generator" content="JSDoc 3.6.2">
6 <meta charset="utf-8">
7 <title>keyu 2.0.0 &raquo; Source: logic/index.js</title>
8 <link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Karla:400,400i,700,700i" type="text/css">
9 <link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Noto+Serif:400,400i,700,700i" type="text/css">
10 <link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Inconsolata:500" type="text/css">
11 <link href="css/baseline.css" rel="stylesheet">
12</head>
13
14<body onload="prettyPrint()">
15 <nav id="jsdoc-navbar" role="navigation" class="jsdoc-navbar">
16 <div id="jsdoc-navbar-container">
17 <div id="jsdoc-navbar-content">
18 <a href="index.html" class="jsdoc-navbar-package-name">keyu 2.<wbr>0.<wbr>0</a>
19 </div>
20 </div>
21 </nav>
22 <div id="jsdoc-body-container">
23 <div id="jsdoc-content">
24 <div id="jsdoc-content-container">
25 <div id="jsdoc-banner" role="banner">
26 </div>
27 <div id="jsdoc-main" role="main">
28 <header class="page-header">
29 <h1>Source: logic/index.js</h1>
30 </header>
31 <article>
32 <pre class="prettyprint linenums"><code>/** @module logic **/
33const { curry } &#x3D; require(&#x27;../fp&#x27;);
34
35/** Will evaluate the first function, if it throws any exception will evaluate the second one.
36 * @argument {Function} mainFn function to be executed.
37 * @argument {Function|*} failOver function or value to fail over if first one fails.
38 * @returns {Function} excepting to receive fn arguments.
39 * @example
40 * const jsonOr &#x3D; either(parse.JSON,value &#x3D;&gt; &#x60;Cannot parse ${value} as json&#x60;)
41 * jsonOr(null) // -&gt; &quot;Cannot parse null as json&quot;
42 * @example
43 * const jsonOr &#x3D; either(parse.JSON,33)
44 * jsonOr(null) // -&gt; 33
45 * jsonOr(&#x27;{&quot;a&quot;:1}&#x27;) // -&gt; {a:1}
46 * @method
47 */
48const either &#x3D; (mainFn, failOver) &#x3D;&gt; (...arg) &#x3D;&gt; {
49 try {
50 return mainFn(...arg);
51 } catch (e) {
52 return fnOrValue(failOver, e);
53 }
54};
55/** Given a value that can be a function if it&#x27;s a function we call it passing the data to it
56 * if not we just return it
57 * @argument {Function|*} fnOrVal a function or any value
58 * @arugment {*} data any kind of data
59 * @example
60 * fnOrValue(3,4) // -&gt; 3
61 * fnOrValue(4,null) // -&gt; 4
62 * fnOrValue(x &#x3D;&gt; x+1,4) // -&gt; 5
63 * fnOrValue(x &#x3D;&gt; x*2,4) // -&gt; 8
64 * @returns {*}
65 * @method
66 */
67const fnOrValue &#x3D; curry((fnOrVal, data) &#x3D;&gt; (typeof fnOrVal &#x3D;&#x3D;&#x3D; &#x27;function&#x27; ? fnOrVal(data) : fnOrVal));
68/** Function that returns the passed value
69 * @argument {*} x any value
70 * @returns {*} any value
71 * @example
72 * [1,2].map(identity) // -&gt; [1,2]
73 * @method
74 */
75const identity &#x3D; x &#x3D;&gt; x;
76/** Function that negates any passed function value
77 * @argument {Function} fn function to be negated
78 * @returns {Boolean} negated boolean value
79 * @example
80 * const isNumber &#x3D; not(isNaN)
81 * isNumber(33) // -&gt; true
82 * @method
83 */
84const not &#x3D; fn &#x3D;&gt; (...args) &#x3D;&gt; !fn(...args);
85
86module.exports &#x3D; { either, fnOrValue, identity, not };
87</code></pre>
88 </article>
89 </div>
90 </div>
91 <nav id="jsdoc-toc-nav" role="navigation"></nav>
92 </div>
93 </div>
94 <footer id="jsdoc-footer" class="jsdoc-footer">
95 <div id="jsdoc-footer-container">
96 <p>
97 Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.2 on June 17, 2019.
98 </p>
99 </div>
100 </footer>
101 <script src="scripts/jquery.min.js"></script>
102 <script src="scripts/jquery.cookie.js"></script>
103 <script src="scripts/tree.jquery.js"></script>
104 <script src="scripts/prettify.js"></script>
105 <script src="scripts/jsdoc-toc.js"></script>
106 <script src="scripts/linenumber.js"></script>
107 <script src="scripts/scrollanchor.js"></script>
108</body>
109
110</html>
\No newline at end of file