Skip to content

Commit

Permalink
Merge branch 'master' into gh-pages
Browse files Browse the repository at this point in the history
  • Loading branch information
jashkenas committed Apr 2, 2015
2 parents 1d0786a + a11976e commit e4743ab
Show file tree
Hide file tree
Showing 12 changed files with 495 additions and 378 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ matrix:
- node_js: "0.10"
env: BROWSER=true
before_install:
- npm install -g npm
- npm install -g npm@2.6
- npm install -g karma-cli
before_script:
- npm install karma-sauce-launcher
Expand Down
4 changes: 2 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "underscore",
"version": "1.8.2",
"version": "1.8.3",
"main": "underscore.js",
"keywords": ["util", "functional", "server", "client", "browser"],
"ignore" : ["docs", "test", "*.yml", "CNAME", "index.html", "favicon.ico", "CONTRIBUTING.md"]
"ignore" : ["docs", "test", "*.yml", "CNAME", "index.html", "favicon.ico", "CONTRIBUTING.md", ".*", "component.json", "package.json", "karma.*"]
}
2 changes: 1 addition & 1 deletion component.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"repo" : "jashkenas/underscore",
"main" : "underscore.js",
"scripts" : ["underscore.js"],
"version" : "1.8.2",
"version" : "1.8.3",
"license" : "MIT"
}
630 changes: 333 additions & 297 deletions docs/underscore.html

Large diffs are not rendered by default.

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

<a class="toc_title" href="#">
Underscore.js <span class="version">(1.8.2)</span>
Underscore.js <span class="version">(1.8.3)</span>
</a>
<ul class="toc_section">
<li>&raquo; <a href="https://github.com/jashkenas/underscore">GitHub Repository</a></li>
Expand Down Expand Up @@ -279,6 +279,7 @@
<li>- <a href="#mapObject">mapObject</a></li>
<li>- <a href="#pairs">pairs</a></li>
<li>- <a href="#invert">invert</a></li>
<li>- <a href="#create">create</a></li>
<li>- <a href="#object-functions">functions</a></li>
<li>- <a href="#findKey">findKey</a></li>
<li>- <a href="#extend">extend</a></li>
Expand Down Expand Up @@ -402,11 +403,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.8.2)</a></td>
<td><i>51kb, Uncompressed with Plentiful Comments</i></td>
<td><a href="underscore.js">Development Version (1.8.3)</a></td>
<td><i>52kb, Uncompressed with Plentiful Comments</i></td>
</tr>
<tr>
<td><a href="underscore-min.js">Production Version (1.8.2)</a></td>
<td><a href="underscore-min.js">Production Version (1.8.3)</a></td>
<td>
<i>5.7kb, Minified and Gzipped</i>
&nbsp;<small>(<a href="underscore-min.map">Source Map</a>)</small>
Expand Down Expand Up @@ -939,14 +940,15 @@ <h2 id="arrays">Array Functions</h2>
<span class="alias">Alias: <b>unique</b></span>
<br />
Produces a duplicate-free version of the <b>array</b>, using <i>===</i> to test
object equality. If you know in advance that the <b>array</b> is sorted,
object equality. In particular only the first occurence of each value is kept.
If you know in advance that the <b>array</b> is sorted,
passing <i>true</i> for <b>isSorted</b> will run a much faster algorithm.
If you want to compute unique items based on a transformation, pass an
<b>iteratee</b> function.
</p>
<pre>
_.uniq([1, 2, 1, 3, 1, 4]);
=&gt; [1, 2, 3, 4]
_.uniq([1, 2, 1, 4, 1, 3]);
=&gt; [1, 2, 4, 3]
</pre>

<p id="zip">
Expand Down Expand Up @@ -1369,7 +1371,7 @@ <h2 id="objects">Object Functions</h2>
</pre>

<p id="mapObject">
<b class="header">mapObject</b><code>_.mapObject(array, iteratee, [context])</code>
<b class="header">mapObject</b><code>_.mapObject(object, iteratee, [context])</code>
<br />
Like <a href="#map">map</a>, but for objects. Transform the value
of each property in turn.
Expand Down Expand Up @@ -1401,6 +1403,17 @@ <h2 id="objects">Object Functions</h2>
<pre>
_.invert({Moe: "Moses", Larry: "Louis", Curly: "Jerome"});
=&gt; {Moses: "Moe", Louis: "Larry", Jerome: "Curly"};
</pre>

<p id="create">
<b class="header">create</b><code>_.create(prototype, props)</code>
<br />
Creates a new object with the given prototype, optionally attaching
<b>props</b> as <i>own</i> properties. Basically, <tt>Object.create</tt>,
but without all of the property descriptor jazz.
</p>
<pre>
var moe = _.create(Stooge.prototype, {name: "Moe"});
</pre>

<p id="object-functions">
Expand Down Expand Up @@ -2192,6 +2205,20 @@ <h2 id="links">Links &amp; Suggested Reading</h2>

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

<p id="1.8.3">
<b class="header">1.8.3</b> &mdash; <small><i>April 2, 2015</i></small> &mdash; <a href="https://github.com/jashkenas/underscore/compare/1.8.2...1.8.3">Diff</a> &mdash; <a href="https://cdn.rawgit.com/jashkenas/underscore/1.8.3/index.html">Docs</a><br />
<ul>
<li>
Adds an <tt>_.create</tt> method, as a slimmed down version of
<tt>Object.create</tt>.
</li>
<li>
Works around an iOS bug that can improperly cause <tt>isArrayLike</tt>
to be JIT-ed. Also fixes a bug when passing <tt>0</tt> to <tt>isArrayLike</tt>.
</li>
</ul>
</p>

<p id="1.8.2">
<b class="header">1.8.2</b> &mdash; <small><i>Feb. 22, 2015</i></small> &mdash; <a href="https://github.com/jashkenas/underscore/compare/1.8.1...1.8.2">Diff</a> &mdash; <a href="https://cdn.rawgit.com/jashkenas/underscore/1.8.2/index.html">Docs</a><br />
<ul>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"url": "git://github.com/jashkenas/underscore.git"
},
"main": "underscore.js",
"version": "1.8.2",
"version": "1.8.3",
"devDependencies": {
"docco": "*",
"eslint": "0.6.x",
Expand Down
6 changes: 6 additions & 0 deletions test/arrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,9 @@
strictEqual(_.indexOf([1, 2, NaN, NaN], NaN), 2, 'Expected [1, 2, NaN] to contain NaN');
strictEqual(_.indexOf([1, 2, Infinity], NaN), -1, 'Expected [1, 2, NaN] to contain NaN');

strictEqual(_.indexOf([1, 2, NaN, NaN], NaN, 1), 2, 'startIndex does not affect result');
strictEqual(_.indexOf([1, 2, NaN, NaN], NaN, -2), 2, 'startIndex does not affect result');

(function() {
strictEqual(_.indexOf(arguments, NaN), 2, 'Expected arguments [1, 2, NaN] to contain NaN');
}(1, 2, NaN, NaN));
Expand Down Expand Up @@ -418,6 +421,9 @@
strictEqual(_.lastIndexOf([1, 2, NaN, NaN], NaN), 3, 'Expected [1, 2, NaN] to contain NaN');
strictEqual(_.lastIndexOf([1, 2, Infinity], NaN), -1, 'Expected [1, 2, NaN] to contain NaN');

strictEqual(_.lastIndexOf([1, 2, NaN, NaN], NaN, 2), 2, 'fromIndex does not affect result');
strictEqual(_.lastIndexOf([1, 2, NaN, NaN], NaN, -2), 2, 'fromIndex does not affect result');

(function() {
strictEqual(_.lastIndexOf(arguments, NaN), 3, 'Expected arguments [1, 2, NaN] to contain NaN');
}(1, 2, NaN, NaN));
Expand Down
22 changes: 16 additions & 6 deletions test/collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
deepEqual(answers, ['one', 'two', 'three'], 'iterating over objects works, and ignores the object prototype.');
delete obj.constructor.prototype.four;

// ensure the each function is JITed
_(1000).times(function() { _.each([], function(){}); });
var count = 0;
obj = {1 : 'foo', 2 : 'bar', 3 : 'baz'};
_.each(obj, function(value, key){ count++; });
equal(count, 3, 'the fun should be called only 3 times');

var answer = null;
_.each([1, 2, 3], function(num, index, arr){ if (_.include(arr, num)) answer = true; });
ok(answer, 'can reference the original collection from inside the iterator');
Expand Down Expand Up @@ -420,12 +427,14 @@
strictEqual(_.includes, _.contains, 'alias for includes');

var numbers = [1, 2, 3, 1, 2, 3, 1, 2, 3];
strictEqual(_.includes(numbers, 1, 1), true);
strictEqual(_.includes(numbers, 1, -1), false);
strictEqual(_.includes(numbers, 1, -2), false);
strictEqual(_.includes(numbers, 1, -3), true);
strictEqual(_.includes(numbers, 1, 6), true);
strictEqual(_.includes(numbers, 1, 7), false);
strictEqual(_.includes(numbers, 1, 1), true, 'contains takes a fromIndex');
strictEqual(_.includes(numbers, 1, -1), false, 'contains takes a fromIndex');
strictEqual(_.includes(numbers, 1, -2), false, 'contains takes a fromIndex');
strictEqual(_.includes(numbers, 1, -3), true, 'contains takes a fromIndex');
strictEqual(_.includes(numbers, 1, 6), true, 'contains takes a fromIndex');
strictEqual(_.includes(numbers, 1, 7), false, 'contains takes a fromIndex');

ok(_.every([1, 2, 3], _.partial(_.contains, numbers)), 'fromIndex is guarded');
});

test('includes with NaN', function() {
Expand Down Expand Up @@ -789,6 +798,7 @@
equal(_.size(new String('hello')), 5, 'can compute the size of string object');

equal(_.size(null), 0, 'handles nulls');
equal(_.size(0), 0, 'handles numbers');
});

test('partition', function() {
Expand Down
26 changes: 26 additions & 0 deletions test/objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,32 @@
equal(_.clone(null), null, 'non objects should not be changed by clone');
});

test('create', function() {
var Parent = function() {};
Parent.prototype = {foo: function() {}, bar: 2};

_.each(['foo', null, undefined, 1], function(val) {
deepEqual(_.create(val), {}, 'should return empty object when a non-object is provided');
});

ok(_.create([]) instanceof Array, 'should return new instance of array when array is provided');

var Child = function() {};
Child.prototype = _.create(Parent.prototype);
ok(new Child instanceof Parent, 'object should inherit prototype');

var func = function() {};
Child.prototype = _.create(Parent.prototype, {func: func});
strictEqual(Child.prototype.func, func, 'properties should be added to object');

Child.prototype = _.create(Parent.prototype, {constructor: Child});
strictEqual(Child.prototype.constructor, Child);

Child.prototype.foo = 'foo';
var created = _.create(Child.prototype, new Child);
ok(!created.hasOwnProperty('foo'), 'should only add own properties');
});

test('isEqual', function() {
function First() {
this.value = 1;
Expand Down
4 changes: 2 additions & 2 deletions underscore-min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion underscore-min.map

Large diffs are not rendered by default.

Loading

0 comments on commit e4743ab

Please sign in to comment.