UNPKG

fluentnode

Version:

Fluent apis for node (based on the concepts used in C#'s FluentSharp

462 lines (306 loc) 16.1 kB
<!DOCTYPE html> <html> <head> <title>Object.litcoffee</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <ul id="jump_to"> <li> <a class="large" href="javascript:void(0);">Jump To &hellip;</a> <a class="small" href="javascript:void(0);">+</a> <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="Array.html"> Array.litcoffee </a> <a class="source" href="Boolean.html"> Boolean.litcoffee </a> <a class="source" href="Function.html"> Function.litcoffee </a> <a class="source" href="Number.html"> Number.litcoffee </a> <a class="source" href="Object.html"> Object.litcoffee </a> <a class="source" href="String.html"> String.litcoffee </a> <a class="source" href="_register.html"> _register.js </a> <a class="source" href="_to_map_and_write_Tests.html"> _to_map_and_write_Tests.litcoffee </a> <a class="source" href="assert_Array.html"> assert_Array.litcoffee </a> <a class="source" href="assert_Boolean.html"> assert_Boolean.litcoffee </a> <a class="source" href="assert_Function.html"> assert_Function.litcoffee </a> <a class="source" href="assert_Number.html"> assert_Number.litcoffee </a> <a class="source" href="assert_Object.html"> assert_Object.litcoffee </a> <a class="source" href="assert_String.html"> assert_String.litcoffee </a> <a class="source" href="console.html"> console.litcoffee </a> <a class="source" href="fs.html"> fs.litcoffee </a> <a class="source" href="globals.html"> globals.litcoffee </a> <a class="source" href="http.html"> http.litcoffee </a> <a class="source" href="index.html"> index.md </a> <a class="source" href="path.html"> path.litcoffee </a> <a class="source" href="process.html"> process.litcoffee </a> <a class="source" href="Array.test.html"> Array.test.coffee </a> <a class="source" href="Boolean.test.html"> Boolean.test.coffee </a> <a class="source" href="Function.test.html"> Function.test.coffee </a> <a class="source" href="Number.test.html"> Number.test.coffee </a> <a class="source" href="Object.test.html"> Object.test.coffee </a> <a class="source" href="String.test.html"> String.test.coffee </a> <a class="source" href="Array.test.html"> Array.test.coffee </a> <a class="source" href="Boolean.test.html"> Boolean.test.coffee </a> <a class="source" href="Function.test.html"> Function.test.coffee </a> <a class="source" href="Number.test.html"> Number.test.coffee </a> <a class="source" href="Object.test.html"> Object.test.coffee </a> <a class="source" href="String.test.html"> String.test.coffee </a> <a class="source" href="console.test.html"> console.test.coffee </a> <a class="source" href="fs.test.html"> fs.test.coffee </a> <a class="source" href="globals.test.html"> globals.test.coffee </a> <a class="source" href="http.test.html"> http.test.coffee </a> <a class="source" href="path.test.html"> path.test.coffee </a> <a class="source" href="process.test.html"> process.test.coffee </a> </div> </li> </ul> <ul class="sections"> <li id="title"> <div class="annotation"> <h1>Object.litcoffee</h1> </div> </li> <li id="section-1"> <div class="annotation"> <div class="pilwrap "> <a class="pilcrow" href="#section-1">&#182;</a> </div> <p>These Object prototypes have to be written using Object.defineProperty so that we can set the enumerable value to false (otherwise ‘for item of xyz’ would include these methods)</p> <p>dependencies</p> </div> <div class="content"><div class='highlight'><pre><span class="hljs-built_in">require</span> <span class="hljs-string">'./fs'</span></pre></div></div> </li> <li id="section-2"> <div class="annotation"> <div class="pilwrap "> <a class="pilcrow" href="#section-2">&#182;</a> </div> <p>todo: add check for already mapped methods. once that is done we should be able to add this method safely</p> <pre><code>Object.defineProperty Object.prototype, <span class="hljs-string">'json'</span>, enumerable : <span class="hljs-literal">false</span>, writable : <span class="hljs-literal">true</span>, <span class="hljs-attribute">value</span>: <span class="hljs-function">-&gt;</span> <span class="hljs-keyword">return</span> JSON.stringify(@) </code></pre><p><strong>str</strong></p> </div> <div class="content"><div class='highlight'><pre>Object.defineProperty Object.prototype, <span class="hljs-string">'str'</span>, enumerable : <span class="hljs-literal">false</span>, writable : <span class="hljs-literal">true</span>, <span class="hljs-attribute">value</span>: <span class="hljs-function">-&gt;</span> <span class="hljs-keyword">return</span> @.toString()</pre></div></div> </li> <li id="section-3"> <div class="annotation"> <div class="pilwrap "> <a class="pilcrow" href="#section-3">&#182;</a> </div> <p><strong>json_pretty</strong></p> </div> <div class="content"><div class='highlight'><pre>Object.defineProperty Object.prototype, <span class="hljs-string">'json_pretty'</span>, enumerable : <span class="hljs-literal">false</span>, writable : <span class="hljs-literal">true</span>, <span class="hljs-attribute">value</span>: <span class="hljs-function">-&gt;</span> <span class="hljs-keyword">return</span> JSON.stringify(@,<span class="hljs-literal">null</span>,<span class="hljs-string">' '</span>)</pre></div></div> </li> <li id="section-4"> <div class="annotation"> <div class="pilwrap "> <a class="pilcrow" href="#section-4">&#182;</a> </div> <p><strong>json_inspect</strong></p> </div> <div class="content"><div class='highlight'><pre>Object.defineProperty Object.prototype, <span class="hljs-string">'json_inspect'</span>, enumerable : <span class="hljs-literal">false</span>, writable : <span class="hljs-literal">true</span>, <span class="hljs-attribute">value</span>: <span class="hljs-function">-&gt;</span> <span class="hljs-keyword">return</span> <span class="hljs-built_in">require</span>(<span class="hljs-string">'util'</span>).inspect(@)</pre></div></div> </li> <li id="section-5"> <div class="annotation"> <div class="pilwrap "> <a class="pilcrow" href="#section-5">&#182;</a> </div> <p><strong>keys</strong></p> </div> <div class="content"><div class='highlight'><pre>Object.defineProperty Object.prototype, <span class="hljs-string">'keys'</span>, enumerable : <span class="hljs-literal">false</span>, writable : <span class="hljs-literal">true</span>, <span class="hljs-attribute">value</span>: <span class="hljs-function">-&gt;</span> <span class="hljs-keyword">return</span> (key <span class="hljs-keyword">for</span> own key <span class="hljs-keyword">of</span> @)</pre></div></div> </li> <li id="section-6"> <div class="annotation"> <div class="pilwrap "> <a class="pilcrow" href="#section-6">&#182;</a> </div> <p><strong>keys_All</strong></p> </div> <div class="content"><div class='highlight'><pre>Object.defineProperty Object.prototype, <span class="hljs-string">'keys_All'</span>, enumerable : <span class="hljs-literal">false</span>, writable : <span class="hljs-literal">true</span>, <span class="hljs-attribute">value</span>: <span class="hljs-function">-&gt;</span> <span class="hljs-keyword">return</span> (key <span class="hljs-keyword">for</span> key <span class="hljs-keyword">of</span> @)</pre></div></div> </li> <li id="section-7"> <div class="annotation"> <div class="pilwrap "> <a class="pilcrow" href="#section-7">&#182;</a> </div> <p><strong>call_Function</strong></p> </div> <div class="content"><div class='highlight'><pre>Object.defineProperty Object.prototype, <span class="hljs-string">'call_Function'</span>, enumerable : <span class="hljs-literal">false</span>, writable : <span class="hljs-literal">true</span>, <span class="hljs-attribute">value</span>: <span class="hljs-function"><span class="hljs-params">(method, params...)</span>-&gt;</span> callParams = [@] callParams.push param <span class="hljs-keyword">for</span> param <span class="hljs-keyword">in</span> params <span class="hljs-keyword">return</span> method.apply(<span class="hljs-literal">null</span>,callParams)</pre></div></div> </li> <li id="section-8"> <div class="annotation"> <div class="pilwrap "> <a class="pilcrow" href="#section-8">&#182;</a> </div> <p>@.load_Json target</p> </div> <div class="content"><div class='highlight'><pre>Object.defineProperty Object.prototype, <span class="hljs-string">'load_Json'</span>, enumerable : <span class="hljs-literal">false</span>, writable : <span class="hljs-literal">true</span>, <span class="hljs-attribute">value</span>: <span class="hljs-function"><span class="hljs-params">()</span>-&gt;</span> JSON.parse(@.file_Contents())</pre></div></div> </li> <li id="section-9"> <div class="annotation"> <div class="pilwrap "> <a class="pilcrow" href="#section-9">&#182;</a> </div> <p>@.save_Json target</p> </div> <div class="content"><div class='highlight'><pre>Object.defineProperty Object.prototype, <span class="hljs-string">'save_Json'</span>, enumerable : <span class="hljs-literal">false</span>, writable : <span class="hljs-literal">true</span>, <span class="hljs-attribute">value</span>: <span class="hljs-function"><span class="hljs-params">(target)</span>-&gt;</span> data = JSON.stringify(@,<span class="hljs-literal">null</span>,<span class="hljs-string">' '</span>) <span class="hljs-keyword">return</span> data.saveAs(target)</pre></div></div> </li> <li id="section-10"> <div class="annotation"> <div class="pilwrap "> <a class="pilcrow" href="#section-10">&#182;</a> </div> <p><strong>repl_Me</strong></p> </div> <div class="content"><div class='highlight'><pre>Object.defineProperty Object.prototype, <span class="hljs-string">'repl_Me'</span>, enumerable : <span class="hljs-literal">false</span>, writable : <span class="hljs-literal">true</span>, <span class="hljs-attribute">value</span>: <span class="hljs-function"><span class="hljs-params">(onExit)</span>-&gt;</span> repl = <span class="hljs-built_in">require</span>(<span class="hljs-string">'repl'</span>) replServer = repl.start {<span class="hljs-attribute">prompt</span>: <span class="hljs-string">'[fluentnode] repl&gt; '</span>} replServer.context.that = @ replServer.context.replServer = replServer replServer.<span class="hljs-literal">on</span> <span class="hljs-string">'exit'</span>, <span class="hljs-function">-&gt;</span> onExit() replServer</pre></div></div> </li> <li id="section-11"> <div class="annotation"> <div class="pilwrap "> <a class="pilcrow" href="#section-11">&#182;</a> </div> <hr> </div> </li> <li id="section-12"> <div class="annotation"> <div class="pilwrap "> <a class="pilcrow" href="#section-12">&#182;</a> </div> <p>back to <a href="index.html">index</a></p> </div> </li> </ul> </div> </body> </html>