Skip to content

Commit

Permalink
Underscore.js 1.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jashkenas committed Sep 27, 2012
1 parent ac6beae commit 37609e8
Show file tree
Hide file tree
Showing 7 changed files with 546 additions and 295 deletions.
7 changes: 1 addition & 6 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
require 'rubygems'
require 'uglifier'

HEADER = /((^\s*\/\/.*\n)+)/

desc "Use the Closure Compiler to compress Underscore.js"
task :build do
source = File.read('underscore.js')
header = source.match(HEADER)
min = Uglifier.compile(source)
File.open('underscore-min.js', 'w') do |file|
file.write header[1].squeeze(' ') + min
end
File.open('underscore-min.js', 'w') {|f| f.write min }
end

desc "Build the docco documentation"
Expand Down
8 changes: 7 additions & 1 deletion docs/docco.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ h1, h2, h3, h4, h5, h6 {
h1 {
margin-top: 40px;
}
hr {
border: 0 none;
border-top: 1px solid #e5e5ee;
height: 1px;
margin: 20px 0;
}
#container {
position: relative;
}
Expand Down Expand Up @@ -115,7 +121,7 @@ table td {
}
pre, tt, code {
font-size: 12px; line-height: 18px;
font-family: Monaco, Consolas, "Lucida Console", monospace;
font-family: Menlo, Monaco, Consolas, "Lucida Console", monospace;
margin: 0; padding: 0;
}

Expand Down
636 changes: 377 additions & 259 deletions docs/underscore.html

Large diffs are not rendered by default.

161 changes: 153 additions & 8 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@
<div id="sidebar" class="interface">

<a class="toc_title" href="#">
Underscore.js <span class="version">(1.3.3)</span>
Underscore.js <span class="version">(1.4.0)</span>
</a>

<a class="toc_title" href="#">
Expand All @@ -196,6 +196,7 @@
<li>- <a href="#reduceRight">reduceRight</a></li>
<li>- <a href="#find">find</a></li>
<li>- <a href="#filter">filter</a></li>
<li>- <a href="#where">where</a></li>
<li>- <a href="#reject">reject</a></li>
<li>- <a href="#all">all</a></li>
<li>- <a href="#any">any</a></li>
Expand All @@ -206,6 +207,7 @@
<li>- <a href="#min">min</a></li>
<li>- <a href="#sortBy">sortBy</a></li>
<li>- <a href="#groupBy">groupBy</a></li>
<li>- <a href="#countBy">countBy</a></li>
<li>- <a href="#shuffle">shuffle</a></li>
<li>- <a href="#toArray">toArray</a></li>
<li>- <a href="#size">size</a></li>
Expand All @@ -227,6 +229,7 @@
<li>- <a href="#difference">difference</a></li>
<li>- <a href="#uniq">uniq</a></li>
<li>- <a href="#zip">zip</a></li>
<li>- <a href="#object">object</a></li>
<li>- <a href="#indexOf">indexOf</a></li>
<li>- <a href="#lastIndexOf">lastIndexOf</a></li>
<li>- <a href="#sortedIndex">sortedIndex</a></li>
Expand Down Expand Up @@ -256,6 +259,8 @@
<ul class="toc_section">
<li>- <a href="#keys">keys</a></li>
<li>- <a href="#values">values</a></li>
<li>- <a href="#pairs">pairs</a></li>
<li>- <a href="#invert">invert</a></li>
<li>- <a href="#object-functions">functions</a></li>
<li>- <a href="#extend">extend</a></li>
<li>- <a href="#pick">pick</a></li>
Expand Down Expand Up @@ -289,6 +294,7 @@
<li>- <a href="#noConflict">noConflict</a></li>
<li>- <a href="#identity">identity</a></li>
<li>- <a href="#times">times</a></li>
<li>- <a href="#random">random</a></li>
<li>- <a href="#mixin">mixin</a></li>
<li>- <a href="#uniqueId">uniqueId</a></li>
<li>- <a href="#escape">escape</a></li>
Expand Down Expand Up @@ -367,11 +373,11 @@ <h2>Downloads <i style="padding-left: 12px; font-size:12px;">(Right-click, and u

<table>
<tr>
<td><a href="underscore.js">Development Version (1.3.3)</a></td>
<td><i>37kb, Uncompressed with Plentiful Comments</i></td>
<td><a href="underscore.js">Development Version (1.4.0)</a></td>
<td><i>40kb, Uncompressed with Plentiful Comments</i></td>
</tr>
<tr>
<td><a href="underscore-min.js">Production Version (1.3.3)</a></td>
<td><a href="underscore-min.js">Production Version (1.4.0)</a></td>
<td><i>4kb, Minified and Gzipped</i></td>
</tr>
<tr>
Expand Down Expand Up @@ -477,6 +483,18 @@ <h2 id="collections">Collection Functions (Arrays or Objects)</h2>
=&gt; [2, 4, 6]
</pre>

<p id="where">
<b class="header">where</b><code>_.where(list, properties)</code>
<br />
Looks through each value in the <b>list</b>, returning an array of all
the values that contain all of the key-value pairs listed in <b>properties</b>.
</p>
<pre>
_.where(listOfPlays, {author: "Shakespeare", year: 1611});
=&gt; [{title: "Cymbeline", author: "Shakespeare", year: 1611},
{title: "The Tempest", author: "Shakespeare", year: 1611}]
</pre>

<p id="reject">
<b class="header">reject</b><code>_.reject(list, iterator, [context])</code>
<br />
Expand Down Expand Up @@ -602,6 +620,21 @@ <h2 id="collections">Collection Functions (Arrays or Objects)</h2>

_.groupBy(['one', 'two', 'three'], 'length');
=&gt; {3: ["one", "two"], 5: ["three"]}
</pre>

<p id="countBy">
<b class="header">countBy</b><code>_.countBy(list, iterator)</code>
<br />
Sorts a list into groups and returns a count for the number of objects
in each group.
Similar to <tt>groupBy</tt>, but instead of returning a list of values,
returns a count for the number of values in that group.
</p>
<pre>
_.countBy([1, 2, 3, 4, 5], function(num) {
return num % 2 == 0 ? 'even' : 'odd';
});
=&gt; {odd: 3, even: 2}
</pre>

<p id="shuffle">
Expand Down Expand Up @@ -789,6 +822,20 @@ <h2 id="arrays">Array Functions</h2>
<pre>
_.zip(['moe', 'larry', 'curly'], [30, 40, 50], [true, false, false]);
=&gt; [["moe", 30, true], ["larry", 40, false], ["curly", 50, false]]
</pre>

<p id="object">
<b class="header">object</b><code>_.object(list, [values])</code>
<br />
Converts arrays into objects. Pass either a single list of
<tt>[key, value]</tt> pairs, or a list of keys, and a list of values.
</p>
<pre>
_.object(['moe', 'larry', 'curly'], [30, 40, 50]);
=&gt; {moe: 30, larry: 40, curly: 50}

_.object([['moe', 30], ['larry', 40], ['curly', 50]]);
=&gt; {moe: 30, larry: 40, curly: 50}
</pre>

<p id="indexOf">
Expand All @@ -798,19 +845,22 @@ <h2 id="arrays">Array Functions</h2>
or <i>-1</i> if value is not present in the <b>array</b>. Uses the native
<b>indexOf</b> function unless it's missing. If you're working with a
large array, and you know that the array is already sorted, pass <tt>true</tt>
for <b>isSorted</b> to use a faster binary search.
for <b>isSorted</b> to use a faster binary search ... or, pass a number as
the third argument in order to look for the first matching value in the
array after the given index.
</p>
<pre>
_.indexOf([1, 2, 3], 2);
=&gt; 1
</pre>

<p id="lastIndexOf">
<b class="header">lastIndexOf</b><code>_.lastIndexOf(array, value)</code>
<b class="header">lastIndexOf</b><code>_.lastIndexOf(array, value, [fromIndex])</code>
<br />
Returns the index of the last occurrence of <b>value</b> in the <b>array</b>,
or <i>-1</i> if value is not present. Uses the native <b>lastIndexOf</b>
function if possible.
function if possible. Pass <b>fromIndex</b> to start your search at a
given index.
</p>
<pre>
_.lastIndexOf([1, 2, 3, 1, 2, 3], 2);
Expand Down Expand Up @@ -1056,6 +1106,28 @@ <h2 id="objects">Object Functions</h2>
<pre>
_.values({one : 1, two : 2, three : 3});
=&gt; [1, 2, 3]
</pre>

<p id="pairs">
<b class="header">pairs</b><code>_.pairs(object)</code>
<br />
Convert an object into a list of <tt>[key, value]</tt> pairs.
</p>
<pre>
_.pairs({one : 1, two : 2, three : 3});
=&gt; [[one: 1], [two: 2], [three: 3]]
</pre>

<p id="invert">
<b class="header">invert</b><code>_.invert(object)</code>
<br />
Returns a copy of the <b>object</b> where the keys have become the values
and the values the keys. For this to work, all of your object's values
should be unique and string serializable.
</p>
<pre>
_.invert({Moe: "Moses", Larry: "Louis", Curly: "Jerome"});
=&gt; {Moses: "Moe", Louis: "Larry", Jerome: "Curly"};
</pre>

<p id="object-functions">
Expand Down Expand Up @@ -1370,11 +1442,23 @@ <h2 id="utility">Utility Functions</h2>
<p id="times">
<b class="header">times</b><code>_.times(n, iterator, [context])</code>
<br />
Invokes the given iterator function <b>n</b> times. Each invocation of <b>iterator</b> is called with an <tt>index</tt> argument.
Invokes the given iterator function <b>n</b> times. Each invocation of
<b>iterator</b> is called with an <tt>index</tt> argument.
</p>
<pre>
_(3).times(function(n){ genie.grantWishNumber(n); });</pre>

<p id="random">
<b class="header">random</b><code>_.random(min, max)</code>
<br />
Returns a random integer between <b>min</b> and <b>max</b>, inclusive.
If you only pass one argument, it will return a number between <tt>0</tt>
and that number.
</p>
<pre>
_.random(0, 100);
=&gt; 42</pre>

<p id="mixin">
<b class="header">mixin</b><code>_.mixin(object)</code>
<br />
Expand Down Expand Up @@ -1662,6 +1746,67 @@ <h2 id="links">Links &amp; Suggested Reading</h2>
</p>

<h2 id="changelog">Change Log</h2>

<p>
<b class="header">1.4.0</b> &mdash; <small><i>Sept. 27, 2012</i></small> &mdash; <a href="https://github.com/documentcloud/backbone/compare/1.3.3...1.4.0">Diff</a><br />
<ul>
<li>
Added a <tt>pairs</tt> function, for turning a JavaScript object
into <tt>[key, value]</tt> pairs ... as well as an <tt>object</tt>
function, for converting an array of <tt>[key, value]</tt> pairs
into an object.
</li>
<li>
Added a <tt>countBy</tt> function, for counting the number of objects
in a list that match a certain criteria.
</li>
<li>
Added an <tt>invert</tt> function, for performing a simple inversion
of the keys and values in an object.
</li>
<li>
Added a <tt>where</tt> function, for easy cases of filtering a list
for objects with specific values.
</li>
<li>
Added an <tt>omit</tt> function, for filtering an object to remove
certain keys.
</li>
<li>
Added a <tt>random</tt> function, to return a random number in a
given range.
</li>
<li>
<tt>_.debounce</tt>'d functions now return their last updated value,
just like <tt>_.throttle</tt>'d functions.
</li>
<li>
The <tt>sortBy</tt> function now runs a stable sort algorithm.
</li>
<li>
Added the optional <tt>fromIndex</tt> option to <tt>indexOf</tt> and
<tt>lastIndexOf</tt>.
</li>
<li>
"Sparse" arrays are no longer supported in Underscore iteration
functions. Use a <tt>for</tt> instead (or better yet, an object).
</li>
<li>
The <tt>min</tt> and <tt>max</tt> functions may now be called on
<i>very</i> large arrays.
</li>
<li>
Interpolation in templates now represents <tt>null</tt> and
<tt>undefined</tt> as the empty string.
</li>
<li>
A number of edge-cases fixes and tweaks, which you can spot in the
<a href="https://github.com/documentcloud/backbone/compare/1.3.3...1.4.0">diff</a>.
Depending on how you're using Underscore, <b>1.4.0</b> may be more
backwards-incompatible than usual &mdash; please test when you upgrade.
</li>
</ul>
</p>

<p>
<b class="header">1.3.3</b> &mdash; <small><i>April 10, 2012</i></small><br />
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name" : "underscore",
"description" : "JavaScript's functional programming helper library.",
"homepage" : "http://documentcloud.github.com/underscore/",
"homepage" : "http://underscorejs.org",
"keywords" : ["util", "functional", "server", "client", "browser"],
"author" : "Jeremy Ashkenas <jeremy@documentcloud.org>",
"repository" : {"type": "git", "url": "git://github.com/documentcloud/underscore.git"},
"main" : "underscore.js",
"version" : "1.3.3"
"version" : "1.4.0"
}
Loading

0 comments on commit 37609e8

Please sign in to comment.