UNPKG

fluentnode

Version:

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

609 lines (391 loc) 21 kB
<!DOCTYPE html> <html> <head> <title>Array.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="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="fluentnode.html"> fluentnode.coffee </a> <a class="source" href="index.html"> index.md </a> <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="console.html"> console.litcoffee </a> <a class="source" href="crypto.html"> crypto.litcoffee </a> <a class="source" href="fs.html"> fs.litcoffee </a> <a class="source" href="http.GET.html"> http.GET.litcoffee </a> <a class="source" href="http.POST.html"> http.POST.litcoffee </a> <a class="source" href="http.Server.html"> http.Server.litcoffee </a> <a class="source" href="http.html"> http.litcoffee </a> <a class="source" href="path.html"> path.litcoffee </a> <a class="source" href="process.html"> process.litcoffee </a> <a class="source" href="encoding.html"> encoding.litcoffee </a> <a class="source" href="globals.html"> globals.litcoffee </a> <a class="source" href="assert_Array.test.html"> assert_Array.test.coffee </a> <a class="source" href="assert_Boolean.test.html"> assert_Boolean.test.coffee </a> <a class="source" href="assert_Function.test.html"> assert_Function.test.coffee </a> <a class="source" href="assert_Number.test.html"> assert_Number.test.coffee </a> <a class="source" href="assert_Object.test.html"> assert_Object.test.coffee </a> <a class="source" href="assert_String.test.html"> assert_String.test.coffee </a> <a class="source" href="fluentnode.test.html"> fluentnode.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="crypto.test.html"> crypto.test.coffee </a> <a class="source" href="fs.test.html"> fs.test.coffee </a> <a class="source" href="http.GET.test.html"> http.GET.test.coffee </a> <a class="source" href="http.POST.test.html"> http.POST.test.coffee </a> <a class="source" href="http.Server.test.html"> http.Server.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> <a class="source" href="encoding.test.html"> encoding.test.coffee </a> <a class="source" href="globals.test.html"> globals.test.coffee </a> </div> </li> </ul> <ul class="sections"> <li id="title"> <div class="annotation"> <h1>Array.litcoffee</h1> </div> </li> <li id="section-1"> <div class="annotation"> <div class="pilwrap "> <a class="pilcrow" href="#section-1">&#182;</a> </div> <p><strong>fluent-array</strong> are methods that extend the Javascript’s Array object</p> <p>@.<strong>add</strong> (value…)</p> <p>adds a value to the current array</p> </div> <div class="content"><div class='highlight'><pre><span class="hljs-attribute">Array</span>::add = <span class="hljs-function"><span class="hljs-params">(value...)</span>-&gt;</span> <span class="hljs-keyword">for</span> item <span class="hljs-keyword">in</span> value @.push(item) @</pre></div></div> </li> <li id="section-2"> <div class="annotation"> <div class="pilwrap "> <a class="pilcrow" href="#section-2">&#182;</a> </div> <p>@.<strong>contains</strong> (value)</p> <p>returns true if the current array has <code>value</code></p> <p>Suports the case when <code>value</code> is a an Array, where all provided elements of the <code>value</code> array are expected to exists in @</p> </div> <div class="content"><div class='highlight'><pre><span class="hljs-attribute">Array</span>::contains = <span class="hljs-function"><span class="hljs-params">(value)</span>-&gt;</span> <span class="hljs-keyword">if</span> value <span class="hljs-keyword">instanceof</span> Array <span class="hljs-keyword">for</span> item <span class="hljs-keyword">in</span> value <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> (item <span class="hljs-keyword">in</span> @) <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span> <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>; <span class="hljs-keyword">else</span> (value <span class="hljs-keyword">in</span> @)</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>empty</strong> ()</p> </div> <div class="content"><div class='highlight'><pre><span class="hljs-attribute">Array</span>::empty = <span class="hljs-function">-&gt;</span> @.length == <span class="hljs-number">0</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>item</strong> (index)</p> <p>Returns item[index] if array has that item</p> <p>Note: Double check behaviour of Array.length and check for possible edge cases</p> </div> <div class="content"><div class='highlight'><pre><span class="hljs-attribute">Array</span>::item = <span class="hljs-function"><span class="hljs-params">(index)</span>-&gt;</span> <span class="hljs-keyword">if</span> <span class="hljs-keyword">typeof</span>(index) <span class="hljs-keyword">is</span> <span class="hljs-string">'number'</span> <span class="hljs-keyword">if</span> @.length &gt; index &gt; -<span class="hljs-number">1</span> <span class="hljs-keyword">return</span> @[index] <span class="hljs-literal">null</span></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>nth</strong> ()</p> </div> <div class="content"><div class='highlight'><pre><span class="hljs-attribute">Array</span>::nth = <span class="hljs-attribute">Array</span>::item</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>first</strong> () @.<strong>second</strong> () @.<strong>third</strong> () @.<strong>fourth</strong> ()</p> <p>Helper functions for the nornally requested Array elements</p> </div> <div class="content"><div class='highlight'><pre><span class="hljs-attribute">Array</span>::first = <span class="hljs-function">-&gt;</span> @.item(<span class="hljs-number">0</span>) <span class="hljs-attribute">Array</span>::second = <span class="hljs-function">-&gt;</span> @.item(<span class="hljs-number">1</span>) <span class="hljs-attribute">Array</span>::third = <span class="hljs-function">-&gt;</span> @.item(<span class="hljs-number">2</span>) <span class="hljs-attribute">Array</span>::fourth = <span class="hljs-function">-&gt;</span> @.item(<span class="hljs-number">3</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>last</strong> ()</p> </div> <div class="content"><div class='highlight'><pre><span class="hljs-attribute">Array</span>::last = <span class="hljs-function">-&gt;</span> <span class="hljs-keyword">if</span>(@.length) @[@.length-<span class="hljs-number">1</span>] <span class="hljs-keyword">else</span> <span class="hljs-literal">null</span></pre></div></div> </li> <li id="section-8"> <div class="annotation"> <div class="pilwrap "> <a class="pilcrow" href="#section-8">&#182;</a> </div> <p>@.<strong>log</strong> ()</p> </div> <div class="content"><div class='highlight'><pre><span class="hljs-attribute">Array</span>::log = <span class="hljs-function">-&gt;</span> @.str().log() @</pre></div></div> </li> <li id="section-9"> <div class="annotation"> <div class="pilwrap "> <a class="pilcrow" href="#section-9">&#182;</a> </div> <p>@.<strong>not_Contains</strong> ()</p> </div> <div class="content"><div class='highlight'><pre><span class="hljs-attribute">Array</span>::not_Contains = <span class="hljs-function"><span class="hljs-params">(value)</span>-&gt;</span> value <span class="hljs-keyword">not</span> <span class="hljs-keyword">in</span> @</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>not_Empty</strong> ()</p> </div> <div class="content"><div class='highlight'><pre><span class="hljs-attribute">Array</span>::not_Empty = <span class="hljs-function">-&gt;</span> @.length != <span class="hljs-number">0</span></pre></div></div> </li> <li id="section-11"> <div class="annotation"> <div class="pilwrap "> <a class="pilcrow" href="#section-11">&#182;</a> </div> <p>@.<strong>remove_At</strong> index</p> </div> <div class="content"><div class='highlight'><pre><span class="hljs-attribute">Array</span>::remove_At = <span class="hljs-function"><span class="hljs-params">(index)</span>-&gt;</span> @.splice(index,<span class="hljs-number">1</span>) @</pre></div></div> </li> <li id="section-12"> <div class="annotation"> <div class="pilwrap "> <a class="pilcrow" href="#section-12">&#182;</a> </div> <p>@.<strong>remove_First</strong></p> </div> <div class="content"><div class='highlight'><pre><span class="hljs-attribute">Array</span>::remove_First = <span class="hljs-function"><span class="hljs-params">()</span>-&gt;</span> @.remove_At <span class="hljs-number">0</span></pre></div></div> </li> <li id="section-13"> <div class="annotation"> <div class="pilwrap "> <a class="pilcrow" href="#section-13">&#182;</a> </div> <p>@.<strong>remove_If_Contains</strong></p> <p>Removes an element from an array if it contains a particular string Note that all elements (and match) will be converted into strings before comparison</p> </div> <div class="content"><div class='highlight'><pre><span class="hljs-attribute">Array</span>::remove_If_Contains = <span class="hljs-function"><span class="hljs-params">(value)</span>-&gt;</span> <span class="hljs-keyword">return</span> @ <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> value @.filter (word) -&gt; word.str().not_Contains(value.str())</pre></div></div> </li> <li id="section-14"> <div class="annotation"> <div class="pilwrap "> <a class="pilcrow" href="#section-14">&#182;</a> </div> <p>@.<strong>size</strong></p> </div> <div class="content"><div class='highlight'><pre><span class="hljs-attribute">Array</span>::size = <span class="hljs-function">-&gt;</span> @.length</pre></div></div> </li> <li id="section-15"> <div class="annotation"> <div class="pilwrap "> <a class="pilcrow" href="#section-15">&#182;</a> </div> <p>@.<strong>starts_With</strong> value</p> </div> <div class="content"><div class='highlight'><pre><span class="hljs-attribute">Array</span>::starts_With = <span class="hljs-function"><span class="hljs-params">(value)</span>-&gt;</span> (item <span class="hljs-keyword">for</span> item <span class="hljs-keyword">in</span> @ <span class="hljs-keyword">when</span> value &amp;&amp; item.starts_With(value))</pre></div></div> </li> <li id="section-16"> <div class="annotation"> <div class="pilwrap "> <a class="pilcrow" href="#section-16">&#182;</a> </div> <p>@.<strong>take</strong> value</p> </div> <div class="content"><div class='highlight'><pre><span class="hljs-attribute">Array</span>::take = <span class="hljs-function"><span class="hljs-params">(size)</span>-&gt;</span> <span class="hljs-keyword">if</span> size <span class="hljs-keyword">is</span> -<span class="hljs-number">1</span> <span class="hljs-keyword">then</span> @ <span class="hljs-keyword">else</span> @.slice(<span class="hljs-number">0</span>,size)</pre></div></div> </li> <li id="section-17"> <div class="annotation"> <div class="pilwrap "> <a class="pilcrow" href="#section-17">&#182;</a> </div> <p>@.<strong>unique</strong></p> </div> <div class="content"><div class='highlight'><pre><span class="hljs-attribute">Array</span>::unique = <span class="hljs-function"><span class="hljs-params">()</span> -&gt;</span> output = {} output[@[key]] = @[key] <span class="hljs-keyword">for</span> key <span class="hljs-keyword">in</span> [<span class="hljs-number">0.</span>..<span class="hljs-property">@length</span>] output.keys()</pre></div></div> </li> <li id="section-18"> <div class="annotation"> <div class="pilwrap "> <a class="pilcrow" href="#section-18">&#182;</a> </div> <hr> </div> </li> <li id="section-19"> <div class="annotation"> <div class="pilwrap "> <a class="pilcrow" href="#section-19">&#182;</a> </div> <p>back to <a href="index.html">index</a></p> </div> </li> </ul> </div> </body> </html>