lodash-contrib
Version:
The brass buckles on lodash's utility belt
567 lines (410 loc) • 19.7 kB
HTML
<html>
<head>
<title>_.function.predicates.js.md</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 …</a>
<a class="small" href="javascript:void(0);">+</a>
<div id="jump_wrapper">
<div id="jump_page_wrapper">
<div id="jump_page">
<a class="source" href="_.array.builders.js.html">
_.array.builders.js.md
</a>
<a class="source" href="_.array.selectors.js.html">
_.array.selectors.js.md
</a>
<a class="source" href="_.collections.walk.js.html">
_.collections.walk.js.md
</a>
<a class="source" href="_.function.arity.js.html">
_.function.arity.js.md
</a>
<a class="source" href="_.function.combinators.js.html">
_.function.combinators.js.md
</a>
<a class="source" href="_.function.iterators.js.html">
_.function.iterators.js.md
</a>
<a class="source" href="_.function.predicates.js.html">
_.function.predicates.js.md
</a>
<a class="source" href="_.object.builders.js.html">
_.object.builders.js.md
</a>
<a class="source" href="_.object.selectors.js.html">
_.object.selectors.js.md
</a>
<a class="source" href="_.util.existential.js.html">
_.util.existential.js.md
</a>
<a class="source" href="_.util.operators.js.html">
_.util.operators.js.md
</a>
<a class="source" href="_.util.strings.js.html">
_.util.strings.js.md
</a>
<a class="source" href="_.util.trampolines.js.html">
_.util.trampolines.js.md
</a>
<a class="source" href="index.html">
index.md
</a>
</div>
</div>
</li>
</ul>
<ul class="sections">
<li id="title">
<div class="annotation">
<h1>_.function.predicates.js.md</h1>
</div>
</li>
<li id="section-1">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-1">¶</a>
</div>
<h3 id="function-predicates">function.predicates</h3>
<blockquote>
<p>Functions which return whether the input meets a condition.</p>
</blockquote>
<hr>
</div>
</li>
<li id="section-2">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-2">¶</a>
</div>
<h4 id="isassociative">isAssociative</h4>
<p><strong>Signature:</strong> <code>isAssociative(value:Any)</code></p>
<p>Returns a boolean indicating whether or not the value is an associative object.
An associative object is one where its elements can be accessed via a key or
index (e.g. arrays, <code>arguments</code>, objects).</p>
<pre><code class="lang-javascript">_.isAssociative([<span class="hljs-string">"Athens"</span>, <span class="hljs-string">"Sparta"</span>]);
<span class="hljs-comment">// => true</span>
_.isAssociative(<span class="hljs-number">42</span>);
<span class="hljs-comment">// => false</span>
</code></pre>
<hr>
</div>
</li>
<li id="section-3">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-3">¶</a>
</div>
<h4 id="isdecreasing">isDecreasing</h4>
<p><strong>Signature:</strong> <code>_.isDecreasing(values:Any...)</code></p>
<p>Checks whether the arguments are monotonically decreasing values (i.e. whether
each argument is less than the previous argument.)</p>
<pre><code class="lang-javascript">_.isDecreasing(<span class="hljs-number">3</span>, <span class="hljs-number">2</span>, <span class="hljs-number">1</span>);
<span class="hljs-comment">// => true</span>
_.isDecreasing(<span class="hljs-number">15</span>, <span class="hljs-number">12</span>, <span class="hljs-number">2</span>);
<span class="hljs-comment">// => true</span>
_.isDecreasing(<span class="hljs-number">2</span>, <span class="hljs-number">3</span>);
<span class="hljs-comment">// => false</span>
</code></pre>
<hr>
</div>
</li>
<li id="section-4">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-4">¶</a>
</div>
<h4 id="iseven">isEven</h4>
<p><strong>Signature:</strong> <code>_.isEven(value:Any)</code></p>
<p>Checks whether the value is an even number.</p>
<pre><code class="lang-javascript">_.isEven(<span class="hljs-number">12</span>);
<span class="hljs-comment">// => true</span>
_.isEven(<span class="hljs-number">3</span>);
<span class="hljs-comment">// => false</span>
_.isEven({});
<span class="hljs-comment">// => false</span>
</code></pre>
<hr>
</div>
</li>
<li id="section-5">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-5">¶</a>
</div>
<h4 id="isfloat">isFloat</h4>
<p><strong>Signature:</strong> <code>_.isFloat(value:Any)</code></p>
<p>Checks whether the value is a “float.” For the purposes of this function, a float
is a numeric value that is not an integer. A numeric value may be a number, a
string containing a number, a <code>Number</code> object, etc.</p>
<p><strong>NOTE:</strong> JavaScript itself makes no distinction between integers and floats. For
the purposes of this function both <code>1</code> and <code>1.0</code> are considered integers.</p>
<pre><code class="lang-javascript">_.isFloat(<span class="hljs-number">1.1</span>);
<span class="hljs-comment">// => true</span>
_.isFloat(<span class="hljs-number">1</span>);
<span class="hljs-comment">// => false</span>
_.isFloat(<span class="hljs-number">1.0</span>);
<span class="hljs-comment">// => false</span>
_.isFloat(<span class="hljs-string">"2.15"</span>);
<span class="hljs-comment">// => true</span>
</code></pre>
<hr>
</div>
</li>
<li id="section-6">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-6">¶</a>
</div>
<h4 id="isincreasing">isIncreasing</h4>
<p><strong>Signature:</strong> <code>_.isIncreasing(value:Any...)</code></p>
<p>Checks whether the arguments are monotonically increasing values (i.e. each
argument is greater than the previous argument.)</p>
<pre><code class="lang-javascript">_.isIncreasing(<span class="hljs-number">1</span>, <span class="hljs-number">12</span>, <span class="hljs-number">15</span>);
<span class="hljs-comment">// => true</span>
_.isIncreasing(<span class="hljs-number">1</span>);
<span class="hljs-comment">// => true</span>
_.isIncreasing(<span class="hljs-number">5</span>, <span class="hljs-number">4</span>);
<span class="hljs-comment">// => false</span>
</code></pre>
<hr>
</div>
</li>
<li id="section-7">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-7">¶</a>
</div>
<h4 id="isindexed">isIndexed</h4>
<p><strong>Signature:</strong> <code>_.isIndexed(value:Any)</code></p>
<p>Checks whether the value is “indexed.” An indexed value is one which accepts a
numerical index to access its elements. (e.g. arrays and strings)</p>
<p><strong>NOTE:</strong> lodash does not support cross-browser consistent use of strings as
array-like values, so be wary in IE 8 when using string objects and in IE7 and
earlier when using string literals & objects.</p>
<pre><code class="lang-javascript">_.isIndexed(<span class="hljs-string">"Socrates"</span>);
<span class="hljs-comment">// => true</span>
_.isIndexed({poison: <span class="hljs-string">"hemlock"</span>});
<span class="hljs-comment">// => false</span>
</code></pre>
<hr>
</div>
</li>
<li id="section-8">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-8">¶</a>
</div>
<h4 id="isinstanceof">isInstanceOf</h4>
<p><strong>Signature:</strong> <code>_.isInstanceOf(value:Any, constructor:Function)</code></p>
<p>Checks whether the value is an instance of the constructor.</p>
<pre><code class="lang-javascript">_.isInstanceOf(<span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>(), <span class="hljs-built_in">Date</span>);
<span class="hljs-comment">// => true</span>
_.isInstanceOf(<span class="hljs-string">"Hippocrates"</span>, <span class="hljs-built_in">RegExp</span>);
<span class="hljs-comment">// => false</span>
</code></pre>
<hr>
</div>
</li>
<li id="section-9">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-9">¶</a>
</div>
<h4 id="isinteger">isInteger</h4>
<p><strong>Signature:</strong> <code>_.isInteger(value:Any)</code></p>
<p>Checks whether the value is a numeric integer. A numeric value can be a string
containing a number, a <code>Number</code> object, etc.</p>
<pre><code class="lang-javascript">_.isInteger(<span class="hljs-number">18</span>);
<span class="hljs-comment">// => true</span>
_.isInteger(<span class="hljs-string">"18"</span>);
<span class="hljs-comment">// => true</span>
_.isInteger(<span class="hljs-number">2.5</span>);
<span class="hljs-comment">// => false</span>
_.isInteger(-<span class="hljs-number">1</span>);
<span class="hljs-comment">// => true</span>
</code></pre>
<hr>
</div>
</li>
<li id="section-10">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-10">¶</a>
</div>
<h4 id="isjson">isJSON</h4>
<p><strong>Signature:</strong> <code>_.isJSON(value:Any)</code></p>
<p>Checks whether the value is valid JSON. <a href="http://www.json.org/">See the spec</a> for
more information on what constitutes valid JSON.</p>
<p><strong>NOTE:</strong> This function relies on <code>JSON.parse</code> which is not available in IE7 and
earlier.</p>
<pre><code class="lang-javascript">_.isJSON(<span class="hljs-string">'{ "name": "Crockford" }'</span>);
<span class="hljs-comment">// => true</span>
_.isJSON({ name: <span class="hljs-string">"Crocket"</span> });
<span class="hljs-comment">// => false</span>
</code></pre>
<hr>
</div>
</li>
<li id="section-11">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-11">¶</a>
</div>
<h4 id="isnegative">isNegative</h4>
<p><strong>Signature:</strong> <code>_.isNegative(value:Any)</code></p>
<p>Checks whether the value is a negative number.</p>
<pre><code class="lang-javascript">_.isNegative(-<span class="hljs-number">2</span>);
<span class="hljs-comment">// => true</span>
_.isNegative(<span class="hljs-number">5</span>);
<span class="hljs-comment">// => false</span>
</code></pre>
<hr>
</div>
</li>
<li id="section-12">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-12">¶</a>
</div>
<h4 id="isnumeric">isNumeric</h4>
<p><strong>Signature:</strong> <code>_.isNumeric(value:Any)</code></p>
<p>A numeric is something that contains a numeric value, regardless of its type. It
can be a string containing a numeric value, exponential notation, a <code>Number</code>
object, etc.</p>
<pre><code class="lang-javascript">_.isNumeric(<span class="hljs-string">"14"</span>);
<span class="hljs-comment">// => true</span>
_.isNumeric(<span class="hljs-string">"fourteen"</span>);
<span class="hljs-comment">// => false</span>
</code></pre>
<hr>
</div>
</li>
<li id="section-13">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-13">¶</a>
</div>
<h4 id="isodd">isOdd</h4>
<p><strong>Signature:</strong> <code>_.isOdd(value:Any)</code></p>
<p>Checks whether the value is an odd number.</p>
<pre><code class="lang-javascript">_.isOdd(<span class="hljs-number">3</span>);
<span class="hljs-comment">// => true</span>
_.isOdd(<span class="hljs-number">2</span>);
<span class="hljs-comment">// => false</span>
_.isOdd({});
<span class="hljs-comment">// => false</span>
</code></pre>
<hr>
</div>
</li>
<li id="section-14">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-14">¶</a>
</div>
<h4 id="isplainobject">isPlainObject</h4>
<p><strong>Signature:</strong> <code>_.isPlainObject(value:Any);</code></p>
<p>Checks whether the value is a “plain” object created as an object literal (<code>{}</code>)
or explicitly constructed with <code>new Object()</code>. Instances of other constructors
are <strong>not</strong> plain objects.</p>
<pre><code class="lang-javascript">_.isPlainObject({});
<span class="hljs-comment">// => true</span>
_.isPlainObject(<span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>());
<span class="hljs-comment">// => false</span>
_.isPlainObject([]);
<span class="hljs-comment">// => false</span>
</code></pre>
<hr>
</div>
</li>
<li id="section-15">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-15">¶</a>
</div>
<h4 id="ispositive">isPositive</h4>
<p><strong>Signature:</strong> <code>_.isPositive(value:Any)</code></p>
<p>Checks whether the value is a positive number.</p>
<pre><code class="lang-javascript">_.isPositive(<span class="hljs-number">21</span>);
<span class="hljs-comment">// => true</span>
_.isPositive(-<span class="hljs-number">3</span>);
<span class="hljs-comment">// => false</span>
</code></pre>
<hr>
</div>
</li>
<li id="section-16">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-16">¶</a>
</div>
<h4 id="issequential">isSequential</h4>
<p><strong>Signature:</strong> <code>_.isSequential(value:Any)</code></p>
<p>Checks whether the value is a sequential composite type (i.e. arrays and
<code>arguments</code>).</p>
<pre><code class="lang-javascript">_.isSequential([<span class="hljs-string">"Herodotus"</span>, <span class="hljs-string">"Thucidydes"</span>);
<span class="hljs-comment">// => true</span>
_.isSequential(<span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>);
<span class="hljs-comment">// => false</span>
</code></pre>
<hr>
</div>
</li>
<li id="section-17">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-17">¶</a>
</div>
<h4 id="isvaliddate">isValidDate</h4>
<p><strong>Signature:</strong> <code>_.isValidDate(value:Any)</code></p>
<p>Checks whether the value is a valid date. That is, the value is both an instance
of <code>Date</code> and it represents an actual date.</p>
<p><span class="label label-danger">Warning:</span> This function does not verify
whether the original input to <code>Date</code> is a real date. For instance,
<code>new Date("02/30/2014")</code> is considered a valid date because <code>Date</code> coerces that
into a representation of 03/02/2014. To validate strings representing a date,
consider using a date/time library like [Moment.js.][momentjs]</p>
<pre><code class="lang-javascript">_.isValidDate(<span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>(<span class="hljs-string">"January 1, 1900"</span>));
<span class="hljs-comment">// => true</span>
_.isValidDate(<span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>(<span class="hljs-string">"The Last Great Time War"</span>));
<span class="hljs-comment">// => false</span>
</code></pre>
<hr>
</div>
</li>
<li id="section-18">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-18">¶</a>
</div>
<h4 id="iszero">isZero</h4>
<p><strong>Signature:</strong> <code>_.isZero(value:Any)</code></p>
<p>Checks whether the value is <code>0</code>.</p>
<pre><code class="lang-javascript">_.isZero(<span class="hljs-number">0</span>);
<span class="hljs-comment">// => true</span>
_.isZero(<span class="hljs-string">"Pythagoras"</span>);
<span class="hljs-comment">// => false</span>
</code></pre>
<hr>
</div>
</li>
<li id="section-19">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-19">¶</a>
</div>
</div>
</li>
</ul>
</div>
</body>
</html>