diff options
author | isaacs <i@izs.me> | 2014-07-25 04:51:29 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2014-07-25 04:52:02 +0400 |
commit | ea547e29f1245e516fc67641875841c10f04e1ee (patch) | |
tree | d4ee0d8a6c49f20ce4a402f17bd4e350136c1a7b /node_modules/columnify | |
parent | 33ccd13d161ff185d9c9c545013e0775f86c13ac (diff) |
Bump semver to version 3
This makes the '^' operator stricter for 0.x.y versions, even if 'x' is
not 0.
As a direct result, several *other* deps had to be updated, because they
either depended on semver 2.x, or because the new stricter rules meant
that they (or their deps) were no longer valid.
The update to 'read-installed', in particular, causes a test failure.
That update must be rolled back, or the test made to pass, prior to a
stable npm 2.0.0 release going out.
Diffstat (limited to 'node_modules/columnify')
45 files changed, 12602 insertions, 527 deletions
diff --git a/node_modules/columnify/node_modules/strip-ansi/cli.js b/node_modules/columnify/node_modules/strip-ansi/cli.js index 602ae00e8..f8019cdae 100755 --- a/node_modules/columnify/node_modules/strip-ansi/cli.js +++ b/node_modules/columnify/node_modules/strip-ansi/cli.js @@ -1,30 +1,18 @@ #!/usr/bin/env node 'use strict'; var fs = require('fs'); -var pkg = require('./package.json'); -var strip = require('./'); +var strip = require('./index'); var input = process.argv[2]; -function help() { - console.log([ - pkg.description, - '', - 'Usage', - ' $ strip-ansi <input-file> > <output-file>', - ' $ cat <input-file> | strip-ansi > <output-file>', - '', - 'Example', - ' $ strip-ansi unicorn.txt > unicorn-stripped.txt' - ].join('\n')); -} - -if (process.argv.indexOf('--help') !== -1) { - help(); +if (process.argv.indexOf('-h') !== -1 || process.argv.indexOf('--help') !== -1) { + console.log('strip-ansi <input file> > <output file>'); + console.log('or'); + console.log('cat <input file> | strip-ansi > <output file>'); return; } -if (process.argv.indexOf('--version') !== -1) { - console.log(pkg.version); +if (process.argv.indexOf('-v') !== -1 || process.argv.indexOf('--version') !== -1) { + console.log(require('./package').version); return; } diff --git a/node_modules/columnify/node_modules/strip-ansi/index.js b/node_modules/columnify/node_modules/strip-ansi/index.js index 11e072e4e..9ce2f3d48 100644 --- a/node_modules/columnify/node_modules/strip-ansi/index.js +++ b/node_modules/columnify/node_modules/strip-ansi/index.js @@ -1,6 +1,4 @@ 'use strict'; -var ansiRegex = require('ansi-regex'); - module.exports = function (str) { - return typeof str === 'string' ? str.replace(ansiRegex, '') : str; + return typeof str === 'string' ? str.replace(/\x1B\[([0-9]{1,3}(;[0-9]{1,3})*)?[m|K]/g, '') : str; }; diff --git a/node_modules/columnify/node_modules/strip-ansi/node_modules/ansi-regex/index.js b/node_modules/columnify/node_modules/strip-ansi/node_modules/ansi-regex/index.js deleted file mode 100644 index 182e43457..000000000 --- a/node_modules/columnify/node_modules/strip-ansi/node_modules/ansi-regex/index.js +++ /dev/null @@ -1,2 +0,0 @@ -'use strict'; -module.exports = /\x1B\[([0-9]{1,3}(;[0-9]{1,3})*)?[m|K]/g; diff --git a/node_modules/columnify/node_modules/strip-ansi/node_modules/ansi-regex/package.json b/node_modules/columnify/node_modules/strip-ansi/node_modules/ansi-regex/package.json deleted file mode 100644 index 6b53e50dc..000000000 --- a/node_modules/columnify/node_modules/strip-ansi/node_modules/ansi-regex/package.json +++ /dev/null @@ -1,75 +0,0 @@ -{ - "name": "ansi-regex", - "version": "0.1.0", - "description": "Regular expression for matching ANSI escape codes", - "license": "MIT", - "repository": { - "type": "git", - "url": "git://github.com/sindresorhus/ansi-regex" - }, - "author": { - "name": "Sindre Sorhus", - "email": "sindresorhus@gmail.com", - "url": "http://sindresorhus.com" - }, - "engines": { - "node": ">=0.10.0" - }, - "scripts": { - "test": "mocha" - }, - "files": [ - "index.js" - ], - "keywords": [ - "ansi", - "styles", - "color", - "colour", - "colors", - "terminal", - "console", - "cli", - "string", - "tty", - "escape", - "formatting", - "rgb", - "256", - "shell", - "xterm", - "command-line", - "text", - "regex", - "regexp", - "re" - ], - "devDependencies": { - "mocha": "*" - }, - "bugs": { - "url": "https://github.com/sindresorhus/ansi-regex/issues" - }, - "homepage": "https://github.com/sindresorhus/ansi-regex", - "_id": "ansi-regex@0.1.0", - "_shasum": "55ca60db6900857c423ae9297980026f941ed903", - "_from": "ansi-regex@^0.1.0", - "_npmVersion": "1.4.9", - "_npmUser": { - "name": "sindresorhus", - "email": "sindresorhus@gmail.com" - }, - "maintainers": [ - { - "name": "sindresorhus", - "email": "sindresorhus@gmail.com" - } - ], - "dist": { - "shasum": "55ca60db6900857c423ae9297980026f941ed903", - "tarball": "http://registry.npmjs.org/ansi-regex/-/ansi-regex-0.1.0.tgz" - }, - "directories": {}, - "_resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-0.1.0.tgz", - "readme": "ERROR: No README data found!" -} diff --git a/node_modules/columnify/node_modules/strip-ansi/node_modules/ansi-regex/readme.md b/node_modules/columnify/node_modules/strip-ansi/node_modules/ansi-regex/readme.md deleted file mode 100644 index 72c248cd7..000000000 --- a/node_modules/columnify/node_modules/strip-ansi/node_modules/ansi-regex/readme.md +++ /dev/null @@ -1,28 +0,0 @@ -# ansi-regex [![Build Status](https://travis-ci.org/sindresorhus/ansi-regex.svg?branch=master)](https://travis-ci.org/sindresorhus/ansi-regex) - -> Regular expression for matching [ANSI escape codes](http://en.wikipedia.org/wiki/ANSI_escape_code) - - -## Install - -```sh -$ npm install --save ansi-regex -``` - - -## Usage - -```js -var ansiRegex = require('ansi-regex'); - -ansiRegex.test('\x1b[4mcake\x1b[0m'); -//=> true - -ansiRegex.test('cake'); -//=> false -``` - - -## License - -MIT © [Sindre Sorhus](http://sindresorhus.com) diff --git a/node_modules/columnify/node_modules/strip-ansi/package.json b/node_modules/columnify/node_modules/strip-ansi/package.json index ea6a22fe2..e0c5bc43f 100644 --- a/node_modules/columnify/node_modules/strip-ansi/package.json +++ b/node_modules/columnify/node_modules/strip-ansi/package.json @@ -1,7 +1,7 @@ { "name": "strip-ansi", - "version": "0.2.2", - "description": "Strip ANSI escape codes", + "version": "0.2.1", + "description": "Strip ANSI escape codes (used for colorizing strings in the terminal)", "license": "MIT", "bin": { "strip-ansi": "cli.js" @@ -50,9 +50,6 @@ "command-line", "text" ], - "dependencies": { - "ansi-regex": "^0.1.0" - }, "devDependencies": { "mocha": "*" }, @@ -60,10 +57,13 @@ "url": "https://github.com/sindresorhus/strip-ansi/issues" }, "homepage": "https://github.com/sindresorhus/strip-ansi", - "_id": "strip-ansi@0.2.2", - "_shasum": "854d290c981525fc8c397a910b025ae2d54ffc08", - "_from": "strip-ansi@^0.2.1", - "_npmVersion": "1.4.9", + "_id": "strip-ansi@0.2.1", + "dist": { + "shasum": "09218505ccf1083a41460150571355efabaa126e", + "tarball": "http://registry.npmjs.org/strip-ansi/-/strip-ansi-0.2.1.tgz" + }, + "_from": "strip-ansi@0.2.1", + "_npmVersion": "1.4.6", "_npmUser": { "name": "sindresorhus", "email": "sindresorhus@gmail.com" @@ -74,11 +74,7 @@ "email": "sindresorhus@gmail.com" } ], - "dist": { - "shasum": "854d290c981525fc8c397a910b025ae2d54ffc08", - "tarball": "http://registry.npmjs.org/strip-ansi/-/strip-ansi-0.2.2.tgz" - }, "directories": {}, - "_resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-0.2.2.tgz", - "readme": "ERROR: No README data found!" + "_shasum": "09218505ccf1083a41460150571355efabaa126e", + "_resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-0.2.1.tgz" } diff --git a/node_modules/columnify/node_modules/strip-ansi/readme.md b/node_modules/columnify/node_modules/strip-ansi/readme.md index 5477079d0..c6a0634fa 100644 --- a/node_modules/columnify/node_modules/strip-ansi/readme.md +++ b/node_modules/columnify/node_modules/strip-ansi/readme.md @@ -1,11 +1,13 @@ # strip-ansi [![Build Status](https://travis-ci.org/sindresorhus/strip-ansi.svg?branch=master)](https://travis-ci.org/sindresorhus/strip-ansi) -> Strip [ANSI escape codes](http://en.wikipedia.org/wiki/ANSI_escape_code) +> Strip [ANSI escape codes](http://en.wikipedia.org/wiki/ANSI_escape_code#Colors_and_Styles) (used for colorizing strings in the terminal) + +Used in the terminal color module [chalk](https://github.com/sindresorhus/chalk). ## Install -```sh +```bash $ npm install --save strip-ansi ``` @@ -22,22 +24,23 @@ stripAnsi('\x1b[4mcake\x1b[0m'); ## CLI -```sh +You can also use it as a CLI app by installing it globally: + +```bash $ npm install --global strip-ansi ``` -```sh -$ strip-ansi --help +#### Usage -Usage - $ strip-ansi <input-file> > <output-file> - $ cat <input-file> | strip-ansi > <output-file> +```bash +$ strip-ansi --help -Example - $ strip-ansi unicorn.txt > unicorn-stripped.txt +strip-ansi <input-file> +or +cat <input-file> | strip-ansi ``` ## License -MIT © [Sindre Sorhus](http://sindresorhus.com) +[MIT](http://opensource.org/licenses/MIT) © [Sindre Sorhus](http://sindresorhus.com) diff --git a/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/.editorconfig b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/.editorconfig new file mode 100644 index 000000000..8e920719d --- /dev/null +++ b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/.editorconfig @@ -0,0 +1,14 @@ +# This file is for unifying the coding style for different editors and IDEs +# editorconfig.org + +root = true + +[*] +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[**.{js,json,html}] +indent_style = space +indent_size = 2 diff --git a/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/.gitignore b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/.gitignore new file mode 100644 index 000000000..029616c3c --- /dev/null +++ b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/.gitignore @@ -0,0 +1,2 @@ +raw +node_modules diff --git a/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/.travis.yml b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/.travis.yml new file mode 100644 index 000000000..dbf89b3a4 --- /dev/null +++ b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/.travis.yml @@ -0,0 +1,8 @@ +language: node_js +node_js: + - 0.8 + - '0.10' +before_install: + - 'npm install npm -g' +notifications: + email: false diff --git a/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/CNAME b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/CNAME new file mode 100644 index 000000000..a007e65c4 --- /dev/null +++ b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/CNAME @@ -0,0 +1 @@ +underscorejs.org diff --git a/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/CONTRIBUTING.md b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/CONTRIBUTING.md new file mode 100644 index 000000000..8b22557d1 --- /dev/null +++ b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/CONTRIBUTING.md @@ -0,0 +1,11 @@ +## How to contribute to Underscore.js + +* Before you open a ticket or send a pull request, [search](https://github.com/jashkenas/underscore/issues) for previous discussions about the same feature or issue. Add to the earlier ticket if you find one. + +* If you're proposing a new feature, make sure it isn't already implemented in [Underscore-Contrib](https://github.com/documentcloud/underscore-contrib). + +* Before sending a pull request for a feature, be sure to have [tests](http://underscorejs.org/test/). + +* Use the same coding style as the rest of the [codebase](https://github.com/jashkenas/underscore/blob/master/underscore.js). + +* In your pull request, do not add documentation or re-build the minified `underscore-min.js` file. We'll do those things before cutting a new release. diff --git a/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/bower.json b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/bower.json new file mode 100644 index 000000000..2d3e0291c --- /dev/null +++ b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/bower.json @@ -0,0 +1,7 @@ +{ + "name": "underscore", + "version": "1.6.0", + "main": "underscore.js", + "keywords": ["util", "functional", "server", "client", "browser"], + "ignore" : ["docs", "test", "*.yml", "CNAME", "index.html", "favicon.ico", "CONTRIBUTING.md"] +} diff --git a/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/component.json b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/component.json new file mode 100644 index 000000000..bb1775e70 --- /dev/null +++ b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/component.json @@ -0,0 +1,10 @@ +{ + "name" : "underscore", + "description" : "JavaScript's functional programming helper library.", + "keywords" : ["util", "functional", "server", "client", "browser"], + "repo" : "jashkenas/underscore", + "main" : "underscore.js", + "scripts" : ["underscore.js"], + "version" : "1.6.0", + "license" : "MIT" +} diff --git a/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/docs/docco.css b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/docs/docco.css new file mode 100644 index 000000000..a2899ac87 --- /dev/null +++ b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/docs/docco.css @@ -0,0 +1,506 @@ +/*--------------------- Typography ----------------------------*/ + +@font-face { + font-family: 'aller-light'; + src: url('public/fonts/aller-light.eot'); + src: url('public/fonts/aller-light.eot?#iefix') format('embedded-opentype'), + url('public/fonts/aller-light.woff') format('woff'), + url('public/fonts/aller-light.ttf') format('truetype'); + font-weight: normal; + font-style: normal; +} + +@font-face { + font-family: 'aller-bold'; + src: url('public/fonts/aller-bold.eot'); + src: url('public/fonts/aller-bold.eot?#iefix') format('embedded-opentype'), + url('public/fonts/aller-bold.woff') format('woff'), + url('public/fonts/aller-bold.ttf') format('truetype'); + font-weight: normal; + font-style: normal; +} + +@font-face { + font-family: 'novecento-bold'; + src: url('public/fonts/novecento-bold.eot'); + src: url('public/fonts/novecento-bold.eot?#iefix') format('embedded-opentype'), + url('public/fonts/novecento-bold.woff') format('woff'), + url('public/fonts/novecento-bold.ttf') format('truetype'); + font-weight: normal; + font-style: normal; +} + +/*--------------------- Layout ----------------------------*/ +html { height: 100%; } +body { + font-family: "aller-light"; + font-size: 14px; + line-height: 18px; + color: #30404f; + margin: 0; padding: 0; + height:100%; +} +#container { min-height: 100%; } + +a { + color: #000; +} + +b, strong { + font-weight: normal; + font-family: "aller-bold"; +} + +p { + margin: 15px 0 0px; +} + .annotation ul, .annotation ol { + margin: 25px 0; + } + .annotation ul li, .annotation ol li { + font-size: 14px; + line-height: 18px; + margin: 10px 0; + } + +h1, h2, h3, h4, h5, h6 { + color: #112233; + line-height: 1em; + font-weight: normal; + font-family: "novecento-bold"; + text-transform: uppercase; + margin: 30px 0 15px 0; +} + +h1 { + margin-top: 40px; +} + +hr { + border: 0; + background: 1px #ddd; + height: 1px; + margin: 20px 0; +} + +pre, tt, code { + font-size: 12px; line-height: 16px; + font-family: Menlo, Monaco, Consolas, "Lucida Console", monospace; + margin: 0; padding: 0; +} + .annotation pre { + display: block; + margin: 0; + padding: 7px 10px; + background: #fcfcfc; + -moz-box-shadow: inset 0 0 10px rgba(0,0,0,0.1); + -webkit-box-shadow: inset 0 0 10px rgba(0,0,0,0.1); + box-shadow: inset 0 0 10px rgba(0,0,0,0.1); + overflow-x: auto; + } + .annotation pre code { + border: 0; + padding: 0; + background: transparent; + } + + +blockquote { + border-left: 5px solid #ccc; + margin: 0; + padding: 1px 0 1px 1em; +} + .sections blockquote p { + font-family: Menlo, Consolas, Monaco, monospace; + font-size: 12px; line-height: 16px; + color: #999; + margin: 10px 0 0; + white-space: pre-wrap; + } + +ul.sections { + list-style: none; + padding:0 0 5px 0;; + margin:0; +} + +/* + Force border-box so that % widths fit the parent + container without overlap because of margin/padding. + + More Info : http://www.quirksmode.org/css/box.html +*/ +ul.sections > li > div { + -moz-box-sizing: border-box; /* firefox */ + -ms-box-sizing: border-box; /* ie */ + -webkit-box-sizing: border-box; /* webkit */ + -khtml-box-sizing: border-box; /* konqueror */ + box-sizing: border-box; /* css3 */ +} + + +/*---------------------- Jump Page -----------------------------*/ +#jump_to, #jump_page { + margin: 0; + background: white; + -webkit-box-shadow: 0 0 25px #777; -moz-box-shadow: 0 0 25px #777; + -webkit-border-bottom-left-radius: 5px; -moz-border-radius-bottomleft: 5px; + font: 16px Arial; + cursor: pointer; + text-align: right; + list-style: none; +} + +#jump_to a { + text-decoration: none; +} + +#jump_to a.large { + display: none; +} +#jump_to a.small { + font-size: 22px; + font-weight: bold; + color: #676767; +} + +#jump_to, #jump_wrapper { + position: fixed; + right: 0; top: 0; + padding: 10px 15px; + margin:0; +} + +#jump_wrapper { + display: none; + padding:0; +} + +#jump_to:hover #jump_wrapper { + display: block; +} + +#jump_page { + padding: 5px 0 3px; + margin: 0 0 25px 25px; +} + +#jump_page .source { + display: block; + padding: 15px; + text-decoration: none; + border-top: 1px solid #eee; +} + +#jump_page .source:hover { + background: #f5f5ff; +} + +#jump_page .source:first-child { +} + +/*---------------------- Low resolutions (> 320px) ---------------------*/ +@media only screen and (min-width: 320px) { + .pilwrap { display: none; } + + ul.sections > li > div { + display: block; + padding:5px 10px 0 10px; + } + + ul.sections > li > div.annotation ul, ul.sections > li > div.annotation ol { + padding-left: 30px; + } + + ul.sections > li > div.content { + overflow-x:auto; + -webkit-box-shadow: inset 0 0 5px #e5e5ee; + box-shadow: inset 0 0 5px #e5e5ee; + border: 1px solid #dedede; + margin:5px 10px 5px 10px; + padding-bottom: 5px; + } + + ul.sections > li > div.annotation pre { + margin: 7px 0 7px; + padding-left: 15px; + } + + ul.sections > li > div.annotation p tt, .annotation code { + background: #f8f8ff; + border: 1px solid #dedede; + font-size: 12px; + padding: 0 0.2em; + } +} + +/*---------------------- (> 481px) ---------------------*/ +@media only screen and (min-width: 481px) { + #container { + position: relative; + } + body { + background-color: #F5F5FF; + font-size: 15px; + line-height: 21px; + } + pre, tt, code { + line-height: 18px; + } + p, ul, ol { + margin: 0 0 15px; + } + + + #jump_to { + padding: 5px 10px; + } + #jump_wrapper { + padding: 0; + } + #jump_to, #jump_page { + font: 10px Arial; + text-transform: uppercase; + } + #jump_page .source { + padding: 5px 10px; + } + #jump_to a.large { + display: inline-block; + } + #jump_to a.small { + display: none; + } + + + + #background { + position: absolute; + top: 0; bottom: 0; + width: 350px; + background: #fff; + border-right: 1px solid #e5e5ee; + z-index: -1; + } + + ul.sections > li > div.annotation ul, ul.sections > li > div.annotation ol { + padding-left: 40px; + } + + ul.sections > li { + white-space: nowrap; + } + + ul.sections > li > div { + display: inline-block; + } + + ul.sections > li > div.annotation { + max-width: 350px; + min-width: 350px; + min-height: 5px; + padding: 13px; + overflow-x: hidden; + white-space: normal; + vertical-align: top; + text-align: left; + } + ul.sections > li > div.annotation pre { + margin: 15px 0 15px; + padding-left: 15px; + } + + ul.sections > li > div.content { + padding: 13px; + vertical-align: top; + border: none; + -webkit-box-shadow: none; + box-shadow: none; + } + + .pilwrap { + position: relative; + display: inline; + } + + .pilcrow { + font: 12px Arial; + text-decoration: none; + color: #454545; + position: absolute; + top: 3px; left: -20px; + padding: 1px 2px; + opacity: 0; + -webkit-transition: opacity 0.2s linear; + } + .for-h1 .pilcrow { + top: 47px; + } + .for-h2 .pilcrow, .for-h3 .pilcrow, .for-h4 .pilcrow { + top: 35px; + } + + ul.sections > li > div.annotation:hover .pilcrow { + opacity: 1; + } +} + +/*---------------------- (> 1025px) ---------------------*/ +@media only screen and (min-width: 1025px) { + + body { + font-size: 16px; + line-height: 24px; + } + + #background { + width: 525px; + } + ul.sections > li > div.annotation { + max-width: 525px; + min-width: 525px; + padding: 10px 25px 1px 50px; + } + ul.sections > li > div.content { + padding: 9px 15px 16px 25px; + } +} + +/*---------------------- Syntax Highlighting -----------------------------*/ + +td.linenos { background-color: #f0f0f0; padding-right: 10px; } +span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; } +/* + +github.com style (c) Vasily Polovnyov <vast@whiteants.net> + +*/ + +pre code { + display: block; padding: 0.5em; + color: #000; + background: #f8f8ff +} + +pre .hljs-comment, +pre .hljs-template_comment, +pre .hljs-diff .hljs-header, +pre .hljs-javadoc { + color: #408080; + font-style: italic +} + +pre .hljs-keyword, +pre .hljs-assignment, +pre .hljs-literal, +pre .hljs-css .hljs-rule .hljs-keyword, +pre .hljs-winutils, +pre .hljs-javascript .hljs-title, +pre .hljs-lisp .hljs-title, +pre .hljs-subst { + color: #954121; + /*font-weight: bold*/ +} + +pre .hljs-number, +pre .hljs-hexcolor { + color: #40a070 +} + +pre .hljs-string, +pre .hljs-tag .hljs-value, +pre .hljs-phpdoc, +pre .hljs-tex .hljs-formula { + color: #219161; +} + +pre .hljs-title, +pre .hljs-id { + color: #19469D; +} +pre .hljs-params { + color: #00F; +} + +pre .hljs-javascript .hljs-title, +pre .hljs-lisp .hljs-title, +pre .hljs-subst { + font-weight: normal +} + +pre .hljs-class .hljs-title, +pre .hljs-haskell .hljs-label, +pre .hljs-tex .hljs-command { + color: #458; + font-weight: bold +} + +pre .hljs-tag, +pre .hljs-tag .hljs-title, +pre .hljs-rules .hljs-property, +pre .hljs-django .hljs-tag .hljs-keyword { + color: #000080; + font-weight: normal +} + +pre .hljs-attribute, +pre .hljs-variable, +pre .hljs-instancevar, +pre .hljs-lisp .hljs-body { + color: #008080 +} + +pre .hljs-regexp { + color: #B68 +} + +pre .hljs-class { + color: #458; + font-weight: bold +} + +pre .hljs-symbol, +pre .hljs-ruby .hljs-symbol .hljs-string, +pre .hljs-ruby .hljs-symbol .hljs-keyword, +pre .hljs-ruby .hljs-symbol .hljs-keymethods, +pre .hljs-lisp .hljs-keyword, +pre .hljs-tex .hljs-special, +pre .hljs-input_number { + color: #990073 +} + +pre .hljs-builtin, +pre .hljs-constructor, +pre .hljs-built_in, +pre .hljs-lisp .hljs-title { + color: #0086b3 +} + +pre .hljs-preprocessor, +pre .hljs-pi, +pre .hljs-doctype, +pre .hljs-shebang, +pre .hljs-cdata { + color: #999; + font-weight: bold +} + +pre .hljs-deletion { + background: #fdd +} + +pre .hljs-addition { + background: #dfd +} + +pre .hljs-diff .hljs-change { + background: #0086b3 +} + +pre .hljs-chunk { + color: #aaa +} + +pre .hljs-tex .hljs-formula { + opacity: 0.5; +} diff --git a/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/docs/favicon.ico b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/docs/favicon.ico Binary files differnew file mode 100644 index 000000000..030496838 --- /dev/null +++ b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/docs/favicon.ico diff --git a/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/docs/images/background.png b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/docs/images/background.png Binary files differnew file mode 100644 index 000000000..90ee6934d --- /dev/null +++ b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/docs/images/background.png diff --git a/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/docs/images/underscore.png b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/docs/images/underscore.png Binary files differnew file mode 100644 index 000000000..3449cbe2a --- /dev/null +++ b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/docs/images/underscore.png diff --git a/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/docs/public/fonts/aller-bold.eot b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/docs/public/fonts/aller-bold.eot Binary files differnew file mode 100644 index 000000000..1b32532a8 --- /dev/null +++ b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/docs/public/fonts/aller-bold.eot diff --git a/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/docs/public/fonts/aller-bold.ttf b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/docs/public/fonts/aller-bold.ttf Binary files differnew file mode 100644 index 000000000..dc4cc9c27 --- /dev/null +++ b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/docs/public/fonts/aller-bold.ttf diff --git a/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/docs/public/fonts/aller-bold.woff b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/docs/public/fonts/aller-bold.woff Binary files differnew file mode 100644 index 000000000..fa16fd0ab --- /dev/null +++ b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/docs/public/fonts/aller-bold.woff diff --git a/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/docs/public/fonts/aller-light.eot b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/docs/public/fonts/aller-light.eot Binary files differnew file mode 100644 index 000000000..40bd654b5 --- /dev/null +++ b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/docs/public/fonts/aller-light.eot diff --git a/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/docs/public/fonts/aller-light.ttf b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/docs/public/fonts/aller-light.ttf Binary files differnew file mode 100644 index 000000000..c2c72902a --- /dev/null +++ b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/docs/public/fonts/aller-light.ttf diff --git a/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/docs/public/fonts/aller-light.woff b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/docs/public/fonts/aller-light.woff Binary files differnew file mode 100644 index 000000000..81a09d18e --- /dev/null +++ b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/docs/public/fonts/aller-light.woff diff --git a/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/docs/public/fonts/novecento-bold.eot b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/docs/public/fonts/novecento-bold.eot Binary files differnew file mode 100644 index 000000000..98a9a7fba --- /dev/null +++ b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/docs/public/fonts/novecento-bold.eot diff --git a/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/docs/public/fonts/novecento-bold.ttf b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/docs/public/fonts/novecento-bold.ttf Binary files differnew file mode 100644 index 000000000..2af39b08b --- /dev/null +++ b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/docs/public/fonts/novecento-bold.ttf diff --git a/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/docs/public/fonts/novecento-bold.woff b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/docs/public/fonts/novecento-bold.woff Binary files differnew file mode 100644 index 000000000..de558b5a2 --- /dev/null +++ b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/docs/public/fonts/novecento-bold.woff diff --git a/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/docs/public/stylesheets/normalize.css b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/docs/public/stylesheets/normalize.css new file mode 100644 index 000000000..73abb76fa --- /dev/null +++ b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/docs/public/stylesheets/normalize.css @@ -0,0 +1,375 @@ +/*! normalize.css v2.0.1 | MIT License | git.io/normalize */ + +/* ========================================================================== + HTML5 display definitions + ========================================================================== */ + +/* + * Corrects `block` display not defined in IE 8/9. + */ + +article, +aside, +details, +figcaption, +figure, +footer, +header, +hgroup, +nav, +section, +summary { + display: block; +} + +/* + * Corrects `inline-block` display not defined in IE 8/9. + */ + +audio, +canvas, +video { + display: inline-block; +} + +/* + * Prevents modern browsers from displaying `audio` without controls. + * Remove excess height in iOS 5 devices. + */ + +audio:not([controls]) { + display: none; + height: 0; +} + +/* + * Addresses styling for `hidden` attribute not present in IE 8/9. + */ + +[hidden] { + display: none; +} + +/* ========================================================================== + Base + ========================================================================== */ + +/* + * 1. Sets default font family to sans-serif. + * 2. Prevents iOS text size adjust after orientation change, without disabling + * user zoom. + */ + +html { + font-family: sans-serif; /* 1 */ + -webkit-text-size-adjust: 100%; /* 2 */ + -ms-text-size-adjust: 100%; /* 2 */ +} + +/* + * Removes default margin. + */ + +body { + margin: 0; +} + +/* ========================================================================== + Links + ========================================================================== */ + +/* + * Addresses `outline` inconsistency between Chrome and other browsers. + */ + +a:focus { + outline: thin dotted; +} + +/* + * Improves readability when focused and also mouse hovered in all browsers. + */ + +a:active, +a:hover { + outline: 0; +} + +/* ========================================================================== + Typography + ========================================================================== */ + +/* + * Addresses `h1` font sizes within `section` and `article` in Firefox 4+, + * Safari 5, and Chrome. + */ + +h1 { + font-size: 2em; +} + +/* + * Addresses styling not present in IE 8/9, Safari 5, and Chrome. + */ + +abbr[title] { + border-bottom: 1px dotted; +} + +/* + * Addresses style set to `bolder` in Firefox 4+, Safari 5, and Chrome. + */ + +b, +strong { + font-weight: bold; +} + +/* + * Addresses styling not present in Safari 5 and Chrome. + */ + +dfn { + font-style: italic; +} + +/* + * Addresses styling not present in IE 8/9. + */ + +mark { + background: #ff0; + color: #000; +} + + +/* + * Corrects font family set oddly in Safari 5 and Chrome. + */ + +code, +kbd, +pre, +samp { + font-family: monospace, serif; + font-size: 1em; +} + +/* + * Improves readability of pre-formatted text in all browsers. + */ + +pre { + white-space: pre; + white-space: pre-wrap; + word-wrap: break-word; +} + +/* + * Sets consistent quote types. + */ + +q { + quotes: "\201C" "\201D" "\2018" "\2019"; +} + +/* + * Addresses inconsistent and variable font size in all browsers. + */ + +small { + font-size: 80%; +} + +/* + * Prevents `sub` and `sup` affecting `line-height` in all browsers. + */ + +sub, +sup { + font-size: 75%; + line-height: 0; + position: relative; + vertical-align: baseline; +} + +sup { + top: -0.5em; +} + +sub { + bottom: -0.25em; +} + +/* ========================================================================== + Embedded content + ========================================================================== */ + +/* + * Removes border when inside `a` element in IE 8/9. + */ + +img { + border: 0; +} + +/* + * Corrects overflow displayed oddly in IE 9. + */ + +svg:not(:root) { + overflow: hidden; +} + +/* ========================================================================== + Figures + ========================================================================== */ + +/* + * Addresses margin not present in IE 8/9 and Safari 5. + */ + +figure { + margin: 0; +} + +/* ========================================================================== + Forms + ========================================================================== */ + +/* + * Define consistent border, margin, and padding. + */ + +fieldset { + border: 1px solid #c0c0c0; + margin: 0 2px; + padding: 0.35em 0.625em 0.75em; +} + +/* + * 1. Corrects color not being inherited in IE 8/9. + * 2. Remove padding so people aren't caught out if they zero out fieldsets. + */ + +legend { + border: 0; /* 1 */ + padding: 0; /* 2 */ +} + +/* + * 1. Corrects font family not being inherited in all browsers. + * 2. Corrects font size not being inherited in all browsers. + * 3. Addresses margins set differently in Firefox 4+, Safari 5, and Chrome + */ + +button, +input, +select, +textarea { + font-family: inherit; /* 1 */ + font-size: 100%; /* 2 */ + margin: 0; /* 3 */ +} + +/* + * Addresses Firefox 4+ setting `line-height` on `input` using `!important` in + * the UA stylesheet. + */ + +button, +input { + line-height: normal; +} + +/* + * 1. Avoid the WebKit bug in Android 4.0.* where (2) destroys native `audio` + * and `video` controls. + * 2. Corrects inability to style clickable `input` types in iOS. + * 3. Improves usability and consistency of cursor style between image-type + * `input` and others. + */ + +button, +html input[type="button"], /* 1 */ +input[type="reset"], +input[type="submit"] { + -webkit-appearance: button; /* 2 */ + cursor: pointer; /* 3 */ +} + +/* + * Re-set default cursor for disabled elements. + */ + +button[disabled], +input[disabled] { + cursor: default; +} + +/* + * 1. Addresses box sizing set to `content-box` in IE 8/9. + * 2. Removes excess padding in IE 8/9. + */ + +input[type="checkbox"], +input[type="radio"] { + box-sizing: border-box; /* 1 */ + padding: 0; /* 2 */ +} + +/* + * 1. Addresses `appearance` set to `searchfield` in Safari 5 and Chrome. + * 2. Addresses `box-sizing` set to `border-box` in Safari 5 and Chrome + * (include `-moz` to future-proof). + */ + +input[type="search"] { + -webkit-appearance: textfield; /* 1 */ + -moz-box-sizing: content-box; + -webkit-box-sizing: content-box; /* 2 */ + box-sizing: content-box; +} + +/* + * Removes inner padding and search cancel button in Safari 5 and Chrome + * on OS X. + */ + +input[type="search"]::-webkit-search-cancel-button, +input[type="search"]::-webkit-search-decoration { + -webkit-appearance: none; +} + +/* + * Removes inner padding and border in Firefox 4+. + */ + +button::-moz-focus-inner, +input::-moz-focus-inner { + border: 0; + padding: 0; +} + +/* + * 1. Removes default vertical scrollbar in IE 8/9. + * 2. Improves readability and alignment in all browsers. + */ + +textarea { + overflow: auto; /* 1 */ + vertical-align: top; /* 2 */ +} + +/* ========================================================================== + Tables + ========================================================================== */ + +/* + * Remove most spacing between table cells. + */ + +table { + border-collapse: collapse; + border-spacing: 0; +}
\ No newline at end of file diff --git a/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/docs/underscore.html b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/docs/underscore.html new file mode 100644 index 000000000..014d5dece --- /dev/null +++ b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/docs/underscore.html @@ -0,0 +1,3261 @@ +<!DOCTYPE html> + +<html> +<head> + <title>underscore.js</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 class="sections"> + + <li id="title"> + <div class="annotation"> + <h1>underscore.js</h1> + </div> + </li> + + + + <li id="section-1"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-1">¶</a> + </div> + <pre><code>Underscore.js <span class="hljs-number">1.6</span><span class="hljs-number">.0</span> +http:<span class="hljs-comment">//underscorejs.org</span> +(c) <span class="hljs-number">2009</span>-<span class="hljs-number">2014</span> Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors +Underscore may be freely distributed under the MIT license. +</code></pre> + </div> + + <div class="content"><div class='highlight'><pre> +(<span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> {</span></pre></div></div> + + </li> + + + <li id="section-2"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-2">¶</a> + </div> + <h2 id="baseline-setup">Baseline setup</h2> + + </div> + + </li> + + + <li id="section-3"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-3">¶</a> + </div> + + </div> + + </li> + + + <li id="section-4"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-4">¶</a> + </div> + <p>Establish the root object, <code>window</code> in the browser, or <code>exports</code> on the server.</p> + + </div> + + <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">var</span> root = <span class="hljs-keyword">this</span>;</pre></div></div> + + </li> + + + <li id="section-5"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-5">¶</a> + </div> + <p>Save the previous value of the <code>_</code> variable.</p> + + </div> + + <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">var</span> previousUnderscore = root._;</pre></div></div> + + </li> + + + <li id="section-6"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-6">¶</a> + </div> + <p>Establish the object that gets returned to break out of a loop iteration.</p> + + </div> + + <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">var</span> breaker = {};</pre></div></div> + + </li> + + + <li id="section-7"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-7">¶</a> + </div> + <p>Save bytes in the minified (but not gzipped) version:</p> + + </div> + + <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">var</span> ArrayProto = <span class="hljs-built_in">Array</span>.prototype, ObjProto = <span class="hljs-built_in">Object</span>.prototype, FuncProto = <span class="hljs-built_in">Function</span>.prototype;</pre></div></div> + + </li> + + + <li id="section-8"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-8">¶</a> + </div> + <p>Create quick reference variables for speed access to core prototypes.</p> + + </div> + + <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">var</span> + push = ArrayProto.push, + slice = ArrayProto.slice, + concat = ArrayProto.concat, + toString = ObjProto.toString, + hasOwnProperty = ObjProto.hasOwnProperty;</pre></div></div> + + </li> + + + <li id="section-9"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-9">¶</a> + </div> + <p>All <strong>ECMAScript 5</strong> native function implementations that we hope to use +are declared here.</p> + + </div> + + <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">var</span> + nativeForEach = ArrayProto.forEach, + nativeMap = ArrayProto.map, + nativeReduce = ArrayProto.reduce, + nativeReduceRight = ArrayProto.reduceRight, + nativeFilter = ArrayProto.filter, + nativeEvery = ArrayProto.every, + nativeSome = ArrayProto.some, + nativeIndexOf = ArrayProto.indexOf, + nativeLastIndexOf = ArrayProto.lastIndexOf, + nativeIsArray = <span class="hljs-built_in">Array</span>.isArray, + nativeKeys = <span class="hljs-built_in">Object</span>.keys, + nativeBind = FuncProto.bind;</pre></div></div> + + </li> + + + <li id="section-10"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-10">¶</a> + </div> + <p>Create a safe reference to the Underscore object for use below.</p> + + </div> + + <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">var</span> _ = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(obj)</span> {</span> + <span class="hljs-keyword">if</span> (obj <span class="hljs-keyword">instanceof</span> _) <span class="hljs-keyword">return</span> obj; + <span class="hljs-keyword">if</span> (!(<span class="hljs-keyword">this</span> <span class="hljs-keyword">instanceof</span> _)) <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> _(obj); + <span class="hljs-keyword">this</span>._wrapped = obj; + };</pre></div></div> + + </li> + + + <li id="section-11"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-11">¶</a> + </div> + <p>Export the Underscore object for <strong>Node.js</strong>, with +backwards-compatibility for the old <code>require()</code> API. If we’re in +the browser, add <code>_</code> as a global object via a string identifier, +for Closure Compiler “advanced” mode.</p> + + </div> + + <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> exports !== <span class="hljs-string">'undefined'</span>) { + <span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> module !== <span class="hljs-string">'undefined'</span> && module.exports) { + exports = module.exports = _; + } + exports._ = _; + } <span class="hljs-keyword">else</span> { + root._ = _; + }</pre></div></div> + + </li> + + + <li id="section-12"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-12">¶</a> + </div> + <p>Current version.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.VERSION = <span class="hljs-string">'1.6.0'</span>;</pre></div></div> + + </li> + + + <li id="section-13"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-13">¶</a> + </div> + <h2 id="collection-functions">Collection Functions</h2> + + </div> + + </li> + + + <li id="section-14"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-14">¶</a> + </div> + + </div> + + </li> + + + <li id="section-15"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-15">¶</a> + </div> + <p>The cornerstone, an <code>each</code> implementation, aka <code>forEach</code>. +Handles objects with the built-in <code>forEach</code>, arrays, and raw objects. +Delegates to <strong>ECMAScript 5</strong>‘s native <code>forEach</code> if available.</p> + + </div> + + <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">var</span> each = _.each = _.forEach = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(obj, iterator, context)</span> {</span> + <span class="hljs-keyword">if</span> (obj == <span class="hljs-literal">null</span>) <span class="hljs-keyword">return</span> obj; + <span class="hljs-keyword">if</span> (nativeForEach && obj.forEach === nativeForEach) { + obj.forEach(iterator, context); + } <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (obj.length === +obj.length) { + <span class="hljs-keyword">for</span> (<span class="hljs-keyword">var</span> i = <span class="hljs-number">0</span>, length = obj.length; i < length; i++) { + <span class="hljs-keyword">if</span> (iterator.call(context, obj[i], i, obj) === breaker) <span class="hljs-keyword">return</span>; + } + } <span class="hljs-keyword">else</span> { + <span class="hljs-keyword">var</span> keys = _.keys(obj); + <span class="hljs-keyword">for</span> (<span class="hljs-keyword">var</span> i = <span class="hljs-number">0</span>, length = keys.length; i < length; i++) { + <span class="hljs-keyword">if</span> (iterator.call(context, obj[keys[i]], keys[i], obj) === breaker) <span class="hljs-keyword">return</span>; + } + } + <span class="hljs-keyword">return</span> obj; + };</pre></div></div> + + </li> + + + <li id="section-16"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-16">¶</a> + </div> + <p>Return the results of applying the iterator to each element. +Delegates to <strong>ECMAScript 5</strong>‘s native <code>map</code> if available.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.map = _.collect = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(obj, iterator, context)</span> {</span> + <span class="hljs-keyword">var</span> results = []; + <span class="hljs-keyword">if</span> (obj == <span class="hljs-literal">null</span>) <span class="hljs-keyword">return</span> results; + <span class="hljs-keyword">if</span> (nativeMap && obj.map === nativeMap) <span class="hljs-keyword">return</span> obj.map(iterator, context); + each(obj, <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(value, index, list)</span> {</span> + results.push(iterator.call(context, value, index, list)); + }); + <span class="hljs-keyword">return</span> results; + }; + + <span class="hljs-keyword">var</span> reduceError = <span class="hljs-string">'Reduce of empty array with no initial value'</span>;</pre></div></div> + + </li> + + + <li id="section-17"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-17">¶</a> + </div> + <p><strong>Reduce</strong> builds up a single result from a list of values, aka <code>inject</code>, +or <code>foldl</code>. Delegates to <strong>ECMAScript 5</strong>‘s native <code>reduce</code> if available.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.reduce = _.foldl = _.inject = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(obj, iterator, memo, context)</span> {</span> + <span class="hljs-keyword">var</span> initial = <span class="hljs-built_in">arguments</span>.length > <span class="hljs-number">2</span>; + <span class="hljs-keyword">if</span> (obj == <span class="hljs-literal">null</span>) obj = []; + <span class="hljs-keyword">if</span> (nativeReduce && obj.reduce === nativeReduce) { + <span class="hljs-keyword">if</span> (context) iterator = _.bind(iterator, context); + <span class="hljs-keyword">return</span> initial ? obj.reduce(iterator, memo) : obj.reduce(iterator); + } + each(obj, <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(value, index, list)</span> {</span> + <span class="hljs-keyword">if</span> (!initial) { + memo = value; + initial = <span class="hljs-literal">true</span>; + } <span class="hljs-keyword">else</span> { + memo = iterator.call(context, memo, value, index, list); + } + }); + <span class="hljs-keyword">if</span> (!initial) <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">TypeError</span>(reduceError); + <span class="hljs-keyword">return</span> memo; + };</pre></div></div> + + </li> + + + <li id="section-18"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-18">¶</a> + </div> + <p>The right-associative version of reduce, also known as <code>foldr</code>. +Delegates to <strong>ECMAScript 5</strong>‘s native <code>reduceRight</code> if available.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.reduceRight = _.foldr = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(obj, iterator, memo, context)</span> {</span> + <span class="hljs-keyword">var</span> initial = <span class="hljs-built_in">arguments</span>.length > <span class="hljs-number">2</span>; + <span class="hljs-keyword">if</span> (obj == <span class="hljs-literal">null</span>) obj = []; + <span class="hljs-keyword">if</span> (nativeReduceRight && obj.reduceRight === nativeReduceRight) { + <span class="hljs-keyword">if</span> (context) iterator = _.bind(iterator, context); + <span class="hljs-keyword">return</span> initial ? obj.reduceRight(iterator, memo) : obj.reduceRight(iterator); + } + <span class="hljs-keyword">var</span> length = obj.length; + <span class="hljs-keyword">if</span> (length !== +length) { + <span class="hljs-keyword">var</span> keys = _.keys(obj); + length = keys.length; + } + each(obj, <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(value, index, list)</span> {</span> + index = keys ? keys[--length] : --length; + <span class="hljs-keyword">if</span> (!initial) { + memo = obj[index]; + initial = <span class="hljs-literal">true</span>; + } <span class="hljs-keyword">else</span> { + memo = iterator.call(context, memo, obj[index], index, list); + } + }); + <span class="hljs-keyword">if</span> (!initial) <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">TypeError</span>(reduceError); + <span class="hljs-keyword">return</span> memo; + };</pre></div></div> + + </li> + + + <li id="section-19"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-19">¶</a> + </div> + <p>Return the first value which passes a truth test. Aliased as <code>detect</code>.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.find = _.detect = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(obj, predicate, context)</span> {</span> + <span class="hljs-keyword">var</span> result; + any(obj, <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(value, index, list)</span> {</span> + <span class="hljs-keyword">if</span> (predicate.call(context, value, index, list)) { + result = value; + <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>; + } + }); + <span class="hljs-keyword">return</span> result; + };</pre></div></div> + + </li> + + + <li id="section-20"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-20">¶</a> + </div> + <p>Return all the elements that pass a truth test. +Delegates to <strong>ECMAScript 5</strong>‘s native <code>filter</code> if available. +Aliased as <code>select</code>.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.filter = _.select = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(obj, predicate, context)</span> {</span> + <span class="hljs-keyword">var</span> results = []; + <span class="hljs-keyword">if</span> (obj == <span class="hljs-literal">null</span>) <span class="hljs-keyword">return</span> results; + <span class="hljs-keyword">if</span> (nativeFilter && obj.filter === nativeFilter) <span class="hljs-keyword">return</span> obj.filter(predicate, context); + each(obj, <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(value, index, list)</span> {</span> + <span class="hljs-keyword">if</span> (predicate.call(context, value, index, list)) results.push(value); + }); + <span class="hljs-keyword">return</span> results; + };</pre></div></div> + + </li> + + + <li id="section-21"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-21">¶</a> + </div> + <p>Return all the elements for which a truth test fails.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.reject = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(obj, predicate, context)</span> {</span> + <span class="hljs-keyword">return</span> _.filter(obj, <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(value, index, list)</span> {</span> + <span class="hljs-keyword">return</span> !predicate.call(context, value, index, list); + }, context); + };</pre></div></div> + + </li> + + + <li id="section-22"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-22">¶</a> + </div> + <p>Determine whether all of the elements match a truth test. +Delegates to <strong>ECMAScript 5</strong>‘s native <code>every</code> if available. +Aliased as <code>all</code>.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.every = _.all = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(obj, predicate, context)</span> {</span> + predicate || (predicate = _.identity); + <span class="hljs-keyword">var</span> result = <span class="hljs-literal">true</span>; + <span class="hljs-keyword">if</span> (obj == <span class="hljs-literal">null</span>) <span class="hljs-keyword">return</span> result; + <span class="hljs-keyword">if</span> (nativeEvery && obj.every === nativeEvery) <span class="hljs-keyword">return</span> obj.every(predicate, context); + each(obj, <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(value, index, list)</span> {</span> + <span class="hljs-keyword">if</span> (!(result = result && predicate.call(context, value, index, list))) <span class="hljs-keyword">return</span> breaker; + }); + <span class="hljs-keyword">return</span> !!result; + };</pre></div></div> + + </li> + + + <li id="section-23"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-23">¶</a> + </div> + <p>Determine if at least one element in the object matches a truth test. +Delegates to <strong>ECMAScript 5</strong>‘s native <code>some</code> if available. +Aliased as <code>any</code>.</p> + + </div> + + <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">var</span> any = _.some = _.any = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(obj, predicate, context)</span> {</span> + predicate || (predicate = _.identity); + <span class="hljs-keyword">var</span> result = <span class="hljs-literal">false</span>; + <span class="hljs-keyword">if</span> (obj == <span class="hljs-literal">null</span>) <span class="hljs-keyword">return</span> result; + <span class="hljs-keyword">if</span> (nativeSome && obj.some === nativeSome) <span class="hljs-keyword">return</span> obj.some(predicate, context); + each(obj, <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(value, index, list)</span> {</span> + <span class="hljs-keyword">if</span> (result || (result = predicate.call(context, value, index, list))) <span class="hljs-keyword">return</span> breaker; + }); + <span class="hljs-keyword">return</span> !!result; + };</pre></div></div> + + </li> + + + <li id="section-24"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-24">¶</a> + </div> + <p>Determine if the array or object contains a given value (using <code>===</code>). +Aliased as <code>include</code>.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.contains = _.include = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(obj, target)</span> {</span> + <span class="hljs-keyword">if</span> (obj == <span class="hljs-literal">null</span>) <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>; + <span class="hljs-keyword">if</span> (nativeIndexOf && obj.indexOf === nativeIndexOf) <span class="hljs-keyword">return</span> obj.indexOf(target) != -<span class="hljs-number">1</span>; + <span class="hljs-keyword">return</span> any(obj, <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(value)</span> {</span> + <span class="hljs-keyword">return</span> value === target; + }); + };</pre></div></div> + + </li> + + + <li id="section-25"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-25">¶</a> + </div> + <p>Invoke a method (with arguments) on every item in a collection.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.invoke = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(obj, method)</span> {</span> + <span class="hljs-keyword">var</span> args = slice.call(<span class="hljs-built_in">arguments</span>, <span class="hljs-number">2</span>); + <span class="hljs-keyword">var</span> isFunc = _.isFunction(method); + <span class="hljs-keyword">return</span> _.map(obj, <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(value)</span> {</span> + <span class="hljs-keyword">return</span> (isFunc ? method : value[method]).apply(value, args); + }); + };</pre></div></div> + + </li> + + + <li id="section-26"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-26">¶</a> + </div> + <p>Convenience version of a common use case of <code>map</code>: fetching a property.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.pluck = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(obj, key)</span> {</span> + <span class="hljs-keyword">return</span> _.map(obj, _.property(key)); + };</pre></div></div> + + </li> + + + <li id="section-27"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-27">¶</a> + </div> + <p>Convenience version of a common use case of <code>filter</code>: selecting only objects +containing specific <code>key:value</code> pairs.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.where = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(obj, attrs)</span> {</span> + <span class="hljs-keyword">return</span> _.filter(obj, _.matches(attrs)); + };</pre></div></div> + + </li> + + + <li id="section-28"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-28">¶</a> + </div> + <p>Convenience version of a common use case of <code>find</code>: getting the first object +containing specific <code>key:value</code> pairs.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.findWhere = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(obj, attrs)</span> {</span> + <span class="hljs-keyword">return</span> _.find(obj, _.matches(attrs)); + };</pre></div></div> + + </li> + + + <li id="section-29"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-29">¶</a> + </div> + <p>Return the maximum element or (element-based computation). +Can’t optimize arrays of integers longer than 65,535 elements. +See <a href="https://bugs.webkit.org/show_bug.cgi?id=80797">WebKit Bug 80797</a></p> + + </div> + + <div class="content"><div class='highlight'><pre> _.max = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(obj, iterator, context)</span> {</span> + <span class="hljs-keyword">if</span> (!iterator && _.isArray(obj) && obj[<span class="hljs-number">0</span>] === +obj[<span class="hljs-number">0</span>] && obj.length < <span class="hljs-number">65535</span>) { + <span class="hljs-keyword">return</span> <span class="hljs-built_in">Math</span>.max.apply(<span class="hljs-built_in">Math</span>, obj); + } + <span class="hljs-keyword">var</span> result = -<span class="hljs-literal">Infinity</span>, lastComputed = -<span class="hljs-literal">Infinity</span>; + each(obj, <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(value, index, list)</span> {</span> + <span class="hljs-keyword">var</span> computed = iterator ? iterator.call(context, value, index, list) : value; + <span class="hljs-keyword">if</span> (computed > lastComputed) { + result = value; + lastComputed = computed; + } + }); + <span class="hljs-keyword">return</span> result; + };</pre></div></div> + + </li> + + + <li id="section-30"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-30">¶</a> + </div> + <p>Return the minimum element (or element-based computation).</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.min = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(obj, iterator, context)</span> {</span> + <span class="hljs-keyword">if</span> (!iterator && _.isArray(obj) && obj[<span class="hljs-number">0</span>] === +obj[<span class="hljs-number">0</span>] && obj.length < <span class="hljs-number">65535</span>) { + <span class="hljs-keyword">return</span> <span class="hljs-built_in">Math</span>.min.apply(<span class="hljs-built_in">Math</span>, obj); + } + <span class="hljs-keyword">var</span> result = <span class="hljs-literal">Infinity</span>, lastComputed = <span class="hljs-literal">Infinity</span>; + each(obj, <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(value, index, list)</span> {</span> + <span class="hljs-keyword">var</span> computed = iterator ? iterator.call(context, value, index, list) : value; + <span class="hljs-keyword">if</span> (computed < lastComputed) { + result = value; + lastComputed = computed; + } + }); + <span class="hljs-keyword">return</span> result; + };</pre></div></div> + + </li> + + + <li id="section-31"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-31">¶</a> + </div> + <p>Shuffle an array, using the modern version of the +<a href="http://en.wikipedia.org/wiki/Fisher–Yates_shuffle">Fisher-Yates shuffle</a>.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.shuffle = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(obj)</span> {</span> + <span class="hljs-keyword">var</span> rand; + <span class="hljs-keyword">var</span> index = <span class="hljs-number">0</span>; + <span class="hljs-keyword">var</span> shuffled = []; + each(obj, <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(value)</span> {</span> + rand = _.random(index++); + shuffled[index - <span class="hljs-number">1</span>] = shuffled[rand]; + shuffled[rand] = value; + }); + <span class="hljs-keyword">return</span> shuffled; + };</pre></div></div> + + </li> + + + <li id="section-32"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-32">¶</a> + </div> + <p>Sample <strong>n</strong> random values from a collection. +If <strong>n</strong> is not specified, returns a single random element. +The internal <code>guard</code> argument allows it to work with <code>map</code>.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.sample = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(obj, n, guard)</span> {</span> + <span class="hljs-keyword">if</span> (n == <span class="hljs-literal">null</span> || guard) { + <span class="hljs-keyword">if</span> (obj.length !== +obj.length) obj = _.values(obj); + <span class="hljs-keyword">return</span> obj[_.random(obj.length - <span class="hljs-number">1</span>)]; + } + <span class="hljs-keyword">return</span> _.shuffle(obj).slice(<span class="hljs-number">0</span>, <span class="hljs-built_in">Math</span>.max(<span class="hljs-number">0</span>, n)); + };</pre></div></div> + + </li> + + + <li id="section-33"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-33">¶</a> + </div> + <p>An internal function to generate lookup iterators.</p> + + </div> + + <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">var</span> lookupIterator = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(value)</span> {</span> + <span class="hljs-keyword">if</span> (value == <span class="hljs-literal">null</span>) <span class="hljs-keyword">return</span> _.identity; + <span class="hljs-keyword">if</span> (_.isFunction(value)) <span class="hljs-keyword">return</span> value; + <span class="hljs-keyword">return</span> _.property(value); + };</pre></div></div> + + </li> + + + <li id="section-34"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-34">¶</a> + </div> + <p>Sort the object’s values by a criterion produced by an iterator.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.sortBy = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(obj, iterator, context)</span> {</span> + iterator = lookupIterator(iterator); + <span class="hljs-keyword">return</span> _.pluck(_.map(obj, <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(value, index, list)</span> {</span> + <span class="hljs-keyword">return</span> { + value: value, + index: index, + criteria: iterator.call(context, value, index, list) + }; + }).sort(<span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(left, right)</span> {</span> + <span class="hljs-keyword">var</span> a = left.criteria; + <span class="hljs-keyword">var</span> b = right.criteria; + <span class="hljs-keyword">if</span> (a !== b) { + <span class="hljs-keyword">if</span> (a > b || a === <span class="hljs-keyword">void</span> <span class="hljs-number">0</span>) <span class="hljs-keyword">return</span> <span class="hljs-number">1</span>; + <span class="hljs-keyword">if</span> (a < b || b === <span class="hljs-keyword">void</span> <span class="hljs-number">0</span>) <span class="hljs-keyword">return</span> -<span class="hljs-number">1</span>; + } + <span class="hljs-keyword">return</span> left.index - right.index; + }), <span class="hljs-string">'value'</span>); + };</pre></div></div> + + </li> + + + <li id="section-35"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-35">¶</a> + </div> + <p>An internal function used for aggregate “group by” operations.</p> + + </div> + + <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">var</span> group = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(behavior)</span> {</span> + <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(obj, iterator, context)</span> {</span> + <span class="hljs-keyword">var</span> result = {}; + iterator = lookupIterator(iterator); + each(obj, <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(value, index)</span> {</span> + <span class="hljs-keyword">var</span> key = iterator.call(context, value, index, obj); + behavior(result, key, value); + }); + <span class="hljs-keyword">return</span> result; + }; + };</pre></div></div> + + </li> + + + <li id="section-36"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-36">¶</a> + </div> + <p>Groups the object’s values by a criterion. Pass either a string attribute +to group by, or a function that returns the criterion.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.groupBy = group(<span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(result, key, value)</span> {</span> + _.has(result, key) ? result[key].push(value) : result[key] = [value]; + });</pre></div></div> + + </li> + + + <li id="section-37"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-37">¶</a> + </div> + <p>Indexes the object’s values by a criterion, similar to <code>groupBy</code>, but for +when you know that your index values will be unique.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.indexBy = group(<span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(result, key, value)</span> {</span> + result[key] = value; + });</pre></div></div> + + </li> + + + <li id="section-38"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-38">¶</a> + </div> + <p>Counts instances of an object that group by a certain criterion. Pass +either a string attribute to count by, or a function that returns the +criterion.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.countBy = group(<span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(result, key)</span> {</span> + _.has(result, key) ? result[key]++ : result[key] = <span class="hljs-number">1</span>; + });</pre></div></div> + + </li> + + + <li id="section-39"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-39">¶</a> + </div> + <p>Use a comparator function to figure out the smallest index at which +an object should be inserted so as to maintain order. Uses binary search.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.sortedIndex = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(array, obj, iterator, context)</span> {</span> + iterator = lookupIterator(iterator); + <span class="hljs-keyword">var</span> value = iterator.call(context, obj); + <span class="hljs-keyword">var</span> low = <span class="hljs-number">0</span>, high = array.length; + <span class="hljs-keyword">while</span> (low < high) { + <span class="hljs-keyword">var</span> mid = (low + high) >>> <span class="hljs-number">1</span>; + iterator.call(context, array[mid]) < value ? low = mid + <span class="hljs-number">1</span> : high = mid; + } + <span class="hljs-keyword">return</span> low; + };</pre></div></div> + + </li> + + + <li id="section-40"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-40">¶</a> + </div> + <p>Safely create a real, live array from anything iterable.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.toArray = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(obj)</span> {</span> + <span class="hljs-keyword">if</span> (!obj) <span class="hljs-keyword">return</span> []; + <span class="hljs-keyword">if</span> (_.isArray(obj)) <span class="hljs-keyword">return</span> slice.call(obj); + <span class="hljs-keyword">if</span> (obj.length === +obj.length) <span class="hljs-keyword">return</span> _.map(obj, _.identity); + <span class="hljs-keyword">return</span> _.values(obj); + };</pre></div></div> + + </li> + + + <li id="section-41"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-41">¶</a> + </div> + <p>Return the number of elements in an object.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.size = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(obj)</span> {</span> + <span class="hljs-keyword">if</span> (obj == <span class="hljs-literal">null</span>) <span class="hljs-keyword">return</span> <span class="hljs-number">0</span>; + <span class="hljs-keyword">return</span> (obj.length === +obj.length) ? obj.length : _.keys(obj).length; + };</pre></div></div> + + </li> + + + <li id="section-42"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-42">¶</a> + </div> + <h2 id="array-functions">Array Functions</h2> + + </div> + + </li> + + + <li id="section-43"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-43">¶</a> + </div> + + </div> + + </li> + + + <li id="section-44"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-44">¶</a> + </div> + <p>Get the first element of an array. Passing <strong>n</strong> will return the first N +values in the array. Aliased as <code>head</code> and <code>take</code>. The <strong>guard</strong> check +allows it to work with <code>_.map</code>.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.first = _.head = _.take = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(array, n, guard)</span> {</span> + <span class="hljs-keyword">if</span> (array == <span class="hljs-literal">null</span>) <span class="hljs-keyword">return</span> <span class="hljs-keyword">void</span> <span class="hljs-number">0</span>; + <span class="hljs-keyword">if</span> ((n == <span class="hljs-literal">null</span>) || guard) <span class="hljs-keyword">return</span> array[<span class="hljs-number">0</span>]; + <span class="hljs-keyword">if</span> (n < <span class="hljs-number">0</span>) <span class="hljs-keyword">return</span> []; + <span class="hljs-keyword">return</span> slice.call(array, <span class="hljs-number">0</span>, n); + };</pre></div></div> + + </li> + + + <li id="section-45"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-45">¶</a> + </div> + <p>Returns everything but the last entry of the array. Especially useful on +the arguments object. Passing <strong>n</strong> will return all the values in +the array, excluding the last N. The <strong>guard</strong> check allows it to work with +<code>_.map</code>.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.initial = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(array, n, guard)</span> {</span> + <span class="hljs-keyword">return</span> slice.call(array, <span class="hljs-number">0</span>, array.length - ((n == <span class="hljs-literal">null</span>) || guard ? <span class="hljs-number">1</span> : n)); + };</pre></div></div> + + </li> + + + <li id="section-46"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-46">¶</a> + </div> + <p>Get the last element of an array. Passing <strong>n</strong> will return the last N +values in the array. The <strong>guard</strong> check allows it to work with <code>_.map</code>.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.last = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(array, n, guard)</span> {</span> + <span class="hljs-keyword">if</span> (array == <span class="hljs-literal">null</span>) <span class="hljs-keyword">return</span> <span class="hljs-keyword">void</span> <span class="hljs-number">0</span>; + <span class="hljs-keyword">if</span> ((n == <span class="hljs-literal">null</span>) || guard) <span class="hljs-keyword">return</span> array[array.length - <span class="hljs-number">1</span>]; + <span class="hljs-keyword">return</span> slice.call(array, <span class="hljs-built_in">Math</span>.max(array.length - n, <span class="hljs-number">0</span>)); + };</pre></div></div> + + </li> + + + <li id="section-47"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-47">¶</a> + </div> + <p>Returns everything but the first entry of the array. Aliased as <code>tail</code> and <code>drop</code>. +Especially useful on the arguments object. Passing an <strong>n</strong> will return +the rest N values in the array. The <strong>guard</strong> +check allows it to work with <code>_.map</code>.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.rest = _.tail = _.drop = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(array, n, guard)</span> {</span> + <span class="hljs-keyword">return</span> slice.call(array, (n == <span class="hljs-literal">null</span>) || guard ? <span class="hljs-number">1</span> : n); + };</pre></div></div> + + </li> + + + <li id="section-48"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-48">¶</a> + </div> + <p>Trim out all falsy values from an array.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.compact = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(array)</span> {</span> + <span class="hljs-keyword">return</span> _.filter(array, _.identity); + };</pre></div></div> + + </li> + + + <li id="section-49"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-49">¶</a> + </div> + <p>Internal implementation of a recursive <code>flatten</code> function.</p> + + </div> + + <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">var</span> flatten = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(input, shallow, output)</span> {</span> + <span class="hljs-keyword">if</span> (shallow && _.every(input, _.isArray)) { + <span class="hljs-keyword">return</span> concat.apply(output, input); + } + each(input, <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(value)</span> {</span> + <span class="hljs-keyword">if</span> (_.isArray(value) || _.isArguments(value)) { + shallow ? push.apply(output, value) : flatten(value, shallow, output); + } <span class="hljs-keyword">else</span> { + output.push(value); + } + }); + <span class="hljs-keyword">return</span> output; + };</pre></div></div> + + </li> + + + <li id="section-50"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-50">¶</a> + </div> + <p>Flatten out an array, either recursively (by default), or just one level.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.flatten = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(array, shallow)</span> {</span> + <span class="hljs-keyword">return</span> flatten(array, shallow, []); + };</pre></div></div> + + </li> + + + <li id="section-51"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-51">¶</a> + </div> + <p>Return a version of the array that does not contain the specified value(s).</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.without = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(array)</span> {</span> + <span class="hljs-keyword">return</span> _.difference(array, slice.call(<span class="hljs-built_in">arguments</span>, <span class="hljs-number">1</span>)); + };</pre></div></div> + + </li> + + + <li id="section-52"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-52">¶</a> + </div> + <p>Split an array into two arrays: one whose elements all satisfy the given +predicate, and one whose elements all do not satisfy the predicate.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.partition = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(array, predicate)</span> {</span> + <span class="hljs-keyword">var</span> pass = [], fail = []; + each(array, <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(elem)</span> {</span> + (predicate(elem) ? pass : fail).push(elem); + }); + <span class="hljs-keyword">return</span> [pass, fail]; + };</pre></div></div> + + </li> + + + <li id="section-53"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-53">¶</a> + </div> + <p>Produce a duplicate-free version of the array. If the array has already +been sorted, you have the option of using a faster algorithm. +Aliased as <code>unique</code>.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.uniq = _.unique = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(array, isSorted, iterator, context)</span> {</span> + <span class="hljs-keyword">if</span> (_.isFunction(isSorted)) { + context = iterator; + iterator = isSorted; + isSorted = <span class="hljs-literal">false</span>; + } + <span class="hljs-keyword">var</span> initial = iterator ? _.map(array, iterator, context) : array; + <span class="hljs-keyword">var</span> results = []; + <span class="hljs-keyword">var</span> seen = []; + each(initial, <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(value, index)</span> {</span> + <span class="hljs-keyword">if</span> (isSorted ? (!index || seen[seen.length - <span class="hljs-number">1</span>] !== value) : !_.contains(seen, value)) { + seen.push(value); + results.push(array[index]); + } + }); + <span class="hljs-keyword">return</span> results; + };</pre></div></div> + + </li> + + + <li id="section-54"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-54">¶</a> + </div> + <p>Produce an array that contains the union: each distinct element from all of +the passed-in arrays.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.union = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> {</span> + <span class="hljs-keyword">return</span> _.uniq(_.flatten(<span class="hljs-built_in">arguments</span>, <span class="hljs-literal">true</span>)); + };</pre></div></div> + + </li> + + + <li id="section-55"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-55">¶</a> + </div> + <p>Produce an array that contains every item shared between all the +passed-in arrays.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.intersection = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(array)</span> {</span> + <span class="hljs-keyword">var</span> rest = slice.call(<span class="hljs-built_in">arguments</span>, <span class="hljs-number">1</span>); + <span class="hljs-keyword">return</span> _.filter(_.uniq(array), <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(item)</span> {</span> + <span class="hljs-keyword">return</span> _.every(rest, <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(other)</span> {</span> + <span class="hljs-keyword">return</span> _.contains(other, item); + }); + }); + };</pre></div></div> + + </li> + + + <li id="section-56"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-56">¶</a> + </div> + <p>Take the difference between one array and a number of other arrays. +Only the elements present in just the first array will remain.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.difference = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(array)</span> {</span> + <span class="hljs-keyword">var</span> rest = concat.apply(ArrayProto, slice.call(<span class="hljs-built_in">arguments</span>, <span class="hljs-number">1</span>)); + <span class="hljs-keyword">return</span> _.filter(array, <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(value)</span>{</span> <span class="hljs-keyword">return</span> !_.contains(rest, value); }); + };</pre></div></div> + + </li> + + + <li id="section-57"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-57">¶</a> + </div> + <p>Zip together multiple lists into a single array — elements that share +an index go together.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.zip = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> {</span> + <span class="hljs-keyword">var</span> length = _.max(_.pluck(<span class="hljs-built_in">arguments</span>, <span class="hljs-string">'length'</span>).concat(<span class="hljs-number">0</span>)); + <span class="hljs-keyword">var</span> results = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Array</span>(length); + <span class="hljs-keyword">for</span> (<span class="hljs-keyword">var</span> i = <span class="hljs-number">0</span>; i < length; i++) { + results[i] = _.pluck(<span class="hljs-built_in">arguments</span>, <span class="hljs-string">''</span> + i); + } + <span class="hljs-keyword">return</span> results; + };</pre></div></div> + + </li> + + + <li id="section-58"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-58">¶</a> + </div> + <p>Converts lists into objects. Pass either a single array of <code>[key, value]</code> +pairs, or two parallel arrays of the same length — one of keys, and one of +the corresponding values.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.object = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(list, values)</span> {</span> + <span class="hljs-keyword">if</span> (list == <span class="hljs-literal">null</span>) <span class="hljs-keyword">return</span> {}; + <span class="hljs-keyword">var</span> result = {}; + <span class="hljs-keyword">for</span> (<span class="hljs-keyword">var</span> i = <span class="hljs-number">0</span>, length = list.length; i < length; i++) { + <span class="hljs-keyword">if</span> (values) { + result[list[i]] = values[i]; + } <span class="hljs-keyword">else</span> { + result[list[i][<span class="hljs-number">0</span>]] = list[i][<span class="hljs-number">1</span>]; + } + } + <span class="hljs-keyword">return</span> result; + };</pre></div></div> + + </li> + + + <li id="section-59"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-59">¶</a> + </div> + <p>If the browser doesn’t supply us with indexOf (I’m looking at you, <strong>MSIE</strong>), +we need this function. Return the position of the first occurrence of an +item in an array, or -1 if the item is not included in the array. +Delegates to <strong>ECMAScript 5</strong>‘s native <code>indexOf</code> if available. +If the array is large and already in sort order, pass <code>true</code> +for <strong>isSorted</strong> to use binary search.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.indexOf = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(array, item, isSorted)</span> {</span> + <span class="hljs-keyword">if</span> (array == <span class="hljs-literal">null</span>) <span class="hljs-keyword">return</span> -<span class="hljs-number">1</span>; + <span class="hljs-keyword">var</span> i = <span class="hljs-number">0</span>, length = array.length; + <span class="hljs-keyword">if</span> (isSorted) { + <span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> isSorted == <span class="hljs-string">'number'</span>) { + i = (isSorted < <span class="hljs-number">0</span> ? <span class="hljs-built_in">Math</span>.max(<span class="hljs-number">0</span>, length + isSorted) : isSorted); + } <span class="hljs-keyword">else</span> { + i = _.sortedIndex(array, item); + <span class="hljs-keyword">return</span> array[i] === item ? i : -<span class="hljs-number">1</span>; + } + } + <span class="hljs-keyword">if</span> (nativeIndexOf && array.indexOf === nativeIndexOf) <span class="hljs-keyword">return</span> array.indexOf(item, isSorted); + <span class="hljs-keyword">for</span> (; i < length; i++) <span class="hljs-keyword">if</span> (array[i] === item) <span class="hljs-keyword">return</span> i; + <span class="hljs-keyword">return</span> -<span class="hljs-number">1</span>; + };</pre></div></div> + + </li> + + + <li id="section-60"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-60">¶</a> + </div> + <p>Delegates to <strong>ECMAScript 5</strong>‘s native <code>lastIndexOf</code> if available.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.lastIndexOf = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(array, item, from)</span> {</span> + <span class="hljs-keyword">if</span> (array == <span class="hljs-literal">null</span>) <span class="hljs-keyword">return</span> -<span class="hljs-number">1</span>; + <span class="hljs-keyword">var</span> hasIndex = from != <span class="hljs-literal">null</span>; + <span class="hljs-keyword">if</span> (nativeLastIndexOf && array.lastIndexOf === nativeLastIndexOf) { + <span class="hljs-keyword">return</span> hasIndex ? array.lastIndexOf(item, from) : array.lastIndexOf(item); + } + <span class="hljs-keyword">var</span> i = (hasIndex ? from : array.length); + <span class="hljs-keyword">while</span> (i--) <span class="hljs-keyword">if</span> (array[i] === item) <span class="hljs-keyword">return</span> i; + <span class="hljs-keyword">return</span> -<span class="hljs-number">1</span>; + };</pre></div></div> + + </li> + + + <li id="section-61"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-61">¶</a> + </div> + <p>Generate an integer Array containing an arithmetic progression. A port of +the native Python <code>range()</code> function. See +<a href="http://docs.python.org/library/functions.html#range">the Python documentation</a>.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.range = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(start, stop, step)</span> {</span> + <span class="hljs-keyword">if</span> (<span class="hljs-built_in">arguments</span>.length <= <span class="hljs-number">1</span>) { + stop = start || <span class="hljs-number">0</span>; + start = <span class="hljs-number">0</span>; + } + step = <span class="hljs-built_in">arguments</span>[<span class="hljs-number">2</span>] || <span class="hljs-number">1</span>; + + <span class="hljs-keyword">var</span> length = <span class="hljs-built_in">Math</span>.max(<span class="hljs-built_in">Math</span>.ceil((stop - start) / step), <span class="hljs-number">0</span>); + <span class="hljs-keyword">var</span> idx = <span class="hljs-number">0</span>; + <span class="hljs-keyword">var</span> range = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Array</span>(length); + + <span class="hljs-keyword">while</span>(idx < length) { + range[idx++] = start; + start += step; + } + + <span class="hljs-keyword">return</span> range; + };</pre></div></div> + + </li> + + + <li id="section-62"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-62">¶</a> + </div> + <h2 id="function-ahem-functions">Function (ahem) Functions</h2> + + </div> + + </li> + + + <li id="section-63"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-63">¶</a> + </div> + + </div> + + </li> + + + <li id="section-64"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-64">¶</a> + </div> + <p>Reusable constructor function for prototype setting.</p> + + </div> + + <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">var</span> ctor = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span>{</span>};</pre></div></div> + + </li> + + + <li id="section-65"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-65">¶</a> + </div> + <p>Create a function bound to a given object (assigning <code>this</code>, and arguments, +optionally). Delegates to <strong>ECMAScript 5</strong>‘s native <code>Function.bind</code> if +available.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.bind = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(func, context)</span> {</span> + <span class="hljs-keyword">var</span> args, bound; + <span class="hljs-keyword">if</span> (nativeBind && func.bind === nativeBind) <span class="hljs-keyword">return</span> nativeBind.apply(func, slice.call(<span class="hljs-built_in">arguments</span>, <span class="hljs-number">1</span>)); + <span class="hljs-keyword">if</span> (!_.isFunction(func)) <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">TypeError</span>; + args = slice.call(<span class="hljs-built_in">arguments</span>, <span class="hljs-number">2</span>); + <span class="hljs-keyword">return</span> bound = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> {</span> + <span class="hljs-keyword">if</span> (!(<span class="hljs-keyword">this</span> <span class="hljs-keyword">instanceof</span> bound)) <span class="hljs-keyword">return</span> func.apply(context, args.concat(slice.call(<span class="hljs-built_in">arguments</span>))); + ctor.prototype = func.prototype; + <span class="hljs-keyword">var</span> self = <span class="hljs-keyword">new</span> ctor; + ctor.prototype = <span class="hljs-literal">null</span>; + <span class="hljs-keyword">var</span> result = func.apply(self, args.concat(slice.call(<span class="hljs-built_in">arguments</span>))); + <span class="hljs-keyword">if</span> (<span class="hljs-built_in">Object</span>(result) === result) <span class="hljs-keyword">return</span> result; + <span class="hljs-keyword">return</span> self; + }; + };</pre></div></div> + + </li> + + + <li id="section-66"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-66">¶</a> + </div> + <p>Partially apply a function by creating a version that has had some of its +arguments pre-filled, without changing its dynamic <code>this</code> context. _ acts +as a placeholder, allowing any combination of arguments to be pre-filled.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.partial = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(func)</span> {</span> + <span class="hljs-keyword">var</span> boundArgs = slice.call(<span class="hljs-built_in">arguments</span>, <span class="hljs-number">1</span>); + <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> {</span> + <span class="hljs-keyword">var</span> position = <span class="hljs-number">0</span>; + <span class="hljs-keyword">var</span> args = boundArgs.slice(); + <span class="hljs-keyword">for</span> (<span class="hljs-keyword">var</span> i = <span class="hljs-number">0</span>, length = args.length; i < length; i++) { + <span class="hljs-keyword">if</span> (args[i] === _) args[i] = <span class="hljs-built_in">arguments</span>[position++]; + } + <span class="hljs-keyword">while</span> (position < <span class="hljs-built_in">arguments</span>.length) args.push(<span class="hljs-built_in">arguments</span>[position++]); + <span class="hljs-keyword">return</span> func.apply(<span class="hljs-keyword">this</span>, args); + }; + };</pre></div></div> + + </li> + + + <li id="section-67"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-67">¶</a> + </div> + <p>Bind a number of an object’s methods to that object. Remaining arguments +are the method names to be bound. Useful for ensuring that all callbacks +defined on an object belong to it.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.bindAll = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(obj)</span> {</span> + <span class="hljs-keyword">var</span> funcs = slice.call(<span class="hljs-built_in">arguments</span>, <span class="hljs-number">1</span>); + <span class="hljs-keyword">if</span> (funcs.length === <span class="hljs-number">0</span>) <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span>(<span class="hljs-string">'bindAll must be passed function names'</span>); + each(funcs, <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(f)</span> {</span> obj[f] = _.bind(obj[f], obj); }); + <span class="hljs-keyword">return</span> obj; + };</pre></div></div> + + </li> + + + <li id="section-68"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-68">¶</a> + </div> + <p>Memoize an expensive function by storing its results.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.memoize = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(func, hasher)</span> {</span> + <span class="hljs-keyword">var</span> memo = {}; + hasher || (hasher = _.identity); + <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> {</span> + <span class="hljs-keyword">var</span> key = hasher.apply(<span class="hljs-keyword">this</span>, <span class="hljs-built_in">arguments</span>); + <span class="hljs-keyword">return</span> _.has(memo, key) ? memo[key] : (memo[key] = func.apply(<span class="hljs-keyword">this</span>, <span class="hljs-built_in">arguments</span>)); + }; + };</pre></div></div> + + </li> + + + <li id="section-69"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-69">¶</a> + </div> + <p>Delays a function for the given number of milliseconds, and then calls +it with the arguments supplied.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.delay = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(func, wait)</span> {</span> + <span class="hljs-keyword">var</span> args = slice.call(<span class="hljs-built_in">arguments</span>, <span class="hljs-number">2</span>); + <span class="hljs-keyword">return</span> setTimeout(<span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span>{</span> <span class="hljs-keyword">return</span> func.apply(<span class="hljs-literal">null</span>, args); }, wait); + };</pre></div></div> + + </li> + + + <li id="section-70"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-70">¶</a> + </div> + <p>Defers a function, scheduling it to run after the current call stack has +cleared.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.defer = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(func)</span> {</span> + <span class="hljs-keyword">return</span> _.delay.apply(_, [func, <span class="hljs-number">1</span>].concat(slice.call(<span class="hljs-built_in">arguments</span>, <span class="hljs-number">1</span>))); + };</pre></div></div> + + </li> + + + <li id="section-71"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-71">¶</a> + </div> + <p>Returns a function, that, when invoked, will only be triggered at most once +during a given window of time. Normally, the throttled function will run +as much as it can, without ever going more than once per <code>wait</code> duration; +but if you’d like to disable the execution on the leading edge, pass +<code>{leading: false}</code>. To disable execution on the trailing edge, ditto.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.throttle = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(func, wait, options)</span> {</span> + <span class="hljs-keyword">var</span> context, args, result; + <span class="hljs-keyword">var</span> timeout = <span class="hljs-literal">null</span>; + <span class="hljs-keyword">var</span> previous = <span class="hljs-number">0</span>; + options || (options = {}); + <span class="hljs-keyword">var</span> later = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> {</span> + previous = options.leading === <span class="hljs-literal">false</span> ? <span class="hljs-number">0</span> : _.now(); + timeout = <span class="hljs-literal">null</span>; + result = func.apply(context, args); + context = args = <span class="hljs-literal">null</span>; + }; + <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> {</span> + <span class="hljs-keyword">var</span> now = _.now(); + <span class="hljs-keyword">if</span> (!previous && options.leading === <span class="hljs-literal">false</span>) previous = now; + <span class="hljs-keyword">var</span> remaining = wait - (now - previous); + context = <span class="hljs-keyword">this</span>; + args = <span class="hljs-built_in">arguments</span>; + <span class="hljs-keyword">if</span> (remaining <= <span class="hljs-number">0</span>) { + clearTimeout(timeout); + timeout = <span class="hljs-literal">null</span>; + previous = now; + result = func.apply(context, args); + context = args = <span class="hljs-literal">null</span>; + } <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (!timeout && options.trailing !== <span class="hljs-literal">false</span>) { + timeout = setTimeout(later, remaining); + } + <span class="hljs-keyword">return</span> result; + }; + };</pre></div></div> + + </li> + + + <li id="section-72"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-72">¶</a> + </div> + <p>Returns a function, that, as long as it continues to be invoked, will not +be triggered. The function will be called after it stops being called for +N milliseconds. If <code>immediate</code> is passed, trigger the function on the +leading edge, instead of the trailing.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.debounce = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(func, wait, immediate)</span> {</span> + <span class="hljs-keyword">var</span> timeout, args, context, timestamp, result; + + <span class="hljs-keyword">var</span> later = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> {</span> + <span class="hljs-keyword">var</span> last = _.now() - timestamp; + <span class="hljs-keyword">if</span> (last < wait) { + timeout = setTimeout(later, wait - last); + } <span class="hljs-keyword">else</span> { + timeout = <span class="hljs-literal">null</span>; + <span class="hljs-keyword">if</span> (!immediate) { + result = func.apply(context, args); + context = args = <span class="hljs-literal">null</span>; + } + } + }; + + <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> {</span> + context = <span class="hljs-keyword">this</span>; + args = <span class="hljs-built_in">arguments</span>; + timestamp = _.now(); + <span class="hljs-keyword">var</span> callNow = immediate && !timeout; + <span class="hljs-keyword">if</span> (!timeout) { + timeout = setTimeout(later, wait); + } + <span class="hljs-keyword">if</span> (callNow) { + result = func.apply(context, args); + context = args = <span class="hljs-literal">null</span>; + } + + <span class="hljs-keyword">return</span> result; + }; + };</pre></div></div> + + </li> + + + <li id="section-73"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-73">¶</a> + </div> + <p>Returns a function that will be executed at most one time, no matter how +often you call it. Useful for lazy initialization.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.once = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(func)</span> {</span> + <span class="hljs-keyword">var</span> ran = <span class="hljs-literal">false</span>, memo; + <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> {</span> + <span class="hljs-keyword">if</span> (ran) <span class="hljs-keyword">return</span> memo; + ran = <span class="hljs-literal">true</span>; + memo = func.apply(<span class="hljs-keyword">this</span>, <span class="hljs-built_in">arguments</span>); + func = <span class="hljs-literal">null</span>; + <span class="hljs-keyword">return</span> memo; + }; + };</pre></div></div> + + </li> + + + <li id="section-74"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-74">¶</a> + </div> + <p>Returns the first function passed as an argument to the second, +allowing you to adjust arguments, run code before and after, and +conditionally execute the original function.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.wrap = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(func, wrapper)</span> {</span> + <span class="hljs-keyword">return</span> _.partial(wrapper, func); + };</pre></div></div> + + </li> + + + <li id="section-75"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-75">¶</a> + </div> + <p>Returns a function that is the composition of a list of functions, each +consuming the return value of the function that follows.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.compose = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> {</span> + <span class="hljs-keyword">var</span> funcs = <span class="hljs-built_in">arguments</span>; + <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> {</span> + <span class="hljs-keyword">var</span> args = <span class="hljs-built_in">arguments</span>; + <span class="hljs-keyword">for</span> (<span class="hljs-keyword">var</span> i = funcs.length - <span class="hljs-number">1</span>; i >= <span class="hljs-number">0</span>; i--) { + args = [funcs[i].apply(<span class="hljs-keyword">this</span>, args)]; + } + <span class="hljs-keyword">return</span> args[<span class="hljs-number">0</span>]; + }; + };</pre></div></div> + + </li> + + + <li id="section-76"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-76">¶</a> + </div> + <p>Returns a function that will only be executed after being called N times.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.after = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(times, func)</span> {</span> + <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> {</span> + <span class="hljs-keyword">if</span> (--times < <span class="hljs-number">1</span>) { + <span class="hljs-keyword">return</span> func.apply(<span class="hljs-keyword">this</span>, <span class="hljs-built_in">arguments</span>); + } + }; + };</pre></div></div> + + </li> + + + <li id="section-77"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-77">¶</a> + </div> + <h2 id="object-functions">Object Functions</h2> + + </div> + + </li> + + + <li id="section-78"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-78">¶</a> + </div> + + </div> + + </li> + + + <li id="section-79"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-79">¶</a> + </div> + <p>Retrieve the names of an object’s properties. +Delegates to <strong>ECMAScript 5</strong>‘s native <code>Object.keys</code></p> + + </div> + + <div class="content"><div class='highlight'><pre> _.keys = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(obj)</span> {</span> + <span class="hljs-keyword">if</span> (!_.isObject(obj)) <span class="hljs-keyword">return</span> []; + <span class="hljs-keyword">if</span> (nativeKeys) <span class="hljs-keyword">return</span> nativeKeys(obj); + <span class="hljs-keyword">var</span> keys = []; + <span class="hljs-keyword">for</span> (<span class="hljs-keyword">var</span> key <span class="hljs-keyword">in</span> obj) <span class="hljs-keyword">if</span> (_.has(obj, key)) keys.push(key); + <span class="hljs-keyword">return</span> keys; + };</pre></div></div> + + </li> + + + <li id="section-80"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-80">¶</a> + </div> + <p>Retrieve the values of an object’s properties.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.values = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(obj)</span> {</span> + <span class="hljs-keyword">var</span> keys = _.keys(obj); + <span class="hljs-keyword">var</span> length = keys.length; + <span class="hljs-keyword">var</span> values = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Array</span>(length); + <span class="hljs-keyword">for</span> (<span class="hljs-keyword">var</span> i = <span class="hljs-number">0</span>; i < length; i++) { + values[i] = obj[keys[i]]; + } + <span class="hljs-keyword">return</span> values; + };</pre></div></div> + + </li> + + + <li id="section-81"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-81">¶</a> + </div> + <p>Convert an object into a list of <code>[key, value]</code> pairs.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.pairs = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(obj)</span> {</span> + <span class="hljs-keyword">var</span> keys = _.keys(obj); + <span class="hljs-keyword">var</span> length = keys.length; + <span class="hljs-keyword">var</span> pairs = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Array</span>(length); + <span class="hljs-keyword">for</span> (<span class="hljs-keyword">var</span> i = <span class="hljs-number">0</span>; i < length; i++) { + pairs[i] = [keys[i], obj[keys[i]]]; + } + <span class="hljs-keyword">return</span> pairs; + };</pre></div></div> + + </li> + + + <li id="section-82"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-82">¶</a> + </div> + <p>Invert the keys and values of an object. The values must be serializable.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.invert = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(obj)</span> {</span> + <span class="hljs-keyword">var</span> result = {}; + <span class="hljs-keyword">var</span> keys = _.keys(obj); + <span class="hljs-keyword">for</span> (<span class="hljs-keyword">var</span> i = <span class="hljs-number">0</span>, length = keys.length; i < length; i++) { + result[obj[keys[i]]] = keys[i]; + } + <span class="hljs-keyword">return</span> result; + };</pre></div></div> + + </li> + + + <li id="section-83"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-83">¶</a> + </div> + <p>Return a sorted list of the function names available on the object. +Aliased as <code>methods</code></p> + + </div> + + <div class="content"><div class='highlight'><pre> _.functions = _.methods = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(obj)</span> {</span> + <span class="hljs-keyword">var</span> names = []; + <span class="hljs-keyword">for</span> (<span class="hljs-keyword">var</span> key <span class="hljs-keyword">in</span> obj) { + <span class="hljs-keyword">if</span> (_.isFunction(obj[key])) names.push(key); + } + <span class="hljs-keyword">return</span> names.sort(); + };</pre></div></div> + + </li> + + + <li id="section-84"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-84">¶</a> + </div> + <p>Extend a given object with all the properties in passed-in object(s).</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.extend = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(obj)</span> {</span> + each(slice.call(<span class="hljs-built_in">arguments</span>, <span class="hljs-number">1</span>), <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(source)</span> {</span> + <span class="hljs-keyword">if</span> (source) { + <span class="hljs-keyword">for</span> (<span class="hljs-keyword">var</span> prop <span class="hljs-keyword">in</span> source) { + obj[prop] = source[prop]; + } + } + }); + <span class="hljs-keyword">return</span> obj; + };</pre></div></div> + + </li> + + + <li id="section-85"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-85">¶</a> + </div> + <p>Return a copy of the object only containing the whitelisted properties.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.pick = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(obj)</span> {</span> + <span class="hljs-keyword">var</span> copy = {}; + <span class="hljs-keyword">var</span> keys = concat.apply(ArrayProto, slice.call(<span class="hljs-built_in">arguments</span>, <span class="hljs-number">1</span>)); + each(keys, <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(key)</span> {</span> + <span class="hljs-keyword">if</span> (key <span class="hljs-keyword">in</span> obj) copy[key] = obj[key]; + }); + <span class="hljs-keyword">return</span> copy; + };</pre></div></div> + + </li> + + + <li id="section-86"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-86">¶</a> + </div> + <p>Return a copy of the object without the blacklisted properties.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.omit = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(obj)</span> {</span> + <span class="hljs-keyword">var</span> copy = {}; + <span class="hljs-keyword">var</span> keys = concat.apply(ArrayProto, slice.call(<span class="hljs-built_in">arguments</span>, <span class="hljs-number">1</span>)); + <span class="hljs-keyword">for</span> (<span class="hljs-keyword">var</span> key <span class="hljs-keyword">in</span> obj) { + <span class="hljs-keyword">if</span> (!_.contains(keys, key)) copy[key] = obj[key]; + } + <span class="hljs-keyword">return</span> copy; + };</pre></div></div> + + </li> + + + <li id="section-87"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-87">¶</a> + </div> + <p>Fill in a given object with default properties.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.defaults = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(obj)</span> {</span> + each(slice.call(<span class="hljs-built_in">arguments</span>, <span class="hljs-number">1</span>), <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(source)</span> {</span> + <span class="hljs-keyword">if</span> (source) { + <span class="hljs-keyword">for</span> (<span class="hljs-keyword">var</span> prop <span class="hljs-keyword">in</span> source) { + <span class="hljs-keyword">if</span> (obj[prop] === <span class="hljs-keyword">void</span> <span class="hljs-number">0</span>) obj[prop] = source[prop]; + } + } + }); + <span class="hljs-keyword">return</span> obj; + };</pre></div></div> + + </li> + + + <li id="section-88"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-88">¶</a> + </div> + <p>Create a (shallow-cloned) duplicate of an object.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.clone = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(obj)</span> {</span> + <span class="hljs-keyword">if</span> (!_.isObject(obj)) <span class="hljs-keyword">return</span> obj; + <span class="hljs-keyword">return</span> _.isArray(obj) ? obj.slice() : _.extend({}, obj); + };</pre></div></div> + + </li> + + + <li id="section-89"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-89">¶</a> + </div> + <p>Invokes interceptor with the obj, and then returns obj. +The primary purpose of this method is to “tap into” a method chain, in +order to perform operations on intermediate results within the chain.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.tap = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(obj, interceptor)</span> {</span> + interceptor(obj); + <span class="hljs-keyword">return</span> obj; + };</pre></div></div> + + </li> + + + <li id="section-90"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-90">¶</a> + </div> + <p>Internal recursive comparison function for <code>isEqual</code>.</p> + + </div> + + <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">var</span> eq = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(a, b, aStack, bStack)</span> {</span></pre></div></div> + + </li> + + + <li id="section-91"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-91">¶</a> + </div> + <p>Identical objects are equal. <code>0 === -0</code>, but they aren’t identical. +See the <a href="http://wiki.ecmascript.org/doku.php?id=harmony:egal">Harmony <code>egal</code> proposal</a>.</p> + + </div> + + <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">if</span> (a === b) <span class="hljs-keyword">return</span> a !== <span class="hljs-number">0</span> || <span class="hljs-number">1</span> / a == <span class="hljs-number">1</span> / b;</pre></div></div> + + </li> + + + <li id="section-92"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-92">¶</a> + </div> + <p>A strict comparison is necessary because <code>null == undefined</code>.</p> + + </div> + + <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">if</span> (a == <span class="hljs-literal">null</span> || b == <span class="hljs-literal">null</span>) <span class="hljs-keyword">return</span> a === b;</pre></div></div> + + </li> + + + <li id="section-93"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-93">¶</a> + </div> + <p>Unwrap any wrapped objects.</p> + + </div> + + <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">if</span> (a <span class="hljs-keyword">instanceof</span> _) a = a._wrapped; + <span class="hljs-keyword">if</span> (b <span class="hljs-keyword">instanceof</span> _) b = b._wrapped;</pre></div></div> + + </li> + + + <li id="section-94"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-94">¶</a> + </div> + <p>Compare <code>[[Class]]</code> names.</p> + + </div> + + <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">var</span> className = toString.call(a); + <span class="hljs-keyword">if</span> (className != toString.call(b)) <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>; + <span class="hljs-keyword">switch</span> (className) {</pre></div></div> + + </li> + + + <li id="section-95"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-95">¶</a> + </div> + <p>Strings, numbers, dates, and booleans are compared by value.</p> + + </div> + + <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">case</span> <span class="hljs-string">'[object String]'</span>:</pre></div></div> + + </li> + + + <li id="section-96"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-96">¶</a> + </div> + <p>Primitives and their corresponding object wrappers are equivalent; thus, <code>"5"</code> is +equivalent to <code>new String("5")</code>.</p> + + </div> + + <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">return</span> a == <span class="hljs-built_in">String</span>(b); + <span class="hljs-keyword">case</span> <span class="hljs-string">'[object Number]'</span>:</pre></div></div> + + </li> + + + <li id="section-97"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-97">¶</a> + </div> + <p><code>NaN</code>s are equivalent, but non-reflexive. An <code>egal</code> comparison is performed for +other numeric values.</p> + + </div> + + <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">return</span> a != +a ? b != +b : (a == <span class="hljs-number">0</span> ? <span class="hljs-number">1</span> / a == <span class="hljs-number">1</span> / b : a == +b); + <span class="hljs-keyword">case</span> <span class="hljs-string">'[object Date]'</span>: + <span class="hljs-keyword">case</span> <span class="hljs-string">'[object Boolean]'</span>:</pre></div></div> + + </li> + + + <li id="section-98"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-98">¶</a> + </div> + <p>Coerce dates and booleans to numeric primitive values. Dates are compared by their +millisecond representations. Note that invalid dates with millisecond representations +of <code>NaN</code> are not equivalent.</p> + + </div> + + <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">return</span> +a == +b;</pre></div></div> + + </li> + + + <li id="section-99"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-99">¶</a> + </div> + <p>RegExps are compared by their source patterns and flags.</p> + + </div> + + <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">case</span> <span class="hljs-string">'[object RegExp]'</span>: + <span class="hljs-keyword">return</span> a.source == b.source && + a.global == b.global && + a.multiline == b.multiline && + a.ignoreCase == b.ignoreCase; + } + <span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> a != <span class="hljs-string">'object'</span> || <span class="hljs-keyword">typeof</span> b != <span class="hljs-string">'object'</span>) <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;</pre></div></div> + + </li> + + + <li id="section-100"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-100">¶</a> + </div> + <p>Assume equality for cyclic structures. The algorithm for detecting cyclic +structures is adapted from ES 5.1 section 15.12.3, abstract operation <code>JO</code>.</p> + + </div> + + <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">var</span> length = aStack.length; + <span class="hljs-keyword">while</span> (length--) {</pre></div></div> + + </li> + + + <li id="section-101"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-101">¶</a> + </div> + <p>Linear search. Performance is inversely proportional to the number of +unique nested structures.</p> + + </div> + + <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">if</span> (aStack[length] == a) <span class="hljs-keyword">return</span> bStack[length] == b; + }</pre></div></div> + + </li> + + + <li id="section-102"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-102">¶</a> + </div> + <p>Objects with different constructors are not equivalent, but <code>Object</code>s +from different frames are.</p> + + </div> + + <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">var</span> aCtor = a.constructor, bCtor = b.constructor; + <span class="hljs-keyword">if</span> (aCtor !== bCtor && !(_.isFunction(aCtor) && (aCtor <span class="hljs-keyword">instanceof</span> aCtor) && + _.isFunction(bCtor) && (bCtor <span class="hljs-keyword">instanceof</span> bCtor)) + && (<span class="hljs-string">'constructor'</span> <span class="hljs-keyword">in</span> a && <span class="hljs-string">'constructor'</span> <span class="hljs-keyword">in</span> b)) { + <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>; + }</pre></div></div> + + </li> + + + <li id="section-103"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-103">¶</a> + </div> + <p>Add the first object to the stack of traversed objects.</p> + + </div> + + <div class="content"><div class='highlight'><pre> aStack.push(a); + bStack.push(b); + <span class="hljs-keyword">var</span> size = <span class="hljs-number">0</span>, result = <span class="hljs-literal">true</span>;</pre></div></div> + + </li> + + + <li id="section-104"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-104">¶</a> + </div> + <p>Recursively compare objects and arrays.</p> + + </div> + + <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">if</span> (className == <span class="hljs-string">'[object Array]'</span>) {</pre></div></div> + + </li> + + + <li id="section-105"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-105">¶</a> + </div> + <p>Compare array lengths to determine if a deep comparison is necessary.</p> + + </div> + + <div class="content"><div class='highlight'><pre> size = a.length; + result = size == b.length; + <span class="hljs-keyword">if</span> (result) {</pre></div></div> + + </li> + + + <li id="section-106"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-106">¶</a> + </div> + <p>Deep compare the contents, ignoring non-numeric properties.</p> + + </div> + + <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">while</span> (size--) { + <span class="hljs-keyword">if</span> (!(result = eq(a[size], b[size], aStack, bStack))) <span class="hljs-keyword">break</span>; + } + } + } <span class="hljs-keyword">else</span> {</pre></div></div> + + </li> + + + <li id="section-107"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-107">¶</a> + </div> + <p>Deep compare objects.</p> + + </div> + + <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">for</span> (<span class="hljs-keyword">var</span> key <span class="hljs-keyword">in</span> a) { + <span class="hljs-keyword">if</span> (_.has(a, key)) {</pre></div></div> + + </li> + + + <li id="section-108"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-108">¶</a> + </div> + <p>Count the expected number of properties.</p> + + </div> + + <div class="content"><div class='highlight'><pre> size++;</pre></div></div> + + </li> + + + <li id="section-109"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-109">¶</a> + </div> + <p>Deep compare each member.</p> + + </div> + + <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">if</span> (!(result = _.has(b, key) && eq(a[key], b[key], aStack, bStack))) <span class="hljs-keyword">break</span>; + } + }</pre></div></div> + + </li> + + + <li id="section-110"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-110">¶</a> + </div> + <p>Ensure that both objects contain the same number of properties.</p> + + </div> + + <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">if</span> (result) { + <span class="hljs-keyword">for</span> (key <span class="hljs-keyword">in</span> b) { + <span class="hljs-keyword">if</span> (_.has(b, key) && !(size--)) <span class="hljs-keyword">break</span>; + } + result = !size; + } + }</pre></div></div> + + </li> + + + <li id="section-111"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-111">¶</a> + </div> + <p>Remove the first object from the stack of traversed objects.</p> + + </div> + + <div class="content"><div class='highlight'><pre> aStack.pop(); + bStack.pop(); + <span class="hljs-keyword">return</span> result; + };</pre></div></div> + + </li> + + + <li id="section-112"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-112">¶</a> + </div> + <p>Perform a deep comparison to check if two objects are equal.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.isEqual = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(a, b)</span> {</span> + <span class="hljs-keyword">return</span> eq(a, b, [], []); + };</pre></div></div> + + </li> + + + <li id="section-113"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-113">¶</a> + </div> + <p>Is a given array, string, or object empty? +An “empty” object has no enumerable own-properties.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.isEmpty = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(obj)</span> {</span> + <span class="hljs-keyword">if</span> (obj == <span class="hljs-literal">null</span>) <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>; + <span class="hljs-keyword">if</span> (_.isArray(obj) || _.isString(obj)) <span class="hljs-keyword">return</span> obj.length === <span class="hljs-number">0</span>; + <span class="hljs-keyword">for</span> (<span class="hljs-keyword">var</span> key <span class="hljs-keyword">in</span> obj) <span class="hljs-keyword">if</span> (_.has(obj, key)) <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>; + <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>; + };</pre></div></div> + + </li> + + + <li id="section-114"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-114">¶</a> + </div> + <p>Is a given value a DOM element?</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.isElement = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(obj)</span> {</span> + <span class="hljs-keyword">return</span> !!(obj && obj.nodeType === <span class="hljs-number">1</span>); + };</pre></div></div> + + </li> + + + <li id="section-115"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-115">¶</a> + </div> + <p>Is a given value an array? +Delegates to ECMA5’s native Array.isArray</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.isArray = nativeIsArray || <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(obj)</span> {</span> + <span class="hljs-keyword">return</span> toString.call(obj) == <span class="hljs-string">'[object Array]'</span>; + };</pre></div></div> + + </li> + + + <li id="section-116"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-116">¶</a> + </div> + <p>Is a given variable an object?</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.isObject = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(obj)</span> {</span> + <span class="hljs-keyword">return</span> obj === <span class="hljs-built_in">Object</span>(obj); + };</pre></div></div> + + </li> + + + <li id="section-117"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-117">¶</a> + </div> + <p>Add some isType methods: isArguments, isFunction, isString, isNumber, isDate, isRegExp.</p> + + </div> + + <div class="content"><div class='highlight'><pre> each([<span class="hljs-string">'Arguments'</span>, <span class="hljs-string">'Function'</span>, <span class="hljs-string">'String'</span>, <span class="hljs-string">'Number'</span>, <span class="hljs-string">'Date'</span>, <span class="hljs-string">'RegExp'</span>], <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(name)</span> {</span> + _[<span class="hljs-string">'is'</span> + name] = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(obj)</span> {</span> + <span class="hljs-keyword">return</span> toString.call(obj) == <span class="hljs-string">'[object '</span> + name + <span class="hljs-string">']'</span>; + }; + });</pre></div></div> + + </li> + + + <li id="section-118"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-118">¶</a> + </div> + <p>Define a fallback version of the method in browsers (ahem, IE), where +there isn’t any inspectable “Arguments” type.</p> + + </div> + + <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">if</span> (!_.isArguments(<span class="hljs-built_in">arguments</span>)) { + _.isArguments = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(obj)</span> {</span> + <span class="hljs-keyword">return</span> !!(obj && _.has(obj, <span class="hljs-string">'callee'</span>)); + }; + }</pre></div></div> + + </li> + + + <li id="section-119"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-119">¶</a> + </div> + <p>Optimize <code>isFunction</code> if appropriate.</p> + + </div> + + <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> (<span class="hljs-regexp">/./</span>) !== <span class="hljs-string">'function'</span>) { + _.isFunction = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(obj)</span> {</span> + <span class="hljs-keyword">return</span> <span class="hljs-keyword">typeof</span> obj === <span class="hljs-string">'function'</span>; + }; + }</pre></div></div> + + </li> + + + <li id="section-120"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-120">¶</a> + </div> + <p>Is a given object a finite number?</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.isFinite = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(obj)</span> {</span> + <span class="hljs-keyword">return</span> <span class="hljs-built_in">isFinite</span>(obj) && !<span class="hljs-built_in">isNaN</span>(<span class="hljs-built_in">parseFloat</span>(obj)); + };</pre></div></div> + + </li> + + + <li id="section-121"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-121">¶</a> + </div> + <p>Is the given value <code>NaN</code>? (NaN is the only number which does not equal itself).</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.isNaN = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(obj)</span> {</span> + <span class="hljs-keyword">return</span> _.isNumber(obj) && obj != +obj; + };</pre></div></div> + + </li> + + + <li id="section-122"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-122">¶</a> + </div> + <p>Is a given value a boolean?</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.isBoolean = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(obj)</span> {</span> + <span class="hljs-keyword">return</span> obj === <span class="hljs-literal">true</span> || obj === <span class="hljs-literal">false</span> || toString.call(obj) == <span class="hljs-string">'[object Boolean]'</span>; + };</pre></div></div> + + </li> + + + <li id="section-123"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-123">¶</a> + </div> + <p>Is a given value equal to null?</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.isNull = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(obj)</span> {</span> + <span class="hljs-keyword">return</span> obj === <span class="hljs-literal">null</span>; + };</pre></div></div> + + </li> + + + <li id="section-124"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-124">¶</a> + </div> + <p>Is a given variable undefined?</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.isUndefined = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(obj)</span> {</span> + <span class="hljs-keyword">return</span> obj === <span class="hljs-keyword">void</span> <span class="hljs-number">0</span>; + };</pre></div></div> + + </li> + + + <li id="section-125"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-125">¶</a> + </div> + <p>Shortcut function for checking if an object has a given property directly +on itself (in other words, not on a prototype).</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.has = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(obj, key)</span> {</span> + <span class="hljs-keyword">return</span> hasOwnProperty.call(obj, key); + };</pre></div></div> + + </li> + + + <li id="section-126"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-126">¶</a> + </div> + <h2 id="utility-functions">Utility Functions</h2> + + </div> + + </li> + + + <li id="section-127"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-127">¶</a> + </div> + + </div> + + </li> + + + <li id="section-128"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-128">¶</a> + </div> + <p>Run Underscore.js in <em>noConflict</em> mode, returning the <code>_</code> variable to its +previous owner. Returns a reference to the Underscore object.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.noConflict = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> {</span> + root._ = previousUnderscore; + <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>; + };</pre></div></div> + + </li> + + + <li id="section-129"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-129">¶</a> + </div> + <p>Keep the identity function around for default iterators.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.identity = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(value)</span> {</span> + <span class="hljs-keyword">return</span> value; + }; + + _.constant = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(value)</span> {</span> + <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-params">()</span> {</span> + <span class="hljs-keyword">return</span> value; + }; + }; + + _.property = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(key)</span> {</span> + <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(obj)</span> {</span> + <span class="hljs-keyword">return</span> obj[key]; + }; + };</pre></div></div> + + </li> + + + <li id="section-130"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-130">¶</a> + </div> + <p>Returns a predicate for checking whether an object has a given set of <code>key:value</code> pairs.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.matches = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(attrs)</span> {</span> + <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(obj)</span> {</span> + <span class="hljs-keyword">if</span> (obj === attrs) <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>; <span class="hljs-comment">//avoid comparing an object to itself.</span> + <span class="hljs-keyword">for</span> (<span class="hljs-keyword">var</span> key <span class="hljs-keyword">in</span> attrs) { + <span class="hljs-keyword">if</span> (attrs[key] !== obj[key]) + <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>; + } + <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>; + } + };</pre></div></div> + + </li> + + + <li id="section-131"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-131">¶</a> + </div> + <p>Run a function <strong>n</strong> times.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.times = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(n, iterator, context)</span> {</span> + <span class="hljs-keyword">var</span> accum = <span class="hljs-built_in">Array</span>(<span class="hljs-built_in">Math</span>.max(<span class="hljs-number">0</span>, n)); + <span class="hljs-keyword">for</span> (<span class="hljs-keyword">var</span> i = <span class="hljs-number">0</span>; i < n; i++) accum[i] = iterator.call(context, i); + <span class="hljs-keyword">return</span> accum; + };</pre></div></div> + + </li> + + + <li id="section-132"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-132">¶</a> + </div> + <p>Return a random integer between min and max (inclusive).</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.random = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(min, max)</span> {</span> + <span class="hljs-keyword">if</span> (max == <span class="hljs-literal">null</span>) { + max = min; + min = <span class="hljs-number">0</span>; + } + <span class="hljs-keyword">return</span> min + <span class="hljs-built_in">Math</span>.floor(<span class="hljs-built_in">Math</span>.random() * (max - min + <span class="hljs-number">1</span>)); + };</pre></div></div> + + </li> + + + <li id="section-133"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-133">¶</a> + </div> + <p>A (possibly faster) way to get the current timestamp as an integer.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.now = <span class="hljs-built_in">Date</span>.now || <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> {</span> <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>().getTime(); };</pre></div></div> + + </li> + + + <li id="section-134"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-134">¶</a> + </div> + <p>List of HTML entities for escaping.</p> + + </div> + + <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">var</span> entityMap = { + <span class="hljs-built_in">escape</span>: { + <span class="hljs-string">'&'</span>: <span class="hljs-string">'&amp;'</span>, + <span class="hljs-string">'<'</span>: <span class="hljs-string">'&lt;'</span>, + <span class="hljs-string">'>'</span>: <span class="hljs-string">'&gt;'</span>, + <span class="hljs-string">'"'</span>: <span class="hljs-string">'&quot;'</span>, + <span class="hljs-string">"'"</span>: <span class="hljs-string">'&#x27;'</span> + } + }; + entityMap.unescape = _.invert(entityMap.escape);</pre></div></div> + + </li> + + + <li id="section-135"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-135">¶</a> + </div> + <p>Regexes containing the keys and values listed immediately above.</p> + + </div> + + <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">var</span> entityRegexes = { + <span class="hljs-built_in">escape</span>: <span class="hljs-keyword">new</span> <span class="hljs-built_in">RegExp</span>(<span class="hljs-string">'['</span> + _.keys(entityMap.escape).join(<span class="hljs-string">''</span>) + <span class="hljs-string">']'</span>, <span class="hljs-string">'g'</span>), + <span class="hljs-built_in">unescape</span>: <span class="hljs-keyword">new</span> <span class="hljs-built_in">RegExp</span>(<span class="hljs-string">'('</span> + _.keys(entityMap.unescape).join(<span class="hljs-string">'|'</span>) + <span class="hljs-string">')'</span>, <span class="hljs-string">'g'</span>) + };</pre></div></div> + + </li> + + + <li id="section-136"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-136">¶</a> + </div> + <p>Functions for escaping and unescaping strings to/from HTML interpolation.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.each([<span class="hljs-string">'escape'</span>, <span class="hljs-string">'unescape'</span>], <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(method)</span> {</span> + _[method] = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(string)</span> {</span> + <span class="hljs-keyword">if</span> (string == <span class="hljs-literal">null</span>) <span class="hljs-keyword">return</span> <span class="hljs-string">''</span>; + <span class="hljs-keyword">return</span> (<span class="hljs-string">''</span> + string).replace(entityRegexes[method], <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(match)</span> {</span> + <span class="hljs-keyword">return</span> entityMap[method][match]; + }); + }; + });</pre></div></div> + + </li> + + + <li id="section-137"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-137">¶</a> + </div> + <p>If the value of the named <code>property</code> is a function then invoke it with the +<code>object</code> as context; otherwise, return it.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.result = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(object, property)</span> {</span> + <span class="hljs-keyword">if</span> (object == <span class="hljs-literal">null</span>) <span class="hljs-keyword">return</span> <span class="hljs-keyword">void</span> <span class="hljs-number">0</span>; + <span class="hljs-keyword">var</span> value = object[property]; + <span class="hljs-keyword">return</span> _.isFunction(value) ? value.call(object) : value; + };</pre></div></div> + + </li> + + + <li id="section-138"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-138">¶</a> + </div> + <p>Add your own custom functions to the Underscore object.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.mixin = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(obj)</span> {</span> + each(_.functions(obj), <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(name)</span> {</span> + <span class="hljs-keyword">var</span> func = _[name] = obj[name]; + _.prototype[name] = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> {</span> + <span class="hljs-keyword">var</span> args = [<span class="hljs-keyword">this</span>._wrapped]; + push.apply(args, <span class="hljs-built_in">arguments</span>); + <span class="hljs-keyword">return</span> result.call(<span class="hljs-keyword">this</span>, func.apply(_, args)); + }; + }); + };</pre></div></div> + + </li> + + + <li id="section-139"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-139">¶</a> + </div> + <p>Generate a unique integer id (unique within the entire client session). +Useful for temporary DOM ids.</p> + + </div> + + <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">var</span> idCounter = <span class="hljs-number">0</span>; + _.uniqueId = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(prefix)</span> {</span> + <span class="hljs-keyword">var</span> id = ++idCounter + <span class="hljs-string">''</span>; + <span class="hljs-keyword">return</span> prefix ? prefix + id : id; + };</pre></div></div> + + </li> + + + <li id="section-140"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-140">¶</a> + </div> + <p>By default, Underscore uses ERB-style template delimiters, change the +following template settings to use alternative delimiters.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.templateSettings = { + evaluate : <span class="hljs-regexp">/<%([\s\S]+?)%>/g</span>, + interpolate : <span class="hljs-regexp">/<%=([\s\S]+?)%>/g</span>, + <span class="hljs-built_in">escape</span> : <span class="hljs-regexp">/<%-([\s\S]+?)%>/g</span> + };</pre></div></div> + + </li> + + + <li id="section-141"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-141">¶</a> + </div> + <p>When customizing <code>templateSettings</code>, if you don’t want to define an +interpolation, evaluation or escaping regex, we need one that is +guaranteed not to match.</p> + + </div> + + <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">var</span> noMatch = <span class="hljs-regexp">/(.)^/</span>;</pre></div></div> + + </li> + + + <li id="section-142"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-142">¶</a> + </div> + <p>Certain characters need to be escaped so that they can be put into a +string literal.</p> + + </div> + + <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">var</span> escapes = { + <span class="hljs-string">"'"</span>: <span class="hljs-string">"'"</span>, + <span class="hljs-string">'\\'</span>: <span class="hljs-string">'\\'</span>, + <span class="hljs-string">'\r'</span>: <span class="hljs-string">'r'</span>, + <span class="hljs-string">'\n'</span>: <span class="hljs-string">'n'</span>, + <span class="hljs-string">'\t'</span>: <span class="hljs-string">'t'</span>, + <span class="hljs-string">'\u2028'</span>: <span class="hljs-string">'u2028'</span>, + <span class="hljs-string">'\u2029'</span>: <span class="hljs-string">'u2029'</span> + }; + + <span class="hljs-keyword">var</span> escaper = <span class="hljs-regexp">/\\|'|\r|\n|\t|\u2028|\u2029/g</span>;</pre></div></div> + + </li> + + + <li id="section-143"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-143">¶</a> + </div> + <p>JavaScript micro-templating, similar to John Resig’s implementation. +Underscore templating handles arbitrary delimiters, preserves whitespace, +and correctly escapes quotes within interpolated code.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.template = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(text, data, settings)</span> {</span> + <span class="hljs-keyword">var</span> render; + settings = _.defaults({}, settings, _.templateSettings);</pre></div></div> + + </li> + + + <li id="section-144"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-144">¶</a> + </div> + <p>Combine delimiters into one regular expression via alternation.</p> + + </div> + + <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">var</span> matcher = <span class="hljs-keyword">new</span> <span class="hljs-built_in">RegExp</span>([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join(<span class="hljs-string">'|'</span>) + <span class="hljs-string">'|$'</span>, <span class="hljs-string">'g'</span>);</pre></div></div> + + </li> + + + <li id="section-145"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-145">¶</a> + </div> + <p>Compile the template source, escaping string literals appropriately.</p> + + </div> + + <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">var</span> index = <span class="hljs-number">0</span>; + <span class="hljs-keyword">var</span> source = <span class="hljs-string">"__p+='"</span>; + text.replace(matcher, <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(match, escape, interpolate, evaluate, offset)</span> {</span> + source += text.slice(index, offset) + .replace(escaper, <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(match)</span> {</span> <span class="hljs-keyword">return</span> <span class="hljs-string">'\\'</span> + escapes[match]; }); + + <span class="hljs-keyword">if</span> (<span class="hljs-built_in">escape</span>) { + source += <span class="hljs-string">"'+\n((__t=("</span> + <span class="hljs-built_in">escape</span> + <span class="hljs-string">"))==null?'':_.escape(__t))+\n'"</span>; + } + <span class="hljs-keyword">if</span> (interpolate) { + source += <span class="hljs-string">"'+\n((__t=("</span> + interpolate + <span class="hljs-string">"))==null?'':__t)+\n'"</span>; + } + <span class="hljs-keyword">if</span> (evaluate) { + source += <span class="hljs-string">"';\n"</span> + evaluate + <span class="hljs-string">"\n__p+='"</span>; + } + index = offset + match.length; + <span class="hljs-keyword">return</span> match; + }); + source += <span class="hljs-string">"';\n"</span>;</pre></div></div> + + </li> + + + <li id="section-146"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-146">¶</a> + </div> + <p>If a variable is not specified, place data values in local scope.</p> + + </div> + + <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">if</span> (!settings.variable) source = <span class="hljs-string">'with(obj||{}){\n'</span> + source + <span class="hljs-string">'}\n'</span>; + + source = <span class="hljs-string">"var __t,__p='',__j=Array.prototype.join,"</span> + + <span class="hljs-string">"print=function(){__p+=__j.call(arguments,'');};\n"</span> + + source + <span class="hljs-string">"return __p;\n"</span>; + + <span class="hljs-keyword">try</span> { + render = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Function</span>(settings.variable || <span class="hljs-string">'obj'</span>, <span class="hljs-string">'_'</span>, source); + } <span class="hljs-keyword">catch</span> (e) { + e.source = source; + <span class="hljs-keyword">throw</span> e; + } + + <span class="hljs-keyword">if</span> (data) <span class="hljs-keyword">return</span> render(data, _); + <span class="hljs-keyword">var</span> template = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(data)</span> {</span> + <span class="hljs-keyword">return</span> render.call(<span class="hljs-keyword">this</span>, data, _); + };</pre></div></div> + + </li> + + + <li id="section-147"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-147">¶</a> + </div> + <p>Provide the compiled function source as a convenience for precompilation.</p> + + </div> + + <div class="content"><div class='highlight'><pre> template.source = <span class="hljs-string">'function('</span> + (settings.variable || <span class="hljs-string">'obj'</span>) + <span class="hljs-string">'){\n'</span> + source + <span class="hljs-string">'}'</span>; + + <span class="hljs-keyword">return</span> template; + };</pre></div></div> + + </li> + + + <li id="section-148"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-148">¶</a> + </div> + <p>Add a “chain” function, which will delegate to the wrapper.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.chain = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(obj)</span> {</span> + <span class="hljs-keyword">return</span> _(obj).chain(); + };</pre></div></div> + + </li> + + + <li id="section-149"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-149">¶</a> + </div> + <h2 id="oop">OOP</h2> + + </div> + + </li> + + + <li id="section-150"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-150">¶</a> + </div> + <p>If Underscore is called as a function, it returns a wrapped object that +can be used OO-style. This wrapper holds altered versions of all the +underscore functions. Wrapped objects may be chained.</p> + + </div> + + </li> + + + <li id="section-151"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-151">¶</a> + </div> + <p>Helper function to continue chaining intermediate results.</p> + + </div> + + <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">var</span> result = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(obj)</span> {</span> + <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>._chain ? _(obj).chain() : obj; + };</pre></div></div> + + </li> + + + <li id="section-152"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-152">¶</a> + </div> + <p>Add all of the Underscore functions to the wrapper object.</p> + + </div> + + <div class="content"><div class='highlight'><pre> _.mixin(_);</pre></div></div> + + </li> + + + <li id="section-153"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-153">¶</a> + </div> + <p>Add all mutator Array functions to the wrapper.</p> + + </div> + + <div class="content"><div class='highlight'><pre> each([<span class="hljs-string">'pop'</span>, <span class="hljs-string">'push'</span>, <span class="hljs-string">'reverse'</span>, <span class="hljs-string">'shift'</span>, <span class="hljs-string">'sort'</span>, <span class="hljs-string">'splice'</span>, <span class="hljs-string">'unshift'</span>], <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(name)</span> {</span> + <span class="hljs-keyword">var</span> method = ArrayProto[name]; + _.prototype[name] = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> {</span> + <span class="hljs-keyword">var</span> obj = <span class="hljs-keyword">this</span>._wrapped; + method.apply(obj, <span class="hljs-built_in">arguments</span>); + <span class="hljs-keyword">if</span> ((name == <span class="hljs-string">'shift'</span> || name == <span class="hljs-string">'splice'</span>) && obj.length === <span class="hljs-number">0</span>) <span class="hljs-keyword">delete</span> obj[<span class="hljs-number">0</span>]; + <span class="hljs-keyword">return</span> result.call(<span class="hljs-keyword">this</span>, obj); + }; + });</pre></div></div> + + </li> + + + <li id="section-154"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-154">¶</a> + </div> + <p>Add all accessor Array functions to the wrapper.</p> + + </div> + + <div class="content"><div class='highlight'><pre> each([<span class="hljs-string">'concat'</span>, <span class="hljs-string">'join'</span>, <span class="hljs-string">'slice'</span>], <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(name)</span> {</span> + <span class="hljs-keyword">var</span> method = ArrayProto[name]; + _.prototype[name] = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> {</span> + <span class="hljs-keyword">return</span> result.call(<span class="hljs-keyword">this</span>, method.apply(<span class="hljs-keyword">this</span>._wrapped, <span class="hljs-built_in">arguments</span>)); + }; + }); + + _.extend(_.prototype, {</pre></div></div> + + </li> + + + <li id="section-155"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-155">¶</a> + </div> + <p>Start chaining a wrapped Underscore object.</p> + + </div> + + <div class="content"><div class='highlight'><pre> chain: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> {</span> + <span class="hljs-keyword">this</span>._chain = <span class="hljs-literal">true</span>; + <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>; + },</pre></div></div> + + </li> + + + <li id="section-156"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-156">¶</a> + </div> + <p>Extracts the result from a wrapped and chained object.</p> + + </div> + + <div class="content"><div class='highlight'><pre> value: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> {</span> + <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>._wrapped; + } + + });</pre></div></div> + + </li> + + + <li id="section-157"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-157">¶</a> + </div> + <p>AMD registration happens at the end for compatibility with AMD loaders +that may not enforce next-turn semantics on modules. Even though general +practice for AMD registration is to be anonymous, underscore registers +as a named module because, like jQuery, it is a base library that is +popular enough to be bundled in a third party lib, but not be part of +an AMD load request. Those cases could generate an error when an +anonymous define() is called outside of a loader request.</p> + + </div> + + <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> define === <span class="hljs-string">'function'</span> && define.amd) { + define(<span class="hljs-string">'underscore'</span>, [], <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> {</span> + <span class="hljs-keyword">return</span> _; + }); + } +}).call(<span class="hljs-keyword">this</span>);</pre></div></div> + + </li> + + </ul> + </div> +</body> +</html> diff --git a/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/favicon.ico b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/favicon.ico Binary files differnew file mode 100644 index 000000000..030496838 --- /dev/null +++ b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/favicon.ico diff --git a/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/index.html b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/index.html new file mode 100644 index 000000000..785750f3e --- /dev/null +++ b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/index.html @@ -0,0 +1,2777 @@ +<!DOCTYPE HTML> +<html> +<head> + <meta http-equiv="content-type" content="text/html;charset=UTF-8" /> + <meta http-equiv="X-UA-Compatible" content="chrome=1" /> + <meta name="viewport" content="width=device-width, initial-scale=1.0"/> + <meta name="viewport" content="target-densitydpi=device-dpi" /> + <meta name="HandheldFriendly" content="true"/> + <link rel="canonical" href="http://underscorejs.org/" /> + <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" /> + <title>Underscore.js</title> + <style> + body { + font-size: 14px; + line-height: 22px; + background: #f4f4f4 url(docs/images/background.png); + color: #000; + font-family: Helvetica Neue, Helvetica, Arial; + } + .interface { + font-family: "Lucida Grande", "Lucida Sans Unicode", Helvetica, Arial, sans-serif !important; + } + div#sidebar { + background: #fff; + position: fixed; + top: 0; left: 0; bottom: 0; + width: 200px; + overflow-y: auto; + overflow-x: hidden; + -webkit-overflow-scrolling: touch; + padding: 15px 0 30px 30px; + border-right: 1px solid #bbb; + box-shadow: 0 0 20px #ccc; -webkit-box-shadow: 0 0 20px #ccc; -moz-box-shadow: 0 0 20px #ccc; + } + a.toc_title, a.toc_title:visited { + display: block; + color: black; + font-weight: bold; + margin-top: 15px; + } + a.toc_title:hover { + text-decoration: underline; + } + #sidebar .version { + font-size: 10px; + font-weight: normal; + } + ul.toc_section { + font-size: 11px; + line-height: 14px; + margin: 5px 0 0 0; + padding-left: 0px; + list-style-type: none; + font-family: Lucida Grande; + } + .toc_section li { + cursor: pointer; + margin: 0 0 3px 0; + } + .toc_section li a { + text-decoration: none; + color: black; + } + .toc_section li a:hover { + text-decoration: underline; + } + div.container { + width: 550px; + margin: 40px 0 50px 260px; + } + img#logo { + width: 396px; + height: 69px; + } + div.warning { + margin-top: 15px; + font: bold 11px Arial; + color: #770000; + } + p { + margin: 20px 0; + width: 550px; + } + a, a:visited { + color: #444; + } + a:active, a:hover { + color: #000; + } + h1, h2, h3, h4, h5, h6 { + padding-top: 20px; + } + h2 { + font-size: 20px; + } + b.header { + font-size: 16px; + line-height: 30px; + } + span.alias { + font-size: 14px; + font-style: italic; + margin-left: 20px; + } + table, tr, td { + margin: 0; padding: 0; + } + td { + padding: 2px 12px 2px 0; + } + table .rule { + height: 1px; + background: #ccc; + margin: 5px 0; + } + ul { + list-style-type: circle; + padding: 0 0 0 20px; + } + li { + margin-bottom: 10px; + } + code, pre, tt { + font-family: Monaco, Consolas, "Lucida Console", monospace; + font-size: 12px; + line-height: 18px; + font-style: normal; + } + tt { + padding: 0px 3px; + background: #fff; + border: 1px solid #ddd; + zoom: 1; + } + code { + margin-left: 20px; + } + pre { + font-size: 12px; + padding: 2px 0 2px 15px; + border-left: 5px solid #bbb; + margin: 0px 0 30px; + } + @media only screen and (-webkit-min-device-pixel-ratio: 1.5) and (max-width: 640px), + only screen and (-o-min-device-pixel-ratio: 3/2) and (max-width: 640px), + only screen and (min-device-pixel-ratio: 1.5) and (max-width: 640px) { + img { + max-width: 100%; + } + div#sidebar { + -webkit-overflow-scrolling: initial; + position: relative; + width: 90%; + height: 120px; + left: 0; + top: -7px; + padding: 10px 0 10px 30px; + border: 0; + } + img#logo { + width: auto; + height: auto; + } + div.container { + margin: 0; + width: 100%; + } + p, div.container ul { + max-width: 98%; + overflow-x: scroll; + } + pre { + overflow: scroll; + } + } + </style> +</head> +<body> + + <div id="sidebar" class="interface"> + + <a class="toc_title" href="#"> + Underscore.js <span class="version">(1.6.0)</span> + </a> + <ul class="toc_section"> + <li>» <a href="https://github.com/jashkenas/underscore">GitHub Repository</a></li> + <li>» <a href="docs/underscore.html">Annotated Source</a></li> + <li>» <a href="http://documentcloud.github.io/underscore-contrib/">Underscore-contrib</a></li> + </ul> + + <a class="toc_title" href="#"> + Introduction + </a> + + <a class="toc_title" href="#collections"> + Collections + </a> + <ul class="toc_section"> + <li>- <a href="#each">each</a></li> + <li>- <a href="#map">map</a></li> + <li>- <a href="#reduce">reduce</a></li> + <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="#findWhere">findWhere</a></li> + <li>- <a href="#reject">reject</a></li> + <li>- <a href="#every">every</a></li> + <li>- <a href="#some">some</a></li> + <li>- <a href="#contains">contains</a></li> + <li>- <a href="#invoke">invoke</a></li> + <li>- <a href="#pluck">pluck</a></li> + <li>- <a href="#max">max</a></li> + <li>- <a href="#min">min</a></li> + <li>- <a href="#sortBy">sortBy</a></li> + <li>- <a href="#groupBy">groupBy</a></li> + <li>- <a href="#indexBy">indexBy</a></li> + <li>- <a href="#countBy">countBy</a></li> + <li>- <a href="#shuffle">shuffle</a></li> + <li>- <a href="#sample">sample</a></li> + <li>- <a href="#toArray">toArray</a></li> + <li>- <a href="#size">size</a></li> + <li>- <a href="#partition">partition</a></li> + </ul> + + <a class="toc_title" href="#arrays"> + Arrays + </a> + <ul class="toc_section"> + <li>- <a href="#first">first</a></li> + <li>- <a href="#initial">initial</a></li> + <li>- <a href="#last">last</a></li> + <li>- <a href="#rest">rest</a></li> + <li>- <a href="#compact">compact</a></li> + <li>- <a href="#flatten">flatten</a></li> + <li>- <a href="#without">without</a></li> + <li>- <a href="#union">union</a></li> + <li>- <a href="#intersection">intersection</a></li> + <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> + <li>- <a href="#range">range</a></li> + </ul> + + <a class="toc_title" href="#functions"> + Functions + </a> + <ul class="toc_section"> + <li>- <a href="#bind">bind</a></li> + <li>- <a href="#bindAll">bindAll</a></li> + <li>- <a href="#partial">partial</a></li> + <li>- <a href="#memoize">memoize</a></li> + <li>- <a href="#delay">delay</a></li> + <li>- <a href="#defer">defer</a></li> + <li>- <a href="#throttle">throttle</a></li> + <li>- <a href="#debounce">debounce</a></li> + <li>- <a href="#once">once</a></li> + <li>- <a href="#after">after</a></li> + <li>- <a href="#wrap">wrap</a></li> + <li>- <a href="#negate">negate</a></li> + <li>- <a href="#compose">compose</a></li> + </ul> + + <a class="toc_title" href="#objects"> + Objects + </a> + <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> + <li>- <a href="#omit">omit</a></li> + <li>- <a href="#defaults">defaults</a></li> + <li>- <a href="#clone">clone</a></li> + <li>- <a href="#tap">tap</a></li> + <li>- <a href="#has">has</a></li> + <li>- <a href="#matches">matches</a></li> + <li>- <a href="#property">property</a></li> + <li>- <a href="#isEqual">isEqual</a></li> + <li>- <a href="#isEmpty">isEmpty</a></li> + <li>- <a href="#isElement">isElement</a></li> + <li>- <a href="#isArray">isArray</a></li> + <li>- <a href="#isObject">isObject</a></li> + <li>- <a href="#isArguments">isArguments</a></li> + <li>- <a href="#isFunction">isFunction</a></li> + <li>- <a href="#isString">isString</a></li> + <li>- <a href="#isNumber">isNumber</a></li> + <li>- <a href="#isFinite">isFinite</a></li> + <li>- <a href="#isBoolean">isBoolean</a></li> + <li>- <a href="#isDate">isDate</a></li> + <li>- <a href="#isRegExp">isRegExp</a></li> + <li>- <a href="#isNaN">isNaN</a></li> + <li>- <a href="#isNull">isNull</a></li> + <li>- <a href="#isUndefined">isUndefined</a></li> + </ul> + + <a class="toc_title" href="#utility"> + Utility + </a> + <ul class="toc_section"> + <li>- <a href="#noConflict">noConflict</a></li> + <li>- <a href="#identity">identity</a></li> + <li>- <a href="#constant">constant</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> + <li>- <a href="#unescape">unescape</a></li> + <li>- <a href="#result">result</a></li> + <li>- <a href="#now">now</a></li> + <li>- <a href="#template">template</a></li> + </ul> + + <a class="toc_title" href="#chaining"> + Chaining + </a> + <ul class="toc_section"> + <li>- <a href="#chain">chain</a></li> + <li>- <a href="#value">value</a></li> + </ul> + + <a class="toc_title" href="#links"> + Links + </a> + + <a class="toc_title" href="#changelog"> + Change Log + </a> + + </div> + + <div class="container"> + + <p id="introduction"> + <img id="logo" src="docs/images/underscore.png" alt="Underscore.js" /> + </p> + + <p> + <a href="http://github.com/jashkenas/underscore/">Underscore</a> + is a JavaScript library that provides a whole mess of useful functional + programming helpers without extending any built-in objects. + It’s the answer to the question: “If I sit down in front of a + blank HTML page, and want to start being productive immediately, what do I need?” + … and the tie to go along with + <a href="http://jquery.com">jQuery</a>'s tux and + <a href="http://backbonejs.org">Backbone</a>'s suspenders. + </p> + + <p> + Underscore provides 80-odd functions that support both the usual + functional suspects: <b>map</b>, <b>filter</b>, <b>invoke</b> — + as well as more specialized helpers: function binding, javascript + templating, deep equality testing, and so on. + </p> + + <p> + A complete <a href="test/">Test & Benchmark Suite</a> + is included for your perusal. + </p> + + <p> + You may also read through the <a href="docs/underscore.html">annotated source code</a>. + </p> + + <p> + Enjoying Underscore, and want to turn it up to 11? Try <a href="http://documentcloud.github.io/underscore-contrib/">Underscore-contrib</a>. + </p> + + <p> + The project is + <a href="https://github.com/jashkenas/underscore">hosted on GitHub</a>. + You can report bugs and discuss features on the + <a href="https://github.com/jashkenas/underscore/issues">issues page</a>, + on Freenode in the <tt>#documentcloud</tt> channel, + or send tweets to <a href="https://twitter.com/documentcloud">@documentcloud</a>. + </p> + + <p> + <i>Underscore is an open-source component of <a href="http://documentcloud.org/">DocumentCloud</a>.</i> + </p> + + <h2>Downloads <i style="padding-left: 12px; font-size:12px;">(Right-click, and use "Save As")</i></h2> + + <table> + <tr> + <td><a href="underscore.js">Development Version (1.6.0)</a></td> + <td><i>44kb, Uncompressed with Plentiful Comments</i></td> + </tr> + <tr> + <td><a href="underscore-min.js">Production Version (1.6.0)</a></td> + <td> + <i>5.0kb, Minified and Gzipped</i> + <small>(<a href="underscore-min.map">Source Map</a>)</small> + </td> + </tr> + <tr> + <td colspan="2"><div class="rule"></div></td> + </tr> + <tr> + <td><a href="https://raw.github.com/jashkenas/underscore/master/underscore.js">Edge Version</a></td> + <td><i>Unreleased, current <tt>master</tt>, use at your own risk</i></td> + </tr> + </table> + + <h2>Installation</h2> + + <ul> + <li> + <b>Node.js</b> <tt>npm install underscore</tt> + </li> + <li> + <b>Require.js</b> <tt>require(["underscore"], ...</tt> + </li> + <li> + <b>Bower</b> <tt>bower install underscore</tt> + </li> + <li> + <b>Component</b> <tt>component install jashkenas/underscore</tt> + </li> + </ul> + + <div id="documentation"> + + <h2 id="collections">Collection Functions (Arrays or Objects)</h2> + + <p id="each"> + <b class="header">each</b><code>_.each(list, iterator, [context])</code> + <span class="alias">Alias: <b>forEach</b></span> + <br /> + Iterates over a <b>list</b> of elements, yielding each in turn to an <b>iterator</b> + function. The <b>iterator</b> is bound to the <b>context</b> object, if one is + passed. Each invocation of <b>iterator</b> is called with three arguments: + <tt>(element, index, list)</tt>. If <b>list</b> is a JavaScript object, <b>iterator</b>'s + arguments will be <tt>(value, key, list)</tt>. Returns the <b>list</b> for chaining. + </p> + <pre> +_.each([1, 2, 3], alert); +=> alerts each number in turn... +_.each({one: 1, two: 2, three: 3}, alert); +=> alerts each number value in turn...</pre> + + <p> + <i> + Note: Collection functions work on arrays, objects, and + array-like objects such as</i> <tt>arguments</tt>, <tt>NodeList</tt><i> + and similar. But it works by duck-typing, so avoid passing objects with + a numeric <tt>length</tt> property. It's also good to note that an + <tt>each</tt> loop cannot be broken out of — to break, use <b>_.find</b> + instead. + </i> + </p> + + <p id="map"> + <b class="header">map</b><code>_.map(list, iterator, [context])</code> + <span class="alias">Alias: <b>collect</b></span> + <br /> + Produces a new array of values by mapping each value in <b>list</b> + through a transformation function (<b>iterator</b>). If <b>list</b> + is a JavaScript object, <b>iterator</b>'s arguments will be + <tt>(value, key, list)</tt>. + </p> + <pre> +_.map([1, 2, 3], function(num){ return num * 3; }); +=> [3, 6, 9] +_.map({one: 1, two: 2, three: 3}, function(num, key){ return num * 3; }); +=> [3, 6, 9]</pre> + + <p id="reduce"> + <b class="header">reduce</b><code>_.reduce(list, iterator, memo, [context])</code> + <span class="alias">Aliases: <b>inject, foldl</b></span> + <br /> + Also known as <b>inject</b> and <b>foldl</b>, <b>reduce</b> boils down a + <b>list</b> of values into a single value. <b>Memo</b> is the initial state + of the reduction, and each successive step of it should be returned by + <b>iterator</b>. The iterator is passed four arguments: the <tt>memo</tt>, + then the <tt>value</tt> and <tt>index</tt> (or key) of the iteration, + and finally a reference to the entire <tt>list</tt>. + </p> + <pre> +var sum = _.reduce([1, 2, 3], function(memo, num){ return memo + num; }, 0); +=> 6 +</pre> + + <p id="reduceRight"> + <b class="header">reduceRight</b><code>_.reduceRight(list, iterator, memo, [context])</code> + <span class="alias">Alias: <b>foldr</b></span> + <br /> + The right-associative version of <b>reduce</b>. Delegates to the + JavaScript 1.8 version of <b>reduceRight</b>, if it exists. <b>Foldr</b> + is not as useful in JavaScript as it would be in a language with lazy + evaluation. + </p> + <pre> +var list = [[0, 1], [2, 3], [4, 5]]; +var flat = _.reduceRight(list, function(a, b) { return a.concat(b); }, []); +=> [4, 5, 2, 3, 0, 1] +</pre> + + <p id="find"> + <b class="header">find</b><code>_.find(list, predicate, [context])</code> + <span class="alias">Alias: <b>detect</b></span> + <br /> + Looks through each value in the <b>list</b>, returning the first one that + passes a truth test (<b>predicate</b>), or <tt>undefined</tt> if no value + passes the test. The function returns as + soon as it finds an acceptable element, and doesn't traverse the + entire list. + </p> + <pre> +var even = _.find([1, 2, 3, 4, 5, 6], function(num){ return num % 2 == 0; }); +=> 2 +</pre> + + <p id="filter"> + <b class="header">filter</b><code>_.filter(list, predicate, [context])</code> + <span class="alias">Alias: <b>select</b></span> + <br /> + Looks through each value in the <b>list</b>, returning an array of all + the values that pass a truth test (<b>predicate</b>). + </p> + <pre> +var evens = _.filter([1, 2, 3, 4, 5, 6], function(num){ return num % 2 == 0; }); +=> [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}); +=> [{title: "Cymbeline", author: "Shakespeare", year: 1611}, + {title: "The Tempest", author: "Shakespeare", year: 1611}] +</pre> + + <p id="findWhere"> + <b class="header">findWhere</b><code>_.findWhere(list, properties)</code> + <br /> + Looks through the <b>list</b> and returns the <i>first</i> value that matches + all of the key-value pairs listed in <b>properties</b>. + </p> + <p> + If no match is found, or if <b>list</b> is empty, <i>undefined</i> will be + returned. + </p> + <pre> +_.findWhere(publicServicePulitzers, {newsroom: "The New York Times"}); +=> {year: 1918, newsroom: "The New York Times", + reason: "For its public service in publishing in full so many official reports, + documents and speeches by European statesmen relating to the progress and + conduct of the war."} +</pre> + + <p id="reject"> + <b class="header">reject</b><code>_.reject(list, predicate, [context])</code> + <br /> + Returns the values in <b>list</b> without the elements that the truth + test (<b>predicate</b>) passes. The opposite of <b>filter</b>. + </p> + <pre> +var odds = _.reject([1, 2, 3, 4, 5, 6], function(num){ return num % 2 == 0; }); +=> [1, 3, 5] +</pre> + + <p id="every"> + <b class="header">every</b><code>_.every(list, [predicate], [context])</code> + <span class="alias">Alias: <b>all</b></span> + <br /> + Returns <i>true</i> if all of the values in the <b>list</b> pass the + <b>predicate</b> truth test. + </p> + <pre> +_.every([true, 1, null, 'yes'], _.identity); +=> false +</pre> + + <p id="some"> + <b class="header">some</b><code>_.some(list, [predicate], [context])</code> + <span class="alias">Alias: <b>any</b></span> + <br /> + Returns <i>true</i> if any of the values in the <b>list</b> pass the + <b>predicate</b> truth test. Short-circuits and stops traversing the list + if a true element is found. + </p> + <pre> +_.some([null, 0, 'yes', false]); +=> true +</pre> + + <p id="contains"> + <b class="header">contains</b><code>_.contains(list, value)</code> + <span class="alias">Alias: <b>include</b></span> + <br /> + Returns <i>true</i> if the <b>value</b> is present in the <b>list</b>. + Uses <b>indexOf</b> internally, if <b>list</b> is an Array. + </p> + <pre> +_.contains([1, 2, 3], 3); +=> true +</pre> + + <p id="invoke"> + <b class="header">invoke</b><code>_.invoke(list, methodName, *arguments)</code> + <br /> + Calls the method named by <b>methodName</b> on each value in the <b>list</b>. + Any extra arguments passed to <b>invoke</b> will be forwarded on to the + method invocation. + </p> + <pre> +_.invoke([[5, 1, 7], [3, 2, 1]], 'sort'); +=> [[1, 5, 7], [1, 2, 3]] +</pre> + + <p id="pluck"> + <b class="header">pluck</b><code>_.pluck(list, propertyName)</code> + <br /> + A convenient version of what is perhaps the most common use-case for + <b>map</b>: extracting a list of property values. + </p> + <pre> +var stooges = [{name: 'moe', age: 40}, {name: 'larry', age: 50}, {name: 'curly', age: 60}]; +_.pluck(stooges, 'name'); +=> ["moe", "larry", "curly"] +</pre> + + <p id="max"> + <b class="header">max</b><code>_.max(list, [iterator], [context])</code> + <br /> + Returns the maximum value in <b>list</b>. If an <b>iterator</b> + function is provided, it will be used on each value to generate the + criterion by which the value is ranked. <i>-Infinity</i> is returned + if <b>list</b> is empty, so an <a href="#isEmpty">isEmpty</a> guard + may be required. + </p> + <pre> +var stooges = [{name: 'moe', age: 40}, {name: 'larry', age: 50}, {name: 'curly', age: 60}]; +_.max(stooges, function(stooge){ return stooge.age; }); +=> {name: 'curly', age: 60}; +</pre> + + <p id="min"> + <b class="header">min</b><code>_.min(list, [iterator], [context])</code> + <br /> + Returns the minimum value in <b>list</b>. If an <b>iterator</b> + function is provided, it will be used on each value to generate the + criterion by which the value is ranked. <i>Infinity</i> is returned + if <b>list</b> is empty, so an <a href="#isEmpty">isEmpty</a> guard + may be required. + </p> + <pre> +var numbers = [10, 5, 100, 2, 1000]; +_.min(numbers); +=> 2 +</pre> + + <p id="sortBy"> + <b class="header">sortBy</b><code>_.sortBy(list, iterator, [context])</code> + <br /> + Returns a (stably) sorted copy of <b>list</b>, ranked in ascending + order by the results of running each value through <b>iterator</b>. + Iterator may also be the string name of the property to sort by (eg. + <tt>length</tt>). + </p> + <pre> +_.sortBy([1, 2, 3, 4, 5, 6], function(num){ return Math.sin(num); }); +=> [5, 4, 6, 3, 1, 2] +</pre> + + <p id="groupBy"> + <b class="header">groupBy</b><code>_.groupBy(list, iterator, [context])</code> + <br /> + Splits a collection into sets, grouped by the result of running each + value through <b>iterator</b>. If <b>iterator</b> is a string instead of + a function, groups by the property named by <b>iterator</b> on each of + the values. + </p> + <pre> +_.groupBy([1.3, 2.1, 2.4], function(num){ return Math.floor(num); }); +=> {1: [1.3], 2: [2.1, 2.4]} + +_.groupBy(['one', 'two', 'three'], 'length'); +=> {3: ["one", "two"], 5: ["three"]} +</pre> + + <p id="indexBy"> + <b class="header">indexBy</b><code>_.indexBy(list, iterator, [context])</code> + <br /> + Given a <b>list</b>, and an <b>iterator</b> function that returns a + key for each element in the list (or a property name), + returns an object with an index of each item. + Just like <a href="#groupBy">groupBy</a>, but for when you know your + keys are unique. + </p> + <pre> +var stooges = [{name: 'moe', age: 40}, {name: 'larry', age: 50}, {name: 'curly', age: 60}]; +_.indexBy(stooges, 'age'); +=> { + "40": {name: 'moe', age: 40}, + "50": {name: 'larry', age: 50}, + "60": {name: 'curly', age: 60} +} +</pre> + + <p id="countBy"> + <b class="header">countBy</b><code>_.countBy(list, iterator, [context])</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'; +}); +=> {odd: 3, even: 2} +</pre> + + <p id="shuffle"> + <b class="header">shuffle</b><code>_.shuffle(list)</code> + <br /> + Returns a shuffled copy of the <b>list</b>, using a version of the + <a href="http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle">Fisher-Yates shuffle</a>. + </p> + <pre> +_.shuffle([1, 2, 3, 4, 5, 6]); +=> [4, 1, 6, 3, 5, 2] +</pre> + + <p id="sample"> + <b class="header">sample</b><code>_.sample(list, [n])</code> + <br /> + Produce a random sample from the <b>list</b>. Pass a number to + return <b>n</b> random elements from the list. Otherwise a single random + item will be returned. + </p> + <pre> +_.sample([1, 2, 3, 4, 5, 6]); +=> 4 + +_.sample([1, 2, 3, 4, 5, 6], 3); +=> [1, 6, 2] +</pre> + + <p id="toArray"> + <b class="header">toArray</b><code>_.toArray(list)</code> + <br /> + Creates a real Array from the <b>list</b> (anything that can be + iterated over). Useful for transmuting the <b>arguments</b> object. + </p> + <pre> +(function(){ return _.toArray(arguments).slice(1); })(1, 2, 3, 4); +=> [2, 3, 4] +</pre> + + <p id="size"> + <b class="header">size</b><code>_.size(list)</code> + <br /> + Return the number of values in the <b>list</b>. + </p> + <pre> +_.size({one: 1, two: 2, three: 3}); +=> 3 +</pre> + + <p id="partition"> + <b class="header">partition</b><code>_.partition(array, predicate)</code> + <br /> + Split <b>array</b> into two arrays: one whose elements all satisfy + <b>predicate</b> and one whose elements all do not satisfy <b>predicate</b>. + </p> + <pre> +_.partition([0, 1, 2, 3, 4, 5], isOdd); +=> [[1, 3, 5], [0, 2, 4]] +</pre> + + <h2 id="arrays">Array Functions</h2> + + <p> + <i> + Note: All array functions will also work on the <b>arguments</b> object. + However, Underscore functions are not designed to work on "sparse" arrays. + </i> + </p> + + <p id="first"> + <b class="header">first</b><code>_.first(array, [n])</code> + <span class="alias">Alias: <b>head</b>, <b>take</b></span> + <br /> + Returns the first element of an <b>array</b>. Passing <b>n</b> will + return the first <b>n</b> elements of the array. + </p> + <pre> +_.first([5, 4, 3, 2, 1]); +=> 5 +</pre> + + <p id="initial"> + <b class="header">initial</b><code>_.initial(array, [n])</code> + <br /> + Returns everything but the last entry of the array. Especially useful on + the arguments object. Pass <b>n</b> to exclude the last <b>n</b> elements + from the result. + </p> + <pre> +_.initial([5, 4, 3, 2, 1]); +=> [5, 4, 3, 2] +</pre> + + <p id="last"> + <b class="header">last</b><code>_.last(array, [n])</code> + <br /> + Returns the last element of an <b>array</b>. Passing <b>n</b> will return + the last <b>n</b> elements of the array. + </p> + <pre> +_.last([5, 4, 3, 2, 1]); +=> 1 +</pre> + + <p id="rest"> + <b class="header">rest</b><code>_.rest(array, [index])</code> + <span class="alias">Alias: <b>tail, drop</b></span> + <br /> + Returns the <b>rest</b> of the elements in an array. Pass an <b>index</b> + to return the values of the array from that index onward. + </p> + <pre> +_.rest([5, 4, 3, 2, 1]); +=> [4, 3, 2, 1] +</pre> + + <p id="compact"> + <b class="header">compact</b><code>_.compact(array)</code> + <br /> + Returns a copy of the <b>array</b> with all falsy values removed. + In JavaScript, <i>false</i>, <i>null</i>, <i>0</i>, <i>""</i>, + <i>undefined</i> and <i>NaN</i> are all falsy. + </p> + <pre> +_.compact([0, 1, false, 2, '', 3]); +=> [1, 2, 3] +</pre> + + <p id="flatten"> + <b class="header">flatten</b><code>_.flatten(array, [shallow])</code> + <br /> + Flattens a nested <b>array</b> (the nesting can be to any depth). If you + pass <b>shallow</b>, the array will only be flattened a single level. + </p> + <pre> +_.flatten([1, [2], [3, [[4]]]]); +=> [1, 2, 3, 4]; + +_.flatten([1, [2], [3, [[4]]]], true); +=> [1, 2, 3, [[4]]]; +</pre> + + <p id="without"> + <b class="header">without</b><code>_.without(array, *values)</code> + <br /> + Returns a copy of the <b>array</b> with all instances of the <b>values</b> + removed. + </p> + <pre> +_.without([1, 2, 1, 0, 3, 1, 4], 0, 1); +=> [2, 3, 4] +</pre> + + <p id="union"> + <b class="header">union</b><code>_.union(*arrays)</code> + <br /> + Computes the union of the passed-in <b>arrays</b>: the list of unique items, + in order, that are present in one or more of the <b>arrays</b>. + </p> + <pre> +_.union([1, 2, 3], [101, 2, 1, 10], [2, 1]); +=> [1, 2, 3, 101, 10] +</pre> + + <p id="intersection"> + <b class="header">intersection</b><code>_.intersection(*arrays)</code> + <br /> + Computes the list of values that are the intersection of all the <b>arrays</b>. + Each value in the result is present in each of the <b>arrays</b>. + </p> + <pre> +_.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]); +=> [1, 2] +</pre> + + <p id="difference"> + <b class="header">difference</b><code>_.difference(array, *others)</code> + <br /> + Similar to <b>without</b>, but returns the values from <b>array</b> that + are not present in the <b>other</b> arrays. + </p> + <pre> +_.difference([1, 2, 3, 4, 5], [5, 2, 10]); +=> [1, 3, 4] +</pre> + + <p id="uniq"> + <b class="header">uniq</b><code>_.uniq(array, [isSorted], [iterator])</code> + <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, + 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>iterator</b> function. + </p> + <pre> +_.uniq([1, 2, 1, 3, 1, 4]); +=> [1, 2, 3, 4] +</pre> + + <p id="zip"> + <b class="header">zip</b><code>_.zip(*arrays)</code> + <br /> + Merges together the values of each of the <b>arrays</b> with the + values at the corresponding position. Useful when you have separate + data sources that are coordinated through matching array indexes. + If you're working with a matrix of nested arrays, <tt>_.zip.apply</tt> + can transpose the matrix in a similar fashion. + </p> + <pre> +_.zip(['moe', 'larry', 'curly'], [30, 40, 50], [true, false, false]); +=> [["moe", 30, true], ["larry", 40, false], ["curly", 50, false]] + +_.zip.apply(_, arrayOfRowsOfData); +=> arrayOfColumnsOfData +</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. + If duplicate keys exist, the last value wins. + </p> + <pre> +_.object(['moe', 'larry', 'curly'], [30, 40, 50]); +=> {moe: 30, larry: 40, curly: 50} + +_.object([['moe', 30], ['larry', 40], ['curly', 50]]); +=> {moe: 30, larry: 40, curly: 50} +</pre> + + <p id="indexOf"> + <b class="header">indexOf</b><code>_.indexOf(array, value, [isSorted])</code> + <br /> + Returns the index at which <b>value</b> can be found in the <b>array</b>, + or <i>-1</i> if value is not present in the <b>array</b>. 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 ... 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); +=> 1 +</pre> + + <p id="lastIndexOf"> + <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. Pass <b>fromIndex</b> to start your search at a + given index. + </p> + <pre> +_.lastIndexOf([1, 2, 3, 1, 2, 3], 2); +=> 4 +</pre> + + <p id="sortedIndex"> + <b class="header">sortedIndex</b><code>_.sortedIndex(list, value, [iterator], [context])</code> + <br /> + Uses a binary search to determine the index at which the <b>value</b> + <i>should</i> be inserted into the <b>list</b> in order to maintain the <b>list</b>'s + sorted order. If an <b>iterator</b> function is provided, it will be used to compute + the sort ranking of each value, including the <b>value</b> you pass. + Iterator may also be the string name of the property to sort by (eg. <tt>length</tt>). + </p> + <pre> +_.sortedIndex([10, 20, 30, 40, 50], 35); +=> 3 + +var stooges = [{name: 'moe', age: 40}, {name: 'curly', age: 60}]; +_.sortedIndex(stooges, {name: 'larry', age: 50}, 'age'); +=> 1 +</pre> + + <p id="range"> + <b class="header">range</b><code>_.range([start], stop, [step])</code> + <br /> + A function to create flexibly-numbered lists of integers, handy for + <tt>each</tt> and <tt>map</tt> loops. <b>start</b>, if omitted, defaults + to <i>0</i>; <b>step</b> defaults to <i>1</i>. Returns a list of integers + from <b>start</b> to <b>stop</b>, incremented (or decremented) by <b>step</b>, + exclusive. Note that ranges that <b>stop</b> before they <b>start</b> + are considered to be zero-length instead of negative — if you'd like a + negative range, use a negative <b>step</b>. + </p> + <pre> +_.range(10); +=> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] +_.range(1, 11); +=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] +_.range(0, 30, 5); +=> [0, 5, 10, 15, 20, 25] +_.range(0, -10, -1); +=> [0, -1, -2, -3, -4, -5, -6, -7, -8, -9] +_.range(0); +=> [] +</pre> + + <h2 id="functions">Function (uh, ahem) Functions</h2> + + <p id="bind"> + <b class="header">bind</b><code>_.bind(function, object, *arguments)</code> + <br /> + Bind a <b>function</b> to an <b>object</b>, meaning that whenever + the function is called, the value of <i>this</i> will be the <b>object</b>. + Optionally, pass <b>arguments</b> to the <b>function</b> to pre-fill them, + also known as <b>partial application</b>. For partial application without + context binding, use <a href="#partial">partial</a>. + </p> + <pre> +var func = function(greeting){ return greeting + ': ' + this.name }; +func = _.bind(func, {name: 'moe'}, 'hi'); +func(); +=> 'hi: moe' +</pre> + + <p id="bindAll"> + <b class="header">bindAll</b><code>_.bindAll(object, *methodNames)</code> + <br /> + Binds a number of methods on the <b>object</b>, specified by + <b>methodNames</b>, to be run in the context of that object whenever they + are invoked. Very handy for binding functions that are going to be used + as event handlers, which would otherwise be invoked with a fairly useless + <i>this</i>. <b>methodNames</b> are required. + </p> + <pre> +var buttonView = { + label : 'underscore', + onClick: function(){ alert('clicked: ' + this.label); }, + onHover: function(){ console.log('hovering: ' + this.label); } +}; +_.bindAll(buttonView, 'onClick', 'onHover'); +// When the button is clicked, this.label will have the correct value. +jQuery('#underscore_button').bind('click', buttonView.onClick); +</pre> + + <p id="partial"> + <b class="header">partial</b><code>_.partial(function, *arguments)</code> + <br /> + Partially apply a function by filling in any number of its <b>arguments</b>, + <i>without</i> changing its dynamic <tt>this</tt> value. A close cousin + of <a href="#bind">bind</a>. You may pass <tt>_</tt> in your list of + <b>arguments</b> to specify an argument that should not be pre-filled, but + left open to supply at call-time. + </p> + <pre> +var add = function(a, b) { return a + b; }; +add5 = _.partial(add, 5); +add5(10); +=> 15 +</pre> + + <p id="memoize"> + <b class="header">memoize</b><code>_.memoize(function, [hashFunction])</code> + <br /> + Memoizes a given <b>function</b> by caching the computed result. Useful + for speeding up slow-running computations. If passed an optional + <b>hashFunction</b>, it will be used to compute the hash key for storing + the result, based on the arguments to the original function. The default + <b>hashFunction</b> just uses the first argument to the memoized function + as the key. + </p> + <pre> +var fibonacci = _.memoize(function(n) { + return n < 2 ? n: fibonacci(n - 1) + fibonacci(n - 2); +}); +</pre> + + <p id="delay"> + <b class="header">delay</b><code>_.delay(function, wait, *arguments)</code> + <br /> + Much like <b>setTimeout</b>, invokes <b>function</b> after <b>wait</b> + milliseconds. If you pass the optional <b>arguments</b>, they will be + forwarded on to the <b>function</b> when it is invoked. + </p> + <pre> +var log = _.bind(console.log, console); +_.delay(log, 1000, 'logged later'); +=> 'logged later' // Appears after one second. +</pre> + + <p id="defer"> + <b class="header">defer</b><code>_.defer(function, *arguments)</code> + <br /> + Defers invoking the <b>function</b> until the current call stack has cleared, + similar to using <b>setTimeout</b> with a delay of 0. Useful for performing + expensive computations or HTML rendering in chunks without blocking the UI thread + from updating. If you pass the optional <b>arguments</b>, they will be + forwarded on to the <b>function</b> when it is invoked. + </p> + <pre> +_.defer(function(){ alert('deferred'); }); +// Returns from the function before the alert runs. +</pre> + + <p id="throttle"> + <b class="header">throttle</b><code>_.throttle(function, wait, [options])</code> + <br /> + Creates and returns a new, throttled version of the passed function, + that, when invoked repeatedly, will only actually call the original function + at most once per every <b>wait</b> + milliseconds. Useful for rate-limiting events that occur faster than you + can keep up with. + </p> + <p> + By default, <b>throttle</b> will execute the function as soon as you call it + for the first time, and, if you call it again any number of times + during the <b>wait</b> period, as soon as that period is over. + If you'd like to disable the leading-edge + call, pass <tt>{leading: false}</tt>, and if you'd like to disable the + execution on the trailing-edge, pass <br /> <tt>{trailing: false}</tt>. + </p> + <pre> +var throttled = _.throttle(updatePosition, 100); +$(window).scroll(throttled); +</pre> + + <p id="debounce"> + <b class="header">debounce</b><code>_.debounce(function, wait, [immediate])</code> + <br /> + Creates and returns a new debounced version of the passed function which + will postpone its execution until after + <b>wait</b> milliseconds have elapsed since the last time it + was invoked. Useful for implementing behavior that should only happen + <i>after</i> the input has stopped arriving. For example: rendering a + preview of a Markdown comment, recalculating a layout after the window + has stopped being resized, and so on. + </p> + + <p> + Pass <tt>true</tt> for the <b>immediate</b> parameter to cause + <b>debounce</b> to trigger the function on the leading instead of the + trailing edge of the <b>wait</b> interval. Useful in circumstances like + preventing accidental double-clicks on a "submit" button from firing a + second time. + </p> + + <pre> +var lazyLayout = _.debounce(calculateLayout, 300); +$(window).resize(lazyLayout); +</pre> + + <p id="once"> + <b class="header">once</b><code>_.once(function)</code> + <br /> + Creates a version of the function that can only be called one time. + Repeated calls to the modified function will have no effect, returning + the value from the original call. Useful for initialization functions, + instead of having to set a boolean flag and then check it later. + </p> + <pre> +var initialize = _.once(createApplication); +initialize(); +initialize(); +// Application is only created once. +</pre> + + <p id="after"> + <b class="header">after</b><code>_.after(count, function)</code> + <br /> + Creates a version of the function that will only be run after first + being called <b>count</b> times. Useful for grouping asynchronous responses, + where you want to be sure that all the async calls have finished, before + proceeding. + </p> + <pre> +var renderNotes = _.after(notes.length, render); +_.each(notes, function(note) { + note.asyncSave({success: renderNotes}); +}); +// renderNotes is run once, after all notes have saved. +</pre> + + <p id="wrap"> + <b class="header">wrap</b><code>_.wrap(function, wrapper)</code> + <br /> + Wraps the first <b>function</b> inside of the <b>wrapper</b> function, + passing it as the first argument. This allows the <b>wrapper</b> to + execute code before and after the <b>function</b> runs, adjust the arguments, + and execute it conditionally. + </p> + <pre> +var hello = function(name) { return "hello: " + name; }; +hello = _.wrap(hello, function(func) { + return "before, " + func("moe") + ", after"; +}); +hello(); +=> 'before, hello: moe, after' +</pre> + + <p id="negate"> + <b class="header">negate</b><code>_.negate(predicate)</code> + <br /> + Returns a new negated version of the <b>predicate</b> function. + </p> + <pre> +var isFalsy = _.negate(Boolean); +_.find([-2, -1, 0, 1, 2], isFalsy); +=> 0 +</pre> + + <p id="compose"> + <b class="header">compose</b><code>_.compose(*functions)</code> + <br /> + Returns the composition of a list of <b>functions</b>, where each function + consumes the return value of the function that follows. In math terms, + composing the functions <i>f()</i>, <i>g()</i>, and <i>h()</i> produces + <i>f(g(h()))</i>. + </p> + <pre> +var greet = function(name){ return "hi: " + name; }; +var exclaim = function(statement){ return statement.toUpperCase() + "!"; }; +var welcome = _.compose(greet, exclaim); +welcome('moe'); +=> 'hi: MOE!' +</pre> + + <h2 id="objects">Object Functions</h2> + + <p id="keys"> + <b class="header">keys</b><code>_.keys(object)</code> + <br /> + Retrieve all the names of the <b>object</b>'s properties. + </p> + <pre> +_.keys({one: 1, two: 2, three: 3}); +=> ["one", "two", "three"] +</pre> + + <p id="values"> + <b class="header">values</b><code>_.values(object)</code> + <br /> + Return all of the values of the <b>object</b>'s properties. + </p> + <pre> +_.values({one: 1, two: 2, three: 3}); +=> [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}); +=> [["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"}); +=> {Moses: "Moe", Louis: "Larry", Jerome: "Curly"}; +</pre> + + <p id="object-functions"> + <b class="header">functions</b><code>_.functions(object)</code> + <span class="alias">Alias: <b>methods</b></span> + <br /> + Returns a sorted list of the names of every method in an object — + that is to say, the name of every function property of the object. + </p> + <pre> +_.functions(_); +=> ["all", "any", "bind", "bindAll", "clone", "compact", "compose" ... +</pre> + + <p id="extend"> + <b class="header">extend</b><code>_.extend(destination, *sources)</code> + <br /> + Copy all of the properties in the <b>source</b> objects over to the + <b>destination</b> object, and return the <b>destination</b> object. + It's in-order, so the last source will override properties of the same + name in previous arguments. + </p> + <pre> +_.extend({name: 'moe'}, {age: 50}); +=> {name: 'moe', age: 50} +</pre> + + <p id="pick"> + <b class="header">pick</b><code>_.pick(object, *keys)</code> + <br /> + Return a copy of the <b>object</b>, filtered to only have values for + the whitelisted <b>keys</b> (or array of valid keys). Alternatively + accepts a predicate indicating which keys to pick. + </p> + <pre> +_.pick({name: 'moe', age: 50, userid: 'moe1'}, 'name', 'age'); +=> {name: 'moe', age: 50} +_.pick({name: 'moe', age: 50, userid: 'moe1'}, function(value, key, object) { + return _.isNumber(value); +}); +=> {age: 50} +</pre> + + <p id="omit"> + <b class="header">omit</b><code>_.omit(object, *keys)</code> + <br /> + Return a copy of the <b>object</b>, filtered to omit the blacklisted + <b>keys</b> (or array of keys). Alternatively accepts a predicate + indicating which keys to omit. + </p> + <pre> +_.omit({name: 'moe', age: 50, userid: 'moe1'}, 'userid'); +=> {name: 'moe', age: 50} +_.omit({name: 'moe', age: 50, userid: 'moe1'}, function(value, key, object) { + return _.isNumber(value); +}); +=> {name: 'moe', userid: 'moe1'} +</pre> + + <p id="defaults"> + <b class="header">defaults</b><code>_.defaults(object, *defaults)</code> + <br /> + Fill in <tt>undefined</tt> properties in <b>object</b> with the first + value present in the following list of <b>defaults</b> objects. + </p> + <pre> +var iceCream = {flavor: "chocolate"}; +_.defaults(iceCream, {flavor: "vanilla", sprinkles: "lots"}); +=> {flavor: "chocolate", sprinkles: "lots"} +</pre> + + <p id="clone"> + <b class="header">clone</b><code>_.clone(object)</code> + <br /> + Create a shallow-copied clone of the <b>object</b>. Any nested objects + or arrays will be copied by reference, not duplicated. + </p> + <pre> +_.clone({name: 'moe'}); +=> {name: 'moe'}; +</pre> + + <p id="tap"> + <b class="header">tap</b><code>_.tap(object, interceptor)</code> + <br /> + Invokes <b>interceptor</b> with the <b>object</b>, and then returns <b>object</b>. + The primary purpose of this method is to "tap into" a method chain, in order to perform operations on intermediate results within the chain. + </p> + <pre> +_.chain([1,2,3,200]) + .filter(function(num) { return num % 2 == 0; }) + .tap(alert) + .map(function(num) { return num * num }) + .value(); +=> // [2, 200] (alerted) +=> [4, 40000] +</pre> + + <p id="has"> + <b class="header">has</b><code>_.has(object, key)</code> + <br /> + Does the object contain the given key? Identical to + <tt>object.hasOwnProperty(key)</tt>, but uses a safe reference to the + <tt>hasOwnProperty</tt> function, in case it's been + <a href="http://www.devthought.com/2012/01/18/an-object-is-not-a-hash/">overridden accidentally</a>. + </p> + <pre> +_.has({a: 1, b: 2, c: 3}, "b"); +=> true +</pre> + + <p id="property"> + <b class="header">property</b><code>_.property(key)</code> + <br /> + Returns a function that will itself return the <tt>key</tt> + property of any passed-in object. + </p> + <pre> +var moe = {name: 'moe'}; +'moe' === _.property('name')(moe); +=> true</pre> + + <p id="matches"> + <b class="header">matches</b><code>_.matches(attrs)</code> + <br /> + Returns a predicate function that will tell you if a passed in object + contains all of the key/value properties present in <b>attrs</b>. + </p> + <pre> +var ready = _.matches({selected: true, visible: true}); +var readyToGoList = _.filter(list, ready);</pre> + + <p id="isEqual"> + <b class="header">isEqual</b><code>_.isEqual(object, other)</code> + <br /> + Performs an optimized deep comparison between the two objects, to determine + if they should be considered equal. + </p> + <pre> +var moe = {name: 'moe', luckyNumbers: [13, 27, 34]}; +var clone = {name: 'moe', luckyNumbers: [13, 27, 34]}; +moe == clone; +=> false +_.isEqual(moe, clone); +=> true +</pre> + + <p id="isEmpty"> + <b class="header">isEmpty</b><code>_.isEmpty(object)</code> + <br /> + Returns <i>true</i> if an enumerable <b>object</b> contains no + values (no enumerable own-properties). For strings and array-like + objects <tt>_.isEmpty</tt> checks if the length property is 0. + </p> + <pre> +_.isEmpty([1, 2, 3]); +=> false +_.isEmpty({}); +=> true +</pre> + + <p id="isElement"> + <b class="header">isElement</b><code>_.isElement(object)</code> + <br /> + Returns <i>true</i> if <b>object</b> is a DOM element. + </p> + <pre> +_.isElement(jQuery('body')[0]); +=> true +</pre> + + <p id="isArray"> + <b class="header">isArray</b><code>_.isArray(object)</code> + <br /> + Returns <i>true</i> if <b>object</b> is an Array. + </p> + <pre> +(function(){ return _.isArray(arguments); })(); +=> false +_.isArray([1,2,3]); +=> true +</pre> + + <p id="isObject"> + <b class="header">isObject</b><code>_.isObject(value)</code> + <br /> + Returns <i>true</i> if <b>value</b> is an Object. Note that JavaScript + arrays and functions are objects, while (normal) strings and numbers are not. + </p> + <pre> +_.isObject({}); +=> true +_.isObject(1); +=> false +</pre> + + <p id="isArguments"> + <b class="header">isArguments</b><code>_.isArguments(object)</code> + <br /> + Returns <i>true</i> if <b>object</b> is an Arguments object. + </p> + <pre> +(function(){ return _.isArguments(arguments); })(1, 2, 3); +=> true +_.isArguments([1,2,3]); +=> false +</pre> + + <p id="isFunction"> + <b class="header">isFunction</b><code>_.isFunction(object)</code> + <br /> + Returns <i>true</i> if <b>object</b> is a Function. + </p> + <pre> +_.isFunction(alert); +=> true +</pre> + + <p id="isString"> + <b class="header">isString</b><code>_.isString(object)</code> + <br /> + Returns <i>true</i> if <b>object</b> is a String. + </p> + <pre> +_.isString("moe"); +=> true +</pre> + + <p id="isNumber"> + <b class="header">isNumber</b><code>_.isNumber(object)</code> + <br /> + Returns <i>true</i> if <b>object</b> is a Number (including <tt>NaN</tt>). + </p> + <pre> +_.isNumber(8.4 * 5); +=> true +</pre> + + <p id="isFinite"> + <b class="header">isFinite</b><code>_.isFinite(object)</code> + <br /> + Returns <i>true</i> if <b>object</b> is a finite Number. + </p> + <pre> +_.isFinite(-101); +=> true + +_.isFinite(-Infinity); +=> false +</pre> + + <p id="isBoolean"> + <b class="header">isBoolean</b><code>_.isBoolean(object)</code> + <br /> + Returns <i>true</i> if <b>object</b> is either <i>true</i> or <i>false</i>. + </p> + <pre> +_.isBoolean(null); +=> false +</pre> + + <p id="isDate"> + <b class="header">isDate</b><code>_.isDate(object)</code> + <br /> + Returns <i>true</i> if <b>object</b> is a Date. + </p> + <pre> +_.isDate(new Date()); +=> true +</pre> + + <p id="isRegExp"> + <b class="header">isRegExp</b><code>_.isRegExp(object)</code> + <br /> + Returns <i>true</i> if <b>object</b> is a RegExp. + </p> + <pre> +_.isRegExp(/moe/); +=> true +</pre> + + <p id="isNaN"> + <b class="header">isNaN</b><code>_.isNaN(object)</code> + <br /> + Returns <i>true</i> if <b>object</b> is <i>NaN</i>.<br /> Note: this is not + the same as the native <b>isNaN</b> function, which will also return + true for many other not-number values, such as <tt>undefined</tt>. + </p> + <pre> +_.isNaN(NaN); +=> true +isNaN(undefined); +=> true +_.isNaN(undefined); +=> false +</pre> + + <p id="isNull"> + <b class="header">isNull</b><code>_.isNull(object)</code> + <br /> + Returns <i>true</i> if the value of <b>object</b> is <i>null</i>. + </p> + <pre> +_.isNull(null); +=> true +_.isNull(undefined); +=> false +</pre> + + <p id="isUndefined"> + <b class="header">isUndefined</b><code>_.isUndefined(value)</code> + <br /> + Returns <i>true</i> if <b>value</b> is <i>undefined</i>. + </p> + <pre> +_.isUndefined(window.missingVariable); +=> true +</pre> + + <h2 id="utility">Utility Functions</h2> + + <p id="noConflict"> + <b class="header">noConflict</b><code>_.noConflict()</code> + <br /> + Give control of the "_" variable back to its previous owner. Returns + a reference to the <b>Underscore</b> object. + </p> + <pre> +var underscore = _.noConflict();</pre> + + <p id="identity"> + <b class="header">identity</b><code>_.identity(value)</code> + <br /> + Returns the same value that is used as the argument. In math: + <tt>f(x) = x</tt><br /> + This function looks useless, but is used throughout Underscore as + a default iterator. + </p> + <pre> +var moe = {name: 'moe'}; +moe === _.identity(moe); +=> true</pre> + + <p id="constant"> + <b class="header">constant</b><code>_.constant(value)</code> + <br /> + Creates a function that returns the same value that is used as the + argument of <tt>_.constant</tt>. + </p> + <pre> +var moe = {name: 'moe'}; +moe === _.constant(moe)(); +=> true</pre> + + <p id="noop"> + <b class="header">noop</b><code>_.noop()</code> + <br /> + Returns <tt>undefined</tt> irrespective of the arguments passed to it. + Useful as the default for optional callback arguments. + </p> + + <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. Produces an + array of the returned values. + <br /> + <i>Note: this example uses the <a href="#chaining">chaining syntax</a></i>. + </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); +=> 42</pre> + + <p id="mixin"> + <b class="header">mixin</b><code>_.mixin(object)</code> + <br /> + Allows you to extend Underscore with your own utility functions. Pass + a hash of <tt>{name: function}</tt> definitions to have your functions + added to the Underscore object, as well as the OOP wrapper. + </p> + <pre> +_.mixin({ + capitalize: function(string) { + return string.charAt(0).toUpperCase() + string.substring(1).toLowerCase(); + } +}); +_("fabio").capitalize(); +=> "Fabio" +</pre> + + <p id="uniqueId"> + <b class="header">uniqueId</b><code>_.uniqueId([prefix])</code> + <br /> + Generate a globally-unique id for client-side models or DOM elements + that need one. If <b>prefix</b> is passed, the id will be appended to it. + </p> + <pre> +_.uniqueId('contact_'); +=> 'contact_104'</pre> + + <p id="escape"> + <b class="header">escape</b><code>_.escape(string)</code> + <br /> + Escapes a string for insertion into HTML, replacing + <tt>&</tt>, <tt><</tt>, <tt>></tt>, <tt>"</tt>, and <tt>'</tt> characters. + </p> + <pre> +_.escape('Curly, Larry & Moe'); +=> "Curly, Larry &amp; Moe"</pre> + + <p id="unescape"> + <b class="header">unescape</b><code>_.unescape(string)</code> + <br /> + The opposite of <a href="#escape"><b>escape</b></a>, replaces + <tt>&amp;</tt>, <tt>&lt;</tt>, <tt>&gt;</tt>, + <tt>&quot;</tt>, and <tt>&#x27;</tt> + with their unescaped counterparts. + </p> + <pre> +_.unescape('Curly, Larry &amp; Moe'); +=> "Curly, Larry & Moe"</pre> + + <p id="result"> + <b class="header">result</b><code>_.result(object, property)</code> + <br /> + If the value of the named <b>property</b> is a function then invoke it + with the <b>object</b> as context; otherwise, return it. + </p> + <pre> +var object = {cheese: 'crumpets', stuff: function(){ return 'nonsense'; }}; +_.result(object, 'cheese'); +=> "crumpets" +_.result(object, 'stuff'); +=> "nonsense"</pre> + + <p id="now"> + <b class="header">now</b><code>_.now()</code> + <br /> + Returns an integer timestamp for the current time, using the fastest + method available in the runtime. Useful for implementing timing/animation + functions. + </p> + <pre> +_.now(); +=> 1392066795351 +</pre> + + <p id="template"> + <b class="header">template</b><code>_.template(templateString, [data], [settings])</code> + <br /> + Compiles JavaScript templates into functions that can be evaluated + for rendering. Useful for rendering complicated bits of HTML from JSON + data sources. Template functions can both interpolate variables, using + <tt><%= … %></tt>, as well as execute arbitrary JavaScript code, with + <tt><% … %></tt>. If you wish to interpolate a value, and have + it be HTML-escaped, use <tt><%- … %></tt> When you evaluate a template function, pass in a + <b>data</b> object that has properties corresponding to the template's free + variables. If you're writing a one-off, you can pass the <b>data</b> + object as the second parameter to <b>template</b> in order to render + immediately instead of returning a template function. The <b>settings</b> argument + should be a hash containing any <tt>_.templateSettings</tt> that should be overridden. + </p> + + <pre> +var compiled = _.template("hello: <%= name %>"); +compiled({name: 'moe'}); +=> "hello: moe" + +var list = "<% _.each(people, function(name) { %> <li><%= name %></li> <% }); %>"; +_.template(list, {people: ['moe', 'curly', 'larry']}); +=> "<li>moe</li><li>curly</li><li>larry</li>" + +var template = _.template("<b><%- value %></b>"); +template({value: '<script>'}); +=> "<b>&lt;script&gt;</b>"</pre> + + <p> + You can also use <tt>print</tt> from within JavaScript code. This is + sometimes more convenient than using <tt><%= ... %></tt>. + </p> + + <pre> +var compiled = _.template("<% print('Hello ' + epithet); %>"); +compiled({epithet: "stooge"}); +=> "Hello stooge"</pre> + + <p> + If ERB-style delimiters aren't your cup of tea, you can change Underscore's + template settings to use different symbols to set off interpolated code. + Define an <b>interpolate</b> regex to match expressions that should be + interpolated verbatim, an <b>escape</b> regex to match expressions that should + be inserted after being HTML escaped, and an <b>evaluate</b> regex to match + expressions that should be evaluated without insertion into the resulting + string. You may define or omit any combination of the three. + For example, to perform + <a href="https://github.com/janl/mustache.js#readme">Mustache.js</a> + style templating: + </p> + + <pre> +_.templateSettings = { + interpolate: /\{\{(.+?)\}\}/g +}; + +var template = _.template("Hello {{ name }}!"); +template({name: "Mustache"}); +=> "Hello Mustache!"</pre> + + <p> + By default, <b>template</b> places the values from your data in the local scope + via the <tt>with</tt> statement. However, you can specify a single variable name + with the <b>variable</b> setting. This can significantly improve the speed + at which a template is able to render. + </p> + + <pre> +_.template("Using 'with': <%= data.answer %>", {answer: 'no'}, {variable: 'data'}); +=> "Using 'with': no"</pre> + + <p> + Precompiling your templates can be a big help when debugging errors you can't + reproduce. This is because precompiled templates can provide line numbers and + a stack trace, something that is not possible when compiling templates on the client. + The <b>source</b> property is available on the compiled template + function for easy precompilation. + </p> + + <pre><script> + JST.project = <%= _.template(jstText).source %>; +</script></pre> + + + <h2 id="chaining">Chaining</h2> + + <p> + You can use Underscore in either an object-oriented or a functional style, + depending on your preference. The following two lines of code are + identical ways to double a list of numbers. + </p> + + <pre> +_.map([1, 2, 3], function(n){ return n * 2; }); +_([1, 2, 3]).map(function(n){ return n * 2; });</pre> + + <p> + Calling <tt>chain</tt> will cause all future method calls to return + wrapped objects. When you've finished the computation, call + <tt>value</tt> to retrieve the final value. Here's an example of chaining + together a <b>map/flatten/reduce</b>, in order to get the word count of + every word in a song. + </p> + +<pre> +var lyrics = [ + {line: 1, words: "I'm a lumberjack and I'm okay"}, + {line: 2, words: "I sleep all night and I work all day"}, + {line: 3, words: "He's a lumberjack and he's okay"}, + {line: 4, words: "He sleeps all night and he works all day"} +]; + +_.chain(lyrics) + .map(function(line) { return line.words.split(' '); }) + .flatten() + .reduce(function(counts, word) { + counts[word] = (counts[word] || 0) + 1; + return counts; + }, {}) + .value(); + +=> {lumberjack: 2, all: 4, night: 2 ... }</pre> + + <p> + In addition, the + <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/prototype">Array prototype's methods</a> + are proxied through the chained Underscore object, so you can slip a + <tt>reverse</tt> or a <tt>push</tt> into your chain, and continue to + modify the array. + </p> + + <p id="chain"> + <b class="header">chain</b><code>_.chain(obj)</code> + <br /> + Returns a wrapped object. Calling methods on this object will continue + to return wrapped objects until <tt>value</tt> is called. + </p> + <pre> +var stooges = [{name: 'curly', age: 25}, {name: 'moe', age: 21}, {name: 'larry', age: 23}]; +var youngest = _.chain(stooges) + .sortBy(function(stooge){ return stooge.age; }) + .map(function(stooge){ return stooge.name + ' is ' + stooge.age; }) + .first() + .value(); +=> "moe is 21" +</pre> + + <p id="value"> + <b class="header">value</b><code>_(obj).value()</code> + <br /> + Extracts the value of a wrapped object. + </p> + <pre> +_([1, 2, 3]).value(); +=> [1, 2, 3] +</pre> + + <h2 id="links">Links & Suggested Reading</h2> + + <p> + The Underscore documentation is also available in + <a href="http://learning.github.io/underscore/">Simplified Chinese</a>. + </p> + + <p> + <a href="http://mirven.github.io/underscore.lua/">Underscore.lua</a>, + a Lua port of the functions that are applicable in both languages. + Includes OOP-wrapping and chaining. + (<a href="https://github.com/mirven/underscore.lua">source</a>) + </p> + + <p> + <a href="http://underscorem.org/">Underscore.m</a>, an Objective-C port + of many of the Underscore.js functions, using a syntax that encourages + chaining. + (<a href="https://github.com/robb/Underscore.m">source</a>) + </p> + + <p> + <a href="http://kmalakoff.github.io/_.m/">_.m</a>, an alternative + Objective-C port that tries to stick a little closer to the original + Underscore.js API. + (<a href="https://github.com/kmalakoff/_.m">source</a>) + </p> + + <p> + <a href="http://brianhaveri.github.io/Underscore.php/">Underscore.php</a>, + a PHP port of the functions that are applicable in both languages. + Includes OOP-wrapping and chaining. + (<a href="https://github.com/brianhaveri/Underscore.php">source</a>) + </p> + + <p> + <a href="http://vti.github.io/underscore-perl/">Underscore-perl</a>, + a Perl port of many of the Underscore.js functions, + aimed at on Perl hashes and arrays. + (<a href="https://github.com/vti/underscore-perl">source</a>) + </p> + + <p> + <a href="http://russplaysguitar.github.io/UnderscoreCF/">Underscore.cfc</a>, + a Coldfusion port of many of the Underscore.js functions. + (<a href="https://github.com/russplaysguitar/underscorecf">source</a>) + </p> + + <p> + <a href="http://epeli.github.io/underscore.string/">Underscore.string</a>, + an Underscore extension that adds functions for string-manipulation: + <tt>trim</tt>, <tt>startsWith</tt>, <tt>contains</tt>, <tt>capitalize</tt>, + <tt>reverse</tt>, <tt>sprintf</tt>, and more. + </p> + + <p> + Ruby's <a href="http://ruby-doc.org/core/classes/Enumerable.html">Enumerable</a> module. + </p> + + <p> + <a href="http://prototypejs.org/">Prototype.js</a>, which provides + JavaScript with collection functions in the manner closest to Ruby's Enumerable. + </p> + + <p> + Oliver Steele's + <a href="http://osteele.com/sources/javascript/functional/">Functional JavaScript</a>, + which includes comprehensive higher-order function support as well as string lambdas. + </p> + + <p> + Michael Aufreiter's <a href="https://github.com/substance/data">Data.js</a>, + a data manipulation + persistence library for JavaScript. + </p> + + <p> + Python's <a href="http://docs.python.org/library/itertools.html">itertools</a>. + </p> + + <p> + <a href="http://toolz.readthedocs.org/">PyToolz</a>, a Python port + that extends itertools and functools to include much of the + Underscore API. + </p> + + <p> + <a href="https://github.com/Suor/funcy">Funcy</a>, a practical + collection of functional helpers for Python, partially inspired by Underscore. + </p> + + <h2 id="changelog">Change Log</h2> + + + <p id="1.6.0"> + <b class="header">1.6.0</b> — <small><i>February 10, 2014</i></small> — <a href="https://github.com/jashkenas/underscore/compare/1.5.2...1.6.0">Diff</a> — <a href="http://htmlpreview.github.io/?https://raw.github.com/jashkenas/underscore/1.6.0/index.html">Docs</a><br /> + <ul> + <li> + Underscore now registers itself for AMD (Require.js), Bower and Component, + as well as being a CommonJS module and a regular (Java)Script. + An ugliness, but perhaps a necessary one. + </li> + <li> + Added <tt>_.partition</tt>, a way to split a collection into two lists + of results — those that pass and those that fail a particular predicate. + </li> + <li> + Added <tt>_.property</tt>, for easy creation of iterators that pull + specific properties from objects. Useful in conjunction with other + Underscore collection functions. + </li> + <li> + Added <tt>_.matches</tt>, a function that will give you a predicate + that can be used to tell if a given object matches a list of specified + key/value properties. + </li> + <li> + Added <tt>_.constant</tt>, as a higher-order <tt>_.identity</tt>. + </li> + <li> + Added <tt>_.now</tt>, an optimized way to get a timestamp — used + internally to speed up <tt>debounce</tt> and <tt>throttle</tt>. + </li> + <li> + The <tt>_.partial</tt> function may now be used to partially apply + any of its arguments, by passing <tt>_</tt> wherever you'd like a + placeholder variable, to be filled-in later. + </li> + <li> + The <tt>_.each</tt> function now returns a reference to the list for chaining. + </li> + <li> + The <tt>_.keys</tt> function now returns an empty array for + non-objects instead of throwing. + </li> + <li> + … and more miscellaneous refactoring. + </li> + </ul> + </p> + + <p id="1.5.2"> + <b class="header">1.5.2</b> — <small><i>September 7, 2013</i></small> — <a href="https://github.com/jashkenas/underscore/compare/1.5.1...1.5.2">Diff</a> — <a href="http://htmlpreview.github.io/?https://raw.github.com/jashkenas/underscore/1.5.2/index.html">Docs</a><br /> + <ul> + <li> + Added an <tt>indexBy</tt> function, which fits in alongside its + cousins, <tt>countBy</tt> and <tt>groupBy</tt>. + </li> + <li> + Added a <tt>sample</tt> function, for sampling random elements from + arrays. + </li> + <li> + Some optimizations relating to functions that can be implemented + in terms of <tt>_.keys</tt> (which includes, significantly, + <tt>each</tt> on objects). Also for <tt>debounce</tt> in a tight loop. + </li> + </ul> + </p> + + <p id="1.5.1"> + <b class="header">1.5.1</b> — <small><i>July 8, 2013</i></small> — <a href="https://github.com/jashkenas/underscore/compare/1.5.0...1.5.1">Diff</a> — <a href="http://htmlpreview.github.io/?https://raw.github.com/jashkenas/underscore/1.5.1/index.html">Docs</a><br /> + <ul> + <li> + Removed <tt>unzip</tt>, as it's simply the application of <tt>zip</tt> + to an array of arguments. Use <tt>_.zip.apply(_, list)</tt> to + transpose instead. + </li> + </ul> + </p> + + <p id="1.5.0"> + <b class="header">1.5.0</b> — <small><i>July 6, 2013</i></small> — <a href="https://github.com/jashkenas/underscore/compare/1.4.4...1.5.0">Diff</a> — <a href="http://htmlpreview.github.io/?https://raw.github.com/jashkenas/underscore/1.5.0/index.html">Docs</a><br /> + <ul> + <li> + Added a new <tt>unzip</tt> function, as the inverse of <tt>_.zip</tt>. + </li> + <li> + The <tt>throttle</tt> function now takes an <tt>options</tt> argument, + allowing you to disable execution of the throttled function on either + the <b>leading</b> or <b>trailing</b> edge. + </li> + <li> + A source map is now supplied for easier debugging of the minified + production build of Underscore. + </li> + <li> + The <tt>defaults</tt> function now only overrides <tt>undefined</tt> + values, not <tt>null</tt> ones. + </li> + <li> + Removed the ability to call <tt>_.bindAll</tt> with no method name + arguments. It's pretty much always wiser to white-list the names of + the methods you'd like to bind. + </li> + <li> + Removed the ability to call <tt>_.after</tt> with an invocation count + of zero. The minimum number of calls is (naturally) now <tt>1</tt>. + </li> + </ul> + </p> + + <p id="1.4.4"> + <b class="header">1.4.4</b> — <small><i>January 30, 2013</i></small> — <a href="https://github.com/jashkenas/underscore/compare/1.4.3...1.4.4">Diff</a> — <a href="http://htmlpreview.github.io/?https://raw.github.com/jashkenas/underscore/1.4.4/index.html">Docs</a><br /> + <ul> + <li> + Added <tt>_.findWhere</tt>, for finding the first element in a list + that matches a particular set of keys and values. + </li> + <li> + Added <tt>_.partial</tt>, for partially applying a function <i>without</i> + changing its dynamic reference to <tt>this</tt>. + </li> + <li> + Simplified <tt>bind</tt> by removing some edge cases involving + constructor functions. In short: don't <tt>_.bind</tt> your + constructors. + </li> + <li> + A minor optimization to <tt>invoke</tt>. + </li> + <li> + Fix bug in the minified version due to the minifier incorrectly + optimizing-away <tt>isFunction</tt>. + </li> + </ul> + </p> + + <p id="1.4.3"> + <b class="header">1.4.3</b> — <small><i>December 4, 2012</i></small> — <a href="https://github.com/jashkenas/underscore/compare/1.4.2...1.4.3">Diff</a> — <a href="http://htmlpreview.github.io/?https://raw.github.com/jashkenas/underscore/1.4.3/index.html">Docs</a><br /> + <ul> + <li> + Improved Underscore compatibility with Adobe's JS engine that can be + used to script Illustrator, Photoshop, and friends. + </li> + <li> + Added a default <tt>_.identity</tt> iterator to <tt>countBy</tt> and + <tt>groupBy</tt>. + </li> + <li> + The <tt>uniq</tt> function can now take <tt>array, iterator, context</tt> + as the argument list. + </li> + <li> + The <tt>times</tt> function now returns the mapped array of iterator + results. + </li> + <li> + Simplified and fixed bugs in <tt>throttle</tt>. + </li> + </ul> + </p> + + <p id="1.4.2"> + <b class="header">1.4.2</b> — <small><i>October 6, 2012</i></small> — <a href="https://github.com/jashkenas/underscore/compare/1.4.1...1.4.2">Diff</a> — <a href="http://htmlpreview.github.io/?https://raw.github.com/jashkenas/underscore/1.4.2/index.html">Docs</a><br /> + <ul> + <li> + For backwards compatibility, returned to pre-1.4.0 behavior when + passing <tt>null</tt> to iteration functions. They now become no-ops + again. + </li> + </ul> + </p> + + <p id="1.4.1"> + <b class="header">1.4.1</b> — <small><i>October 1, 2012</i></small> — <a href="https://github.com/jashkenas/underscore/compare/1.4.0...1.4.1">Diff</a> — <a href="http://htmlpreview.github.io/?https://raw.github.com/jashkenas/underscore/1.4.1/index.html">Docs</a><br /> + <ul> + <li> + Fixed a 1.4.0 regression in the <tt>lastIndexOf</tt> function. + </li> + </ul> + </p> + + <p id="1.4.0"> + <b class="header">1.4.0</b> — <small><i>September 27, 2012</i></small> — <a href="https://github.com/jashkenas/underscore/compare/1.3.3...1.4.0">Diff</a> — <a href="http://htmlpreview.github.io/?https://raw.github.com/jashkenas/underscore/1.4.0/index.html">Docs</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 do. + </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> loop 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> + <del>Underscore iteration functions no longer accept <tt>null</tt> values + as a no-op argument. You'll get an early error instead.</del> + </li> + <li> + A number of edge-cases fixes and tweaks, which you can spot in the + <a href="https://github.com/jashkenas/underscore/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 — please test when you upgrade. + </li> + </ul> + </p> + + <p id="1.3.3"> + <b class="header">1.3.3</b> — <small><i>April 10, 2012</i></small> — <a href="https://github.com/jashkenas/underscore/compare/1.3.1...1.3.3">Diff</a> — <a href="http://htmlpreview.github.io/?https://raw.github.com/jashkenas/underscore/1.3.3/index.html">Docs</a><br /> + <ul> + <li> + Many improvements to <tt>_.template</tt>, which now provides the + <tt>source</tt> of the template function as a property, for potentially + even more efficient pre-compilation on the server-side. You may now + also set the <tt>variable</tt> option when creating a template, + which will cause your passed-in data to be made available under the + variable you named, instead of using a <tt>with</tt> statement — + significantly improving the speed of rendering the template. + </li> + <li> + Added the <tt>pick</tt> function, which allows you to filter an + object literal with a whitelist of allowed property names. + </li> + <li> + Added the <tt>result</tt> function, for convenience when working + with APIs that allow either functions or raw properties. + </li> + <li> + Added the <tt>isFinite</tt> function, because sometimes knowing that + a value is a number just ain't quite enough. + </li> + <li> + The <tt>sortBy</tt> function may now also be passed the string name + of a property to use as the sort order on each object. + </li> + <li> + Fixed <tt>uniq</tt> to work with sparse arrays. + </li> + <li> + The <tt>difference</tt> function now performs a shallow flatten + instead of a deep one when computing array differences. + </li> + <li> + The <tt>debounce</tt> function now takes an <tt>immediate</tt> + parameter, which will cause the callback to fire on the leading + instead of the trailing edge. + </li> + </ul> + </p> + + <p id="1.3.1"> + <b class="header">1.3.1</b> — <small><i>January 23, 2012</i></small> — <a href="https://github.com/jashkenas/underscore/compare/1.3.0...1.3.1">Diff</a> — <a href="http://htmlpreview.github.io/?https://raw.github.com/jashkenas/underscore/1.3.1/index.html">Docs</a><br /> + <ul> + <li> + Added an <tt>_.has</tt> function, as a safer way to use <tt>hasOwnProperty</tt>. + </li> + <li> + Added <tt>_.collect</tt> as an alias for <tt>_.map</tt>. Smalltalkers, rejoice. + </li> + <li> + Reverted an old change so that <tt>_.extend</tt> will correctly copy + over keys with undefined values again. + </li> + <li> + Bugfix to stop escaping slashes within interpolations in <tt>_.template</tt>. + </li> + </ul> + </p> + + <p id="1.3.0"> + <b class="header">1.3.0</b> — <small><i>January 11, 2012</i></small> — <a href="https://github.com/jashkenas/underscore/compare/1.2.4...1.3.0">Diff</a> — <a href="http://htmlpreview.github.io/?https://raw.github.com/jashkenas/underscore/1.3.0/index.html">Docs</a><br /> + <ul> + <li> + Removed AMD (RequireJS) support from Underscore. If you'd like to use + Underscore with RequireJS, you can load it as a normal script, wrap + or patch your copy, or download a forked version. + </li> + </ul> + </p> + + <p id="1.2.4"> + <b class="header">1.2.4</b> — <small><i>January 4, 2012</i></small> — <a href="https://github.com/jashkenas/underscore/compare/1.2.3...1.2.4">Diff</a> — <a href="http://htmlpreview.github.io/?https://raw.github.com/jashkenas/underscore/1.2.4/index.html">Docs</a><br /> + <ul> + <li> + You now can (and probably should, as it's simpler) + write <tt>_.chain(list)</tt> + instead of <tt>_(list).chain()</tt>. + </li> + <li> + Fix for escaped characters in Underscore templates, and for supporting + customizations of <tt>_.templateSettings</tt> that only define one or + two of the required regexes. + </li> + <li> + Fix for passing an array as the first argument to an <tt>_.wrap</tt>'d function. + </li> + <li> + Improved compatibility with ClojureScript, which adds a <tt>call</tt> + function to <tt>String.prototype</tt>. + </li> + </ul> + </p> + + <p id="1.2.3"> + <b class="header">1.2.3</b> — <small><i>December 7, 2011</i></small> — <a href="https://github.com/jashkenas/underscore/compare/1.2.2...1.2.3">Diff</a> — <a href="http://htmlpreview.github.io/?https://raw.github.com/jashkenas/underscore/1.2.3/index.html">Docs</a><br /> + <ul> + <li> + Dynamic scope is now preserved for compiled <tt>_.template</tt> functions, + so you can use the value of <tt>this</tt> if you like. + </li> + <li> + Sparse array support of <tt>_.indexOf</tt>, <tt>_.lastIndexOf</tt>. + </li> + <li> + Both <tt>_.reduce</tt> and <tt>_.reduceRight</tt> can now be passed an + explicitly <tt>undefined</tt> value. (There's no reason why you'd + want to do this.) + </li> + </ul> + </p> + + <p id="1.2.2"> + <b class="header">1.2.2</b> — <small><i>November 14, 2011</i></small> — <a href="https://github.com/jashkenas/underscore/compare/1.2.1...1.2.2">Diff</a> — <a href="http://htmlpreview.github.io/?https://raw.github.com/jashkenas/underscore/1.2.1/index.html">Docs</a><br /> + <ul> + <li> + Continued tweaks to <tt>_.isEqual</tt> semantics. Now JS primitives are + considered equivalent to their wrapped versions, and arrays are compared + by their numeric properties only <small>(#351)</small>. + </li> + <li> + <tt>_.escape</tt> no longer tries to be smart about not double-escaping + already-escaped HTML entities. Now it just escapes regardless <small>(#350)</small>. + </li> + <li> + In <tt>_.template</tt>, you may now leave semicolons out of evaluated + statements if you wish: <tt><% }) %></tt> <small>(#369)</small>. + </li> + <li> + <tt>_.after(callback, 0)</tt> will now trigger the callback immediately, + making "after" easier to use with asynchronous APIs <small>(#366)</small>. + </li> + </ul> + </p> + + <p id="1.2.1"> + <b class="header">1.2.1</b> — <small><i>October 24, 2011</i></small> — <a href="https://github.com/jashkenas/underscore/compare/1.2.0...1.2.1">Diff</a> — <a href="http://htmlpreview.github.io/?https://raw.github.com/jashkenas/underscore/1.2.1/index.html">Docs</a><br /> + <ul> + <li> + Several important bug fixes for <tt>_.isEqual</tt>, which should now + do better on mutated Arrays, and on non-Array objects with + <tt>length</tt> properties. <small>(#329)</small> + </li> + <li> + <a href="https://github.com/jrburke">James Burke</a> + contributed Underscore exporting for AMD module loaders, and + <a href="https://github.com/tonylukasavage">Tony Lukasavage</a> + for Appcelerator Titanium. + <small>(#335, #338)</small> + </li> + <li> + You can now <tt>_.groupBy(list, 'property')</tt> as a shortcut for + grouping values by a particular common property. + </li> + <li> + <tt>_.throttle</tt>'d functions now fire immediately upon invocation, + and are rate-limited thereafter <small>(#170, #266)</small>. + </li> + <li> + Most of the <tt>_.is[Type]</tt> checks no longer ducktype. + </li> + <li> + The <tt>_.bind</tt> function now also works on constructors, a-la + ES5 ... but you would never want to use <tt>_.bind</tt> on a + constructor function. + </li> + <li> + <tt>_.clone</tt> no longer wraps non-object types in Objects. + </li> + <li> + <tt>_.find</tt> and <tt>_.filter</tt> are now the preferred names for + <tt>_.detect</tt> and <tt>_.select</tt>. + </li> + </ul> + </p> + + <p id="1.2.0"> + <b class="header">1.2.0</b> — <small><i>October 5, 2011</i></small> — <a href="https://github.com/jashkenas/underscore/compare/1.1.7...1.2.0">Diff</a> — <a href="http://htmlpreview.github.io/?https://raw.github.com/jashkenas/underscore/1.2.0/index.html">Docs</a><br /> + <ul> + <li> + The <tt>_.isEqual</tt> function now + supports true deep equality comparisons, with checks for cyclic structures, + thanks to Kit Cambridge. + </li> + <li> + Underscore templates now support HTML escaping interpolations, using + <tt><%- ... %></tt> syntax. + </li> + <li> + Ryan Tenney contributed <tt>_.shuffle</tt>, which uses a modified + Fisher-Yates to give you a shuffled copy of an array. + </li> + <li> + <tt>_.uniq</tt> can now be passed an optional iterator, to determine by + what criteria an object should be considered unique. + </li> + <li> + <tt>_.last</tt> now takes an optional argument which will return the last + N elements of the list. + </li> + <li> + A new <tt>_.initial</tt> function was added, as a mirror of <tt>_.rest</tt>, + which returns all the initial values of a list (except the last N). + </li> + </ul> + </p> + + <p id="1.1.7"> + <b class="header">1.1.7</b> — <small><i>July 13, 2011</i></small> — <a href="https://github.com/jashkenas/underscore/compare/1.1.6...1.1.7">Diff</a> — <a href="http://htmlpreview.github.io/?https://raw.github.com/jashkenas/underscore/1.1.7/index.html">Docs</a><br /> + Added <tt>_.groupBy</tt>, which aggregates a collection into groups of like items. + Added <tt>_.union</tt> and <tt>_.difference</tt>, to complement the + (re-named) <tt>_.intersection</tt>. + Various improvements for support of sparse arrays. + <tt>_.toArray</tt> now returns a clone, if directly passed an array. + <tt>_.functions</tt> now also returns the names of functions that are present + in the prototype chain. + </p> + + <p id="1.1.6"> + <b class="header">1.1.6</b> — <small><i>April 18, 2011</i></small> — <a href="https://github.com/jashkenas/underscore/compare/1.1.5...1.1.6">Diff</a> — <a href="http://htmlpreview.github.io/?https://raw.github.com/jashkenas/underscore/1.1.6/index.html">Docs</a><br /> + Added <tt>_.after</tt>, which will return a function that only runs after + first being called a specified number of times. + <tt>_.invoke</tt> can now take a direct function reference. + <tt>_.every</tt> now requires an iterator function to be passed, which + mirrors the ECMA5 API. + <tt>_.extend</tt> no longer copies keys when the value is undefined. + <tt>_.bind</tt> now errors when trying to bind an undefined value. + </p> + + <p id="1.1.5"> + <b class="header">1.1.5</b> — <small><i>March 20, 2011</i></small> — <a href="https://github.com/jashkenas/underscore/compare/1.1.4...1.1.5">Diff</a> — <a href="http://htmlpreview.github.io/?https://raw.github.com/jashkenas/underscore/1.1.5/index.html">Docs</a><br /> + Added an <tt>_.defaults</tt> function, for use merging together JS objects + representing default options. + Added an <tt>_.once</tt> function, for manufacturing functions that should + only ever execute a single time. + <tt>_.bind</tt> now delegates to the native ECMAScript 5 version, + where available. + <tt>_.keys</tt> now throws an error when used on non-Object values, as in + ECMAScript 5. + Fixed a bug with <tt>_.keys</tt> when used over sparse arrays. + </p> + + <p id="1.1.4"> + <b class="header">1.1.4</b> — <small><i>January 9, 2011</i></small> — <a href="https://github.com/jashkenas/underscore/compare/1.1.3...1.1.4">Diff</a> — <a href="http://htmlpreview.github.io/?https://raw.github.com/jashkenas/underscore/1.1.4/index.html">Docs</a><br /> + Improved compliance with ES5's Array methods when passing <tt>null</tt> + as a value. <tt>_.wrap</tt> now correctly sets <tt>this</tt> for the + wrapped function. <tt>_.indexOf</tt> now takes an optional flag for + finding the insertion index in an array that is guaranteed to already + be sorted. Avoiding the use of <tt>.callee</tt>, to allow <tt>_.isArray</tt> + to work properly in ES5's strict mode. + </p> + + <p id="1.1.3"> + <b class="header">1.1.3</b> — <small><i>December 1, 2010</i></small> — <a href="https://github.com/jashkenas/underscore/compare/1.1.2...1.1.3">Diff</a> — <a href="http://htmlpreview.github.io/?https://raw.github.com/jashkenas/underscore/1.1.3/index.html">Docs</a><br /> + In CommonJS, Underscore may now be required with just: <br /> + <tt>var _ = require("underscore")</tt>. + Added <tt>_.throttle</tt> and <tt>_.debounce</tt> functions. + Removed <tt>_.breakLoop</tt>, in favor of an ECMA5-style un-<i>break</i>-able + each implementation — this removes the try/catch, and you'll now have + better stack traces for exceptions that are thrown within an Underscore iterator. + Improved the <b>isType</b> family of functions for better interoperability + with Internet Explorer host objects. + <tt>_.template</tt> now correctly escapes backslashes in templates. + Improved <tt>_.reduce</tt> compatibility with the ECMA5 version: + if you don't pass an initial value, the first item in the collection is used. + <tt>_.each</tt> no longer returns the iterated collection, for improved + consistency with ES5's <tt>forEach</tt>. + </p> + + <p id="1.1.2"> + <b class="header">1.1.2</b> — <small><i>October 15, 2010</i></small> — <a href="https://github.com/jashkenas/underscore/compare/1.1.1...1.1.2">Diff</a> — <a href="http://htmlpreview.github.io/?https://raw.github.com/jashkenas/underscore/1.1.2/index.html">Docs</a><br /> + Fixed <tt>_.contains</tt>, which was mistakenly pointing at + <tt>_.intersect</tt> instead of <tt>_.include</tt>, like it should + have been. Added <tt>_.unique</tt> as an alias for <tt>_.uniq</tt>. + </p> + + <p id="1.1.1"> + <b class="header">1.1.1</b> — <small><i>October 5, 2010</i></small> — <a href="https://github.com/jashkenas/underscore/compare/1.1.0...1.1.1">Diff</a> — <a href="http://htmlpreview.github.io/?https://raw.github.com/jashkenas/underscore/1.1.1/index.html">Docs</a><br /> + Improved the speed of <tt>_.template</tt>, and its handling of multiline + interpolations. Ryan Tenney contributed optimizations to many Underscore + functions. An annotated version of the source code is now available. + </p> + + <p id="1.1.0"> + <b class="header">1.1.0</b> — <small><i>August 18, 2010</i></small> — <a href="https://github.com/jashkenas/underscore/compare/1.0.4...1.1.0">Diff</a> — <a href="http://htmlpreview.github.io/?https://raw.github.com/jashkenas/underscore/1.1.0/index.html">Docs</a><br /> + The method signature of <tt>_.reduce</tt> has been changed to match + the ECMAScript 5 signature, instead of the Ruby/Prototype.js version. + This is a backwards-incompatible change. <tt>_.template</tt> may now be + called with no arguments, and preserves whitespace. <tt>_.contains</tt> + is a new alias for <tt>_.include</tt>. + </p> + + <p id="1.0.4"> + <b class="header">1.0.4</b> — <small><i>June 22, 2010</i></small> — <a href="https://github.com/jashkenas/underscore/compare/1.0.3...1.0.4">Diff</a> — <a href="http://htmlpreview.github.io/?https://raw.github.com/jashkenas/underscore/1.0.4/index.html">Docs</a><br /> + <a href="http://themoell.com/">Andri Möll</a> contributed the <tt>_.memoize</tt> + function, which can be used to speed up expensive repeated computations + by caching the results. + </p> + + <p id="1.0.3"> + <b class="header">1.0.3</b> — <small><i>June 14, 2010</i></small> — <a href="https://github.com/jashkenas/underscore/compare/1.0.2...1.0.3">Diff</a> — <a href="http://htmlpreview.github.io/?https://raw.github.com/jashkenas/underscore/1.0.3/index.html">Docs</a><br /> + Patch that makes <tt>_.isEqual</tt> return <tt>false</tt> if any property + of the compared object has a <tt>NaN</tt> value. Technically the correct + thing to do, but of questionable semantics. Watch out for NaN comparisons. + </p> + + <p id="1.0.2"> + <b class="header">1.0.2</b> — <small><i>March 23, 2010</i></small> — <a href="https://github.com/jashkenas/underscore/compare/1.0.1...1.0.2">Diff</a> — <a href="http://htmlpreview.github.io/?https://raw.github.com/jashkenas/underscore/1.0.2/index.html">Docs</a><br /> + Fixes <tt>_.isArguments</tt> in recent versions of Opera, which have + arguments objects as real Arrays. + </p> + + <p id="1.0.1"> + <b class="header">1.0.1</b> — <small><i>March 19, 2010</i></small> — <a href="https://github.com/jashkenas/underscore/compare/1.0.0...1.0.1">Diff</a> — <a href="http://htmlpreview.github.io/?https://raw.github.com/jashkenas/underscore/1.0.1/index.html">Docs</a><br /> + Bugfix for <tt>_.isEqual</tt>, when comparing two objects with the same + number of undefined keys, but with different names. + </p> + + <p id="1.0.0"> + <b class="header">1.0.0</b> — <small><i>March 18, 2010</i></small> — <a href="https://github.com/jashkenas/underscore/compare/0.6.0...1.0.0">Diff</a> — <a href="http://htmlpreview.github.io/?https://raw.github.com/jashkenas/underscore/1.0.0/index.html">Docs</a><br /> + Things have been stable for many months now, so Underscore is now + considered to be out of beta, at <b>1.0</b>. Improvements since <b>0.6</b> + include <tt>_.isBoolean</tt>, and the ability to have <tt>_.extend</tt> + take multiple source objects. + </p> + + <p id="0.6.0"> + <b class="header">0.6.0</b> — <small><i>February 24, 2010</i></small> — <a href="https://github.com/jashkenas/underscore/compare/0.5.8...0.6.0">Diff</a> — <a href="http://htmlpreview.github.io/?https://raw.github.com/jashkenas/underscore/0.6.0/index.html">Docs</a><br /> + Major release. Incorporates a number of + <a href="https://github.com/ratbeard">Mile Frawley's</a> refactors for + safer duck-typing on collection functions, and cleaner internals. A new + <tt>_.mixin</tt> method that allows you to extend Underscore with utility + functions of your own. Added <tt>_.times</tt>, which works the same as in + Ruby or Prototype.js. Native support for ECMAScript 5's <tt>Array.isArray</tt>, + and <tt>Object.keys</tt>. + </p> + + <p id="0.5.8"> + <b class="header">0.5.8</b> — <small><i>January 28, 2010</i></small> — <a href="https://github.com/jashkenas/underscore/compare/0.5.7...0.5.8">Diff</a> — <a href="http://htmlpreview.github.io/?https://raw.github.com/jashkenas/underscore/0.5.8/index.html">Docs</a><br /> + Fixed Underscore's collection functions to work on + <a href="https://developer.mozilla.org/En/DOM/NodeList">NodeLists</a> and + <a href="https://developer.mozilla.org/En/DOM/HTMLCollection">HTMLCollections</a> + once more, thanks to + <a href="https://github.com/JustinTulloss">Justin Tulloss</a>. + </p> + + <p id="0.5.7"> + <b class="header">0.5.7</b> — <small><i>January 20, 2010</i></small> — <a href="https://github.com/jashkenas/underscore/compare/0.5.6...0.5.7">Diff</a> — <a href="http://htmlpreview.github.io/?https://raw.github.com/jashkenas/underscore/0.5.7/index.html">Docs</a><br /> + A safer implementation of <tt>_.isArguments</tt>, and a + faster <tt>_.isNumber</tt>,<br />thanks to + <a href="http://jedschmidt.com/">Jed Schmidt</a>. + </p> + + <p id="0.5.6"> + <b class="header">0.5.6</b> — <small><i>January 18, 2010</i></small> — <a href="https://github.com/jashkenas/underscore/compare/0.5.5...0.5.6">Diff</a> — <a href="http://htmlpreview.github.io/?https://raw.github.com/jashkenas/underscore/0.5.6/index.html">Docs</a><br /> + Customizable delimiters for <tt>_.template</tt>, contributed by + <a href="https://github.com/iamnoah">Noah Sloan</a>. + </p> + + <p id="0.5.5"> + <b class="header">0.5.5</b> — <small><i>January 9, 2010</i></small> — <a href="https://github.com/jashkenas/underscore/compare/0.5.4...0.5.5">Diff</a> — <a href="http://htmlpreview.github.io/?https://raw.github.com/jashkenas/underscore/0.5.5/index.html">Docs</a><br /> + Fix for a bug in MobileSafari's OOP-wrapper, with the arguments object. + </p> + + <p id="0.5.4"> + <b class="header">0.5.4</b> — <small><i>January 5, 2010</i></small> — <a href="https://github.com/jashkenas/underscore/compare/0.5.2...0.5.4">Diff</a> — <a href="http://htmlpreview.github.io/?https://raw.github.com/jashkenas/underscore/0.5.4/index.html">Docs</a><br /> + Fix for multiple single quotes within a template string for + <tt>_.template</tt>. See: + <a href="http://www.west-wind.com/Weblog/posts/509108.aspx">Rick Strahl's blog post</a>. + </p> + + <p id="0.5.2"> + <b class="header">0.5.2</b> — <small><i>January 1, 2010</i></small> — <a href="https://github.com/jashkenas/underscore/compare/0.5.1...0.5.2">Diff</a> — <a href="http://htmlpreview.github.io/?https://raw.github.com/jashkenas/underscore/0.5.2/index.html">Docs</a><br /> + New implementations of <tt>isArray</tt>, <tt>isDate</tt>, <tt>isFunction</tt>, + <tt>isNumber</tt>, <tt>isRegExp</tt>, and <tt>isString</tt>, thanks to + a suggestion from + <a href="http://www.broofa.com/">Robert Kieffer</a>. + Instead of doing <tt>Object#toString</tt> + comparisons, they now check for expected properties, which is less safe, + but more than an order of magnitude faster. Most other Underscore + functions saw minor speed improvements as a result. + <a href="http://dolzhenko.org/">Evgeniy Dolzhenko</a> + contributed <tt>_.tap</tt>, + <a href="http://ruby-doc.org/core-1.9/classes/Object.html#M000191">similar to Ruby 1.9's</a>, + which is handy for injecting side effects (like logging) into chained calls. + </p> + + <p id="0.5.1"> + <b class="header">0.5.1</b> — <small><i>December 9, 2009</i></small> — <a href="https://github.com/jashkenas/underscore/compare/0.5.0...0.5.1">Diff</a> — <a href="http://htmlpreview.github.io/?https://raw.github.com/jashkenas/underscore/0.5.1/index.html">Docs</a><br /> + Added an <tt>_.isArguments</tt> function. Lots of little safety checks + and optimizations contributed by + <a href="https://github.com/iamnoah">Noah Sloan</a> and + <a href="http://themoell.com/">Andri Möll</a>. + </p> + + <p id="0.5.0"> + <b class="header">0.5.0</b> — <small><i>December 7, 2009</i></small> — <a href="https://github.com/jashkenas/underscore/compare/0.4.7...0.5.0">Diff</a> — <a href="http://htmlpreview.github.io/?https://raw.github.com/jashkenas/underscore/0.5.0/index.html">Docs</a><br /> + <b>[API Changes]</b> <tt>_.bindAll</tt> now takes the context object as + its first parameter. If no method names are passed, all of the context + object's methods are bound to it, enabling chaining and easier binding. + <tt>_.functions</tt> now takes a single argument and returns the names + of its Function properties. Calling <tt>_.functions(_)</tt> will get you + the previous behavior. + Added <tt>_.isRegExp</tt> so that <tt>isEqual</tt> can now test for RegExp equality. + All of the "is" functions have been shrunk down into a single definition. + <a href="https://github.com/grayrest">Karl Guertin</a> contributed patches. + </p> + + <p id="0.4.7"> + <b class="header">0.4.7</b> — <small><i>December 6, 2009</i></small> — <a href="https://github.com/jashkenas/underscore/compare/0.4.6...0.4.7">Diff</a> — <a href="http://htmlpreview.github.io/?https://raw.github.com/jashkenas/underscore/0.4.7/index.html">Docs</a><br /> + Added <tt>isDate</tt>, <tt>isNaN</tt>, and <tt>isNull</tt>, for completeness. + Optimizations for <tt>isEqual</tt> when checking equality between Arrays + or Dates. <tt>_.keys</tt> is now <small><i><b>25%–2X</b></i></small> faster (depending on your + browser) which speeds up the functions that rely on it, such as <tt>_.each</tt>. + </p> + + <p id="0.4.6"> + <b class="header">0.4.6</b> — <small><i>November 30, 2009</i></small> — <a href="https://github.com/jashkenas/underscore/compare/0.4.5...0.4.6">Diff</a> — <a href="http://htmlpreview.github.io/?https://raw.github.com/jashkenas/underscore/0.4.6/index.html">Docs</a><br /> + Added the <tt>range</tt> function, a port of the + <a href="http://docs.python.org/library/functions.html#range">Python + function of the same name</a>, for generating flexibly-numbered lists + of integers. Original patch contributed by + <a href="https://github.com/kylichuku">Kirill Ishanov</a>. + </p> + + <p id="0.4.5"> + <b class="header">0.4.5</b> — <small><i>November 19, 2009</i></small> — <a href="https://github.com/jashkenas/underscore/compare/0.4.4...0.4.5">Diff</a> — <a href="http://htmlpreview.github.io/?https://raw.github.com/jashkenas/underscore/0.4.5/index.html">Docs</a><br /> + Added <tt>rest</tt> for Arrays and arguments objects, and aliased + <tt>first</tt> as <tt>head</tt>, and <tt>rest</tt> as <tt>tail</tt>, + thanks to <a href="https://github.com/lukesutton">Luke Sutton</a>'s patches. + Added tests ensuring that all Underscore Array functions also work on + <i>arguments</i> objects. + </p> + + <p id="0.4.4"> + <b class="header">0.4.4</b> — <small><i>November 18, 2009</i></small> — <a href="https://github.com/jashkenas/underscore/compare/0.4.3...0.4.4">Diff</a> — <a href="http://htmlpreview.github.io/?https://raw.github.com/jashkenas/underscore/0.4.4/index.html">Docs</a><br /> + Added <tt>isString</tt>, and <tt>isNumber</tt>, for consistency. Fixed + <tt>_.isEqual(NaN, NaN)</tt> to return <i>true</i> (which is debatable). + </p> + + <p id="0.4.3"> + <b class="header">0.4.3</b> — <small><i>November 9, 2009</i></small> — <a href="https://github.com/jashkenas/underscore/compare/0.4.2...0.4.3">Diff</a> — <a href="http://htmlpreview.github.io/?https://raw.github.com/jashkenas/underscore/0.4.3/index.html">Docs</a><br /> + Started using the native <tt>StopIteration</tt> object in browsers that support it. + Fixed Underscore setup for CommonJS environments. + </p> + + <p id="0.4.2"> + <b class="header">0.4.2</b> — <small><i>November 9, 2009</i></small> — <a href="https://github.com/jashkenas/underscore/compare/0.4.1...0.4.2">Diff</a> — <a href="http://htmlpreview.github.io/?https://raw.github.com/jashkenas/underscore/0.4.2/index.html">Docs</a><br /> + Renamed the unwrapping function to <tt>value</tt>, for clarity. + </p> + + <p id="0.4.1"> + <b class="header">0.4.1</b> — <small><i>November 8, 2009</i></small> — <a href="https://github.com/jashkenas/underscore/compare/0.4.0...0.4.1">Diff</a> — <a href="http://htmlpreview.github.io/?https://raw.github.com/jashkenas/underscore/0.4.1/index.html">Docs</a><br /> + Chained Underscore objects now support the Array prototype methods, so + that you can perform the full range of operations on a wrapped array + without having to break your chain. Added a <tt>breakLoop</tt> method + to <b>break</b> in the middle of any Underscore iteration. Added an + <tt>isEmpty</tt> function that works on arrays and objects. + </p> + + <p id="0.4.0"> + <b class="header">0.4.0</b> — <small><i>November 7, 2009</i></small> — <a href="https://github.com/jashkenas/underscore/compare/0.3.3...0.4.0">Diff</a> — <a href="http://htmlpreview.github.io/?https://raw.github.com/jashkenas/underscore/0.4.0/index.html">Docs</a><br /> + All Underscore functions can now be called in an object-oriented style, + like so: <tt>_([1, 2, 3]).map(...);</tt>. Original patch provided by + <a href="http://macournoyer.com/">Marc-André Cournoyer</a>. + Wrapped objects can be chained through multiple + method invocations. A <a href="#object-functions"><tt>functions</tt></a> method + was added, providing a sorted list of all the functions in Underscore. + </p> + + <p id="0.3.3"> + <b class="header">0.3.3</b> — <small><i>October 31, 2009</i></small> — <a href="https://github.com/jashkenas/underscore/compare/0.3.2...0.3.3">Diff</a> — <a href="http://htmlpreview.github.io/?https://raw.github.com/jashkenas/underscore/0.3.3/index.html">Docs</a><br /> + Added the JavaScript 1.8 function <tt>reduceRight</tt>. Aliased it + as <tt>foldr</tt>, and aliased <tt>reduce</tt> as <tt>foldl</tt>. + </p> + + <p id="0.3.2"> + <b class="header">0.3.2</b> — <small><i>October 29, 2009</i></small> — <a href="https://github.com/jashkenas/underscore/compare/0.3.1...0.3.2">Diff</a> — <a href="http://htmlpreview.github.io/?https://raw.github.com/jashkenas/underscore/0.3.2/index.html">Docs</a><br /> + Now runs on stock <a href="http://www.mozilla.org/rhino/">Rhino</a> + interpreters with: <tt>load("underscore.js")</tt>. + Added <a href="#identity"><tt>identity</tt></a> as a utility function. + </p> + + <p id="0.3.1"> + <b class="header">0.3.1</b> — <small><i>October 29, 2009</i></small> — <a href="https://github.com/jashkenas/underscore/compare/0.3.0...0.3.1">Diff</a> — <a href="http://htmlpreview.github.io/?https://raw.github.com/jashkenas/underscore/0.3.1/index.html">Docs</a><br /> + All iterators are now passed in the original collection as their third + argument, the same as JavaScript 1.6's <b>forEach</b>. Iterating over + objects is now called with <tt>(value, key, collection)</tt>, for details + see <a href="#each"><tt>_.each</tt></a>. + </p> + + <p id="0.3.0"> + <b class="header">0.3.0</b> — <small><i>October 29, 2009</i></small> — <a href="https://github.com/jashkenas/underscore/compare/0.2.0...0.3.0">Diff</a> — <a href="http://htmlpreview.github.io/?https://raw.github.com/jashkenas/underscore/0.3.0/index.html">Docs</a><br /> + Added <a href="https://github.com/DmitryBaranovskiy">Dmitry Baranovskiy</a>'s + comprehensive optimizations, merged in + <a href="https://github.com/kriskowal">Kris Kowal</a>'s patches to make Underscore + <a href="http://wiki.commonjs.org/wiki/CommonJS">CommonJS</a> and + <a href="http://narwhaljs.org/">Narwhal</a> compliant. + </p> + + <p id="0.2.0"> + <b class="header">0.2.0</b> — <small><i>October 28, 2009</i></small> — <a href="https://github.com/jashkenas/underscore/compare/0.1.1...0.2.0">Diff</a> — <a href="http://htmlpreview.github.io/?https://raw.github.com/jashkenas/underscore/0.2.0/index.html">Docs</a><br /> + Added <tt>compose</tt> and <tt>lastIndexOf</tt>, renamed <tt>inject</tt> to + <tt>reduce</tt>, added aliases for <tt>inject</tt>, <tt>filter</tt>, + <tt>every</tt>, <tt>some</tt>, and <tt>forEach</tt>. + </p> + + <p id="0.1.1"> + <b class="header">0.1.1</b> — <small><i>October 28, 2009</i></small> — <a href="https://github.com/jashkenas/underscore/compare/0.1.0...0.1.1">Diff</a> — <a href="http://htmlpreview.github.io/?https://raw.github.com/jashkenas/underscore/0.1.1/index.html">Docs</a><br /> + Added <tt>noConflict</tt>, so that the "Underscore" object can be assigned to + other variables. + </p> + + <p id="0.1.0"> + <b class="header">0.1.0</b> — <small><i>October 28, 2009</i></small> — <a href="http://htmlpreview.github.io/?https://raw.github.com/jashkenas/underscore/0.1.1/index.html">Docs</a><br /> + Initial release of Underscore.js. + </p> + + <p> + <a href="http://documentcloud.org/" title="A DocumentCloud Project" style="background:none;"> + <img src="http://jashkenas.s3.amazonaws.com/images/a_documentcloud_project.png" alt="A DocumentCloud Project" /> + </a> + </p> + + </div> + + </div> + + <!-- Include Underscore, so you can play with it in the console. --> + <script type="text/javascript" src="underscore.js"></script> + +</body> +</html> diff --git a/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/package.json b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/package.json index 49e9145c9..70c9ac2c5 100644 --- a/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/package.json +++ b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/package.json @@ -21,11 +21,12 @@ "version": "1.6.0", "devDependencies": { "docco": "0.6.x", - "phantomjs": "1.9.0-1", - "uglify-js": "2.4.x" + "phantomjs": "1.9.7-1", + "uglify-js": "2.4.x", + "eslint": "0.6.x" }, "scripts": { - "test": "phantomjs test/vendor/runner.js test/index.html?noglobals=true", + "test": "phantomjs test/vendor/runner.js test/index.html?noglobals=true && eslint underscore.js", "build": "uglifyjs underscore.js -c \"evaluate=false\" --comments \"/ .*/\" -m --source-map underscore-min.map -o underscore-min.js", "doc": "docco underscore.js" }, @@ -40,28 +41,13 @@ "underscore-min.js", "LICENSE" ], + "readme": " __\n /\\ \\ __\n __ __ ___ \\_\\ \\ __ _ __ ____ ___ ___ _ __ __ /\\_\\ ____\n /\\ \\/\\ \\ /' _ `\\ /'_ \\ /'__`\\/\\ __\\/ ,__\\ / ___\\ / __`\\/\\ __\\/'__`\\ \\/\\ \\ /',__\\\n \\ \\ \\_\\ \\/\\ \\/\\ \\/\\ \\ \\ \\/\\ __/\\ \\ \\//\\__, `\\/\\ \\__//\\ \\ \\ \\ \\ \\//\\ __/ __ \\ \\ \\/\\__, `\\\n \\ \\____/\\ \\_\\ \\_\\ \\___,_\\ \\____\\\\ \\_\\\\/\\____/\\ \\____\\ \\____/\\ \\_\\\\ \\____\\/\\_\\ _\\ \\ \\/\\____/\n \\/___/ \\/_/\\/_/\\/__,_ /\\/____/ \\/_/ \\/___/ \\/____/\\/___/ \\/_/ \\/____/\\/_//\\ \\_\\ \\/___/\n \\ \\____/\n \\/___/\n\nUnderscore.js is a utility-belt library for JavaScript that provides\nsupport for the usual functional suspects (each, map, reduce, filter...)\nwithout extending any core JavaScript objects.\n\nFor Docs, License, Tests, and pre-packed downloads, see:\nhttp://underscorejs.org\n\nUnderscore is an open-sourced component of DocumentCloud:\nhttps://github.com/documentcloud\n\nMany thanks to our contributors:\nhttps://github.com/jashkenas/underscore/contributors\n", + "readmeFilename": "README.md", "bugs": { "url": "https://github.com/jashkenas/underscore/issues" }, "_id": "underscore@1.6.0", - "dist": { - "shasum": "8b38b10cacdef63337b8b24e4ff86d45aea529a8", - "tarball": "http://registry.npmjs.org/underscore/-/underscore-1.6.0.tgz" - }, - "_from": "underscore@>= 1.3.0", - "_npmVersion": "1.3.21", - "_npmUser": { - "name": "jashkenas", - "email": "jashkenas@gmail.com" - }, - "maintainers": [ - { - "name": "jashkenas", - "email": "jashkenas@gmail.com" - } - ], - "directories": {}, - "_shasum": "8b38b10cacdef63337b8b24e4ff86d45aea529a8", - "_resolved": "https://registry.npmjs.org/underscore/-/underscore-1.6.0.tgz", - "readme": "ERROR: No README data found!" + "_shasum": "444b9113da7a490c14f9c9b4230d06363e45a2c0", + "_resolved": "git+https://github.com/jashkenas/underscore#b5591f1e9313a09cf8140abe0cec5d7f75429452", + "_from": "underscore@>=1.3.0" } diff --git a/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/test/arrays.js b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/test/arrays.js new file mode 100644 index 000000000..1621ad03d --- /dev/null +++ b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/test/arrays.js @@ -0,0 +1,323 @@ +(function() { + + module('Arrays'); + + test('first', function() { + equal(_.first([1, 2, 3]), 1, 'can pull out the first element of an array'); + equal(_([1, 2, 3]).first(), 1, 'can perform OO-style "first()"'); + deepEqual(_.first([1, 2, 3], 0), [], 'can pass an index to first'); + deepEqual(_.first([1, 2, 3], 2), [1, 2], 'can pass an index to first'); + deepEqual(_.first([1, 2, 3], 5), [1, 2, 3], 'can pass an index to first'); + var result = (function(){ return _.first(arguments); })(4, 3, 2, 1); + equal(result, 4, 'works on an arguments object.'); + result = _.map([[1, 2, 3], [1, 2, 3]], _.first); + deepEqual(result, [1, 1], 'works well with _.map'); + result = (function() { return _.first([1, 2, 3], 2); })(); + deepEqual(result, [1, 2]); + + equal(_.first(null), undefined, 'handles nulls'); + strictEqual(_.first([1, 2, 3], -1).length, 0); + }); + + test('head', function() { + strictEqual(_.first, _.head, 'alias for first'); + }); + + test('take', function() { + strictEqual(_.first, _.take, 'alias for first'); + }); + + test('rest', function() { + var numbers = [1, 2, 3, 4]; + deepEqual(_.rest(numbers), [2, 3, 4], 'working rest()'); + deepEqual(_.rest(numbers, 0), [1, 2, 3, 4], 'working rest(0)'); + deepEqual(_.rest(numbers, 2), [3, 4], 'rest can take an index'); + var result = (function(){ return _(arguments).rest(); })(1, 2, 3, 4); + deepEqual(result, [2, 3, 4], 'works on arguments object'); + result = _.map([[1, 2, 3], [1, 2, 3]], _.rest); + deepEqual(_.flatten(result), [2, 3, 2, 3], 'works well with _.map'); + result = (function(){ return _(arguments).rest(); })(1, 2, 3, 4); + deepEqual(result, [2, 3, 4], 'works on arguments object'); + }); + + test('tail', function() { + strictEqual(_.rest, _.tail, 'alias for rest'); + }); + + test('drop', function() { + strictEqual(_.rest, _.drop, 'alias for rest'); + }); + + test('initial', function() { + deepEqual(_.initial([1, 2, 3, 4, 5]), [1, 2, 3, 4], 'working initial()'); + deepEqual(_.initial([1, 2, 3, 4], 2), [1, 2], 'initial can take an index'); + deepEqual(_.initial([1, 2, 3, 4], 6), [], 'initial can take a large index'); + var result = (function(){ return _(arguments).initial(); })(1, 2, 3, 4); + deepEqual(result, [1, 2, 3], 'initial works on arguments object'); + result = _.map([[1, 2, 3], [1, 2, 3]], _.initial); + deepEqual(_.flatten(result), [1, 2, 1, 2], 'initial works with _.map'); + }); + + test('last', function() { + equal(_.last([1, 2, 3]), 3, 'can pull out the last element of an array'); + deepEqual(_.last([1, 2, 3], 0), [], 'can pass an index to last'); + deepEqual(_.last([1, 2, 3], 2), [2, 3], 'can pass an index to last'); + deepEqual(_.last([1, 2, 3], 5), [1, 2, 3], 'can pass an index to last'); + var result = (function(){ return _(arguments).last(); })(1, 2, 3, 4); + equal(result, 4, 'works on an arguments object'); + result = _.map([[1, 2, 3], [1, 2, 3]], _.last); + deepEqual(result, [3, 3], 'works well with _.map'); + + equal(_.last(null), undefined, 'handles nulls'); + strictEqual(_.last([1, 2, 3], -1).length, 0); + }); + + test('compact', function() { + equal(_.compact([0, 1, false, 2, false, 3]).length, 3, 'can trim out all falsy values'); + var result = (function(){ return _.compact(arguments).length; })(0, 1, false, 2, false, 3); + equal(result, 3, 'works on an arguments object'); + }); + + test('flatten', function() { + var list = [1, [2], [3, [[[4]]]]]; + deepEqual(_.flatten(list), [1, 2, 3, 4], 'can flatten nested arrays'); + deepEqual(_.flatten(list, true), [1, 2, 3, [[[4]]]], 'can shallowly flatten nested arrays'); + var result = (function(){ return _.flatten(arguments); })(1, [2], [3, [[[4]]]]); + deepEqual(result, [1, 2, 3, 4], 'works on an arguments object'); + list = [[1], [2], [3], [[4]]]; + deepEqual(_.flatten(list, true), [1, 2, 3, [4]], 'can shallowly flatten arrays containing only other arrays'); + }); + + test('without', function() { + var list = [1, 2, 1, 0, 3, 1, 4]; + deepEqual(_.without(list, 0, 1), [2, 3, 4], 'can remove all instances of an object'); + var result = (function(){ return _.without(arguments, 0, 1); })(1, 2, 1, 0, 3, 1, 4); + deepEqual(result, [2, 3, 4], 'works on an arguments object'); + + list = [{one : 1}, {two : 2}]; + ok(_.without(list, {one : 1}).length == 2, 'uses real object identity for comparisons.'); + ok(_.without(list, list[0]).length == 1, 'ditto.'); + }); + + test('uniq', function() { + var list = [1, 2, 1, 3, 1, 4]; + deepEqual(_.uniq(list), [1, 2, 3, 4], 'can find the unique values of an unsorted array'); + + list = [1, 1, 1, 2, 2, 3]; + deepEqual(_.uniq(list, true), [1, 2, 3], 'can find the unique values of a sorted array faster'); + + list = [{name: 'moe'}, {name: 'curly'}, {name: 'larry'}, {name: 'curly'}]; + var iterator = function(value) { return value.name; }; + deepEqual(_.map(_.uniq(list, false, iterator), iterator), ['moe', 'curly', 'larry'], 'can find the unique values of an array using a custom iterator'); + + deepEqual(_.map(_.uniq(list, iterator), iterator), ['moe', 'curly', 'larry'], 'can find the unique values of an array using a custom iterator without specifying whether array is sorted'); + + iterator = function(value) { return value +1; }; + list = [1, 2, 2, 3, 4, 4]; + deepEqual(_.uniq(list, true, iterator), [1, 2, 3, 4], 'iterator works with sorted array'); + + var result = (function(){ return _.uniq(arguments); })(1, 2, 1, 3, 1, 4); + deepEqual(result, [1, 2, 3, 4], 'works on an arguments object'); + + deepEqual(_.uniq(null), []); + + var context = {}; + list = [3]; + _.uniq(list, function(value, index, array) { + strictEqual(this, context); + strictEqual(value, 3); + strictEqual(index, 0); + }, context); + }); + + test('unique', function() { + strictEqual(_.uniq, _.unique, 'alias for uniq'); + }); + + test('intersection', function() { + var stooges = ['moe', 'curly', 'larry'], leaders = ['moe', 'groucho']; + deepEqual(_.intersection(stooges, leaders), ['moe'], 'can take the set intersection of two arrays'); + deepEqual(_(stooges).intersection(leaders), ['moe'], 'can perform an OO-style intersection'); + var result = (function(){ return _.intersection(arguments, leaders); })('moe', 'curly', 'larry'); + deepEqual(result, ['moe'], 'works on an arguments object'); + var theSixStooges = ['moe', 'moe', 'curly', 'curly', 'larry', 'larry']; + deepEqual(_.intersection(theSixStooges, leaders), ['moe'], 'returns a duplicate-free array'); + result = _.intersection([2, 4, 3, 1], [1, 2, 3]); + deepEqual(result, [2, 3, 1], 'preserves order of first array'); + result = _.intersection(null, [1, 2, 3]); + equal(Object.prototype.toString.call(result), '[object Array]', 'returns an empty array when passed null as first argument'); + equal(result.length, 0, 'returns an empty array when passed null as first argument'); + result = _.intersection([1, 2, 3], null); + equal(Object.prototype.toString.call(result), '[object Array]', 'returns an empty array when passed null as argument beyond the first'); + equal(result.length, 0, 'returns an empty array when passed null as argument beyond the first'); + }); + + test('union', function() { + var result = _.union([1, 2, 3], [2, 30, 1], [1, 40]); + deepEqual(result, [1, 2, 3, 30, 40], 'takes the union of a list of arrays'); + + result = _.union([1, 2, 3], [2, 30, 1], [1, 40, [1]]); + deepEqual(result, [1, 2, 3, 30, 40, [1]], 'takes the union of a list of nested arrays'); + + var args = null; + (function(){ args = arguments; })(1, 2, 3); + result = _.union(args, [2, 30, 1], [1, 40]); + deepEqual(result, [1, 2, 3, 30, 40], 'takes the union of a list of arrays'); + + result = _.union([1, 2, 3], 4); + deepEqual(result, [1, 2, 3], 'restrict the union to arrays only'); + }); + + test('difference', function() { + var result = _.difference([1, 2, 3], [2, 30, 40]); + deepEqual(result, [1, 3], 'takes the difference of two arrays'); + + result = _.difference([1, 2, 3, 4], [2, 30, 40], [1, 11, 111]); + deepEqual(result, [3, 4], 'takes the difference of three arrays'); + + result = _.difference([1, 2, 3], 1); + deepEqual(result, [1, 2, 3], 'restrict the difference to arrays only'); + }); + + test('zip', function() { + var names = ['moe', 'larry', 'curly'], ages = [30, 40, 50], leaders = [true]; + deepEqual(_.zip(names, ages, leaders), [ + ['moe', 30, true], + ['larry', 40, undefined], + ['curly', 50, undefined] + ], 'zipped together arrays of different lengths'); + + var stooges = _.zip(['moe', 30, 'stooge 1'], ['larry', 40, 'stooge 2'], ['curly', 50, 'stooge 3']); + deepEqual(stooges, [['moe', 'larry', 'curly'], [30, 40, 50], ['stooge 1', 'stooge 2', 'stooge 3']], 'zipped pairs'); + + // In the case of difference lengths of the tuples undefineds + // should be used as placeholder + stooges = _.zip(['moe', 30], ['larry', 40], ['curly', 50, 'extra data']); + deepEqual(stooges, [['moe', 'larry', 'curly'], [30, 40, 50], [undefined, undefined, 'extra data']], 'zipped pairs with empties'); + + var empty = _.zip([]); + deepEqual(empty, [], 'unzipped empty'); + + deepEqual(_.zip(null), [], 'handles null'); + deepEqual(_.zip(), [], '_.zip() returns []'); + }); + + test('object', function() { + var result = _.object(['moe', 'larry', 'curly'], [30, 40, 50]); + var shouldBe = {moe: 30, larry: 40, curly: 50}; + deepEqual(result, shouldBe, 'two arrays zipped together into an object'); + + result = _.object([['one', 1], ['two', 2], ['three', 3]]); + shouldBe = {one: 1, two: 2, three: 3}; + deepEqual(result, shouldBe, 'an array of pairs zipped together into an object'); + + var stooges = {moe: 30, larry: 40, curly: 50}; + deepEqual(_.object(_.pairs(stooges)), stooges, 'an object converted to pairs and back to an object'); + + deepEqual(_.object(null), {}, 'handles nulls'); + }); + + test('indexOf', function() { + var numbers = [1, 2, 3]; + equal(_.indexOf(numbers, 2), 1, 'can compute indexOf'); + var result = (function(){ return _.indexOf(arguments, 2); })(1, 2, 3); + equal(result, 1, 'works on an arguments object'); + equal(_.indexOf(null, 2), -1, 'handles nulls properly'); + + var num = 35; + numbers = [10, 20, 30, 40, 50]; + var index = _.indexOf(numbers, num, true); + equal(index, -1, '35 is not in the list'); + + numbers = [10, 20, 30, 40, 50]; num = 40; + index = _.indexOf(numbers, num, true); + equal(index, 3, '40 is in the list'); + + numbers = [1, 40, 40, 40, 40, 40, 40, 40, 50, 60, 70]; num = 40; + equal(_.indexOf(numbers, num, true), 1, '40 is in the list'); + equal(_.indexOf(numbers, 6, true), -1, '6 isnt in the list'); + equal(_.indexOf([1, 2, 5, 4, 6, 7], 5, true), -1, 'sorted indexOf doesn\'t uses binary search'); + ok(_.every(["1", [], {}, null], function() { + return _.indexOf(numbers, num, {}) === 1; + }), 'non-nums as fromIndex make indexOf assume sorted'); + + numbers = [1, 2, 3, 1, 2, 3, 1, 2, 3]; + index = _.indexOf(numbers, 2, 5); + equal(index, 7, 'supports the fromIndex argument'); + + index = _.indexOf([,,,], undefined); + equal(index, 0, 'treats sparse arrays as if they were dense'); + + var array = [1, 2, 3, 1, 2, 3]; + strictEqual(_.indexOf(array, 1, -3), 3, 'neg `fromIndex` starts at the right index'); + strictEqual(_.indexOf(array, 1, -2), -1, 'neg `fromIndex` starts at the right index'); + strictEqual(_.indexOf(array, 2, -3), 4); + _.each([-6, -8, -Infinity], function(fromIndex) { + strictEqual(_.indexOf(array, 1, fromIndex), 0); + }); + strictEqual(_.indexOf([1, 2, 3], 1, true), 0); + }); + + test('lastIndexOf', function() { + var numbers = [1, 0, 1]; + var falsey = [, '', 0, false, NaN, null, undefined]; + equal(_.lastIndexOf(numbers, 1), 2); + + numbers = [1, 0, 1, 0, 0, 1, 0, 0, 0]; + numbers.lastIndexOf = null; + equal(_.lastIndexOf(numbers, 1), 5, 'can compute lastIndexOf, even without the native function'); + equal(_.lastIndexOf(numbers, 0), 8, 'lastIndexOf the other element'); + var result = (function(){ return _.lastIndexOf(arguments, 1); })(1, 0, 1, 0, 0, 1, 0, 0, 0); + equal(result, 5, 'works on an arguments object'); + equal(_.lastIndexOf(null, 2), -1, 'handles nulls properly'); + + numbers = [1, 2, 3, 1, 2, 3, 1, 2, 3]; + var index = _.lastIndexOf(numbers, 2, 2); + equal(index, 1, 'supports the fromIndex argument'); + + var array = [1, 2, 3, 1, 2, 3]; + + strictEqual(_.lastIndexOf(array, 1, 0), 0, 'starts at the correct from idx'); + strictEqual(_.lastIndexOf(array, 3), 5, 'should return the index of the last matched value'); + strictEqual(_.lastIndexOf(array, 4), -1, 'should return `-1` for an unmatched value'); + + strictEqual(_.lastIndexOf(array, 1, 2), 0, 'should work with a positive `fromIndex`'); + + _.each([6, 8, Math.pow(2, 32), Infinity], function(fromIndex) { + strictEqual(_.lastIndexOf(array, undefined, fromIndex), -1); + strictEqual(_.lastIndexOf(array, 1, fromIndex), 3); + strictEqual(_.lastIndexOf(array, '', fromIndex), -1); + }); + + var expected = _.map(falsey, function(value) { + return typeof value == 'number' ? -1 : 5; + }); + + var actual = _.map(falsey, function(fromIndex) { + return _.lastIndexOf(array, 3, fromIndex); + }); + + deepEqual(actual, expected, 'should treat falsey `fromIndex` values, except `0` and `NaN`, as `array.length`'); + strictEqual(_.lastIndexOf(array, 3, '1'), 5, 'should treat non-number `fromIndex` values as `array.length`'); + strictEqual(_.lastIndexOf(array, 3, true), 5, 'should treat non-number `fromIndex` values as `array.length`'); + + strictEqual(_.lastIndexOf(array, 2, -3), 1, 'should work with a negative `fromIndex`'); + strictEqual(_.lastIndexOf(array, 1, -3), 3, 'neg `fromIndex` starts at the right index'); + + deepEqual(_.map([-6, -8, -Infinity], function(fromIndex) { + return _.lastIndexOf(array, 1, fromIndex); + }), [0, -1, -1]); + }); + + test('range', function() { + deepEqual(_.range(0), [], 'range with 0 as a first argument generates an empty array'); + deepEqual(_.range(4), [0, 1, 2, 3], 'range with a single positive argument generates an array of elements 0,1,2,...,n-1'); + deepEqual(_.range(5, 8), [5, 6, 7], 'range with two arguments a & b, a<b generates an array of elements a,a+1,a+2,...,b-2,b-1'); + deepEqual(_.range(8, 5), [], 'range with two arguments a & b, b<a generates an empty array'); + deepEqual(_.range(3, 10, 3), [3, 6, 9], 'range with three arguments a & b & c, c < b-a, a < b generates an array of elements a,a+c,a+2c,...,b - (multiplier of a) < c'); + deepEqual(_.range(3, 10, 15), [3], 'range with three arguments a & b & c, c > b-a, a < b generates an array with a single element, equal to a'); + deepEqual(_.range(12, 7, -2), [12, 10, 8], 'range with three arguments a & b & c, a > b, c < 0 generates an array of elements a,a-c,a-2c and ends with the number not less than b'); + deepEqual(_.range(0, -10, -1), [0, -1, -2, -3, -4, -5, -6, -7, -8, -9], 'final example in the Python docs'); + }); + +})(); diff --git a/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/test/chaining.js b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/test/chaining.js new file mode 100644 index 000000000..0f377e2bc --- /dev/null +++ b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/test/chaining.js @@ -0,0 +1,65 @@ +(function() { + + module('Chaining'); + + test('map/flatten/reduce', function() { + var lyrics = [ + "I'm a lumberjack and I'm okay", + "I sleep all night and I work all day", + "He's a lumberjack and he's okay", + "He sleeps all night and he works all day" + ]; + var counts = _(lyrics).chain() + .map(function(line) { return line.split(''); }) + .flatten() + .reduce(function(hash, l) { + hash[l] = hash[l] || 0; + hash[l]++; + return hash; + }, {}).value(); + ok(counts.a == 16 && counts.e == 10, 'counted all the letters in the song'); + }); + + test('select/reject/sortBy', function() { + var numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + numbers = _(numbers).chain().select(function(n) { + return n % 2 === 0; + }).reject(function(n) { + return n % 4 === 0; + }).sortBy(function(n) { + return -n; + }).value(); + deepEqual(numbers, [10, 6, 2], 'filtered and reversed the numbers'); + }); + + test('select/reject/sortBy in functional style', function() { + var numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + numbers = _.chain(numbers).select(function(n) { + return n % 2 === 0; + }).reject(function(n) { + return n % 4 === 0; + }).sortBy(function(n) { + return -n; + }).value(); + deepEqual(numbers, [10, 6, 2], 'filtered and reversed the numbers'); + }); + + test('reverse/concat/unshift/pop/map', function() { + var numbers = [1, 2, 3, 4, 5]; + numbers = _(numbers).chain() + .reverse() + .concat([5, 5, 5]) + .unshift(17) + .pop() + .map(function(n){ return n * 2; }) + .value(); + deepEqual(numbers, [34, 10, 8, 6, 4, 2, 10, 10], 'can chain together array functions.'); + }); + + test('chaining works in small stages', function() { + var o = _([1, 2, 3, 4]).chain(); + deepEqual(o.filter(function(i) { return i < 3; }).value(), [1, 2]); + deepEqual(o.filter(function(i) { return i > 2; }).value(), [3, 4]); + }); + +})(); diff --git a/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/test/collections.js b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/test/collections.js new file mode 100644 index 000000000..0a36bfe85 --- /dev/null +++ b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/test/collections.js @@ -0,0 +1,676 @@ +(function() { + + module('Collections'); + + test('each', function() { + _.each([1, 2, 3], function(num, i) { + equal(num, i + 1, 'each iterators provide value and iteration count'); + }); + + var answers = []; + _.each([1, 2, 3], function(num){ answers.push(num * this.multiplier);}, {multiplier : 5}); + deepEqual(answers, [5, 10, 15], 'context object property accessed'); + + answers = []; + _.each([1, 2, 3], function(num){ answers.push(num); }); + deepEqual(answers, [1, 2, 3], 'aliased as "forEach"'); + + answers = []; + var obj = {one : 1, two : 2, three : 3}; + obj.constructor.prototype.four = 4; + _.each(obj, function(value, key){ answers.push(key); }); + deepEqual(answers, ['one', 'two', 'three'], 'iterating over objects works, and ignores the object prototype.'); + delete obj.constructor.prototype.four; + + 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'); + + answers = 0; + _.each(null, function(){ ++answers; }); + equal(answers, 0, 'handles a null properly'); + + _.each(false, function(){}); + + var a = [1, 2, 3]; + strictEqual(_.each(a, function(){}), a); + strictEqual(_.each(null, function(){}), null); + + var b = [1, 2, 3]; + b.length = 100; + answers = 0; + _.each(b, function(){ ++answers; }); + equal(answers, 100, 'enumerates [0, length)'); + }); + + test('forEach', function() { + strictEqual(_.each, _.forEach, 'alias for each'); + }); + + test('lookupIterator with contexts', function() { + _.each([true, false, 'yes', '', 0, 1, {}], function(context) { + _.each([1], function() { + equal(this, context); + }, context); + }); + }); + + test('map', function() { + var doubled = _.map([1, 2, 3], function(num){ return num * 2; }); + deepEqual(doubled, [2, 4, 6], 'doubled numbers'); + + var tripled = _.map([1, 2, 3], function(num){ return num * this.multiplier; }, {multiplier : 3}); + deepEqual(tripled, [3, 6, 9], 'tripled numbers with context'); + + var doubled = _([1, 2, 3]).map(function(num){ return num * 2; }); + deepEqual(doubled, [2, 4, 6], 'OO-style doubled numbers'); + + if (document.querySelectorAll) { + var ids = _.map(document.querySelectorAll('#map-test *'), function(n){ return n.id; }); + deepEqual(ids, ['id1', 'id2'], 'Can use collection methods on NodeLists.'); + } + + var ids = _.map({length: 2, 0: {id: '1'}, 1: {id: '2'}}, function(n){ + return n.id; + }); + deepEqual(ids, ['1', '2'], 'Can use collection methods on Array-likes.'); + + deepEqual(_.map(null, _.noop), [], 'handles a null properly'); + + deepEqual(_.map([1], function() { + return this.length; + }, [5]), [1], 'called with context'); + + // Passing a property name like _.pluck. + var people = [{name : 'moe', age : 30}, {name : 'curly', age : 50}]; + deepEqual(_.map(people, 'name'), ['moe', 'curly'], 'predicate string map to object properties'); + }); + + test('collect', function() { + strictEqual(_.map, _.collect, 'alias for map'); + }); + + test('reduce', function() { + var sum = _.reduce([1, 2, 3], function(sum, num){ return sum + num; }, 0); + equal(sum, 6, 'can sum up an array'); + + var context = {multiplier : 3}; + sum = _.reduce([1, 2, 3], function(sum, num){ return sum + num * this.multiplier; }, 0, context); + equal(sum, 18, 'can reduce with a context object'); + + sum = _.inject([1, 2, 3], function(sum, num){ return sum + num; }, 0); + equal(sum, 6, 'aliased as "inject"'); + + sum = _([1, 2, 3]).reduce(function(sum, num){ return sum + num; }, 0); + equal(sum, 6, 'OO-style reduce'); + + var sum = _.reduce([1, 2, 3], function(sum, num){ return sum + num; }); + equal(sum, 6, 'default initial value'); + + var prod = _.reduce([1, 2, 3, 4], function(prod, num){ return prod * num; }); + equal(prod, 24, 'can reduce via multiplication'); + + ok(_.reduce(null, _.noop, 138) === 138, 'handles a null (with initial value) properly'); + equal(_.reduce([], _.noop, undefined), undefined, 'undefined can be passed as a special case'); + + raises(function() { _.reduce([], _.noop); }, TypeError, 'throws an error for empty arrays with no initial value'); + raises(function() {_.reduce(null, _.noop);}, TypeError, 'handles a null (without initial value) properly'); + }); + + test('foldl', function() { + strictEqual(_.reduce, _.foldl, 'alias for reduce'); + }); + + test('reduceRight', function() { + var list = _.reduceRight(['foo', 'bar', 'baz'], function(memo, str){ return memo + str; }, ''); + equal(list, 'bazbarfoo', 'can perform right folds'); + + var list = _.reduceRight(['foo', 'bar', 'baz'], function(memo, str){ return memo + str; }); + equal(list, 'bazbarfoo', 'default initial value'); + + var sum = _.reduceRight({a: 1, b: 2, c: 3}, function(sum, num){ return sum + num; }); + equal(sum, 6, 'default initial value on object'); + + ok(_.reduceRight(null, _.noop, 138) === 138, 'handles a null (with initial value) properly'); + + equal(_.reduceRight([], _.noop, undefined), undefined, 'undefined can be passed as a special case'); + + raises(function() { _.reduceRight([], _.noop); }, TypeError, 'throws an error for empty arrays with no initial value'); + raises(function() {_.reduceRight(null, _.noop);}, TypeError, 'handles a null (without initial value) properly'); + + // Assert that the correct arguments are being passed. + + var args, + memo = {}, + object = {a: 1, b: 2}, + lastKey = _.keys(object).pop(); + + var expected = lastKey == 'a' + ? [memo, 1, 'a', object] + : [memo, 2, 'b', object]; + + _.reduceRight(object, function() { + args || (args = _.toArray(arguments)); + }, memo); + + deepEqual(args, expected); + + // And again, with numeric keys. + + object = {'2': 'a', '1': 'b'}; + lastKey = _.keys(object).pop(); + args = null; + + expected = lastKey == '2' + ? [memo, 'a', '2', object] + : [memo, 'b', '1', object]; + + _.reduceRight(object, function() { + args || (args = _.toArray(arguments)); + }, memo); + + deepEqual(args, expected); + }); + + test('foldr', function() { + strictEqual(_.reduceRight, _.foldr, 'alias for reduceRight'); + }); + + test('find', function() { + var array = [1, 2, 3, 4]; + strictEqual(_.find(array, function(n) { return n > 2; }), 3, 'should return first found `value`'); + strictEqual(_.find(array, function() { return false; }), void 0, 'should return `undefined` if `value` is not found'); + + // Matching an object like _.findWhere. + var list = [{a: 1, b: 2}, {a: 2, b: 2}, {a: 1, b: 3}, {a: 1, b: 4}, {a: 2, b: 4}]; + deepEqual(_.find(list, {a: 1}), {a: 1, b: 2}, 'can be used as findWhere'); + deepEqual(_.find(list, {b: 4}), {a: 1, b: 4}); + ok(!_.find(list, {c: 1}), 'undefined when not found'); + ok(!_.find([], {c: 1}), 'undefined when searching empty list'); + + var result = _.find([1, 2, 3], function(num){ return num * 2 == 4; }); + equal(result, 2, 'found the first "2" and broke the loop'); + }); + + test('detect', function() { + strictEqual(_.detect, _.find, 'alias for detect'); + }); + + test('filter', function() { + var evenArray = [1, 2, 3, 4, 5, 6]; + var evenObject = {one: 1, two: 2, three: 3}; + var isEven = function(num){ return num % 2 === 0; }; + + deepEqual(_.filter(evenArray, isEven), [2, 4, 6]); + deepEqual(_.filter(evenObject, isEven), [2], 'can filter objects'); + deepEqual(_.filter([{}, evenObject, []], 'two'), [evenObject], 'predicate string map to object properties'); + + _.filter([1], function() { + equal(this, evenObject, 'given context'); + }, evenObject); + + // Can be used like _.where. + var list = [{a: 1, b: 2}, {a: 2, b: 2}, {a: 1, b: 3}, {a: 1, b: 4}]; + deepEqual(_.filter(list, {a: 1}), [{a: 1, b: 2}, {a: 1, b: 3}, {a: 1, b: 4}]); + deepEqual(_.filter(list, {b: 2}), [{a: 1, b: 2}, {a: 2, b: 2}]); + deepEqual(_.filter(list, {}), list, 'Empty object accepts all items'); + deepEqual(_(list).filter({}), list, 'OO-filter'); + }); + + test('select', function() { + strictEqual(_.filter, _.select, 'alias for filter'); + }); + + test('reject', function() { + var odds = _.reject([1, 2, 3, 4, 5, 6], function(num){ return num % 2 == 0; }); + deepEqual(odds, [1, 3, 5], 'rejected each even number'); + + var context = 'obj'; + + var evens = _.reject([1, 2, 3, 4, 5, 6], function(num){ + equal(context, 'obj'); + return num % 2 != 0; + }, context); + deepEqual(evens, [2, 4, 6], 'rejected each odd number'); + + deepEqual(_.reject([odds, {one: 1, two: 2, three: 3}], 'two'), [odds], 'predicate string map to object properties'); + + // Can be used like _.where. + var list = [{a: 1, b: 2}, {a: 2, b: 2}, {a: 1, b: 3}, {a: 1, b: 4}]; + deepEqual(_.reject(list, {a: 1}), [{a: 2, b: 2}]); + deepEqual(_.reject(list, {b: 2}), [{a: 1, b: 3}, {a: 1, b: 4}]); + deepEqual(_.reject(list, {}), [], 'Returns empty list given empty object'); + deepEqual(_.reject(list, []), [], 'Returns empty list given empty array'); + }); + + test('every', function() { + ok(_.every([], _.identity), 'the empty set'); + ok(_.every([true, true, true], _.identity), 'every true values'); + ok(!_.every([true, false, true], _.identity), 'one false value'); + ok(_.every([0, 10, 28], function(num){ return num % 2 == 0; }), 'even numbers'); + ok(!_.every([0, 11, 28], function(num){ return num % 2 == 0; }), 'an odd number'); + ok(_.every([1], _.identity) === true, 'cast to boolean - true'); + ok(_.every([0], _.identity) === false, 'cast to boolean - false'); + ok(!_.every([undefined, undefined, undefined], _.identity), 'works with arrays of undefined'); + + var list = [{a: 1, b: 2}, {a: 2, b: 2}, {a: 1, b: 3}, {a: 1, b: 4}]; + ok(!_.every(list, {a: 1, b: 2}), 'Can be called with object'); + ok(_.every(list, 'a'), 'String mapped to object property'); + + list = [{a: 1, b: 2}, {a: 2, b: 2, c: true}]; + ok(_.every(list, {b: 2}), 'Can be called with object'); + ok(!_.every(list, 'c'), 'String mapped to object property'); + + ok(_.every({a: 1, b: 2, c: 3, d: 4}, _.isNumber), 'takes objects'); + ok(!_.every({a: 1, b: 2, c: 3, d: 4}, _.isObject), 'takes objects'); + ok(_.every(['a', 'b', 'c', 'd'], _.hasOwnProperty, {a: 1, b: 2, c: 3, d: 4}), 'context works'); + ok(!_.every(['a', 'b', 'c', 'd', 'f'], _.hasOwnProperty, {a: 1, b: 2, c: 3, d: 4}), 'context works'); + }); + + test('all', function() { + strictEqual(_.all, _.every, 'alias for all'); + }); + + test('some', function() { + ok(!_.some([]), 'the empty set'); + ok(!_.some([false, false, false]), 'all false values'); + ok(_.some([false, false, true]), 'one true value'); + ok(_.some([null, 0, 'yes', false]), 'a string'); + ok(!_.some([null, 0, '', false]), 'falsy values'); + ok(!_.some([1, 11, 29], function(num){ return num % 2 == 0; }), 'all odd numbers'); + ok(_.some([1, 10, 29], function(num){ return num % 2 == 0; }), 'an even number'); + ok(_.some([1], _.identity) === true, 'cast to boolean - true'); + ok(_.some([0], _.identity) === false, 'cast to boolean - false'); + ok(_.some([false, false, true])); + + var list = [{a: 1, b: 2}, {a: 2, b: 2}, {a: 1, b: 3}, {a: 1, b: 4}]; + ok(!_.some(list, {a: 5, b: 2}), 'Can be called with object'); + ok(_.some(list, 'a'), 'String mapped to object property'); + + list = [{a: 1, b: 2}, {a: 2, b: 2, c: true}]; + ok(_.some(list, {b: 2}), 'Can be called with object'); + ok(!_.some(list, 'd'), 'String mapped to object property'); + + ok(_.some({a: '1', b: '2', c: '3', d: '4', e: 6}, _.isNumber), 'takes objects'); + ok(!_.some({a: 1, b: 2, c: 3, d: 4}, _.isObject), 'takes objects'); + ok(_.some(['a', 'b', 'c', 'd'], _.hasOwnProperty, {a: 1, b: 2, c: 3, d: 4}), 'context works'); + ok(!_.some(['x', 'y', 'z'], _.hasOwnProperty, {a: 1, b: 2, c: 3, d: 4}), 'context works'); + }); + + test('any', function() { + strictEqual(_.any, _.some, 'alias for any'); + }); + + test('contains', function() { + ok(_.contains([1, 2, 3], 2), 'two is in the array'); + ok(!_.contains([1, 3, 9], 2), 'two is not in the array'); + ok(_.contains({moe: 1, larry: 3, curly: 9}, 3) === true, '_.contains on objects checks their values'); + ok(_([1, 2, 3]).contains(2), 'OO-style contains'); + }); + + test('include', function() { + strictEqual(_.contains, _.include, 'alias for contains'); + }); + + test('invoke', function() { + var list = [[5, 1, 7], [3, 2, 1]]; + var result = _.invoke(list, 'sort'); + deepEqual(result[0], [1, 5, 7], 'first array sorted'); + deepEqual(result[1], [1, 2, 3], 'second array sorted'); + }); + + test('invoke w/ function reference', function() { + var list = [[5, 1, 7], [3, 2, 1]]; + var result = _.invoke(list, Array.prototype.sort); + deepEqual(result[0], [1, 5, 7], 'first array sorted'); + deepEqual(result[1], [1, 2, 3], 'second array sorted'); + }); + + // Relevant when using ClojureScript + test('invoke when strings have a call method', function() { + String.prototype.call = function() { + return 42; + }; + var list = [[5, 1, 7], [3, 2, 1]]; + var s = 'foo'; + equal(s.call(), 42, 'call function exists'); + var result = _.invoke(list, 'sort'); + deepEqual(result[0], [1, 5, 7], 'first array sorted'); + deepEqual(result[1], [1, 2, 3], 'second array sorted'); + delete String.prototype.call; + equal(s.call, undefined, 'call function removed'); + }); + + test('pluck', function() { + var people = [{name: 'moe', age: 30}, {name: 'curly', age: 50}]; + deepEqual(_.pluck(people, 'name'), ['moe', 'curly'], 'pulls names out of objects'); + //compat: most flexible handling of edge cases + deepEqual(_.pluck([{'[object Object]': 1}], {}), [1]); + }); + + test('where', function() { + var list = [{a: 1, b: 2}, {a: 2, b: 2}, {a: 1, b: 3}, {a: 1, b: 4}]; + var result = _.where(list, {a: 1}); + equal(result.length, 3); + equal(result[result.length - 1].b, 4); + result = _.where(list, {b: 2}); + equal(result.length, 2); + equal(result[0].a, 1); + result = _.where(list, {}); + equal(result.length, list.length); + + function test() {} + test.map = _.map; + deepEqual(_.where([_, {a: 1, b: 2}, _], test), [_, _], 'checks properties given function'); + }); + + test('findWhere', function() { + var list = [{a: 1, b: 2}, {a: 2, b: 2}, {a: 1, b: 3}, {a: 1, b: 4}, {a: 2, b: 4}]; + var result = _.findWhere(list, {a: 1}); + deepEqual(result, {a: 1, b: 2}); + result = _.findWhere(list, {b: 4}); + deepEqual(result, {a: 1, b: 4}); + + result = _.findWhere(list, {c: 1}); + ok(_.isUndefined(result), 'undefined when not found'); + + result = _.findWhere([], {c: 1}); + ok(_.isUndefined(result), 'undefined when searching empty list'); + + function test() {} + test.map = _.map; + equal(_.findWhere([_, {a: 1, b: 2}, _], test), _, 'checks properties given function'); + + function TestClass() { + this.y = 5; + this.x = 'foo'; + } + var expect = {c: 1, x: 'foo', y: 5}; + deepEqual(_.findWhere([{y: 5, b: 6}, expect], new TestClass()), expect, 'uses class instance properties'); + }); + + test('max', function() { + equal(3, _.max([1, 2, 3]), 'can perform a regular Math.max'); + + var neg = _.max([1, 2, 3], function(num){ return -num; }); + equal(neg, 1, 'can perform a computation-based max'); + + equal(-Infinity, _.max({}), 'Maximum value of an empty object'); + equal(-Infinity, _.max([]), 'Maximum value of an empty array'); + equal(_.max({'a': 'a'}), -Infinity, 'Maximum value of a non-numeric collection'); + + equal(299999, _.max(_.range(1, 300000)), 'Maximum value of a too-big array'); + + equal(3, _.max([1, 2, 3, 'test']), 'Finds correct max in array starting with num and containing a NaN'); + equal(3, _.max(['test', 1, 2, 3]), 'Finds correct max in array starting with NaN'); + + var a = {x: -Infinity}; + var b = {x: -Infinity}; + var iterator = function(o){ return o.x; }; + equal(_.max([a, b], iterator), a, 'Respects iterator return value of -Infinity'); + + deepEqual(_.max([{'a': 1}, {'a': 0, 'b': 3}, {'a': 4}, {'a': 2}], 'a'), {'a': 4}, 'String keys use property iterator'); + + deepEqual(_.max([0, 2], function(a, b){ return a * this.x; }, {x: 1}), 2, 'Iterator context'); + }); + + test('min', function() { + equal(1, _.min([1, 2, 3]), 'can perform a regular Math.min'); + + var neg = _.min([1, 2, 3], function(num){ return -num; }); + equal(neg, 3, 'can perform a computation-based min'); + + equal(Infinity, _.min({}), 'Minimum value of an empty object'); + equal(Infinity, _.min([]), 'Minimum value of an empty array'); + equal(_.min({'a': 'a'}), Infinity, 'Minimum value of a non-numeric collection'); + + var now = new Date(9999999999); + var then = new Date(0); + equal(_.min([now, then]), then); + + equal(1, _.min(_.range(1, 300000)), 'Minimum value of a too-big array'); + + equal(1, _.min([1, 2, 3, 'test']), 'Finds correct min in array starting with num and containing a NaN'); + equal(1, _.min(['test', 1, 2, 3]), 'Finds correct min in array starting with NaN'); + + var a = {x: Infinity}; + var b = {x: Infinity}; + var iterator = function(o){ return o.x; }; + equal(_.min([a, b], iterator), a, 'Respects iterator return value of Infinity'); + + deepEqual(_.min([{'a': 1}, {'a': 0, 'b': 3}, {'a': 4}, {'a': 2}], 'a'), {'a': 0, 'b': 3}, 'String keys use property iterator'); + + deepEqual(_.min([0, 2], function(a, b){ return a * this.x; }, {x: -1}), 2, 'Iterator context'); + }); + + test('sortBy', function() { + var people = [{name : 'curly', age : 50}, {name : 'moe', age : 30}]; + people = _.sortBy(people, function(person){ return person.age; }); + deepEqual(_.pluck(people, 'name'), ['moe', 'curly'], 'stooges sorted by age'); + + var list = [undefined, 4, 1, undefined, 3, 2]; + deepEqual(_.sortBy(list, _.identity), [1, 2, 3, 4, undefined, undefined], 'sortBy with undefined values'); + + var list = ['one', 'two', 'three', 'four', 'five']; + var sorted = _.sortBy(list, 'length'); + deepEqual(sorted, ['one', 'two', 'four', 'five', 'three'], 'sorted by length'); + + function Pair(x, y) { + this.x = x; + this.y = y; + } + + var collection = [ + new Pair(1, 1), new Pair(1, 2), + new Pair(1, 3), new Pair(1, 4), + new Pair(1, 5), new Pair(1, 6), + new Pair(2, 1), new Pair(2, 2), + new Pair(2, 3), new Pair(2, 4), + new Pair(2, 5), new Pair(2, 6), + new Pair(undefined, 1), new Pair(undefined, 2), + new Pair(undefined, 3), new Pair(undefined, 4), + new Pair(undefined, 5), new Pair(undefined, 6) + ]; + + var actual = _.sortBy(collection, function(pair) { + return pair.x; + }); + + deepEqual(actual, collection, 'sortBy should be stable'); + + deepEqual(_.sortBy(collection, 'x'), collection, 'sortBy accepts property string'); + + var list = ['q', 'w', 'e', 'r', 't', 'y']; + deepEqual(_.sortBy(list), ['e', 'q', 'r', 't', 'w', 'y'], 'uses _.identity if iterator is not specified'); + }); + + test('groupBy', function() { + var parity = _.groupBy([1, 2, 3, 4, 5, 6], function(num){ return num % 2; }); + ok('0' in parity && '1' in parity, 'created a group for each value'); + deepEqual(parity[0], [2, 4, 6], 'put each even number in the right group'); + + var list = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten']; + var grouped = _.groupBy(list, 'length'); + deepEqual(grouped['3'], ['one', 'two', 'six', 'ten']); + deepEqual(grouped['4'], ['four', 'five', 'nine']); + deepEqual(grouped['5'], ['three', 'seven', 'eight']); + + var context = {}; + _.groupBy([{}], function(){ ok(this === context); }, context); + + grouped = _.groupBy([4.2, 6.1, 6.4], function(num) { + return Math.floor(num) > 4 ? 'hasOwnProperty' : 'constructor'; + }); + equal(grouped.constructor.length, 1); + equal(grouped.hasOwnProperty.length, 2); + + var array = [{}]; + _.groupBy(array, function(value, index, obj){ ok(obj === array); }); + + var array = [1, 2, 1, 2, 3]; + var grouped = _.groupBy(array); + equal(grouped['1'].length, 2); + equal(grouped['3'].length, 1); + + var matrix = [ + [1, 2], + [1, 3], + [2, 3] + ]; + deepEqual(_.groupBy(matrix, 0), {1: [[1, 2], [1, 3]], 2: [[2, 3]]}); + deepEqual(_.groupBy(matrix, 1), {2: [[1, 2]], 3: [[1, 3], [2, 3]]}); + }); + + test('indexBy', function() { + var parity = _.indexBy([1, 2, 3, 4, 5], function(num){ return num % 2 == 0; }); + equal(parity['true'], 4); + equal(parity['false'], 5); + + var list = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten']; + var grouped = _.indexBy(list, 'length'); + equal(grouped['3'], 'ten'); + equal(grouped['4'], 'nine'); + equal(grouped['5'], 'eight'); + + var array = [1, 2, 1, 2, 3]; + var grouped = _.indexBy(array); + equal(grouped['1'], 1); + equal(grouped['2'], 2); + equal(grouped['3'], 3); + }); + + test('countBy', function() { + var parity = _.countBy([1, 2, 3, 4, 5], function(num){ return num % 2 == 0; }); + equal(parity['true'], 2); + equal(parity['false'], 3); + + var list = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten']; + var grouped = _.countBy(list, 'length'); + equal(grouped['3'], 4); + equal(grouped['4'], 3); + equal(grouped['5'], 3); + + var context = {}; + _.countBy([{}], function(){ ok(this === context); }, context); + + grouped = _.countBy([4.2, 6.1, 6.4], function(num) { + return Math.floor(num) > 4 ? 'hasOwnProperty' : 'constructor'; + }); + equal(grouped.constructor, 1); + equal(grouped.hasOwnProperty, 2); + + var array = [{}]; + _.countBy(array, function(value, index, obj){ ok(obj === array); }); + + var array = [1, 2, 1, 2, 3]; + var grouped = _.countBy(array); + equal(grouped['1'], 2); + equal(grouped['3'], 1); + }); + + test('sortedIndex', function() { + var numbers = [10, 20, 30, 40, 50], num = 35; + var indexForNum = _.sortedIndex(numbers, num); + equal(indexForNum, 3, '35 should be inserted at index 3'); + + var indexFor30 = _.sortedIndex(numbers, 30); + equal(indexFor30, 2, '30 should be inserted at index 2'); + + var objects = [{x: 10}, {x: 20}, {x: 30}, {x: 40}]; + var iterator = function(obj){ return obj.x; }; + strictEqual(_.sortedIndex(objects, {x: 25}, iterator), 2); + strictEqual(_.sortedIndex(objects, {x: 35}, 'x'), 3); + + var context = {1: 2, 2: 3, 3: 4}; + iterator = function(obj){ return this[obj]; }; + strictEqual(_.sortedIndex([1, 3], 2, iterator, context), 1); + }); + + test('shuffle', function() { + var numbers = _.range(10); + var shuffled = _.shuffle(numbers).sort(); + notStrictEqual(numbers, shuffled, 'original object is unmodified'); + deepEqual(shuffled, numbers, 'contains the same members before and after shuffle'); + }); + + test('sample', function() { + var numbers = _.range(10); + var all_sampled = _.sample(numbers, 10).sort(); + deepEqual(all_sampled, numbers, 'contains the same members before and after sample'); + all_sampled = _.sample(numbers, 20).sort(); + deepEqual(all_sampled, numbers, 'also works when sampling more objects than are present'); + ok(_.contains(numbers, _.sample(numbers)), 'sampling a single element returns something from the array'); + strictEqual(_.sample([]), undefined, 'sampling empty array with no number returns undefined'); + notStrictEqual(_.sample([], 5), [], 'sampling empty array with a number returns an empty array'); + notStrictEqual(_.sample([1, 2, 3], 0), [], 'sampling an array with 0 picks returns an empty array'); + deepEqual(_.sample([1, 2], -1), [], 'sampling a negative number of picks returns an empty array'); + ok(_.contains([1, 2, 3], _.sample({a: 1, b: 2, c: 3})), 'sample one value from an object'); + }); + + test('toArray', function() { + ok(!_.isArray(arguments), 'arguments object is not an array'); + ok(_.isArray(_.toArray(arguments)), 'arguments object converted into array'); + var a = [1, 2, 3]; + ok(_.toArray(a) !== a, 'array is cloned'); + deepEqual(_.toArray(a), [1, 2, 3], 'cloned array contains same elements'); + + var numbers = _.toArray({one : 1, two : 2, three : 3}); + deepEqual(numbers, [1, 2, 3], 'object flattened into array'); + + // test in IE < 9 + try { + var actual = _.toArray(document.childNodes); + } catch(ex) { } + + ok(_.isArray(actual), 'should not throw converting a node list'); + }); + + test('size', function() { + equal(_.size({one : 1, two : 2, three : 3}), 3, 'can compute the size of an object'); + equal(_.size([1, 2, 3]), 3, 'can compute the size of an array'); + equal(_.size({length: 3, 0: 0, 1: 0, 2: 0}), 3, 'can compute the size of Array-likes'); + + var func = function() { + return _.size(arguments); + }; + + equal(func(1, 2, 3, 4), 4, 'can test the size of the arguments object'); + + equal(_.size('hello'), 5, 'can compute the size of a string literal'); + equal(_.size(new String('hello')), 5, 'can compute the size of string object'); + + equal(_.size(null), 0, 'handles nulls'); + }); + + test('partition', function() { + var list = [0, 1, 2, 3, 4, 5]; + deepEqual(_.partition(list, function(x) { return x < 4; }), [[0, 1, 2, 3], [4, 5]], 'handles bool return values'); + deepEqual(_.partition(list, function(x) { return x & 1; }), [[1, 3, 5], [0, 2, 4]], 'handles 0 and 1 return values'); + deepEqual(_.partition(list, function(x) { return x - 3; }), [[0, 1, 2, 4, 5], [3]], 'handles other numeric return values'); + deepEqual(_.partition(list, function(x) { return x > 1 ? null : true; }), [[0, 1], [2, 3, 4, 5]], 'handles null return values'); + deepEqual(_.partition(list, function(x) { if(x < 2) return true; }), [[0, 1], [2, 3, 4, 5]], 'handles undefined return values'); + deepEqual(_.partition({a: 1, b: 2, c: 3}, function(x) { return x > 1; }), [[2, 3], [1]], 'handles objects'); + + deepEqual(_.partition(list, function(x, index) { return index % 2; }), [[1, 3, 5], [0, 2, 4]], 'can reference the array index'); + deepEqual(_.partition(list, function(x, index, arr) { return x === arr.length - 1; }), [[5], [0, 1, 2, 3, 4]], 'can reference the collection'); + + // Default iterator + deepEqual(_.partition([1, false, true, '']), [[1, true], [false, '']], 'Default iterator'); + deepEqual(_.partition([{x: 1}, {x: 0}, {x: 1}], 'x'), [[{x: 1}, {x: 1}], [{x: 0}]], 'Takes a string'); + + // Context + var predicate = function(x){ return x === this.x }; + deepEqual(_.partition([1, 2, 3], predicate, {x: 2}), [[2], [1, 3]], 'partition takes a context argument'); + + deepEqual(_.partition([{a: 1}, {b: 2}, {a: 1, b: 2}], {a: 1}), [[{a: 1}, {a: 1, b: 2}], [{b: 2}]], 'predicate can be object'); + + var object = {a: 1}; + _.partition(object, function(val, key, obj) { + equal(val, 1); + equal(key, 'a'); + equal(object, object); + equal(this, predicate); + }, predicate); + }); + +})(); diff --git a/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/test/functions.js b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/test/functions.js new file mode 100644 index 000000000..47e1e456d --- /dev/null +++ b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/test/functions.js @@ -0,0 +1,535 @@ +(function() { + + module('Functions'); + + test('bind', function() { + var context = {name : 'moe'}; + var func = function(arg) { return 'name: ' + (this.name || arg); }; + var bound = _.bind(func, context); + equal(bound(), 'name: moe', 'can bind a function to a context'); + + bound = _(func).bind(context); + equal(bound(), 'name: moe', 'can do OO-style binding'); + + bound = _.bind(func, null, 'curly'); + equal(bound(), 'name: curly', 'can bind without specifying a context'); + + func = function(salutation, name) { return salutation + ': ' + name; }; + func = _.bind(func, this, 'hello'); + equal(func('moe'), 'hello: moe', 'the function was partially applied in advance'); + + func = _.bind(func, this, 'curly'); + equal(func(), 'hello: curly', 'the function was completely applied in advance'); + + func = function(salutation, firstname, lastname) { return salutation + ': ' + firstname + ' ' + lastname; }; + func = _.bind(func, this, 'hello', 'moe', 'curly'); + equal(func(), 'hello: moe curly', 'the function was partially applied in advance and can accept multiple arguments'); + + func = function(context, message) { equal(this, context, message); }; + _.bind(func, 0, 0, 'can bind a function to `0`')(); + _.bind(func, '', '', 'can bind a function to an empty string')(); + _.bind(func, false, false, 'can bind a function to `false`')(); + + // These tests are only meaningful when using a browser without a native bind function + // To test this with a modern browser, set underscore's nativeBind to undefined + var F = function () { return this; }; + var Boundf = _.bind(F, {hello: 'moe curly'}); + var newBoundf = new Boundf(); + equal(newBoundf.hello, undefined, 'function should not be bound to the context, to comply with ECMAScript 5'); + equal(Boundf().hello, 'moe curly', "When called without the new operator, it's OK to be bound to the context"); + ok(newBoundf instanceof F, 'a bound instance is an instance of the original function'); + + raises(function() { _.bind('notafunction'); }, TypeError, 'throws an error when binding to a non-function'); + }); + + test('partial', function() { + var obj = {name: 'moe'}; + var func = function() { return this.name + ' ' + _.toArray(arguments).join(' '); }; + + obj.func = _.partial(func, 'a', 'b'); + equal(obj.func('c', 'd'), 'moe a b c d', 'can partially apply'); + + obj.func = _.partial(func, _, 'b', _, 'd'); + equal(obj.func('a', 'c'), 'moe a b c d', 'can partially apply with placeholders'); + + func = _.partial(function() { return arguments.length; }, _, 'b', _, 'd'); + equal(func('a', 'c', 'e'), 5, 'accepts more arguments than the number of placeholders'); + equal(func('a'), 4, 'accepts fewer arguments than the number of placeholders'); + + func = _.partial(function() { return typeof arguments[2]; }, _, 'b', _, 'd'); + equal(func('a'), 'undefined', 'unfilled placeholders are undefined'); + }); + + test('bindAll', function() { + var curly = {name : 'curly'}, moe = { + name : 'moe', + getName : function() { return 'name: ' + this.name; }, + sayHi : function() { return 'hi: ' + this.name; } + }; + curly.getName = moe.getName; + _.bindAll(moe, 'getName', 'sayHi'); + curly.sayHi = moe.sayHi; + equal(curly.getName(), 'name: curly', 'unbound function is bound to current object'); + equal(curly.sayHi(), 'hi: moe', 'bound function is still bound to original object'); + + curly = {name : 'curly'}; + moe = { + name : 'moe', + getName : function() { return 'name: ' + this.name; }, + sayHi : function() { return 'hi: ' + this.name; }, + sayLast : function() { return this.sayHi(_.last(arguments)); } + }; + + raises(function() { _.bindAll(moe); }, Error, 'throws an error for bindAll with no functions named'); + raises(function() { _.bindAll(moe, "sayBye"); }, TypeError, 'throws an error for bindAll if the given key is undefined'); + raises(function() { _.bindAll(moe, "name"); }, TypeError, 'throws an error for bindAll if the given key is not a function'); + + _.bindAll(moe, 'sayHi', 'sayLast'); + curly.sayHi = moe.sayHi; + equal(curly.sayHi(), 'hi: moe'); + + var sayLast = moe.sayLast; + equal(sayLast(1, 2, 3, 4, 5, 6, 7, 'Tom'), 'hi: moe', 'createCallback works with any number of arguments'); + }); + + test('memoize', function() { + var fib = function(n) { + return n < 2 ? n : fib(n - 1) + fib(n - 2); + }; + equal(fib(10), 55, 'a memoized version of fibonacci produces identical results'); + fib = _.memoize(fib); // Redefine `fib` for memoization + equal(fib(10), 55, 'a memoized version of fibonacci produces identical results'); + + var o = function(str) { + return str; + }; + var fastO = _.memoize(o); + equal(o('toString'), 'toString', 'checks hasOwnProperty'); + equal(fastO('toString'), 'toString', 'checks hasOwnProperty'); + + // Expose the cache. + var upper = _.memoize(function(s) { + return s.toUpperCase(); + }); + equal(upper('foo'), 'FOO'); + equal(upper('bar'), 'BAR'); + deepEqual(upper.cache, {foo: 'FOO', bar: 'BAR'}); + upper.cache = {foo: 'BAR', bar: 'FOO'}; + equal(upper('foo'), 'BAR'); + equal(upper('bar'), 'FOO'); + + var hashed = _.memoize(function(key) { + //https://github.com/jashkenas/underscore/pull/1679#discussion_r13736209 + ok(/[a-z]+/.test(key), 'hasher doesn\'t change keys'); + return key; + }, function(key) { + return key.toUpperCase(); + }); + hashed('yep'); + deepEqual(hashed.cache, {'YEP': 'yep'}, 'takes a hasher'); + }); + + asyncTest('delay', 2, function() { + var delayed = false; + _.delay(function(){ delayed = true; }, 100); + setTimeout(function(){ ok(!delayed, "didn't delay the function quite yet"); }, 50); + setTimeout(function(){ ok(delayed, 'delayed the function'); start(); }, 150); + }); + + asyncTest('defer', 1, function() { + var deferred = false; + _.defer(function(bool){ deferred = bool; }, true); + _.delay(function(){ ok(deferred, 'deferred the function'); start(); }, 50); + }); + + asyncTest('throttle', 2, function() { + var counter = 0; + var incr = function(){ counter++; }; + var throttledIncr = _.throttle(incr, 32); + throttledIncr(); throttledIncr(); + + equal(counter, 1, 'incr was called immediately'); + _.delay(function(){ equal(counter, 2, 'incr was throttled'); start(); }, 64); + }); + + asyncTest('throttle arguments', 2, function() { + var value = 0; + var update = function(val){ value = val; }; + var throttledUpdate = _.throttle(update, 32); + throttledUpdate(1); throttledUpdate(2); + _.delay(function(){ throttledUpdate(3); }, 64); + equal(value, 1, 'updated to latest value'); + _.delay(function(){ equal(value, 3, 'updated to latest value'); start(); }, 96); + }); + + asyncTest('throttle once', 2, function() { + var counter = 0; + var incr = function(){ return ++counter; }; + var throttledIncr = _.throttle(incr, 32); + var result = throttledIncr(); + _.delay(function(){ + equal(result, 1, 'throttled functions return their value'); + equal(counter, 1, 'incr was called once'); start(); + }, 64); + }); + + asyncTest('throttle twice', 1, function() { + var counter = 0; + var incr = function(){ counter++; }; + var throttledIncr = _.throttle(incr, 32); + throttledIncr(); throttledIncr(); + _.delay(function(){ equal(counter, 2, 'incr was called twice'); start(); }, 64); + }); + + asyncTest('more throttling', 3, function() { + var counter = 0; + var incr = function(){ counter++; }; + var throttledIncr = _.throttle(incr, 30); + throttledIncr(); throttledIncr(); + ok(counter == 1); + _.delay(function(){ + ok(counter == 2); + throttledIncr(); + ok(counter == 3); + start(); + }, 85); + }); + + asyncTest('throttle repeatedly with results', 6, function() { + var counter = 0; + var incr = function(){ return ++counter; }; + var throttledIncr = _.throttle(incr, 100); + var results = []; + var saveResult = function() { results.push(throttledIncr()); }; + saveResult(); saveResult(); + _.delay(saveResult, 50); + _.delay(saveResult, 150); + _.delay(saveResult, 160); + _.delay(saveResult, 230); + _.delay(function() { + equal(results[0], 1, 'incr was called once'); + equal(results[1], 1, 'incr was throttled'); + equal(results[2], 1, 'incr was throttled'); + equal(results[3], 2, 'incr was called twice'); + equal(results[4], 2, 'incr was throttled'); + equal(results[5], 3, 'incr was called trailing'); + start(); + }, 300); + }); + + asyncTest('throttle triggers trailing call when invoked repeatedly', 2, function() { + var counter = 0; + var limit = 48; + var incr = function(){ counter++; }; + var throttledIncr = _.throttle(incr, 32); + + var stamp = new Date; + while ((new Date - stamp) < limit) { + throttledIncr(); + } + var lastCount = counter; + ok(counter > 1); + + _.delay(function() { + ok(counter > lastCount); + start(); + }, 96); + }); + + asyncTest('throttle does not trigger leading call when leading is set to false', 2, function() { + var counter = 0; + var incr = function(){ counter++; }; + var throttledIncr = _.throttle(incr, 60, {leading: false}); + + throttledIncr(); throttledIncr(); + ok(counter === 0); + + _.delay(function() { + ok(counter == 1); + start(); + }, 96); + }); + + asyncTest('more throttle does not trigger leading call when leading is set to false', 3, function() { + var counter = 0; + var incr = function(){ counter++; }; + var throttledIncr = _.throttle(incr, 100, {leading: false}); + + throttledIncr(); + _.delay(throttledIncr, 50); + _.delay(throttledIncr, 60); + _.delay(throttledIncr, 200); + ok(counter === 0); + + _.delay(function() { + ok(counter == 1); + }, 250); + + _.delay(function() { + ok(counter == 2); + start(); + }, 350); + }); + + asyncTest('one more throttle with leading: false test', 2, function() { + var counter = 0; + var incr = function(){ counter++; }; + var throttledIncr = _.throttle(incr, 100, {leading: false}); + + var time = new Date; + while (new Date - time < 350) throttledIncr(); + ok(counter <= 3); + + _.delay(function() { + ok(counter <= 4); + start(); + }, 200); + }); + + asyncTest('throttle does not trigger trailing call when trailing is set to false', 4, function() { + var counter = 0; + var incr = function(){ counter++; }; + var throttledIncr = _.throttle(incr, 60, {trailing: false}); + + throttledIncr(); throttledIncr(); throttledIncr(); + ok(counter === 1); + + _.delay(function() { + ok(counter == 1); + + throttledIncr(); throttledIncr(); + ok(counter == 2); + + _.delay(function() { + ok(counter == 2); + start(); + }, 96); + }, 96); + }); + + asyncTest('throttle continues to function after system time is set backwards', 2, function() { + var counter = 0; + var incr = function(){ counter++; }; + var throttledIncr = _.throttle(incr, 100); + var origNowFunc = _.now; + + throttledIncr(); + ok(counter == 1); + _.now = function () { + return new Date(2013, 0, 1, 1, 1, 1); + }; + + _.delay(function() { + throttledIncr(); + ok(counter == 2); + start(); + _.now = origNowFunc; + }, 200); + }); + + asyncTest('throttle re-entrant', 2, function() { + var sequence = [ + ['b1', 'b2'], + ['c1', 'c2'] + ]; + var value = ''; + var throttledAppend; + var append = function(arg){ + value += this + arg; + var args = sequence.pop() + if (args) { + throttledAppend.call(args[0], args[1]); + } + }; + throttledAppend = _.throttle(append, 32); + throttledAppend.call('a1', 'a2'); + equal(value, 'a1a2'); + _.delay(function(){ + equal(value, 'a1a2c1c2b1b2', 'append was throttled successfully'); + start(); + }, 100); + }); + + asyncTest('debounce', 1, function() { + var counter = 0; + var incr = function(){ counter++; }; + var debouncedIncr = _.debounce(incr, 32); + debouncedIncr(); debouncedIncr(); + _.delay(debouncedIncr, 16); + _.delay(function(){ equal(counter, 1, 'incr was debounced'); start(); }, 96); + }); + + asyncTest('debounce asap', 4, function() { + var a, b; + var counter = 0; + var incr = function(){ return ++counter; }; + var debouncedIncr = _.debounce(incr, 64, true); + a = debouncedIncr(); + b = debouncedIncr(); + equal(a, 1); + equal(b, 1); + equal(counter, 1, 'incr was called immediately'); + _.delay(debouncedIncr, 16); + _.delay(debouncedIncr, 32); + _.delay(debouncedIncr, 48); + _.delay(function(){ equal(counter, 1, 'incr was debounced'); start(); }, 128); + }); + + asyncTest('debounce asap recursively', 2, function() { + var counter = 0; + var debouncedIncr = _.debounce(function(){ + counter++; + if (counter < 10) debouncedIncr(); + }, 32, true); + debouncedIncr(); + equal(counter, 1, 'incr was called immediately'); + _.delay(function(){ equal(counter, 1, 'incr was debounced'); start(); }, 96); + }); + + asyncTest('debounce after system time is set backwards', 2, function() { + var counter = 0; + var origNowFunc = _.now; + var debouncedIncr = _.debounce(function(){ + counter++; + }, 100, true); + + debouncedIncr(); + equal(counter, 1, 'incr was called immediately'); + + _.now = function () { + return new Date(2013, 0, 1, 1, 1, 1); + }; + + _.delay(function() { + debouncedIncr(); + equal(counter, 2, 'incr was debounced successfully'); + start(); + _.now = origNowFunc; + }, 200); + }); + + asyncTest('debounce re-entrant', 2, function() { + var sequence = [ + ['b1', 'b2'] + ]; + var value = ''; + var debouncedAppend; + var append = function(arg){ + value += this + arg; + var args = sequence.pop() + if (args) { + debouncedAppend.call(args[0], args[1]); + } + }; + debouncedAppend = _.debounce(append, 32); + debouncedAppend.call('a1', 'a2'); + equal(value, ''); + _.delay(function(){ + equal(value, 'a1a2b1b2', 'append was debounced successfully'); + start(); + }, 100); + }); + + test('once', function() { + var num = 0; + var increment = _.once(function(){ return ++num; }); + increment(); + increment(); + equal(num, 1); + + equal(increment(), 1, 'stores a memo to the last value'); + }); + + test('Recursive onced function.', 1, function() { + var f = _.once(function(){ + ok(true); + f(); + }); + f(); + }); + + test('wrap', function() { + var greet = function(name){ return 'hi: ' + name; }; + var backwards = _.wrap(greet, function(func, name){ return func(name) + ' ' + name.split('').reverse().join(''); }); + equal(backwards('moe'), 'hi: moe eom', 'wrapped the salutation function'); + + var inner = function(){ return 'Hello '; }; + var obj = {name : 'Moe'}; + obj.hi = _.wrap(inner, function(fn){ return fn() + this.name; }); + equal(obj.hi(), 'Hello Moe'); + + var noop = function(){}; + var wrapped = _.wrap(noop, function(fn){ return Array.prototype.slice.call(arguments, 0); }); + var ret = wrapped(['whats', 'your'], 'vector', 'victor'); + deepEqual(ret, [noop, ['whats', 'your'], 'vector', 'victor']); + }); + + test('negate', function() { + var isOdd = function(n){ return (n & 1) == 1; }; + equal(_.negate(isOdd)(2), true, 'should return the complement of the given function'); + equal(_.negate(isOdd)(3), false, 'should return the complement of the given function'); + }); + + test('compose', function() { + var greet = function(name){ return 'hi: ' + name; }; + var exclaim = function(sentence){ return sentence + '!'; }; + var composed = _.compose(exclaim, greet); + equal(composed('moe'), 'hi: moe!', 'can compose a function that takes another'); + + composed = _.compose(greet, exclaim); + equal(composed('moe'), 'hi: moe!', 'in this case, the functions are also commutative'); + + // f(g(h(x, y, z))) + function h(x, y, z) { + equal(arguments.length, 3, 'First function called with multiple args'); + return z * y; + }; + function g(x) { + equal(arguments.length, 1, 'Composed function is called with 1 argument'); + return x; + }; + function f(x) { + equal(arguments.length, 1, 'Composed function is called with 1 argument'); + return x * 2; + }; + composed = _.compose(f, g, h); + equal(composed(1, 2, 3), 12); + }); + + test('after', function() { + var testAfter = function(afterAmount, timesCalled) { + var afterCalled = 0; + var after = _.after(afterAmount, function() { + afterCalled++; + }); + while (timesCalled--) after(); + return afterCalled; + }; + + equal(testAfter(5, 5), 1, 'after(N) should fire after being called N times'); + equal(testAfter(5, 4), 0, 'after(N) should not fire unless called N times'); + equal(testAfter(0, 0), 0, 'after(0) should not fire immediately'); + equal(testAfter(0, 1), 1, 'after(0) should fire when first invoked'); + }); + + test('before', function() { + var testBefore = function(beforeAmount, timesCalled) { + var beforeCalled = 0; + var before = _.before(beforeAmount, function() { beforeCalled++; }); + while (timesCalled--) before(); + return beforeCalled; + }; + + equal(testBefore(5, 5), 4, 'before(N) should not fire after being called N times'); + equal(testBefore(5, 4), 4, 'before(N) should fire before being called N times'); + equal(testBefore(0, 0), 0, 'before(0) should not fire immediately'); + equal(testBefore(0, 1), 0, 'before(0) should not fire when first invoked'); + + var context = {num: 0}; + var increment = _.before(3, function(){ return ++this.num; }); + _.times(10, increment, context); + equal(increment(), 2, 'stores a memo to the last value'); + equal(context.num, 2, 'provides context'); + }); + +})(); diff --git a/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/test/index.html b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/test/index.html new file mode 100644 index 000000000..f6e9352ef --- /dev/null +++ b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/test/index.html @@ -0,0 +1,26 @@ +<!DOCTYPE html> +<html> +<head> + <title>Underscore Test Suite</title> + <link rel="stylesheet" href="vendor/qunit.css" type="text/css" media="screen"> + <link rel="icon" href="../favicon.ico"> +</head> +<body> + <div id="qunit"></div> + <div id="qunit-fixture"> + <div id="map-test"> + <div id="id1"></div> + <div id="id2"></div> + </div> + </div> + <script src="vendor/qunit.js"></script> + <script src="../underscore.js"></script> + + <script src="collections.js"></script> + <script src="arrays.js"></script> + <script src="functions.js"></script> + <script src="objects.js"></script> + <script src="utility.js"></script> + <script src="chaining.js"></script> +</body> +</html> diff --git a/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/test/objects.js b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/test/objects.js new file mode 100644 index 000000000..dc53db5e3 --- /dev/null +++ b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/test/objects.js @@ -0,0 +1,665 @@ +(function() { + + module('Objects'); + + test('keys', function() { + deepEqual(_.keys({one : 1, two : 2}), ['one', 'two'], 'can extract the keys from an object'); + // the test above is not safe because it relies on for-in enumeration order + var a = []; a[1] = 0; + deepEqual(_.keys(a), ['1'], 'is not fooled by sparse arrays; see issue #95'); + deepEqual(_.keys(null), []); + deepEqual(_.keys(void 0), []); + deepEqual(_.keys(1), []); + deepEqual(_.keys('a'), []); + deepEqual(_.keys(true), []); + }); + + test('values', function() { + deepEqual(_.values({one: 1, two: 2}), [1, 2], 'can extract the values from an object'); + deepEqual(_.values({one: 1, two: 2, length: 3}), [1, 2, 3], '... even when one of them is "length"'); + }); + + test('pairs', function() { + deepEqual(_.pairs({one: 1, two: 2}), [['one', 1], ['two', 2]], 'can convert an object into pairs'); + deepEqual(_.pairs({one: 1, two: 2, length: 3}), [['one', 1], ['two', 2], ['length', 3]], '... even when one of them is "length"'); + }); + + test('invert', function() { + var obj = {first: 'Moe', second: 'Larry', third: 'Curly'}; + deepEqual(_.keys(_.invert(obj)), ['Moe', 'Larry', 'Curly'], 'can invert an object'); + deepEqual(_.invert(_.invert(obj)), obj, 'two inverts gets you back where you started'); + + var obj = {length: 3}; + ok(_.invert(obj)['3'] == 'length', 'can invert an object with "length"') + }); + + test('functions', function() { + var obj = {a : 'dash', b : _.map, c : (/yo/), d : _.reduce}; + deepEqual(['b', 'd'], _.functions(obj), 'can grab the function names of any passed-in object'); + + var Animal = function(){}; + Animal.prototype.run = function(){}; + deepEqual(_.functions(new Animal), ['run'], 'also looks up functions on the prototype'); + }); + + test('methods', function() { + strictEqual(_.functions, _.methods, 'alias for functions'); + }); + + test('extend', function() { + var result; + equal(_.extend({}, {a: 'b'}).a, 'b', 'can extend an object with the attributes of another'); + equal(_.extend({a: 'x'}, {a: 'b'}).a, 'b', 'properties in source override destination'); + equal(_.extend({x: 'x'}, {a: 'b'}).x, 'x', "properties not in source don't get overriden"); + result = _.extend({x: 'x'}, {a: 'a'}, {b: 'b'}); + deepEqual(result, {x: 'x', a: 'a', b: 'b'}, 'can extend from multiple source objects'); + result = _.extend({x: 'x'}, {a: 'a', x: 2}, {a: 'b'}); + deepEqual(result, {x: 2, a: 'b'}, 'extending from multiple source objects last property trumps'); + result = _.extend({}, {a: void 0, b: null}); + deepEqual(_.keys(result), ['a', 'b'], 'extend copies undefined values'); + + try { + result = {}; + _.extend(result, null, undefined, {a: 1}); + } catch(ex) {} + + equal(result.a, 1, 'should not error on `null` or `undefined` sources'); + + strictEqual(_.extend(null, {a: 1}), null, 'extending null results in null'); + strictEqual(_.extend(undefined, {a: 1}), undefined, 'extending undefined results in undefined'); + }); + + test('pick', function() { + var result; + result = _.pick({a: 1, b: 2, c: 3}, 'a', 'c'); + deepEqual(result, {a: 1, c: 3}, 'can restrict properties to those named'); + result = _.pick({a: 1, b: 2, c: 3}, ['b', 'c']); + deepEqual(result, {b: 2, c: 3}, 'can restrict properties to those named in an array'); + result = _.pick({a: 1, b: 2, c: 3}, ['a'], 'b'); + deepEqual(result, {a: 1, b: 2}, 'can restrict properties to those named in mixed args'); + result = _.pick(['a', 'b'], 1); + deepEqual(result, {1: 'b'}, 'can pick numeric properties'); + + deepEqual(_.pick(null, 'a', 'b'), {}, 'non objects return empty object'); + deepEqual(_.pick(undefined, 'toString'), {}, 'null/undefined return empty object'); + deepEqual(_.pick(5, 'toString', 'b'), {toString: Number.prototype.toString}, 'can iterate primitives'); + + var data = {a: 1, b: 2, c: 3}; + var callback = function(value, key, object) { + strictEqual(key, {1: 'a', 2: 'b', 3: 'c'}[value]); + strictEqual(object, data); + return value !== this.value; + }; + result = _.pick(data, callback, {value: 2}); + deepEqual(result, {a: 1, c: 3}, 'can accept a predicate and context'); + + var Obj = function(){}; + Obj.prototype = {a: 1, b: 2, c: 3}; + var instance = new Obj(); + deepEqual(_.pick(instance, 'a', 'c'), {a: 1, c: 3}, 'include prototype props'); + + deepEqual(_.pick(data, function(val, key) { + return this[key] === 3 && this === instance; + }, instance), {c: 3}, 'function is given context'); + }); + + test('omit', function() { + var result; + result = _.omit({a: 1, b: 2, c: 3}, 'b'); + deepEqual(result, {a: 1, c: 3}, 'can omit a single named property'); + result = _.omit({a: 1, b: 2, c: 3}, 'a', 'c'); + deepEqual(result, {b: 2}, 'can omit several named properties'); + result = _.omit({a: 1, b: 2, c: 3}, ['b', 'c']); + deepEqual(result, {a: 1}, 'can omit properties named in an array'); + result = _.omit(['a', 'b'], 0); + deepEqual(result, {1: 'b'}, 'can omit numeric properties'); + + deepEqual(_.omit(null, 'a', 'b'), {}, 'non objects return empty object'); + deepEqual(_.omit(undefined, 'toString'), {}, 'null/undefined return empty object'); + deepEqual(_.omit(5, 'toString', 'b'), {}, 'returns empty object for primitives'); + + var data = {a: 1, b: 2, c: 3}; + var callback = function(value, key, object) { + strictEqual(key, {1: 'a', 2: 'b', 3: 'c'}[value]); + strictEqual(object, data); + return value !== this.value; + }; + result = _.omit(data, callback, {value: 2}); + deepEqual(result, {b: 2}, 'can accept a predicate'); + + var Obj = function(){}; + Obj.prototype = {a: 1, b: 2, c: 3}; + var instance = new Obj(); + deepEqual(_.omit(instance, 'b'), {a: 1, c: 3}, 'include prototype props'); + + deepEqual(_.omit(data, function(val, key) { + return this[key] === 3 && this === instance; + }, instance), {a: 1, b: 2}, 'function is given context'); + }); + + test('defaults', function() { + var result; + var options = {zero: 0, one: 1, empty: '', nan: NaN, nothing: null}; + + _.defaults(options, {zero: 1, one: 10, twenty: 20, nothing: 'str'}); + equal(options.zero, 0, 'value exists'); + equal(options.one, 1, 'value exists'); + equal(options.twenty, 20, 'default applied'); + equal(options.nothing, null, "null isn't overridden"); + + _.defaults(options, {empty: 'full'}, {nan: 'nan'}, {word: 'word'}, {word: 'dog'}); + equal(options.empty, '', 'value exists'); + ok(_.isNaN(options.nan), "NaN isn't overridden"); + equal(options.word, 'word', 'new value is added, first one wins'); + + try { + options = {}; + _.defaults(options, null, undefined, {a: 1}); + } catch(ex) {} + + equal(options.a, 1, 'should not error on `null` or `undefined` sources'); + + strictEqual(_.defaults(null, {a: 1}), null, 'result is null if destination is null'); + strictEqual(_.defaults(undefined, {a: 1}), undefined, 'result is undefined if destination is undefined'); + }); + + test('clone', function() { + var moe = {name : 'moe', lucky : [13, 27, 34]}; + var clone = _.clone(moe); + equal(clone.name, 'moe', 'the clone as the attributes of the original'); + + clone.name = 'curly'; + ok(clone.name == 'curly' && moe.name == 'moe', 'clones can change shallow attributes without affecting the original'); + + clone.lucky.push(101); + equal(_.last(moe.lucky), 101, 'changes to deep attributes are shared with the original'); + + equal(_.clone(undefined), void 0, 'non objects should not be changed by clone'); + equal(_.clone(1), 1, 'non objects should not be changed by clone'); + equal(_.clone(null), null, 'non objects should not be changed by clone'); + }); + + test('isEqual', function() { + function First() { + this.value = 1; + } + First.prototype.value = 1; + function Second() { + this.value = 1; + } + Second.prototype.value = 2; + + // Basic equality and identity comparisons. + ok(_.isEqual(null, null), '`null` is equal to `null`'); + ok(_.isEqual(), '`undefined` is equal to `undefined`'); + + ok(!_.isEqual(0, -0), '`0` is not equal to `-0`'); + ok(!_.isEqual(-0, 0), 'Commutative equality is implemented for `0` and `-0`'); + ok(!_.isEqual(null, undefined), '`null` is not equal to `undefined`'); + ok(!_.isEqual(undefined, null), 'Commutative equality is implemented for `null` and `undefined`'); + + // String object and primitive comparisons. + ok(_.isEqual('Curly', 'Curly'), 'Identical string primitives are equal'); + ok(_.isEqual(new String('Curly'), new String('Curly')), 'String objects with identical primitive values are equal'); + ok(_.isEqual(new String('Curly'), 'Curly'), 'String primitives and their corresponding object wrappers are equal'); + ok(_.isEqual('Curly', new String('Curly')), 'Commutative equality is implemented for string objects and primitives'); + + ok(!_.isEqual('Curly', 'Larry'), 'String primitives with different values are not equal'); + ok(!_.isEqual(new String('Curly'), new String('Larry')), 'String objects with different primitive values are not equal'); + ok(!_.isEqual(new String('Curly'), {toString: function(){ return 'Curly'; }}), 'String objects and objects with a custom `toString` method are not equal'); + + // Number object and primitive comparisons. + ok(_.isEqual(75, 75), 'Identical number primitives are equal'); + ok(_.isEqual(new Number(75), new Number(75)), 'Number objects with identical primitive values are equal'); + ok(_.isEqual(75, new Number(75)), 'Number primitives and their corresponding object wrappers are equal'); + ok(_.isEqual(new Number(75), 75), 'Commutative equality is implemented for number objects and primitives'); + ok(!_.isEqual(new Number(0), -0), '`new Number(0)` and `-0` are not equal'); + ok(!_.isEqual(0, new Number(-0)), 'Commutative equality is implemented for `new Number(0)` and `-0`'); + + ok(!_.isEqual(new Number(75), new Number(63)), 'Number objects with different primitive values are not equal'); + ok(!_.isEqual(new Number(63), {valueOf: function(){ return 63; }}), 'Number objects and objects with a `valueOf` method are not equal'); + + // Comparisons involving `NaN`. + ok(_.isEqual(NaN, NaN), '`NaN` is equal to `NaN`'); + ok(_.isEqual(Object(NaN), NaN), 'Object(`NaN`) is equal to `NaN`'); + ok(!_.isEqual(61, NaN), 'A number primitive is not equal to `NaN`'); + ok(!_.isEqual(new Number(79), NaN), 'A number object is not equal to `NaN`'); + ok(!_.isEqual(Infinity, NaN), '`Infinity` is not equal to `NaN`'); + + // Boolean object and primitive comparisons. + ok(_.isEqual(true, true), 'Identical boolean primitives are equal'); + ok(_.isEqual(new Boolean, new Boolean), 'Boolean objects with identical primitive values are equal'); + ok(_.isEqual(true, new Boolean(true)), 'Boolean primitives and their corresponding object wrappers are equal'); + ok(_.isEqual(new Boolean(true), true), 'Commutative equality is implemented for booleans'); + ok(!_.isEqual(new Boolean(true), new Boolean), 'Boolean objects with different primitive values are not equal'); + + // Common type coercions. + ok(!_.isEqual(new Boolean(false), true), '`new Boolean(false)` is not equal to `true`'); + ok(!_.isEqual('75', 75), 'String and number primitives with like values are not equal'); + ok(!_.isEqual(new Number(63), new String(63)), 'String and number objects with like values are not equal'); + ok(!_.isEqual(75, '75'), 'Commutative equality is implemented for like string and number values'); + ok(!_.isEqual(0, ''), 'Number and string primitives with like values are not equal'); + ok(!_.isEqual(1, true), 'Number and boolean primitives with like values are not equal'); + ok(!_.isEqual(new Boolean(false), new Number(0)), 'Boolean and number objects with like values are not equal'); + ok(!_.isEqual(false, new String('')), 'Boolean primitives and string objects with like values are not equal'); + ok(!_.isEqual(12564504e5, new Date(2009, 9, 25)), 'Dates and their corresponding numeric primitive values are not equal'); + + // Dates. + ok(_.isEqual(new Date(2009, 9, 25), new Date(2009, 9, 25)), 'Date objects referencing identical times are equal'); + ok(!_.isEqual(new Date(2009, 9, 25), new Date(2009, 11, 13)), 'Date objects referencing different times are not equal'); + ok(!_.isEqual(new Date(2009, 11, 13), { + getTime: function(){ + return 12606876e5; + } + }), 'Date objects and objects with a `getTime` method are not equal'); + ok(!_.isEqual(new Date('Curly'), new Date('Curly')), 'Invalid dates are not equal'); + + // Functions. + ok(!_.isEqual(First, Second), 'Different functions with identical bodies and source code representations are not equal'); + + // RegExps. + ok(_.isEqual(/(?:)/gim, /(?:)/gim), 'RegExps with equivalent patterns and flags are equal'); + ok(_.isEqual(/(?:)/gi, /(?:)/ig), 'Flag order is not significant'); + ok(!_.isEqual(/(?:)/g, /(?:)/gi), 'RegExps with equivalent patterns and different flags are not equal'); + ok(!_.isEqual(/Moe/gim, /Curly/gim), 'RegExps with different patterns and equivalent flags are not equal'); + ok(!_.isEqual(/(?:)/gi, /(?:)/g), 'Commutative equality is implemented for RegExps'); + ok(!_.isEqual(/Curly/g, {source: 'Larry', global: true, ignoreCase: false, multiline: false}), 'RegExps and RegExp-like objects are not equal'); + + // Empty arrays, array-like objects, and object literals. + ok(_.isEqual({}, {}), 'Empty object literals are equal'); + ok(_.isEqual([], []), 'Empty array literals are equal'); + ok(_.isEqual([{}], [{}]), 'Empty nested arrays and objects are equal'); + ok(!_.isEqual({length: 0}, []), 'Array-like objects and arrays are not equal.'); + ok(!_.isEqual([], {length: 0}), 'Commutative equality is implemented for array-like objects'); + + ok(!_.isEqual({}, []), 'Object literals and array literals are not equal'); + ok(!_.isEqual([], {}), 'Commutative equality is implemented for objects and arrays'); + + // Arrays with primitive and object values. + ok(_.isEqual([1, 'Larry', true], [1, 'Larry', true]), 'Arrays containing identical primitives are equal'); + ok(_.isEqual([(/Moe/g), new Date(2009, 9, 25)], [(/Moe/g), new Date(2009, 9, 25)]), 'Arrays containing equivalent elements are equal'); + + // Multi-dimensional arrays. + var a = [new Number(47), false, 'Larry', /Moe/, new Date(2009, 11, 13), ['running', 'biking', new String('programming')], {a: 47}]; + var b = [new Number(47), false, 'Larry', /Moe/, new Date(2009, 11, 13), ['running', 'biking', new String('programming')], {a: 47}]; + ok(_.isEqual(a, b), 'Arrays containing nested arrays and objects are recursively compared'); + + // Overwrite the methods defined in ES 5.1 section 15.4.4. + a.forEach = a.map = a.filter = a.every = a.indexOf = a.lastIndexOf = a.some = a.reduce = a.reduceRight = null; + b.join = b.pop = b.reverse = b.shift = b.slice = b.splice = b.concat = b.sort = b.unshift = null; + + // Array elements and properties. + ok(_.isEqual(a, b), 'Arrays containing equivalent elements and different non-numeric properties are equal'); + a.push('White Rocks'); + ok(!_.isEqual(a, b), 'Arrays of different lengths are not equal'); + a.push('East Boulder'); + b.push('Gunbarrel Ranch', 'Teller Farm'); + ok(!_.isEqual(a, b), 'Arrays of identical lengths containing different elements are not equal'); + + // Sparse arrays. + ok(_.isEqual(Array(3), Array(3)), 'Sparse arrays of identical lengths are equal'); + ok(!_.isEqual(Array(3), Array(6)), 'Sparse arrays of different lengths are not equal when both are empty'); + + var sparse = []; + sparse[1] = 5; + ok(_.isEqual(sparse, [undefined, 5]), 'Handles sparse arrays as dense') + + // Simple objects. + ok(_.isEqual({a: 'Curly', b: 1, c: true}, {a: 'Curly', b: 1, c: true}), 'Objects containing identical primitives are equal'); + ok(_.isEqual({a: /Curly/g, b: new Date(2009, 11, 13)}, {a: /Curly/g, b: new Date(2009, 11, 13)}), 'Objects containing equivalent members are equal'); + ok(!_.isEqual({a: 63, b: 75}, {a: 61, b: 55}), 'Objects of identical sizes with different values are not equal'); + ok(!_.isEqual({a: 63, b: 75}, {a: 61, c: 55}), 'Objects of identical sizes with different property names are not equal'); + ok(!_.isEqual({a: 1, b: 2}, {a: 1}), 'Objects of different sizes are not equal'); + ok(!_.isEqual({a: 1}, {a: 1, b: 2}), 'Commutative equality is implemented for objects'); + ok(!_.isEqual({x: 1, y: undefined}, {x: 1, z: 2}), 'Objects with identical keys and different values are not equivalent'); + + // `A` contains nested objects and arrays. + a = { + name: new String('Moe Howard'), + age: new Number(77), + stooge: true, + hobbies: ['acting'], + film: { + name: 'Sing a Song of Six Pants', + release: new Date(1947, 9, 30), + stars: [new String('Larry Fine'), 'Shemp Howard'], + minutes: new Number(16), + seconds: 54 + } + }; + + // `B` contains equivalent nested objects and arrays. + b = { + name: new String('Moe Howard'), + age: new Number(77), + stooge: true, + hobbies: ['acting'], + film: { + name: 'Sing a Song of Six Pants', + release: new Date(1947, 9, 30), + stars: [new String('Larry Fine'), 'Shemp Howard'], + minutes: new Number(16), + seconds: 54 + } + }; + ok(_.isEqual(a, b), 'Objects with nested equivalent members are recursively compared'); + + // Instances. + ok(_.isEqual(new First, new First), 'Object instances are equal'); + ok(!_.isEqual(new First, new Second), 'Objects with different constructors and identical own properties are not equal'); + ok(!_.isEqual({value: 1}, new First), 'Object instances and objects sharing equivalent properties are not equal'); + ok(!_.isEqual({value: 2}, new Second), 'The prototype chain of objects should not be examined'); + + // Circular Arrays. + (a = []).push(a); + (b = []).push(b); + ok(_.isEqual(a, b), 'Arrays containing circular references are equal'); + a.push(new String('Larry')); + b.push(new String('Larry')); + ok(_.isEqual(a, b), 'Arrays containing circular references and equivalent properties are equal'); + a.push('Shemp'); + b.push('Curly'); + ok(!_.isEqual(a, b), 'Arrays containing circular references and different properties are not equal'); + + // More circular arrays #767. + a = ['everything is checked but', 'this', 'is not']; + a[1] = a; + b = ['everything is checked but', ['this', 'array'], 'is not']; + ok(!_.isEqual(a, b), 'Comparison of circular references with non-circular references are not equal'); + + // Circular Objects. + a = {abc: null}; + b = {abc: null}; + a.abc = a; + b.abc = b; + ok(_.isEqual(a, b), 'Objects containing circular references are equal'); + a.def = 75; + b.def = 75; + ok(_.isEqual(a, b), 'Objects containing circular references and equivalent properties are equal'); + a.def = new Number(75); + b.def = new Number(63); + ok(!_.isEqual(a, b), 'Objects containing circular references and different properties are not equal'); + + // More circular objects #767. + a = {everything: 'is checked', but: 'this', is: 'not'}; + a.but = a; + b = {everything: 'is checked', but: {that: 'object'}, is: 'not'}; + ok(!_.isEqual(a, b), 'Comparison of circular references with non-circular object references are not equal'); + + // Cyclic Structures. + a = [{abc: null}]; + b = [{abc: null}]; + (a[0].abc = a).push(a); + (b[0].abc = b).push(b); + ok(_.isEqual(a, b), 'Cyclic structures are equal'); + a[0].def = 'Larry'; + b[0].def = 'Larry'; + ok(_.isEqual(a, b), 'Cyclic structures containing equivalent properties are equal'); + a[0].def = new String('Larry'); + b[0].def = new String('Curly'); + ok(!_.isEqual(a, b), 'Cyclic structures containing different properties are not equal'); + + // Complex Circular References. + a = {foo: {b: {foo: {c: {foo: null}}}}}; + b = {foo: {b: {foo: {c: {foo: null}}}}}; + a.foo.b.foo.c.foo = a; + b.foo.b.foo.c.foo = b; + ok(_.isEqual(a, b), 'Cyclic structures with nested and identically-named properties are equal'); + + // Chaining. + ok(!_.isEqual(_({x: 1, y: undefined}).chain(), _({x: 1, z: 2}).chain()), 'Chained objects containing different values are not equal'); + + a = _({x: 1, y: 2}).chain(); + b = _({x: 1, y: 2}).chain(); + equal(_.isEqual(a.isEqual(b), _(true)), true, '`isEqual` can be chained'); + + // Objects from another frame. + ok(_.isEqual({}, iObject)); + + // Objects without a `constructor` property + if (Object.create) { + a = Object.create(null, {x: {value: 1, enumerable: true}}); + b = {x: 1}; + ok(_.isEqual(a, b), 'Handles objects without a constructor (e.g. from Object.create'); + } + + function Foo() { this.a = 1; } + Foo.prototype.constructor = null; + + var other = { 'a': 1 }; + strictEqual(_.isEqual(new Foo, other), false, 'Objects from different constructors are not equal'); + }); + + test('isEmpty', function() { + ok(!_([1]).isEmpty(), '[1] is not empty'); + ok(_.isEmpty([]), '[] is empty'); + ok(!_.isEmpty({one : 1}), '{one : 1} is not empty'); + ok(_.isEmpty({}), '{} is empty'); + ok(_.isEmpty(new RegExp('')), 'objects with prototype properties are empty'); + ok(_.isEmpty(null), 'null is empty'); + ok(_.isEmpty(), 'undefined is empty'); + ok(_.isEmpty(''), 'the empty string is empty'); + ok(!_.isEmpty('moe'), 'but other strings are not'); + + var obj = {one : 1}; + delete obj.one; + ok(_.isEmpty(obj), 'deleting all the keys from an object empties it'); + + var args = function(){ return arguments; }; + ok(_.isEmpty(args()), 'empty arguments object is empty'); + ok(!_.isEmpty(args('')), 'non-empty arguments object is not empty'); + }); + + // Setup remote variables for iFrame tests. + var iframe = document.createElement('iframe'); + iframe.frameBorder = iframe.height = iframe.width = 0 + document.body.appendChild(iframe); + var iDoc = (iDoc = iframe.contentDocument || iframe.contentWindow).document || iDoc; + iDoc.write( + '<script>\ + parent.iElement = document.createElement("div");\ + parent.iArguments = (function(){ return arguments; })(1, 2, 3);\ + parent.iArray = [1, 2, 3];\ + parent.iString = new String("hello");\ + parent.iNumber = new Number(100);\ + parent.iFunction = (function(){});\ + parent.iDate = new Date();\ + parent.iRegExp = /hi/;\ + parent.iNaN = NaN;\ + parent.iNull = null;\ + parent.iBoolean = new Boolean(false);\ + parent.iUndefined = undefined;\ + parent.iObject = {};\ + </script>' + ); + iDoc.close(); + + test('isElement', function() { + ok(!_.isElement('div'), 'strings are not dom elements'); + ok(_.isElement(document.body), 'the body tag is a DOM element'); + ok(_.isElement(iElement), 'even from another frame'); + }); + + test('isArguments', function() { + var args = (function(){ return arguments; })(1, 2, 3); + ok(!_.isArguments('string'), 'a string is not an arguments object'); + ok(!_.isArguments(_.isArguments), 'a function is not an arguments object'); + ok(_.isArguments(args), 'but the arguments object is an arguments object'); + ok(!_.isArguments(_.toArray(args)), 'but not when it\'s converted into an array'); + ok(!_.isArguments([1, 2, 3]), 'and not vanilla arrays.'); + ok(_.isArguments(iArguments), 'even from another frame'); + }); + + test('isObject', function() { + ok(_.isObject(arguments), 'the arguments object is object'); + ok(_.isObject([1, 2, 3]), 'and arrays'); + ok(_.isObject(document.body), 'and DOM element'); + ok(_.isObject(iElement), 'even from another frame'); + ok(_.isObject(function () {}), 'and functions'); + ok(_.isObject(iFunction), 'even from another frame'); + ok(!_.isObject(null), 'but not null'); + ok(!_.isObject(undefined), 'and not undefined'); + ok(!_.isObject('string'), 'and not string'); + ok(!_.isObject(12), 'and not number'); + ok(!_.isObject(true), 'and not boolean'); + ok(_.isObject(new String('string')), 'but new String()'); + }); + + test('isArray', function() { + ok(!_.isArray(undefined), 'undefined vars are not arrays'); + ok(!_.isArray(arguments), 'the arguments object is not an array'); + ok(_.isArray([1, 2, 3]), 'but arrays are'); + ok(_.isArray(iArray), 'even from another frame'); + }); + + test('isString', function() { + var obj = new String('I am a string object'); + ok(!_.isString(document.body), 'the document body is not a string'); + ok(_.isString([1, 2, 3].join(', ')), 'but strings are'); + ok(_.isString(iString), 'even from another frame'); + ok(_.isString('I am a string literal'), 'string literals are'); + ok(_.isString(obj), 'so are String objects'); + }); + + test('isNumber', function() { + ok(!_.isNumber('string'), 'a string is not a number'); + ok(!_.isNumber(arguments), 'the arguments object is not a number'); + ok(!_.isNumber(undefined), 'undefined is not a number'); + ok(_.isNumber(3 * 4 - 7 / 10), 'but numbers are'); + ok(_.isNumber(NaN), 'NaN *is* a number'); + ok(_.isNumber(Infinity), 'Infinity is a number'); + ok(_.isNumber(iNumber), 'even from another frame'); + ok(!_.isNumber('1'), 'numeric strings are not numbers'); + }); + + test('isBoolean', function() { + ok(!_.isBoolean(2), 'a number is not a boolean'); + ok(!_.isBoolean('string'), 'a string is not a boolean'); + ok(!_.isBoolean('false'), 'the string "false" is not a boolean'); + ok(!_.isBoolean('true'), 'the string "true" is not a boolean'); + ok(!_.isBoolean(arguments), 'the arguments object is not a boolean'); + ok(!_.isBoolean(undefined), 'undefined is not a boolean'); + ok(!_.isBoolean(NaN), 'NaN is not a boolean'); + ok(!_.isBoolean(null), 'null is not a boolean'); + ok(_.isBoolean(true), 'but true is'); + ok(_.isBoolean(false), 'and so is false'); + ok(_.isBoolean(iBoolean), 'even from another frame'); + }); + + test('isFunction', function() { + ok(!_.isFunction(undefined), 'undefined vars are not functions'); + ok(!_.isFunction([1, 2, 3]), 'arrays are not functions'); + ok(!_.isFunction('moe'), 'strings are not functions'); + ok(_.isFunction(_.isFunction), 'but functions are'); + ok(_.isFunction(iFunction), 'even from another frame'); + ok(_.isFunction(function(){}), 'even anonymous ones'); + }); + + test('isDate', function() { + ok(!_.isDate(100), 'numbers are not dates'); + ok(!_.isDate({}), 'objects are not dates'); + ok(_.isDate(new Date()), 'but dates are'); + ok(_.isDate(iDate), 'even from another frame'); + }); + + test('isRegExp', function() { + ok(!_.isRegExp(_.identity), 'functions are not RegExps'); + ok(_.isRegExp(/identity/), 'but RegExps are'); + ok(_.isRegExp(iRegExp), 'even from another frame'); + }); + + test('isFinite', function() { + ok(!_.isFinite(undefined), 'undefined is not finite'); + ok(!_.isFinite(null), 'null is not finite'); + ok(!_.isFinite(NaN), 'NaN is not finite'); + ok(!_.isFinite(Infinity), 'Infinity is not finite'); + ok(!_.isFinite(-Infinity), '-Infinity is not finite'); + ok(_.isFinite('12'), 'Numeric strings are numbers'); + ok(!_.isFinite('1a'), 'Non numeric strings are not numbers'); + ok(!_.isFinite(''), 'Empty strings are not numbers'); + var obj = new Number(5); + ok(_.isFinite(obj), 'Number instances can be finite'); + ok(_.isFinite(0), '0 is finite'); + ok(_.isFinite(123), 'Ints are finite'); + ok(_.isFinite(-12.44), 'Floats are finite'); + }); + + test('isNaN', function() { + ok(!_.isNaN(undefined), 'undefined is not NaN'); + ok(!_.isNaN(null), 'null is not NaN'); + ok(!_.isNaN(0), '0 is not NaN'); + ok(_.isNaN(NaN), 'but NaN is'); + ok(_.isNaN(iNaN), 'even from another frame'); + ok(_.isNaN(new Number(NaN)), 'wrapped NaN is still NaN'); + }); + + test('isNull', function() { + ok(!_.isNull(undefined), 'undefined is not null'); + ok(!_.isNull(NaN), 'NaN is not null'); + ok(_.isNull(null), 'but null is'); + ok(_.isNull(iNull), 'even from another frame'); + }); + + test('isUndefined', function() { + ok(!_.isUndefined(1), 'numbers are defined'); + ok(!_.isUndefined(null), 'null is defined'); + ok(!_.isUndefined(false), 'false is defined'); + ok(!_.isUndefined(NaN), 'NaN is defined'); + ok(_.isUndefined(), 'nothing is undefined'); + ok(_.isUndefined(undefined), 'undefined is undefined'); + ok(_.isUndefined(iUndefined), 'even from another frame'); + }); + + if (window.ActiveXObject) { + test('IE host objects', function() { + var xml = new ActiveXObject('Msxml2.DOMDocument.3.0'); + ok(!_.isNumber(xml)); + ok(!_.isBoolean(xml)); + ok(!_.isNaN(xml)); + ok(!_.isFunction(xml)); + ok(!_.isNull(xml)); + ok(!_.isUndefined(xml)); + }); + } + + test('tap', function() { + var intercepted = null; + var interceptor = function(obj) { intercepted = obj; }; + var returned = _.tap(1, interceptor); + equal(intercepted, 1, 'passes tapped object to interceptor'); + equal(returned, 1, 'returns tapped object'); + + returned = _([1, 2, 3]).chain(). + map(function(n){ return n * 2; }). + max(). + tap(interceptor). + value(); + ok(returned == 6 && intercepted == 6, 'can use tapped objects in a chain'); + }); + + test("has", function () { + var obj = {foo: "bar", func: function () {} }; + ok(_.has(obj, "foo"), "has() checks that the object has a property."); + ok(_.has(obj, "baz") == false, "has() returns false if the object doesn't have the property."); + ok(_.has(obj, "func"), "has() works for functions too."); + obj.hasOwnProperty = null; + ok(_.has(obj, "foo"), "has() works even when the hasOwnProperty method is deleted."); + var child = {}; + child.prototype = obj; + ok(_.has(child, "foo") == false, "has() does not check the prototype chain for a property."); + strictEqual(_.has(null, 'foo'), false, 'has() returns false for null'); + strictEqual(_.has(undefined, 'foo'), false, 'has() returns false for undefined'); + }); + + test("matches", function() { + var moe = {name: 'Moe Howard', hair: true}; + var curly = {name: 'Curly Howard', hair: false}; + var stooges = [moe, curly]; + ok(_.find(stooges, _.matches({hair: false})) === curly, "returns a predicate that can be used by finding functions."); + ok(_.find(stooges, _.matches(moe)) === moe, "can be used to locate an object exists in a collection."); + deepEqual(_.where([null, undefined], {a: 1}), [], 'Do not throw on null values.'); + deepEqual(_.where([null, undefined], null), [null, undefined], 'null matches null'); + deepEqual(_.where([null, undefined], {}), [null, undefined], 'null matches {}'); + }); + +})(); diff --git a/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/test/utility.js b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/test/utility.js new file mode 100644 index 000000000..37c90076d --- /dev/null +++ b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/test/utility.js @@ -0,0 +1,294 @@ +(function() { + + var templateSettings; + + module('Utility', { + + setup: function() { + templateSettings = _.clone(_.templateSettings); + }, + + teardown: function() { + _.templateSettings = templateSettings; + } + + }); + + test('#750 - Return _ instance.', 2, function() { + var instance = _([]); + ok(_(instance) === instance); + ok(new _(instance) === instance); + }); + + test('identity', function() { + var moe = {name : 'moe'}; + equal(_.identity(moe), moe, 'moe is the same as his identity'); + }); + + test('constant', function() { + var moe = {name : 'moe'}; + equal(_.constant(moe)(), moe, 'should create a function that returns moe'); + }); + + test('noop', function() { + strictEqual(_.noop('curly', 'larry', 'moe'), undefined, 'should always return undefined'); + }); + + test('property', function() { + var moe = {name : 'moe'}; + equal(_.property('name')(moe), 'moe', 'should return the property with the given name'); + }); + + test('random', function() { + var array = _.range(1000); + var min = Math.pow(2, 31); + var max = Math.pow(2, 62); + + ok(_.every(array, function() { + return _.random(min, max) >= min; + }), 'should produce a random number greater than or equal to the minimum number'); + + ok(_.some(array, function() { + return _.random(Number.MAX_VALUE) > 0; + }), 'should produce a random number when passed `Number.MAX_VALUE`'); + }); + + test('now', function() { + var diff = _.now() - new Date().getTime(); + ok(diff <= 0 && diff > -5, 'Produces the correct time in milliseconds');//within 5ms + }); + + test('uniqueId', function() { + var ids = [], i = 0; + while(i++ < 100) ids.push(_.uniqueId()); + equal(_.uniq(ids).length, ids.length, 'can generate a globally-unique stream of ids'); + }); + + test('times', function() { + var vals = []; + _.times(3, function (i) { vals.push(i); }); + deepEqual(vals, [0, 1, 2], 'is 0 indexed'); + // + vals = []; + _(3).times(function(i) { vals.push(i); }); + deepEqual(vals, [0, 1, 2], 'works as a wrapper'); + // collects return values + deepEqual([0, 1, 2], _.times(3, function(i) { return i; }), 'collects return values'); + + deepEqual(_.times(0, _.identity), []); + deepEqual(_.times(-1, _.identity), []); + deepEqual(_.times(parseFloat('-Infinity'), _.identity), []); + }); + + test('mixin', function() { + _.mixin({ + myReverse: function(string) { + return string.split('').reverse().join(''); + } + }); + equal(_.myReverse('panacea'), 'aecanap', 'mixed in a function to _'); + equal(_('champ').myReverse(), 'pmahc', 'mixed in a function to the OOP wrapper'); + }); + + test('_.escape', function() { + equal(_.escape('Curly & Moe'), 'Curly & Moe'); + equal(_.escape('<a href="http://moe.com">Curly & Moe\'s</a>'), '<a href="http://moe.com">Curly & Moe's</a>'); + equal(_.escape('Curly & Moe'), 'Curly &amp; Moe'); + equal(_.escape(null), ''); + }); + + test('_.unescape', function() { + var string = 'Curly & Moe'; + equal(_.unescape('Curly & Moe'), string); + equal(_.unescape('<a href="http://moe.com">Curly & Moe's</a>'), '<a href="http://moe.com">Curly & Moe\'s</a>'); + equal(_.unescape('Curly &amp; Moe'), 'Curly & Moe'); + equal(_.unescape(null), ''); + equal(_.unescape(_.escape(string)), string); + }); + + test('template', function() { + var basicTemplate = _.template("<%= thing %> is gettin' on my noives!"); + var result = basicTemplate({thing : 'This'}); + equal(result, "This is gettin' on my noives!", 'can do basic attribute interpolation'); + + var sansSemicolonTemplate = _.template('A <% this %> B'); + equal(sansSemicolonTemplate(), 'A B'); + + var backslashTemplate = _.template('<%= thing %> is \\ridanculous'); + equal(backslashTemplate({thing: 'This'}), 'This is \\ridanculous'); + + var escapeTemplate = _.template('<%= a ? "checked=\\"checked\\"" : "" %>'); + equal(escapeTemplate({a: true}), 'checked="checked"', 'can handle slash escapes in interpolations.'); + + var fancyTemplate = _.template('<ul><% \ + for (var key in people) { \ + %><li><%= people[key] %></li><% } %></ul>'); + result = fancyTemplate({people : {moe : 'Moe', larry : 'Larry', curly : 'Curly'}}); + equal(result, '<ul><li>Moe</li><li>Larry</li><li>Curly</li></ul>', 'can run arbitrary javascript in templates'); + + var escapedCharsInJavascriptTemplate = _.template('<ul><% _.each(numbers.split("\\n"), function(item) { %><li><%= item %></li><% }) %></ul>'); + result = escapedCharsInJavascriptTemplate({numbers: 'one\ntwo\nthree\nfour'}); + equal(result, '<ul><li>one</li><li>two</li><li>three</li><li>four</li></ul>', 'Can use escaped characters (e.g. \\n) in JavaScript'); + + var namespaceCollisionTemplate = _.template('<%= pageCount %> <%= thumbnails[pageCount] %> <% _.each(thumbnails, function(p) { %><div class="thumbnail" rel="<%= p %>"></div><% }); %>'); + result = namespaceCollisionTemplate({ + pageCount: 3, + thumbnails: { + 1: 'p1-thumbnail.gif', + 2: 'p2-thumbnail.gif', + 3: 'p3-thumbnail.gif' + } + }); + equal(result, '3 p3-thumbnail.gif <div class="thumbnail" rel="p1-thumbnail.gif"></div><div class="thumbnail" rel="p2-thumbnail.gif"></div><div class="thumbnail" rel="p3-thumbnail.gif"></div>'); + + var noInterpolateTemplate = _.template('<div><p>Just some text. Hey, I know this is silly but it aids consistency.</p></div>'); + result = noInterpolateTemplate(); + equal(result, '<div><p>Just some text. Hey, I know this is silly but it aids consistency.</p></div>'); + + var quoteTemplate = _.template("It's its, not it's"); + equal(quoteTemplate({}), "It's its, not it's"); + + var quoteInStatementAndBody = _.template("<%\ + if(foo == 'bar'){ \ + %>Statement quotes and 'quotes'.<% } %>"); + equal(quoteInStatementAndBody({foo: 'bar'}), "Statement quotes and 'quotes'."); + + var withNewlinesAndTabs = _.template('This\n\t\tis: <%= x %>.\n\tok.\nend.'); + equal(withNewlinesAndTabs({x: 'that'}), 'This\n\t\tis: that.\n\tok.\nend.'); + + var template = _.template('<i><%- value %></i>'); + var result = template({value: '<script>'}); + equal(result, '<i><script></i>'); + + var stooge = { + name: 'Moe', + template: _.template("I'm <%= this.name %>") + }; + equal(stooge.template(), "I'm Moe"); + + template = _.template('\n \ + <%\n \ + // a comment\n \ + if (data) { data += 12345; }; %>\n \ + <li><%= data %></li>\n \ + '); + equal(template({data : 12345}).replace(/\s/g, ''), '<li>24690</li>'); + + _.templateSettings = { + evaluate : /\{\{([\s\S]+?)\}\}/g, + interpolate : /\{\{=([\s\S]+?)\}\}/g + }; + + var custom = _.template('<ul>{{ for (var key in people) { }}<li>{{= people[key] }}</li>{{ } }}</ul>'); + result = custom({people : {moe : 'Moe', larry : 'Larry', curly : 'Curly'}}); + equal(result, '<ul><li>Moe</li><li>Larry</li><li>Curly</li></ul>', 'can run arbitrary javascript in templates'); + + var customQuote = _.template("It's its, not it's"); + equal(customQuote({}), "It's its, not it's"); + + var quoteInStatementAndBody = _.template("{{ if(foo == 'bar'){ }}Statement quotes and 'quotes'.{{ } }}"); + equal(quoteInStatementAndBody({foo: 'bar'}), "Statement quotes and 'quotes'."); + + _.templateSettings = { + evaluate : /<\?([\s\S]+?)\?>/g, + interpolate : /<\?=([\s\S]+?)\?>/g + }; + + var customWithSpecialChars = _.template('<ul><? for (var key in people) { ?><li><?= people[key] ?></li><? } ?></ul>'); + result = customWithSpecialChars({people : {moe : 'Moe', larry : 'Larry', curly : 'Curly'}}); + equal(result, '<ul><li>Moe</li><li>Larry</li><li>Curly</li></ul>', 'can run arbitrary javascript in templates'); + + var customWithSpecialCharsQuote = _.template("It's its, not it's"); + equal(customWithSpecialCharsQuote({}), "It's its, not it's"); + + var quoteInStatementAndBody = _.template("<? if(foo == 'bar'){ ?>Statement quotes and 'quotes'.<? } ?>"); + equal(quoteInStatementAndBody({foo: 'bar'}), "Statement quotes and 'quotes'."); + + _.templateSettings = { + interpolate : /\{\{(.+?)\}\}/g + }; + + var mustache = _.template('Hello {{planet}}!'); + equal(mustache({planet : 'World'}), 'Hello World!', 'can mimic mustache.js'); + + var templateWithNull = _.template('a null undefined {{planet}}'); + equal(templateWithNull({planet : 'world'}), 'a null undefined world', 'can handle missing escape and evaluate settings'); + }); + + test('_.template provides the generated function source, when a SyntaxError occurs', function() { + try { + _.template('<b><%= if x %></b>'); + } catch (ex) { + var source = ex.source; + } + ok(/__p/.test(source)); + }); + + test('_.template handles \\u2028 & \\u2029', function() { + var tmpl = _.template('<p>\u2028<%= "\\u2028\\u2029" %>\u2029</p>'); + strictEqual(tmpl(), '<p>\u2028\u2028\u2029\u2029</p>'); + }); + + test('result calls functions and returns primitives', function() { + var obj = {w: '', x: 'x', y: function(){ return this.x; }}; + strictEqual(_.result(obj, 'w'), ''); + strictEqual(_.result(obj, 'x'), 'x'); + strictEqual(_.result(obj, 'y'), 'x'); + strictEqual(_.result(obj, 'z'), undefined); + strictEqual(_.result(null, 'x'), undefined); + }); + + test('_.templateSettings.variable', function() { + var s = '<%=data.x%>'; + var data = {x: 'x'}; + strictEqual(_.template(s, data, {variable: 'data'}), 'x'); + _.templateSettings.variable = 'data'; + strictEqual(_.template(s)(data), 'x'); + }); + + test('#547 - _.templateSettings is unchanged by custom settings.', function() { + ok(!_.templateSettings.variable); + _.template('', {}, {variable: 'x'}); + ok(!_.templateSettings.variable); + }); + + test('#556 - undefined template variables.', function() { + var template = _.template('<%=x%>'); + strictEqual(template({x: null}), ''); + strictEqual(template({x: undefined}), ''); + + var templateEscaped = _.template('<%-x%>'); + strictEqual(templateEscaped({x: null}), ''); + strictEqual(templateEscaped({x: undefined}), ''); + + var templateWithProperty = _.template('<%=x.foo%>'); + strictEqual(templateWithProperty({x: {} }), ''); + strictEqual(templateWithProperty({x: {} }), ''); + + var templateWithPropertyEscaped = _.template('<%-x.foo%>'); + strictEqual(templateWithPropertyEscaped({x: {} }), ''); + strictEqual(templateWithPropertyEscaped({x: {} }), ''); + }); + + test('interpolate evaluates code only once.', 2, function() { + var count = 0; + var template = _.template('<%= f() %>'); + template({f: function(){ ok(!(count++)); }}); + + var countEscaped = 0; + var templateEscaped = _.template('<%- f() %>'); + templateEscaped({f: function(){ ok(!(countEscaped++)); }}); + }); + + test('#746 - _.template settings are not modified.', 1, function() { + var settings = {}; + _.template('', null, settings); + deepEqual(settings, {}); + }); + + test('#779 - delimeters are applied to unescaped text.', 1, function() { + var template = _.template('<<\nx\n>>', null, {evaluate: /<<(.*?)>>/g}); + strictEqual(template(), '<<\nx\n>>'); + }); + +})(); diff --git a/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/test/vendor/qunit.css b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/test/vendor/qunit.css new file mode 100644 index 000000000..7ba3f9a30 --- /dev/null +++ b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/test/vendor/qunit.css @@ -0,0 +1,244 @@ +/** + * QUnit v1.12.0 - A JavaScript Unit Testing Framework + * + * http://qunitjs.com + * + * Copyright 2012 jQuery Foundation and other contributors + * Released under the MIT license. + * http://jquery.org/license + */ + +/** Font Family and Sizes */ + +#qunit-tests, #qunit-header, #qunit-banner, #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult { + font-family: "Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial, sans-serif; +} + +#qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult, #qunit-tests li { font-size: small; } +#qunit-tests { font-size: smaller; } + + +/** Resets */ + +#qunit-tests, #qunit-header, #qunit-banner, #qunit-userAgent, #qunit-testresult, #qunit-modulefilter { + margin: 0; + padding: 0; +} + + +/** Header */ + +#qunit-header { + padding: 0.5em 0 0.5em 1em; + + color: #8699a4; + background-color: #0d3349; + + font-size: 1.5em; + line-height: 1em; + font-weight: normal; + + border-radius: 5px 5px 0 0; + -moz-border-radius: 5px 5px 0 0; + -webkit-border-top-right-radius: 5px; + -webkit-border-top-left-radius: 5px; +} + +#qunit-header a { + text-decoration: none; + color: #c2ccd1; +} + +#qunit-header a:hover, +#qunit-header a:focus { + color: #fff; +} + +#qunit-testrunner-toolbar label { + display: inline-block; + padding: 0 .5em 0 .1em; +} + +#qunit-banner { + height: 5px; +} + +#qunit-testrunner-toolbar { + padding: 0.5em 0 0.5em 2em; + color: #5E740B; + background-color: #eee; + overflow: hidden; +} + +#qunit-userAgent { + padding: 0.5em 0 0.5em 2.5em; + background-color: #2b81af; + color: #fff; + text-shadow: rgba(0, 0, 0, 0.5) 2px 2px 1px; +} + +#qunit-modulefilter-container { + float: right; +} + +/** Tests: Pass/Fail */ + +#qunit-tests { + list-style-position: inside; +} + +#qunit-tests li { + padding: 0.4em 0.5em 0.4em 2.5em; + border-bottom: 1px solid #fff; + list-style-position: inside; +} + +#qunit-tests.hidepass li.pass, #qunit-tests.hidepass li.running { + display: none; +} + +#qunit-tests li strong { + cursor: pointer; +} + +#qunit-tests li a { + padding: 0.5em; + color: #c2ccd1; + text-decoration: none; +} +#qunit-tests li a:hover, +#qunit-tests li a:focus { + color: #000; +} + +#qunit-tests li .runtime { + float: right; + font-size: smaller; +} + +.qunit-assert-list { + margin-top: 0.5em; + padding: 0.5em; + + background-color: #fff; + + border-radius: 5px; + -moz-border-radius: 5px; + -webkit-border-radius: 5px; +} + +.qunit-collapsed { + display: none; +} + +#qunit-tests table { + border-collapse: collapse; + margin-top: .2em; +} + +#qunit-tests th { + text-align: right; + vertical-align: top; + padding: 0 .5em 0 0; +} + +#qunit-tests td { + vertical-align: top; +} + +#qunit-tests pre { + margin: 0; + white-space: pre-wrap; + word-wrap: break-word; +} + +#qunit-tests del { + background-color: #e0f2be; + color: #374e0c; + text-decoration: none; +} + +#qunit-tests ins { + background-color: #ffcaca; + color: #500; + text-decoration: none; +} + +/*** Test Counts */ + +#qunit-tests b.counts { color: black; } +#qunit-tests b.passed { color: #5E740B; } +#qunit-tests b.failed { color: #710909; } + +#qunit-tests li li { + padding: 5px; + background-color: #fff; + border-bottom: none; + list-style-position: inside; +} + +/*** Passing Styles */ + +#qunit-tests li li.pass { + color: #3c510c; + background-color: #fff; + border-left: 10px solid #C6E746; +} + +#qunit-tests .pass { color: #528CE0; background-color: #D2E0E6; } +#qunit-tests .pass .test-name { color: #366097; } + +#qunit-tests .pass .test-actual, +#qunit-tests .pass .test-expected { color: #999999; } + +#qunit-banner.qunit-pass { background-color: #C6E746; } + +/*** Failing Styles */ + +#qunit-tests li li.fail { + color: #710909; + background-color: #fff; + border-left: 10px solid #EE5757; + white-space: pre; +} + +#qunit-tests > li:last-child { + border-radius: 0 0 5px 5px; + -moz-border-radius: 0 0 5px 5px; + -webkit-border-bottom-right-radius: 5px; + -webkit-border-bottom-left-radius: 5px; +} + +#qunit-tests .fail { color: #000000; background-color: #EE5757; } +#qunit-tests .fail .test-name, +#qunit-tests .fail .module-name { color: #000000; } + +#qunit-tests .fail .test-actual { color: #EE5757; } +#qunit-tests .fail .test-expected { color: green; } + +#qunit-banner.qunit-fail { background-color: #EE5757; } + + +/** Result */ + +#qunit-testresult { + padding: 0.5em 0.5em 0.5em 2.5em; + + color: #2b81af; + background-color: #D2E0E6; + + border-bottom: 1px solid white; +} +#qunit-testresult .module-name { + font-weight: bold; +} + +/** Fixture */ + +#qunit-fixture { + position: absolute; + top: -10000px; + left: -10000px; + width: 1000px; + height: 1000px; +} diff --git a/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/test/vendor/qunit.js b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/test/vendor/qunit.js new file mode 100644 index 000000000..84c73907d --- /dev/null +++ b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/test/vendor/qunit.js @@ -0,0 +1,2212 @@ +/** + * QUnit v1.12.0 - A JavaScript Unit Testing Framework + * + * http://qunitjs.com + * + * Copyright 2013 jQuery Foundation and other contributors + * Released under the MIT license. + * https://jquery.org/license/ + */ + +(function( window ) { + +var QUnit, + assert, + config, + onErrorFnPrev, + testId = 0, + fileName = (sourceFromStacktrace( 0 ) || "" ).replace(/(:\d+)+\)?/, "").replace(/.+\//, ""), + toString = Object.prototype.toString, + hasOwn = Object.prototype.hasOwnProperty, + // Keep a local reference to Date (GH-283) + Date = window.Date, + setTimeout = window.setTimeout, + defined = { + setTimeout: typeof window.setTimeout !== "undefined", + sessionStorage: (function() { + var x = "qunit-test-string"; + try { + sessionStorage.setItem( x, x ); + sessionStorage.removeItem( x ); + return true; + } catch( e ) { + return false; + } + }()) + }, + /** + * Provides a normalized error string, correcting an issue + * with IE 7 (and prior) where Error.prototype.toString is + * not properly implemented + * + * Based on http://es5.github.com/#x15.11.4.4 + * + * @param {String|Error} error + * @return {String} error message + */ + errorString = function( error ) { + var name, message, + errorString = error.toString(); + if ( errorString.substring( 0, 7 ) === "[object" ) { + name = error.name ? error.name.toString() : "Error"; + message = error.message ? error.message.toString() : ""; + if ( name && message ) { + return name + ": " + message; + } else if ( name ) { + return name; + } else if ( message ) { + return message; + } else { + return "Error"; + } + } else { + return errorString; + } + }, + /** + * Makes a clone of an object using only Array or Object as base, + * and copies over the own enumerable properties. + * + * @param {Object} obj + * @return {Object} New object with only the own properties (recursively). + */ + objectValues = function( obj ) { + // Grunt 0.3.x uses an older version of jshint that still has jshint/jshint#392. + /*jshint newcap: false */ + var key, val, + vals = QUnit.is( "array", obj ) ? [] : {}; + for ( key in obj ) { + if ( hasOwn.call( obj, key ) ) { + val = obj[key]; + vals[key] = val === Object(val) ? objectValues(val) : val; + } + } + return vals; + }; + +function Test( settings ) { + extend( this, settings ); + this.assertions = []; + this.testNumber = ++Test.count; +} + +Test.count = 0; + +Test.prototype = { + init: function() { + var a, b, li, + tests = id( "qunit-tests" ); + + if ( tests ) { + b = document.createElement( "strong" ); + b.innerHTML = this.nameHtml; + + // `a` initialized at top of scope + a = document.createElement( "a" ); + a.innerHTML = "Rerun"; + a.href = QUnit.url({ testNumber: this.testNumber }); + + li = document.createElement( "li" ); + li.appendChild( b ); + li.appendChild( a ); + li.className = "running"; + li.id = this.id = "qunit-test-output" + testId++; + + tests.appendChild( li ); + } + }, + setup: function() { + if ( + // Emit moduleStart when we're switching from one module to another + this.module !== config.previousModule || + // They could be equal (both undefined) but if the previousModule property doesn't + // yet exist it means this is the first test in a suite that isn't wrapped in a + // module, in which case we'll just emit a moduleStart event for 'undefined'. + // Without this, reporters can get testStart before moduleStart which is a problem. + !hasOwn.call( config, "previousModule" ) + ) { + if ( hasOwn.call( config, "previousModule" ) ) { + runLoggingCallbacks( "moduleDone", QUnit, { + name: config.previousModule, + failed: config.moduleStats.bad, + passed: config.moduleStats.all - config.moduleStats.bad, + total: config.moduleStats.all + }); + } + config.previousModule = this.module; + config.moduleStats = { all: 0, bad: 0 }; + runLoggingCallbacks( "moduleStart", QUnit, { + name: this.module + }); + } + + config.current = this; + + this.testEnvironment = extend({ + setup: function() {}, + teardown: function() {} + }, this.moduleTestEnvironment ); + + this.started = +new Date(); + runLoggingCallbacks( "testStart", QUnit, { + name: this.testName, + module: this.module + }); + + /*jshint camelcase:false */ + + + /** + * Expose the current test environment. + * + * @deprecated since 1.12.0: Use QUnit.config.current.testEnvironment instead. + */ + QUnit.current_testEnvironment = this.testEnvironment; + + /*jshint camelcase:true */ + + if ( !config.pollution ) { + saveGlobal(); + } + if ( config.notrycatch ) { + this.testEnvironment.setup.call( this.testEnvironment, QUnit.assert ); + return; + } + try { + this.testEnvironment.setup.call( this.testEnvironment, QUnit.assert ); + } catch( e ) { + QUnit.pushFailure( "Setup failed on " + this.testName + ": " + ( e.message || e ), extractStacktrace( e, 1 ) ); + } + }, + run: function() { + config.current = this; + + var running = id( "qunit-testresult" ); + + if ( running ) { + running.innerHTML = "Running: <br/>" + this.nameHtml; + } + + if ( this.async ) { + QUnit.stop(); + } + + this.callbackStarted = +new Date(); + + if ( config.notrycatch ) { + this.callback.call( this.testEnvironment, QUnit.assert ); + this.callbackRuntime = +new Date() - this.callbackStarted; + return; + } + + try { + this.callback.call( this.testEnvironment, QUnit.assert ); + this.callbackRuntime = +new Date() - this.callbackStarted; + } catch( e ) { + this.callbackRuntime = +new Date() - this.callbackStarted; + + QUnit.pushFailure( "Died on test #" + (this.assertions.length + 1) + " " + this.stack + ": " + ( e.message || e ), extractStacktrace( e, 0 ) ); + // else next test will carry the responsibility + saveGlobal(); + + // Restart the tests if they're blocking + if ( config.blocking ) { + QUnit.start(); + } + } + }, + teardown: function() { + config.current = this; + if ( config.notrycatch ) { + if ( typeof this.callbackRuntime === "undefined" ) { + this.callbackRuntime = +new Date() - this.callbackStarted; + } + this.testEnvironment.teardown.call( this.testEnvironment, QUnit.assert ); + return; + } else { + try { + this.testEnvironment.teardown.call( this.testEnvironment, QUnit.assert ); + } catch( e ) { + QUnit.pushFailure( "Teardown failed on " + this.testName + ": " + ( e.message || e ), extractStacktrace( e, 1 ) ); + } + } + checkPollution(); + }, + finish: function() { + config.current = this; + if ( config.requireExpects && this.expected === null ) { + QUnit.pushFailure( "Expected number of assertions to be defined, but expect() was not called.", this.stack ); + } else if ( this.expected !== null && this.expected !== this.assertions.length ) { + QUnit.pushFailure( "Expected " + this.expected + " assertions, but " + this.assertions.length + " were run", this.stack ); + } else if ( this.expected === null && !this.assertions.length ) { + QUnit.pushFailure( "Expected at least one assertion, but none were run - call expect(0) to accept zero assertions.", this.stack ); + } + + var i, assertion, a, b, time, li, ol, + test = this, + good = 0, + bad = 0, + tests = id( "qunit-tests" ); + + this.runtime = +new Date() - this.started; + config.stats.all += this.assertions.length; + config.moduleStats.all += this.assertions.length; + + if ( tests ) { + ol = document.createElement( "ol" ); + ol.className = "qunit-assert-list"; + + for ( i = 0; i < this.assertions.length; i++ ) { + assertion = this.assertions[i]; + + li = document.createElement( "li" ); + li.className = assertion.result ? "pass" : "fail"; + li.innerHTML = assertion.message || ( assertion.result ? "okay" : "failed" ); + ol.appendChild( li ); + + if ( assertion.result ) { + good++; + } else { + bad++; + config.stats.bad++; + config.moduleStats.bad++; + } + } + + // store result when possible + if ( QUnit.config.reorder && defined.sessionStorage ) { + if ( bad ) { + sessionStorage.setItem( "qunit-test-" + this.module + "-" + this.testName, bad ); + } else { + sessionStorage.removeItem( "qunit-test-" + this.module + "-" + this.testName ); + } + } + + if ( bad === 0 ) { + addClass( ol, "qunit-collapsed" ); + } + + // `b` initialized at top of scope + b = document.createElement( "strong" ); + b.innerHTML = this.nameHtml + " <b class='counts'>(<b class='failed'>" + bad + "</b>, <b class='passed'>" + good + "</b>, " + this.assertions.length + ")</b>"; + + addEvent(b, "click", function() { + var next = b.parentNode.lastChild, + collapsed = hasClass( next, "qunit-collapsed" ); + ( collapsed ? removeClass : addClass )( next, "qunit-collapsed" ); + }); + + addEvent(b, "dblclick", function( e ) { + var target = e && e.target ? e.target : window.event.srcElement; + if ( target.nodeName.toLowerCase() === "span" || target.nodeName.toLowerCase() === "b" ) { + target = target.parentNode; + } + if ( window.location && target.nodeName.toLowerCase() === "strong" ) { + window.location = QUnit.url({ testNumber: test.testNumber }); + } + }); + + // `time` initialized at top of scope + time = document.createElement( "span" ); + time.className = "runtime"; + time.innerHTML = this.runtime + " ms"; + + // `li` initialized at top of scope + li = id( this.id ); + li.className = bad ? "fail" : "pass"; + li.removeChild( li.firstChild ); + a = li.firstChild; + li.appendChild( b ); + li.appendChild( a ); + li.appendChild( time ); + li.appendChild( ol ); + + } else { + for ( i = 0; i < this.assertions.length; i++ ) { + if ( !this.assertions[i].result ) { + bad++; + config.stats.bad++; + config.moduleStats.bad++; + } + } + } + + runLoggingCallbacks( "testDone", QUnit, { + name: this.testName, + module: this.module, + failed: bad, + passed: this.assertions.length - bad, + total: this.assertions.length, + duration: this.runtime + }); + + QUnit.reset(); + + config.current = undefined; + }, + + queue: function() { + var bad, + test = this; + + synchronize(function() { + test.init(); + }); + function run() { + // each of these can by async + synchronize(function() { + test.setup(); + }); + synchronize(function() { + test.run(); + }); + synchronize(function() { + test.teardown(); + }); + synchronize(function() { + test.finish(); + }); + } + + // `bad` initialized at top of scope + // defer when previous test run passed, if storage is available + bad = QUnit.config.reorder && defined.sessionStorage && + +sessionStorage.getItem( "qunit-test-" + this.module + "-" + this.testName ); + + if ( bad ) { + run(); + } else { + synchronize( run, true ); + } + } +}; + +// Root QUnit object. +// `QUnit` initialized at top of scope +QUnit = { + + // call on start of module test to prepend name to all tests + module: function( name, testEnvironment ) { + config.currentModule = name; + config.currentModuleTestEnvironment = testEnvironment; + config.modules[name] = true; + }, + + asyncTest: function( testName, expected, callback ) { + if ( arguments.length === 2 ) { + callback = expected; + expected = null; + } + + QUnit.test( testName, expected, callback, true ); + }, + + test: function( testName, expected, callback, async ) { + var test, + nameHtml = "<span class='test-name'>" + escapeText( testName ) + "</span>"; + + if ( arguments.length === 2 ) { + callback = expected; + expected = null; + } + + if ( config.currentModule ) { + nameHtml = "<span class='module-name'>" + escapeText( config.currentModule ) + "</span>: " + nameHtml; + } + + test = new Test({ + nameHtml: nameHtml, + testName: testName, + expected: expected, + async: async, + callback: callback, + module: config.currentModule, + moduleTestEnvironment: config.currentModuleTestEnvironment, + stack: sourceFromStacktrace( 2 ) + }); + + if ( !validTest( test ) ) { + return; + } + + test.queue(); + }, + + // Specify the number of expected assertions to guarantee that failed test (no assertions are run at all) don't slip through. + expect: function( asserts ) { + if (arguments.length === 1) { + config.current.expected = asserts; + } else { + return config.current.expected; + } + }, + + start: function( count ) { + // QUnit hasn't been initialized yet. + // Note: RequireJS (et al) may delay onLoad + if ( config.semaphore === undefined ) { + QUnit.begin(function() { + // This is triggered at the top of QUnit.load, push start() to the event loop, to allow QUnit.load to finish first + setTimeout(function() { + QUnit.start( count ); + }); + }); + return; + } + + config.semaphore -= count || 1; + // don't start until equal number of stop-calls + if ( config.semaphore > 0 ) { + return; + } + // ignore if start is called more often then stop + if ( config.semaphore < 0 ) { + config.semaphore = 0; + QUnit.pushFailure( "Called start() while already started (QUnit.config.semaphore was 0 already)", null, sourceFromStacktrace(2) ); + return; + } + // A slight delay, to avoid any current callbacks + if ( defined.setTimeout ) { + setTimeout(function() { + if ( config.semaphore > 0 ) { + return; + } + if ( config.timeout ) { + clearTimeout( config.timeout ); + } + + config.blocking = false; + process( true ); + }, 13); + } else { + config.blocking = false; + process( true ); + } + }, + + stop: function( count ) { + config.semaphore += count || 1; + config.blocking = true; + + if ( config.testTimeout && defined.setTimeout ) { + clearTimeout( config.timeout ); + config.timeout = setTimeout(function() { + QUnit.ok( false, "Test timed out" ); + config.semaphore = 1; + QUnit.start(); + }, config.testTimeout ); + } + } +}; + +// `assert` initialized at top of scope +// Assert helpers +// All of these must either call QUnit.push() or manually do: +// - runLoggingCallbacks( "log", .. ); +// - config.current.assertions.push({ .. }); +// We attach it to the QUnit object *after* we expose the public API, +// otherwise `assert` will become a global variable in browsers (#341). +assert = { + /** + * Asserts rough true-ish result. + * @name ok + * @function + * @example ok( "asdfasdf".length > 5, "There must be at least 5 chars" ); + */ + ok: function( result, msg ) { + if ( !config.current ) { + throw new Error( "ok() assertion outside test context, was " + sourceFromStacktrace(2) ); + } + result = !!result; + msg = msg || (result ? "okay" : "failed" ); + + var source, + details = { + module: config.current.module, + name: config.current.testName, + result: result, + message: msg + }; + + msg = "<span class='test-message'>" + escapeText( msg ) + "</span>"; + + if ( !result ) { + source = sourceFromStacktrace( 2 ); + if ( source ) { + details.source = source; + msg += "<table><tr class='test-source'><th>Source: </th><td><pre>" + escapeText( source ) + "</pre></td></tr></table>"; + } + } + runLoggingCallbacks( "log", QUnit, details ); + config.current.assertions.push({ + result: result, + message: msg + }); + }, + + /** + * Assert that the first two arguments are equal, with an optional message. + * Prints out both actual and expected values. + * @name equal + * @function + * @example equal( format( "Received {0} bytes.", 2), "Received 2 bytes.", "format() replaces {0} with next argument" ); + */ + equal: function( actual, expected, message ) { + /*jshint eqeqeq:false */ + QUnit.push( expected == actual, actual, expected, message ); + }, + + /** + * @name notEqual + * @function + */ + notEqual: function( actual, expected, message ) { + /*jshint eqeqeq:false */ + QUnit.push( expected != actual, actual, expected, message ); + }, + + /** + * @name propEqual + * @function + */ + propEqual: function( actual, expected, message ) { + actual = objectValues(actual); + expected = objectValues(expected); + QUnit.push( QUnit.equiv(actual, expected), actual, expected, message ); + }, + + /** + * @name notPropEqual + * @function + */ + notPropEqual: function( actual, expected, message ) { + actual = objectValues(actual); + expected = objectValues(expected); + QUnit.push( !QUnit.equiv(actual, expected), actual, expected, message ); + }, + + /** + * @name deepEqual + * @function + */ + deepEqual: function( actual, expected, message ) { + QUnit.push( QUnit.equiv(actual, expected), actual, expected, message ); + }, + + /** + * @name notDeepEqual + * @function + */ + notDeepEqual: function( actual, expected, message ) { + QUnit.push( !QUnit.equiv(actual, expected), actual, expected, message ); + }, + + /** + * @name strictEqual + * @function + */ + strictEqual: function( actual, expected, message ) { + QUnit.push( expected === actual, actual, expected, message ); + }, + + /** + * @name notStrictEqual + * @function + */ + notStrictEqual: function( actual, expected, message ) { + QUnit.push( expected !== actual, actual, expected, message ); + }, + + "throws": function( block, expected, message ) { + var actual, + expectedOutput = expected, + ok = false; + + // 'expected' is optional + if ( typeof expected === "string" ) { + message = expected; + expected = null; + } + + config.current.ignoreGlobalErrors = true; + try { + block.call( config.current.testEnvironment ); + } catch (e) { + actual = e; + } + config.current.ignoreGlobalErrors = false; + + if ( actual ) { + // we don't want to validate thrown error + if ( !expected ) { + ok = true; + expectedOutput = null; + // expected is a regexp + } else if ( QUnit.objectType( expected ) === "regexp" ) { + ok = expected.test( errorString( actual ) ); + // expected is a constructor + } else if ( actual instanceof expected ) { + ok = true; + // expected is a validation function which returns true is validation passed + } else if ( expected.call( {}, actual ) === true ) { + expectedOutput = null; + ok = true; + } + + QUnit.push( ok, actual, expectedOutput, message ); + } else { + QUnit.pushFailure( message, null, "No exception was thrown." ); + } + } +}; + +/** + * @deprecated since 1.8.0 + * Kept assertion helpers in root for backwards compatibility. + */ +extend( QUnit, assert ); + +/** + * @deprecated since 1.9.0 + * Kept root "raises()" for backwards compatibility. + * (Note that we don't introduce assert.raises). + */ +QUnit.raises = assert[ "throws" ]; + +/** + * @deprecated since 1.0.0, replaced with error pushes since 1.3.0 + * Kept to avoid TypeErrors for undefined methods. + */ +QUnit.equals = function() { + QUnit.push( false, false, false, "QUnit.equals has been deprecated since 2009 (e88049a0), use QUnit.equal instead" ); +}; +QUnit.same = function() { + QUnit.push( false, false, false, "QUnit.same has been deprecated since 2009 (e88049a0), use QUnit.deepEqual instead" ); +}; + +// We want access to the constructor's prototype +(function() { + function F() {} + F.prototype = QUnit; + QUnit = new F(); + // Make F QUnit's constructor so that we can add to the prototype later + QUnit.constructor = F; +}()); + +/** + * Config object: Maintain internal state + * Later exposed as QUnit.config + * `config` initialized at top of scope + */ +config = { + // The queue of tests to run + queue: [], + + // block until document ready + blocking: true, + + // when enabled, show only failing tests + // gets persisted through sessionStorage and can be changed in UI via checkbox + hidepassed: false, + + // by default, run previously failed tests first + // very useful in combination with "Hide passed tests" checked + reorder: true, + + // by default, modify document.title when suite is done + altertitle: true, + + // when enabled, all tests must call expect() + requireExpects: false, + + // add checkboxes that are persisted in the query-string + // when enabled, the id is set to `true` as a `QUnit.config` property + urlConfig: [ + { + id: "noglobals", + label: "Check for Globals", + tooltip: "Enabling this will test if any test introduces new properties on the `window` object. Stored as query-strings." + }, + { + id: "notrycatch", + label: "No try-catch", + tooltip: "Enabling this will run tests outside of a try-catch block. Makes debugging exceptions in IE reasonable. Stored as query-strings." + } + ], + + // Set of all modules. + modules: {}, + + // logging callback queues + begin: [], + done: [], + log: [], + testStart: [], + testDone: [], + moduleStart: [], + moduleDone: [] +}; + +// Export global variables, unless an 'exports' object exists, +// in that case we assume we're in CommonJS (dealt with on the bottom of the script) +if ( typeof exports === "undefined" ) { + extend( window, QUnit.constructor.prototype ); + + // Expose QUnit object + window.QUnit = QUnit; +} + +// Initialize more QUnit.config and QUnit.urlParams +(function() { + var i, + location = window.location || { search: "", protocol: "file:" }, + params = location.search.slice( 1 ).split( "&" ), + length = params.length, + urlParams = {}, + current; + + if ( params[ 0 ] ) { + for ( i = 0; i < length; i++ ) { + current = params[ i ].split( "=" ); + current[ 0 ] = decodeURIComponent( current[ 0 ] ); + // allow just a key to turn on a flag, e.g., test.html?noglobals + current[ 1 ] = current[ 1 ] ? decodeURIComponent( current[ 1 ] ) : true; + urlParams[ current[ 0 ] ] = current[ 1 ]; + } + } + + QUnit.urlParams = urlParams; + + // String search anywhere in moduleName+testName + config.filter = urlParams.filter; + + // Exact match of the module name + config.module = urlParams.module; + + config.testNumber = parseInt( urlParams.testNumber, 10 ) || null; + + // Figure out if we're running the tests from a server or not + QUnit.isLocal = location.protocol === "file:"; +}()); + +// Extend QUnit object, +// these after set here because they should not be exposed as global functions +extend( QUnit, { + assert: assert, + + config: config, + + // Initialize the configuration options + init: function() { + extend( config, { + stats: { all: 0, bad: 0 }, + moduleStats: { all: 0, bad: 0 }, + started: +new Date(), + updateRate: 1000, + blocking: false, + autostart: true, + autorun: false, + filter: "", + queue: [], + semaphore: 1 + }); + + var tests, banner, result, + qunit = id( "qunit" ); + + if ( qunit ) { + qunit.innerHTML = + "<h1 id='qunit-header'>" + escapeText( document.title ) + "</h1>" + + "<h2 id='qunit-banner'></h2>" + + "<div id='qunit-testrunner-toolbar'></div>" + + "<h2 id='qunit-userAgent'></h2>" + + "<ol id='qunit-tests'></ol>"; + } + + tests = id( "qunit-tests" ); + banner = id( "qunit-banner" ); + result = id( "qunit-testresult" ); + + if ( tests ) { + tests.innerHTML = ""; + } + + if ( banner ) { + banner.className = ""; + } + + if ( result ) { + result.parentNode.removeChild( result ); + } + + if ( tests ) { + result = document.createElement( "p" ); + result.id = "qunit-testresult"; + result.className = "result"; + tests.parentNode.insertBefore( result, tests ); + result.innerHTML = "Running...<br/> "; + } + }, + + // Resets the test setup. Useful for tests that modify the DOM. + /* + DEPRECATED: Use multiple tests instead of resetting inside a test. + Use testStart or testDone for custom cleanup. + This method will throw an error in 2.0, and will be removed in 2.1 + */ + reset: function() { + var fixture = id( "qunit-fixture" ); + if ( fixture ) { + fixture.innerHTML = config.fixture; + } + }, + + // Trigger an event on an element. + // @example triggerEvent( document.body, "click" ); + triggerEvent: function( elem, type, event ) { + if ( document.createEvent ) { + event = document.createEvent( "MouseEvents" ); + event.initMouseEvent(type, true, true, elem.ownerDocument.defaultView, + 0, 0, 0, 0, 0, false, false, false, false, 0, null); + + elem.dispatchEvent( event ); + } else if ( elem.fireEvent ) { + elem.fireEvent( "on" + type ); + } + }, + + // Safe object type checking + is: function( type, obj ) { + return QUnit.objectType( obj ) === type; + }, + + objectType: function( obj ) { + if ( typeof obj === "undefined" ) { + return "undefined"; + // consider: typeof null === object + } + if ( obj === null ) { + return "null"; + } + + var match = toString.call( obj ).match(/^\[object\s(.*)\]$/), + type = match && match[1] || ""; + + switch ( type ) { + case "Number": + if ( isNaN(obj) ) { + return "nan"; + } + return "number"; + case "String": + case "Boolean": + case "Array": + case "Date": + case "RegExp": + case "Function": + return type.toLowerCase(); + } + if ( typeof obj === "object" ) { + return "object"; + } + return undefined; + }, + + push: function( result, actual, expected, message ) { + if ( !config.current ) { + throw new Error( "assertion outside test context, was " + sourceFromStacktrace() ); + } + + var output, source, + details = { + module: config.current.module, + name: config.current.testName, + result: result, + message: message, + actual: actual, + expected: expected + }; + + message = escapeText( message ) || ( result ? "okay" : "failed" ); + message = "<span class='test-message'>" + message + "</span>"; + output = message; + + if ( !result ) { + expected = escapeText( QUnit.jsDump.parse(expected) ); + actual = escapeText( QUnit.jsDump.parse(actual) ); + output += "<table><tr class='test-expected'><th>Expected: </th><td><pre>" + expected + "</pre></td></tr>"; + + if ( actual !== expected ) { + output += "<tr class='test-actual'><th>Result: </th><td><pre>" + actual + "</pre></td></tr>"; + output += "<tr class='test-diff'><th>Diff: </th><td><pre>" + QUnit.diff( expected, actual ) + "</pre></td></tr>"; + } + + source = sourceFromStacktrace(); + + if ( source ) { + details.source = source; + output += "<tr class='test-source'><th>Source: </th><td><pre>" + escapeText( source ) + "</pre></td></tr>"; + } + + output += "</table>"; + } + + runLoggingCallbacks( "log", QUnit, details ); + + config.current.assertions.push({ + result: !!result, + message: output + }); + }, + + pushFailure: function( message, source, actual ) { + if ( !config.current ) { + throw new Error( "pushFailure() assertion outside test context, was " + sourceFromStacktrace(2) ); + } + + var output, + details = { + module: config.current.module, + name: config.current.testName, + result: false, + message: message + }; + + message = escapeText( message ) || "error"; + message = "<span class='test-message'>" + message + "</span>"; + output = message; + + output += "<table>"; + + if ( actual ) { + output += "<tr class='test-actual'><th>Result: </th><td><pre>" + escapeText( actual ) + "</pre></td></tr>"; + } + + if ( source ) { + details.source = source; + output += "<tr class='test-source'><th>Source: </th><td><pre>" + escapeText( source ) + "</pre></td></tr>"; + } + + output += "</table>"; + + runLoggingCallbacks( "log", QUnit, details ); + + config.current.assertions.push({ + result: false, + message: output + }); + }, + + url: function( params ) { + params = extend( extend( {}, QUnit.urlParams ), params ); + var key, + querystring = "?"; + + for ( key in params ) { + if ( hasOwn.call( params, key ) ) { + querystring += encodeURIComponent( key ) + "=" + + encodeURIComponent( params[ key ] ) + "&"; + } + } + return window.location.protocol + "//" + window.location.host + + window.location.pathname + querystring.slice( 0, -1 ); + }, + + extend: extend, + id: id, + addEvent: addEvent, + addClass: addClass, + hasClass: hasClass, + removeClass: removeClass + // load, equiv, jsDump, diff: Attached later +}); + +/** + * @deprecated: Created for backwards compatibility with test runner that set the hook function + * into QUnit.{hook}, instead of invoking it and passing the hook function. + * QUnit.constructor is set to the empty F() above so that we can add to it's prototype here. + * Doing this allows us to tell if the following methods have been overwritten on the actual + * QUnit object. + */ +extend( QUnit.constructor.prototype, { + + // Logging callbacks; all receive a single argument with the listed properties + // run test/logs.html for any related changes + begin: registerLoggingCallback( "begin" ), + + // done: { failed, passed, total, runtime } + done: registerLoggingCallback( "done" ), + + // log: { result, actual, expected, message } + log: registerLoggingCallback( "log" ), + + // testStart: { name } + testStart: registerLoggingCallback( "testStart" ), + + // testDone: { name, failed, passed, total, duration } + testDone: registerLoggingCallback( "testDone" ), + + // moduleStart: { name } + moduleStart: registerLoggingCallback( "moduleStart" ), + + // moduleDone: { name, failed, passed, total } + moduleDone: registerLoggingCallback( "moduleDone" ) +}); + +if ( typeof document === "undefined" || document.readyState === "complete" ) { + config.autorun = true; +} + +QUnit.load = function() { + runLoggingCallbacks( "begin", QUnit, {} ); + + // Initialize the config, saving the execution queue + var banner, filter, i, label, len, main, ol, toolbar, userAgent, val, + urlConfigCheckboxesContainer, urlConfigCheckboxes, moduleFilter, + numModules = 0, + moduleNames = [], + moduleFilterHtml = "", + urlConfigHtml = "", + oldconfig = extend( {}, config ); + + QUnit.init(); + extend(config, oldconfig); + + config.blocking = false; + + len = config.urlConfig.length; + + for ( i = 0; i < len; i++ ) { + val = config.urlConfig[i]; + if ( typeof val === "string" ) { + val = { + id: val, + label: val, + tooltip: "[no tooltip available]" + }; + } + config[ val.id ] = QUnit.urlParams[ val.id ]; + urlConfigHtml += "<input id='qunit-urlconfig-" + escapeText( val.id ) + + "' name='" + escapeText( val.id ) + + "' type='checkbox'" + ( config[ val.id ] ? " checked='checked'" : "" ) + + " title='" + escapeText( val.tooltip ) + + "'><label for='qunit-urlconfig-" + escapeText( val.id ) + + "' title='" + escapeText( val.tooltip ) + "'>" + val.label + "</label>"; + } + for ( i in config.modules ) { + if ( config.modules.hasOwnProperty( i ) ) { + moduleNames.push(i); + } + } + numModules = moduleNames.length; + moduleNames.sort( function( a, b ) { + return a.localeCompare( b ); + }); + moduleFilterHtml += "<label for='qunit-modulefilter'>Module: </label><select id='qunit-modulefilter' name='modulefilter'><option value='' " + + ( config.module === undefined ? "selected='selected'" : "" ) + + ">< All Modules ></option>"; + + + for ( i = 0; i < numModules; i++) { + moduleFilterHtml += "<option value='" + escapeText( encodeURIComponent(moduleNames[i]) ) + "' " + + ( config.module === moduleNames[i] ? "selected='selected'" : "" ) + + ">" + escapeText(moduleNames[i]) + "</option>"; + } + moduleFilterHtml += "</select>"; + + // `userAgent` initialized at top of scope + userAgent = id( "qunit-userAgent" ); + if ( userAgent ) { + userAgent.innerHTML = navigator.userAgent; + } + + // `banner` initialized at top of scope + banner = id( "qunit-header" ); + if ( banner ) { + banner.innerHTML = "<a href='" + QUnit.url({ filter: undefined, module: undefined, testNumber: undefined }) + "'>" + banner.innerHTML + "</a> "; + } + + // `toolbar` initialized at top of scope + toolbar = id( "qunit-testrunner-toolbar" ); + if ( toolbar ) { + // `filter` initialized at top of scope + filter = document.createElement( "input" ); + filter.type = "checkbox"; + filter.id = "qunit-filter-pass"; + + addEvent( filter, "click", function() { + var tmp, + ol = document.getElementById( "qunit-tests" ); + + if ( filter.checked ) { + ol.className = ol.className + " hidepass"; + } else { + tmp = " " + ol.className.replace( /[\n\t\r]/g, " " ) + " "; + ol.className = tmp.replace( / hidepass /, " " ); + } + if ( defined.sessionStorage ) { + if (filter.checked) { + sessionStorage.setItem( "qunit-filter-passed-tests", "true" ); + } else { + sessionStorage.removeItem( "qunit-filter-passed-tests" ); + } + } + }); + + if ( config.hidepassed || defined.sessionStorage && sessionStorage.getItem( "qunit-filter-passed-tests" ) ) { + filter.checked = true; + // `ol` initialized at top of scope + ol = document.getElementById( "qunit-tests" ); + ol.className = ol.className + " hidepass"; + } + toolbar.appendChild( filter ); + + // `label` initialized at top of scope + label = document.createElement( "label" ); + label.setAttribute( "for", "qunit-filter-pass" ); + label.setAttribute( "title", "Only show tests and assertions that fail. Stored in sessionStorage." ); + label.innerHTML = "Hide passed tests"; + toolbar.appendChild( label ); + + urlConfigCheckboxesContainer = document.createElement("span"); + urlConfigCheckboxesContainer.innerHTML = urlConfigHtml; + urlConfigCheckboxes = urlConfigCheckboxesContainer.getElementsByTagName("input"); + // For oldIE support: + // * Add handlers to the individual elements instead of the container + // * Use "click" instead of "change" + // * Fallback from event.target to event.srcElement + addEvents( urlConfigCheckboxes, "click", function( event ) { + var params = {}, + target = event.target || event.srcElement; + params[ target.name ] = target.checked ? true : undefined; + window.location = QUnit.url( params ); + }); + toolbar.appendChild( urlConfigCheckboxesContainer ); + + if (numModules > 1) { + moduleFilter = document.createElement( "span" ); + moduleFilter.setAttribute( "id", "qunit-modulefilter-container" ); + moduleFilter.innerHTML = moduleFilterHtml; + addEvent( moduleFilter.lastChild, "change", function() { + var selectBox = moduleFilter.getElementsByTagName("select")[0], + selectedModule = decodeURIComponent(selectBox.options[selectBox.selectedIndex].value); + + window.location = QUnit.url({ + module: ( selectedModule === "" ) ? undefined : selectedModule, + // Remove any existing filters + filter: undefined, + testNumber: undefined + }); + }); + toolbar.appendChild(moduleFilter); + } + } + + // `main` initialized at top of scope + main = id( "qunit-fixture" ); + if ( main ) { + config.fixture = main.innerHTML; + } + + if ( config.autostart ) { + QUnit.start(); + } +}; + +addEvent( window, "load", QUnit.load ); + +// `onErrorFnPrev` initialized at top of scope +// Preserve other handlers +onErrorFnPrev = window.onerror; + +// Cover uncaught exceptions +// Returning true will suppress the default browser handler, +// returning false will let it run. +window.onerror = function ( error, filePath, linerNr ) { + var ret = false; + if ( onErrorFnPrev ) { + ret = onErrorFnPrev( error, filePath, linerNr ); + } + + // Treat return value as window.onerror itself does, + // Only do our handling if not suppressed. + if ( ret !== true ) { + if ( QUnit.config.current ) { + if ( QUnit.config.current.ignoreGlobalErrors ) { + return true; + } + QUnit.pushFailure( error, filePath + ":" + linerNr ); + } else { + QUnit.test( "global failure", extend( function() { + QUnit.pushFailure( error, filePath + ":" + linerNr ); + }, { validTest: validTest } ) ); + } + return false; + } + + return ret; +}; + +function done() { + config.autorun = true; + + // Log the last module results + if ( config.currentModule ) { + runLoggingCallbacks( "moduleDone", QUnit, { + name: config.currentModule, + failed: config.moduleStats.bad, + passed: config.moduleStats.all - config.moduleStats.bad, + total: config.moduleStats.all + }); + } + delete config.previousModule; + + var i, key, + banner = id( "qunit-banner" ), + tests = id( "qunit-tests" ), + runtime = +new Date() - config.started, + passed = config.stats.all - config.stats.bad, + html = [ + "Tests completed in ", + runtime, + " milliseconds.<br/>", + "<span class='passed'>", + passed, + "</span> assertions of <span class='total'>", + config.stats.all, + "</span> passed, <span class='failed'>", + config.stats.bad, + "</span> failed." + ].join( "" ); + + if ( banner ) { + banner.className = ( config.stats.bad ? "qunit-fail" : "qunit-pass" ); + } + + if ( tests ) { + id( "qunit-testresult" ).innerHTML = html; + } + + if ( config.altertitle && typeof document !== "undefined" && document.title ) { + // show ✖ for good, ✔ for bad suite result in title + // use escape sequences in case file gets loaded with non-utf-8-charset + document.title = [ + ( config.stats.bad ? "\u2716" : "\u2714" ), + document.title.replace( /^[\u2714\u2716] /i, "" ) + ].join( " " ); + } + + // clear own sessionStorage items if all tests passed + if ( config.reorder && defined.sessionStorage && config.stats.bad === 0 ) { + // `key` & `i` initialized at top of scope + for ( i = 0; i < sessionStorage.length; i++ ) { + key = sessionStorage.key( i++ ); + if ( key.indexOf( "qunit-test-" ) === 0 ) { + sessionStorage.removeItem( key ); + } + } + } + + // scroll back to top to show results + if ( window.scrollTo ) { + window.scrollTo(0, 0); + } + + runLoggingCallbacks( "done", QUnit, { + failed: config.stats.bad, + passed: passed, + total: config.stats.all, + runtime: runtime + }); +} + +/** @return Boolean: true if this test should be ran */ +function validTest( test ) { + var include, + filter = config.filter && config.filter.toLowerCase(), + module = config.module && config.module.toLowerCase(), + fullName = (test.module + ": " + test.testName).toLowerCase(); + + // Internally-generated tests are always valid + if ( test.callback && test.callback.validTest === validTest ) { + delete test.callback.validTest; + return true; + } + + if ( config.testNumber ) { + return test.testNumber === config.testNumber; + } + + if ( module && ( !test.module || test.module.toLowerCase() !== module ) ) { + return false; + } + + if ( !filter ) { + return true; + } + + include = filter.charAt( 0 ) !== "!"; + if ( !include ) { + filter = filter.slice( 1 ); + } + + // If the filter matches, we need to honour include + if ( fullName.indexOf( filter ) !== -1 ) { + return include; + } + + // Otherwise, do the opposite + return !include; +} + +// so far supports only Firefox, Chrome and Opera (buggy), Safari (for real exceptions) +// Later Safari and IE10 are supposed to support error.stack as well +// See also https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error/Stack +function extractStacktrace( e, offset ) { + offset = offset === undefined ? 3 : offset; + + var stack, include, i; + + if ( e.stacktrace ) { + // Opera + return e.stacktrace.split( "\n" )[ offset + 3 ]; + } else if ( e.stack ) { + // Firefox, Chrome + stack = e.stack.split( "\n" ); + if (/^error$/i.test( stack[0] ) ) { + stack.shift(); + } + if ( fileName ) { + include = []; + for ( i = offset; i < stack.length; i++ ) { + if ( stack[ i ].indexOf( fileName ) !== -1 ) { + break; + } + include.push( stack[ i ] ); + } + if ( include.length ) { + return include.join( "\n" ); + } + } + return stack[ offset ]; + } else if ( e.sourceURL ) { + // Safari, PhantomJS + // hopefully one day Safari provides actual stacktraces + // exclude useless self-reference for generated Error objects + if ( /qunit.js$/.test( e.sourceURL ) ) { + return; + } + // for actual exceptions, this is useful + return e.sourceURL + ":" + e.line; + } +} +function sourceFromStacktrace( offset ) { + try { + throw new Error(); + } catch ( e ) { + return extractStacktrace( e, offset ); + } +} + +/** + * Escape text for attribute or text content. + */ +function escapeText( s ) { + if ( !s ) { + return ""; + } + s = s + ""; + // Both single quotes and double quotes (for attributes) + return s.replace( /['"<>&]/g, function( s ) { + switch( s ) { + case "'": + return "'"; + case "\"": + return """; + case "<": + return "<"; + case ">": + return ">"; + case "&": + return "&"; + } + }); +} + +function synchronize( callback, last ) { + config.queue.push( callback ); + + if ( config.autorun && !config.blocking ) { + process( last ); + } +} + +function process( last ) { + function next() { + process( last ); + } + var start = new Date().getTime(); + config.depth = config.depth ? config.depth + 1 : 1; + + while ( config.queue.length && !config.blocking ) { + if ( !defined.setTimeout || config.updateRate <= 0 || ( ( new Date().getTime() - start ) < config.updateRate ) ) { + config.queue.shift()(); + } else { + setTimeout( next, 13 ); + break; + } + } + config.depth--; + if ( last && !config.blocking && !config.queue.length && config.depth === 0 ) { + done(); + } +} + +function saveGlobal() { + config.pollution = []; + + if ( config.noglobals ) { + for ( var key in window ) { + if ( hasOwn.call( window, key ) ) { + // in Opera sometimes DOM element ids show up here, ignore them + if ( /^qunit-test-output/.test( key ) ) { + continue; + } + config.pollution.push( key ); + } + } + } +} + +function checkPollution() { + var newGlobals, + deletedGlobals, + old = config.pollution; + + saveGlobal(); + + newGlobals = diff( config.pollution, old ); + if ( newGlobals.length > 0 ) { + QUnit.pushFailure( "Introduced global variable(s): " + newGlobals.join(", ") ); + } + + deletedGlobals = diff( old, config.pollution ); + if ( deletedGlobals.length > 0 ) { + QUnit.pushFailure( "Deleted global variable(s): " + deletedGlobals.join(", ") ); + } +} + +// returns a new Array with the elements that are in a but not in b +function diff( a, b ) { + var i, j, + result = a.slice(); + + for ( i = 0; i < result.length; i++ ) { + for ( j = 0; j < b.length; j++ ) { + if ( result[i] === b[j] ) { + result.splice( i, 1 ); + i--; + break; + } + } + } + return result; +} + +function extend( a, b ) { + for ( var prop in b ) { + if ( hasOwn.call( b, prop ) ) { + // Avoid "Member not found" error in IE8 caused by messing with window.constructor + if ( !( prop === "constructor" && a === window ) ) { + if ( b[ prop ] === undefined ) { + delete a[ prop ]; + } else { + a[ prop ] = b[ prop ]; + } + } + } + } + + return a; +} + +/** + * @param {HTMLElement} elem + * @param {string} type + * @param {Function} fn + */ +function addEvent( elem, type, fn ) { + // Standards-based browsers + if ( elem.addEventListener ) { + elem.addEventListener( type, fn, false ); + // IE + } else { + elem.attachEvent( "on" + type, fn ); + } +} + +/** + * @param {Array|NodeList} elems + * @param {string} type + * @param {Function} fn + */ +function addEvents( elems, type, fn ) { + var i = elems.length; + while ( i-- ) { + addEvent( elems[i], type, fn ); + } +} + +function hasClass( elem, name ) { + return (" " + elem.className + " ").indexOf(" " + name + " ") > -1; +} + +function addClass( elem, name ) { + if ( !hasClass( elem, name ) ) { + elem.className += (elem.className ? " " : "") + name; + } +} + +function removeClass( elem, name ) { + var set = " " + elem.className + " "; + // Class name may appear multiple times + while ( set.indexOf(" " + name + " ") > -1 ) { + set = set.replace(" " + name + " " , " "); + } + // If possible, trim it for prettiness, but not necessarily + elem.className = typeof set.trim === "function" ? set.trim() : set.replace(/^\s+|\s+$/g, ""); +} + +function id( name ) { + return !!( typeof document !== "undefined" && document && document.getElementById ) && + document.getElementById( name ); +} + +function registerLoggingCallback( key ) { + return function( callback ) { + config[key].push( callback ); + }; +} + +// Supports deprecated method of completely overwriting logging callbacks +function runLoggingCallbacks( key, scope, args ) { + var i, callbacks; + if ( QUnit.hasOwnProperty( key ) ) { + QUnit[ key ].call(scope, args ); + } else { + callbacks = config[ key ]; + for ( i = 0; i < callbacks.length; i++ ) { + callbacks[ i ].call( scope, args ); + } + } +} + +// Test for equality any JavaScript type. +// Author: Philippe Rathé <prathe@gmail.com> +QUnit.equiv = (function() { + + // Call the o related callback with the given arguments. + function bindCallbacks( o, callbacks, args ) { + var prop = QUnit.objectType( o ); + if ( prop ) { + if ( QUnit.objectType( callbacks[ prop ] ) === "function" ) { + return callbacks[ prop ].apply( callbacks, args ); + } else { + return callbacks[ prop ]; // or undefined + } + } + } + + // the real equiv function + var innerEquiv, + // stack to decide between skip/abort functions + callers = [], + // stack to avoiding loops from circular referencing + parents = [], + parentsB = [], + + getProto = Object.getPrototypeOf || function ( obj ) { + /*jshint camelcase:false */ + return obj.__proto__; + }, + callbacks = (function () { + + // for string, boolean, number and null + function useStrictEquality( b, a ) { + /*jshint eqeqeq:false */ + if ( b instanceof a.constructor || a instanceof b.constructor ) { + // to catch short annotation VS 'new' annotation of a + // declaration + // e.g. var i = 1; + // var j = new Number(1); + return a == b; + } else { + return a === b; + } + } + + return { + "string": useStrictEquality, + "boolean": useStrictEquality, + "number": useStrictEquality, + "null": useStrictEquality, + "undefined": useStrictEquality, + + "nan": function( b ) { + return isNaN( b ); + }, + + "date": function( b, a ) { + return QUnit.objectType( b ) === "date" && a.valueOf() === b.valueOf(); + }, + + "regexp": function( b, a ) { + return QUnit.objectType( b ) === "regexp" && + // the regex itself + a.source === b.source && + // and its modifiers + a.global === b.global && + // (gmi) ... + a.ignoreCase === b.ignoreCase && + a.multiline === b.multiline && + a.sticky === b.sticky; + }, + + // - skip when the property is a method of an instance (OOP) + // - abort otherwise, + // initial === would have catch identical references anyway + "function": function() { + var caller = callers[callers.length - 1]; + return caller !== Object && typeof caller !== "undefined"; + }, + + "array": function( b, a ) { + var i, j, len, loop, aCircular, bCircular; + + // b could be an object literal here + if ( QUnit.objectType( b ) !== "array" ) { + return false; + } + + len = a.length; + if ( len !== b.length ) { + // safe and faster + return false; + } + + // track reference to avoid circular references + parents.push( a ); + parentsB.push( b ); + for ( i = 0; i < len; i++ ) { + loop = false; + for ( j = 0; j < parents.length; j++ ) { + aCircular = parents[j] === a[i]; + bCircular = parentsB[j] === b[i]; + if ( aCircular || bCircular ) { + if ( a[i] === b[i] || aCircular && bCircular ) { + loop = true; + } else { + parents.pop(); + parentsB.pop(); + return false; + } + } + } + if ( !loop && !innerEquiv(a[i], b[i]) ) { + parents.pop(); + parentsB.pop(); + return false; + } + } + parents.pop(); + parentsB.pop(); + return true; + }, + + "object": function( b, a ) { + /*jshint forin:false */ + var i, j, loop, aCircular, bCircular, + // Default to true + eq = true, + aProperties = [], + bProperties = []; + + // comparing constructors is more strict than using + // instanceof + if ( a.constructor !== b.constructor ) { + // Allow objects with no prototype to be equivalent to + // objects with Object as their constructor. + if ( !(( getProto(a) === null && getProto(b) === Object.prototype ) || + ( getProto(b) === null && getProto(a) === Object.prototype ) ) ) { + return false; + } + } + + // stack constructor before traversing properties + callers.push( a.constructor ); + + // track reference to avoid circular references + parents.push( a ); + parentsB.push( b ); + + // be strict: don't ensure hasOwnProperty and go deep + for ( i in a ) { + loop = false; + for ( j = 0; j < parents.length; j++ ) { + aCircular = parents[j] === a[i]; + bCircular = parentsB[j] === b[i]; + if ( aCircular || bCircular ) { + if ( a[i] === b[i] || aCircular && bCircular ) { + loop = true; + } else { + eq = false; + break; + } + } + } + aProperties.push(i); + if ( !loop && !innerEquiv(a[i], b[i]) ) { + eq = false; + break; + } + } + + parents.pop(); + parentsB.pop(); + callers.pop(); // unstack, we are done + + for ( i in b ) { + bProperties.push( i ); // collect b's properties + } + + // Ensures identical properties name + return eq && innerEquiv( aProperties.sort(), bProperties.sort() ); + } + }; + }()); + + innerEquiv = function() { // can take multiple arguments + var args = [].slice.apply( arguments ); + if ( args.length < 2 ) { + return true; // end transition + } + + return (function( a, b ) { + if ( a === b ) { + return true; // catch the most you can + } else if ( a === null || b === null || typeof a === "undefined" || + typeof b === "undefined" || + QUnit.objectType(a) !== QUnit.objectType(b) ) { + return false; // don't lose time with error prone cases + } else { + return bindCallbacks(a, callbacks, [ b, a ]); + } + + // apply transition with (1..n) arguments + }( args[0], args[1] ) && innerEquiv.apply( this, args.splice(1, args.length - 1 )) ); + }; + + return innerEquiv; +}()); + +/** + * jsDump Copyright (c) 2008 Ariel Flesler - aflesler(at)gmail(dot)com | + * http://flesler.blogspot.com Licensed under BSD + * (http://www.opensource.org/licenses/bsd-license.php) Date: 5/15/2008 + * + * @projectDescription Advanced and extensible data dumping for Javascript. + * @version 1.0.0 + * @author Ariel Flesler + * @link {http://flesler.blogspot.com/2008/05/jsdump-pretty-dump-of-any-javascript.html} + */ +QUnit.jsDump = (function() { + function quote( str ) { + return "\"" + str.toString().replace( /"/g, "\\\"" ) + "\""; + } + function literal( o ) { + return o + ""; + } + function join( pre, arr, post ) { + var s = jsDump.separator(), + base = jsDump.indent(), + inner = jsDump.indent(1); + if ( arr.join ) { + arr = arr.join( "," + s + inner ); + } + if ( !arr ) { + return pre + post; + } + return [ pre, inner + arr, base + post ].join(s); + } + function array( arr, stack ) { + var i = arr.length, ret = new Array(i); + this.up(); + while ( i-- ) { + ret[i] = this.parse( arr[i] , undefined , stack); + } + this.down(); + return join( "[", ret, "]" ); + } + + var reName = /^function (\w+)/, + jsDump = { + // type is used mostly internally, you can fix a (custom)type in advance + parse: function( obj, type, stack ) { + stack = stack || [ ]; + var inStack, res, + parser = this.parsers[ type || this.typeOf(obj) ]; + + type = typeof parser; + inStack = inArray( obj, stack ); + + if ( inStack !== -1 ) { + return "recursion(" + (inStack - stack.length) + ")"; + } + if ( type === "function" ) { + stack.push( obj ); + res = parser.call( this, obj, stack ); + stack.pop(); + return res; + } + return ( type === "string" ) ? parser : this.parsers.error; + }, + typeOf: function( obj ) { + var type; + if ( obj === null ) { + type = "null"; + } else if ( typeof obj === "undefined" ) { + type = "undefined"; + } else if ( QUnit.is( "regexp", obj) ) { + type = "regexp"; + } else if ( QUnit.is( "date", obj) ) { + type = "date"; + } else if ( QUnit.is( "function", obj) ) { + type = "function"; + } else if ( typeof obj.setInterval !== undefined && typeof obj.document !== "undefined" && typeof obj.nodeType === "undefined" ) { + type = "window"; + } else if ( obj.nodeType === 9 ) { + type = "document"; + } else if ( obj.nodeType ) { + type = "node"; + } else if ( + // native arrays + toString.call( obj ) === "[object Array]" || + // NodeList objects + ( typeof obj.length === "number" && typeof obj.item !== "undefined" && ( obj.length ? obj.item(0) === obj[0] : ( obj.item( 0 ) === null && typeof obj[0] === "undefined" ) ) ) + ) { + type = "array"; + } else if ( obj.constructor === Error.prototype.constructor ) { + type = "error"; + } else { + type = typeof obj; + } + return type; + }, + separator: function() { + return this.multiline ? this.HTML ? "<br />" : "\n" : this.HTML ? " " : " "; + }, + // extra can be a number, shortcut for increasing-calling-decreasing + indent: function( extra ) { + if ( !this.multiline ) { + return ""; + } + var chr = this.indentChar; + if ( this.HTML ) { + chr = chr.replace( /\t/g, " " ).replace( / /g, " " ); + } + return new Array( this.depth + ( extra || 0 ) ).join(chr); + }, + up: function( a ) { + this.depth += a || 1; + }, + down: function( a ) { + this.depth -= a || 1; + }, + setParser: function( name, parser ) { + this.parsers[name] = parser; + }, + // The next 3 are exposed so you can use them + quote: quote, + literal: literal, + join: join, + // + depth: 1, + // This is the list of parsers, to modify them, use jsDump.setParser + parsers: { + window: "[Window]", + document: "[Document]", + error: function(error) { + return "Error(\"" + error.message + "\")"; + }, + unknown: "[Unknown]", + "null": "null", + "undefined": "undefined", + "function": function( fn ) { + var ret = "function", + // functions never have name in IE + name = "name" in fn ? fn.name : (reName.exec(fn) || [])[1]; + + if ( name ) { + ret += " " + name; + } + ret += "( "; + + ret = [ ret, QUnit.jsDump.parse( fn, "functionArgs" ), "){" ].join( "" ); + return join( ret, QUnit.jsDump.parse(fn,"functionCode" ), "}" ); + }, + array: array, + nodelist: array, + "arguments": array, + object: function( map, stack ) { + /*jshint forin:false */ + var ret = [ ], keys, key, val, i; + QUnit.jsDump.up(); + keys = []; + for ( key in map ) { + keys.push( key ); + } + keys.sort(); + for ( i = 0; i < keys.length; i++ ) { + key = keys[ i ]; + val = map[ key ]; + ret.push( QUnit.jsDump.parse( key, "key" ) + ": " + QUnit.jsDump.parse( val, undefined, stack ) ); + } + QUnit.jsDump.down(); + return join( "{", ret, "}" ); + }, + node: function( node ) { + var len, i, val, + open = QUnit.jsDump.HTML ? "<" : "<", + close = QUnit.jsDump.HTML ? ">" : ">", + tag = node.nodeName.toLowerCase(), + ret = open + tag, + attrs = node.attributes; + + if ( attrs ) { + for ( i = 0, len = attrs.length; i < len; i++ ) { + val = attrs[i].nodeValue; + // IE6 includes all attributes in .attributes, even ones not explicitly set. + // Those have values like undefined, null, 0, false, "" or "inherit". + if ( val && val !== "inherit" ) { + ret += " " + attrs[i].nodeName + "=" + QUnit.jsDump.parse( val, "attribute" ); + } + } + } + ret += close; + + // Show content of TextNode or CDATASection + if ( node.nodeType === 3 || node.nodeType === 4 ) { + ret += node.nodeValue; + } + + return ret + open + "/" + tag + close; + }, + // function calls it internally, it's the arguments part of the function + functionArgs: function( fn ) { + var args, + l = fn.length; + + if ( !l ) { + return ""; + } + + args = new Array(l); + while ( l-- ) { + // 97 is 'a' + args[l] = String.fromCharCode(97+l); + } + return " " + args.join( ", " ) + " "; + }, + // object calls it internally, the key part of an item in a map + key: quote, + // function calls it internally, it's the content of the function + functionCode: "[code]", + // node calls it internally, it's an html attribute value + attribute: quote, + string: quote, + date: quote, + regexp: literal, + number: literal, + "boolean": literal + }, + // if true, entities are escaped ( <, >, \t, space and \n ) + HTML: false, + // indentation unit + indentChar: " ", + // if true, items in a collection, are separated by a \n, else just a space. + multiline: true + }; + + return jsDump; +}()); + +// from jquery.js +function inArray( elem, array ) { + if ( array.indexOf ) { + return array.indexOf( elem ); + } + + for ( var i = 0, length = array.length; i < length; i++ ) { + if ( array[ i ] === elem ) { + return i; + } + } + + return -1; +} + +/* + * Javascript Diff Algorithm + * By John Resig (http://ejohn.org/) + * Modified by Chu Alan "sprite" + * + * Released under the MIT license. + * + * More Info: + * http://ejohn.org/projects/javascript-diff-algorithm/ + * + * Usage: QUnit.diff(expected, actual) + * + * QUnit.diff( "the quick brown fox jumped over", "the quick fox jumps over" ) == "the quick <del>brown </del> fox <del>jumped </del><ins>jumps </ins> over" + */ +QUnit.diff = (function() { + /*jshint eqeqeq:false, eqnull:true */ + function diff( o, n ) { + var i, + ns = {}, + os = {}; + + for ( i = 0; i < n.length; i++ ) { + if ( !hasOwn.call( ns, n[i] ) ) { + ns[ n[i] ] = { + rows: [], + o: null + }; + } + ns[ n[i] ].rows.push( i ); + } + + for ( i = 0; i < o.length; i++ ) { + if ( !hasOwn.call( os, o[i] ) ) { + os[ o[i] ] = { + rows: [], + n: null + }; + } + os[ o[i] ].rows.push( i ); + } + + for ( i in ns ) { + if ( hasOwn.call( ns, i ) ) { + if ( ns[i].rows.length === 1 && hasOwn.call( os, i ) && os[i].rows.length === 1 ) { + n[ ns[i].rows[0] ] = { + text: n[ ns[i].rows[0] ], + row: os[i].rows[0] + }; + o[ os[i].rows[0] ] = { + text: o[ os[i].rows[0] ], + row: ns[i].rows[0] + }; + } + } + } + + for ( i = 0; i < n.length - 1; i++ ) { + if ( n[i].text != null && n[ i + 1 ].text == null && n[i].row + 1 < o.length && o[ n[i].row + 1 ].text == null && + n[ i + 1 ] == o[ n[i].row + 1 ] ) { + + n[ i + 1 ] = { + text: n[ i + 1 ], + row: n[i].row + 1 + }; + o[ n[i].row + 1 ] = { + text: o[ n[i].row + 1 ], + row: i + 1 + }; + } + } + + for ( i = n.length - 1; i > 0; i-- ) { + if ( n[i].text != null && n[ i - 1 ].text == null && n[i].row > 0 && o[ n[i].row - 1 ].text == null && + n[ i - 1 ] == o[ n[i].row - 1 ]) { + + n[ i - 1 ] = { + text: n[ i - 1 ], + row: n[i].row - 1 + }; + o[ n[i].row - 1 ] = { + text: o[ n[i].row - 1 ], + row: i - 1 + }; + } + } + + return { + o: o, + n: n + }; + } + + return function( o, n ) { + o = o.replace( /\s+$/, "" ); + n = n.replace( /\s+$/, "" ); + + var i, pre, + str = "", + out = diff( o === "" ? [] : o.split(/\s+/), n === "" ? [] : n.split(/\s+/) ), + oSpace = o.match(/\s+/g), + nSpace = n.match(/\s+/g); + + if ( oSpace == null ) { + oSpace = [ " " ]; + } + else { + oSpace.push( " " ); + } + + if ( nSpace == null ) { + nSpace = [ " " ]; + } + else { + nSpace.push( " " ); + } + + if ( out.n.length === 0 ) { + for ( i = 0; i < out.o.length; i++ ) { + str += "<del>" + out.o[i] + oSpace[i] + "</del>"; + } + } + else { + if ( out.n[0].text == null ) { + for ( n = 0; n < out.o.length && out.o[n].text == null; n++ ) { + str += "<del>" + out.o[n] + oSpace[n] + "</del>"; + } + } + + for ( i = 0; i < out.n.length; i++ ) { + if (out.n[i].text == null) { + str += "<ins>" + out.n[i] + nSpace[i] + "</ins>"; + } + else { + // `pre` initialized at top of scope + pre = ""; + + for ( n = out.n[i].row + 1; n < out.o.length && out.o[n].text == null; n++ ) { + pre += "<del>" + out.o[n] + oSpace[n] + "</del>"; + } + str += " " + out.n[i].text + nSpace[i] + pre; + } + } + } + + return str; + }; +}()); + +// for CommonJS environments, export everything +if ( typeof exports !== "undefined" ) { + extend( exports, QUnit.constructor.prototype ); +} + +// get at whatever the global object is, like window in browsers +}( (function() {return this;}.call()) )); diff --git a/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/test/vendor/runner.js b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/test/vendor/runner.js new file mode 100644 index 000000000..4b1d38b1b --- /dev/null +++ b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/test/vendor/runner.js @@ -0,0 +1,127 @@ +/* + * QtWebKit-powered headless test runner using PhantomJS + * + * PhantomJS binaries: http://phantomjs.org/download.html + * Requires PhantomJS 1.6+ (1.7+ recommended) + * + * Run with: + * phantomjs runner.js [url-of-your-qunit-testsuite] + * + * e.g. + * phantomjs runner.js http://localhost/qunit/test/index.html + */ + +/*jshint latedef:false */ +/*global phantom:false, require:false, console:false, window:false, QUnit:false */ + +(function() { + 'use strict'; + + var args = require('system').args; + + // arg[0]: scriptName, args[1...]: arguments + if (args.length !== 2) { + console.error('Usage:\n phantomjs runner.js [url-of-your-qunit-testsuite]'); + phantom.exit(1); + } + + var url = args[1], + page = require('webpage').create(); + + // Route `console.log()` calls from within the Page context to the main Phantom context (i.e. current `this`) + page.onConsoleMessage = function(msg) { + console.log(msg); + }; + + page.onInitialized = function() { + page.evaluate(addLogging); + }; + + page.onCallback = function(message) { + var result, + failed; + + if (message) { + if (message.name === 'QUnit.done') { + result = message.data; + failed = !result || result.failed; + + phantom.exit(failed ? 1 : 0); + } + } + }; + + page.open(url, function(status) { + if (status !== 'success') { + console.error('Unable to access network: ' + status); + phantom.exit(1); + } else { + // Cannot do this verification with the 'DOMContentLoaded' handler because it + // will be too late to attach it if a page does not have any script tags. + var qunitMissing = page.evaluate(function() { return (typeof QUnit === 'undefined' || !QUnit); }); + if (qunitMissing) { + console.error('The `QUnit` object is not present on this page.'); + phantom.exit(1); + } + + // Do nothing... the callback mechanism will handle everything! + } + }); + + function addLogging() { + window.document.addEventListener('DOMContentLoaded', function() { + var current_test_assertions = []; + + QUnit.log(function(details) { + var response; + + // Ignore passing assertions + if (details.result) { + return; + } + + response = details.message || ''; + + if (typeof details.expected !== 'undefined') { + if (response) { + response += ', '; + } + + response += 'expected: ' + details.expected + ', but was: ' + details.actual; + if (details.source) { + response += "\n" + details.source; + } + } + + current_test_assertions.push('Failed assertion: ' + response); + }); + + QUnit.testDone(function(result) { + var i, + len, + name = result.module + ': ' + result.name; + + if (result.failed) { + console.log('Test failed: ' + name); + + for (i = 0, len = current_test_assertions.length; i < len; i++) { + console.log(' ' + current_test_assertions[i]); + } + } + + current_test_assertions.length = 0; + }); + + QUnit.done(function(result) { + console.log('Took ' + result.runtime + 'ms to run ' + result.total + ' tests. ' + result.passed + ' passed, ' + result.failed + ' failed.'); + + if (typeof window.callPhantom === 'function') { + window.callPhantom({ + 'name': 'QUnit.done', + 'data': result + }); + } + }); + }, false); + } +})(); diff --git a/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/underscore-min.map b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/underscore-min.map new file mode 100644 index 000000000..47c69bad3 --- /dev/null +++ b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/underscore-min.map @@ -0,0 +1 @@ +{"version":3,"file":"underscore-min.js","sources":["underscore.js"],"names":["root","this","previousUnderscore","_","breaker","ArrayProto","Array","prototype","ObjProto","Object","FuncProto","Function","push","slice","concat","toString","hasOwnProperty","nativeForEach","forEach","nativeMap","map","nativeReduce","reduce","nativeReduceRight","reduceRight","nativeFilter","filter","nativeEvery","every","nativeSome","some","nativeIndexOf","indexOf","nativeLastIndexOf","lastIndexOf","nativeIsArray","isArray","nativeKeys","keys","nativeBind","bind","obj","_wrapped","exports","module","VERSION","each","iterator","context","length","i","call","collect","results","value","index","list","reduceError","foldl","inject","memo","initial","arguments","TypeError","foldr","find","detect","predicate","result","any","select","reject","all","identity","contains","include","target","invoke","method","args","isFunc","isFunction","apply","pluck","key","property","where","attrs","matches","findWhere","max","Math","Infinity","lastComputed","computed","min","shuffle","rand","shuffled","random","sample","n","guard","values","lookupIterator","sortBy","criteria","sort","left","right","a","b","group","behavior","groupBy","has","indexBy","countBy","sortedIndex","array","low","high","mid","toArray","size","first","head","take","last","rest","tail","drop","compact","flatten","input","shallow","output","isArguments","without","difference","partition","pass","fail","elem","uniq","unique","isSorted","seen","union","intersection","item","other","zip","object","from","hasIndex","range","start","stop","step","ceil","idx","ctor","func","bound","self","partial","boundArgs","position","bindAll","funcs","Error","f","memoize","hasher","delay","wait","setTimeout","defer","throttle","options","timeout","previous","later","leading","now","remaining","clearTimeout","trailing","debounce","immediate","timestamp","callNow","once","ran","wrap","wrapper","compose","after","times","isObject","pairs","invert","functions","methods","names","extend","source","prop","pick","copy","omit","defaults","clone","tap","interceptor","eq","aStack","bStack","className","String","global","multiline","ignoreCase","aCtor","constructor","bCtor","pop","isEqual","isEmpty","isString","isElement","nodeType","name","isFinite","isNaN","parseFloat","isNumber","isBoolean","isNull","isUndefined","noConflict","constant","accum","floor","Date","getTime","entityMap","escape","&","<",">","\"","'","unescape","entityRegexes","RegExp","join","string","replace","match","mixin","idCounter","uniqueId","prefix","id","templateSettings","evaluate","interpolate","noMatch","escapes","\\","\r","\n","\t","
","
","escaper","template","text","data","settings","render","matcher","offset","variable","e","chain","_chain","define","amd"],"mappings":"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"}
\ No newline at end of file diff --git a/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/underscore.js b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/underscore.js index 9a4cabecf..bc4505051 100644 --- a/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/underscore.js +++ b/node_modules/columnify/node_modules/wcwidth.js/node_modules/underscore/underscore.js @@ -14,9 +14,6 @@ // Save the previous value of the `_` variable. var previousUnderscore = root._; - // Establish the object that gets returned to break out of a loop iteration. - var breaker = {}; - // Save bytes in the minified (but not gzipped) version: var ArrayProto = Array.prototype, ObjProto = Object.prototype, FuncProto = Function.prototype; @@ -31,15 +28,6 @@ // All **ECMAScript 5** native function implementations that we hope to use // are declared here. var - nativeForEach = ArrayProto.forEach, - nativeMap = ArrayProto.map, - nativeReduce = ArrayProto.reduce, - nativeReduceRight = ArrayProto.reduceRight, - nativeFilter = ArrayProto.filter, - nativeEvery = ArrayProto.every, - nativeSome = ArrayProto.some, - nativeIndexOf = ArrayProto.indexOf, - nativeLastIndexOf = ArrayProto.lastIndexOf, nativeIsArray = Array.isArray, nativeKeys = Object.keys, nativeBind = FuncProto.bind; @@ -67,96 +55,126 @@ // Current version. _.VERSION = '1.6.0'; + // Internal function: creates a callback bound to its context if supplied + var createCallback = function(func, context, argCount) { + if (context === void 0) return func; + switch (argCount == null ? 3 : argCount) { + case 1: return function(value) { + return func.call(context, value); + }; + case 2: return function(value, other) { + return func.call(context, value, other); + }; + case 3: return function(value, index, collection) { + return func.call(context, value, index, collection); + }; + case 4: return function(accumulator, value, index, collection) { + return func.call(context, accumulator, value, index, collection); + }; + } + return function() { + return func.apply(context, arguments); + }; + }; + + // An internal function to generate lookup iterators. + var lookupIterator = function(value, context, argCount) { + if (value == null) return _.identity; + if (_.isFunction(value)) return createCallback(value, context, argCount); + if (_.isObject(value)) return _.matches(value); + return _.property(value); + }; + // Collection Functions // -------------------- // The cornerstone, an `each` implementation, aka `forEach`. - // Handles objects with the built-in `forEach`, arrays, and raw objects. - // Delegates to **ECMAScript 5**'s native `forEach` if available. - var each = _.each = _.forEach = function(obj, iterator, context) { + // Handles raw objects in addition to array-likes. Treats all + // sparse array-likes as if they were dense. + _.each = _.forEach = function(obj, iterator, context) { if (obj == null) return obj; - if (nativeForEach && obj.forEach === nativeForEach) { - obj.forEach(iterator, context); - } else if (obj.length === +obj.length) { - for (var i = 0, length = obj.length; i < length; i++) { - if (iterator.call(context, obj[i], i, obj) === breaker) return; + iterator = createCallback(iterator, context); + var i, length = obj.length; + if (length === +length) { + for (i = 0; i < length; i++) { + iterator(obj[i], i, obj); } } else { var keys = _.keys(obj); - for (var i = 0, length = keys.length; i < length; i++) { - if (iterator.call(context, obj[keys[i]], keys[i], obj) === breaker) return; + for (i = 0, length = keys.length; i < length; i++) { + iterator(obj[keys[i]], keys[i], obj); } } return obj; }; // Return the results of applying the iterator to each element. - // Delegates to **ECMAScript 5**'s native `map` if available. _.map = _.collect = function(obj, iterator, context) { - var results = []; - if (obj == null) return results; - if (nativeMap && obj.map === nativeMap) return obj.map(iterator, context); - each(obj, function(value, index, list) { - results.push(iterator.call(context, value, index, list)); - }); + if (obj == null) return []; + iterator = lookupIterator(iterator, context); + var length = obj.length, + currentKey, keys; + if (length !== +length) { + keys = _.keys(obj); + length = keys.length; + } + var results = Array(length); + for (var index = 0; index < length; index++) { + currentKey = keys ? keys[index] : index; + results[index] = iterator(obj[currentKey], currentKey, obj); + } return results; }; var reduceError = 'Reduce of empty array with no initial value'; // **Reduce** builds up a single result from a list of values, aka `inject`, - // or `foldl`. Delegates to **ECMAScript 5**'s native `reduce` if available. + // or `foldl`. _.reduce = _.foldl = _.inject = function(obj, iterator, memo, context) { var initial = arguments.length > 2; if (obj == null) obj = []; - if (nativeReduce && obj.reduce === nativeReduce) { - if (context) iterator = _.bind(iterator, context); - return initial ? obj.reduce(iterator, memo) : obj.reduce(iterator); - } - each(obj, function(value, index, list) { + iterator = createCallback(iterator, context, 4); + _.each(obj, function(value, index, list) { if (!initial) { memo = value; initial = true; } else { - memo = iterator.call(context, memo, value, index, list); + memo = iterator(memo, value, index, list); } }); - if (!initial) throw new TypeError(reduceError); + if (!initial) throw TypeError(reduceError); return memo; }; // The right-associative version of reduce, also known as `foldr`. - // Delegates to **ECMAScript 5**'s native `reduceRight` if available. _.reduceRight = _.foldr = function(obj, iterator, memo, context) { var initial = arguments.length > 2; if (obj == null) obj = []; - if (nativeReduceRight && obj.reduceRight === nativeReduceRight) { - if (context) iterator = _.bind(iterator, context); - return initial ? obj.reduceRight(iterator, memo) : obj.reduceRight(iterator); - } var length = obj.length; + iterator = createCallback(iterator, context, 4); if (length !== +length) { var keys = _.keys(obj); length = keys.length; } - each(obj, function(value, index, list) { + _.each(obj, function(value, index, list) { index = keys ? keys[--length] : --length; if (!initial) { memo = obj[index]; initial = true; } else { - memo = iterator.call(context, memo, obj[index], index, list); + memo = iterator(memo, obj[index], index, list); } }); - if (!initial) throw new TypeError(reduceError); + if (!initial) throw TypeError(reduceError); return memo; }; // Return the first value which passes a truth test. Aliased as `detect`. _.find = _.detect = function(obj, predicate, context) { var result; - any(obj, function(value, index, list) { - if (predicate.call(context, value, index, list)) { + predicate = lookupIterator(predicate, context); + _.some(obj, function(value, index, list) { + if (predicate(value, index, list)) { result = value; return true; } @@ -165,61 +183,66 @@ }; // Return all the elements that pass a truth test. - // Delegates to **ECMAScript 5**'s native `filter` if available. // Aliased as `select`. _.filter = _.select = function(obj, predicate, context) { var results = []; if (obj == null) return results; - if (nativeFilter && obj.filter === nativeFilter) return obj.filter(predicate, context); - each(obj, function(value, index, list) { - if (predicate.call(context, value, index, list)) results.push(value); + predicate = lookupIterator(predicate, context); + _.each(obj, function(value, index, list) { + if (predicate(value, index, list)) results.push(value); }); return results; }; // Return all the elements for which a truth test fails. _.reject = function(obj, predicate, context) { - return _.filter(obj, function(value, index, list) { - return !predicate.call(context, value, index, list); - }, context); + return _.filter(obj, _.negate(lookupIterator(predicate)), context); }; // Determine whether all of the elements match a truth test. - // Delegates to **ECMAScript 5**'s native `every` if available. // Aliased as `all`. _.every = _.all = function(obj, predicate, context) { - predicate || (predicate = _.identity); - var result = true; - if (obj == null) return result; - if (nativeEvery && obj.every === nativeEvery) return obj.every(predicate, context); - each(obj, function(value, index, list) { - if (!(result = result && predicate.call(context, value, index, list))) return breaker; - }); - return !!result; + if (obj == null) return true; + predicate = lookupIterator(predicate, context); + var length = obj.length; + var index, currentKey, keys; + if (length !== +length) { + keys = _.keys(obj); + length = keys.length; + } + for (index = 0; index < length; index++) { + currentKey = keys ? keys[index] : index; + if (!predicate(obj[currentKey], currentKey, obj)) return false; + } + return true; }; // Determine if at least one element in the object matches a truth test. - // Delegates to **ECMAScript 5**'s native `some` if available. // Aliased as `any`. - var any = _.some = _.any = function(obj, predicate, context) { - predicate || (predicate = _.identity); - var result = false; - if (obj == null) return result; - if (nativeSome && obj.some === nativeSome) return obj.some(predicate, context); - each(obj, function(value, index, list) { - if (result || (result = predicate.call(context, value, index, list))) return breaker; - }); - return !!result; + // Determine if at least one element in the object matches a truth test. + // Aliased as `any`. + _.some = _.any = function(obj, predicate, context) { + if (obj == null) return false; + predicate = lookupIterator(predicate, context); + var length = obj.length; + var index, currentKey, keys; + if (length !== +length) { + keys = _.keys(obj); + length = keys.length; + } + for (index = 0; index < length; index++) { + currentKey = keys ? keys[index] : index; + if (predicate(obj[currentKey], currentKey, obj)) return true; + } + return false; }; // Determine if the array or object contains a given value (using `===`). // Aliased as `include`. _.contains = _.include = function(obj, target) { if (obj == null) return false; - if (nativeIndexOf && obj.indexOf === nativeIndexOf) return obj.indexOf(target) != -1; - return any(obj, function(value) { - return value === target; - }); + if (obj.length !== +obj.length) obj = _.values(obj); + return _.indexOf(obj, target) >= 0; }; // Invoke a method (with arguments) on every item in a collection. @@ -248,37 +271,51 @@ return _.find(obj, _.matches(attrs)); }; - // Return the maximum element or (element-based computation). - // Can't optimize arrays of integers longer than 65,535 elements. - // See [WebKit Bug 80797](https://bugs.webkit.org/show_bug.cgi?id=80797) + // Return the maximum element (or element-based computation). _.max = function(obj, iterator, context) { - if (!iterator && _.isArray(obj) && obj[0] === +obj[0] && obj.length < 65535) { - return Math.max.apply(Math, obj); - } - var result = -Infinity, lastComputed = -Infinity; - each(obj, function(value, index, list) { - var computed = iterator ? iterator.call(context, value, index, list) : value; - if (computed > lastComputed) { - result = value; - lastComputed = computed; + var result = -Infinity, lastComputed = -Infinity, + value, computed; + if (!iterator && _.isArray(obj)) { + for (var i = 0, length = obj.length; i < length; i++) { + value = obj[i]; + if (value > result) { + result = value; + } } - }); + } else { + iterator = lookupIterator(iterator, context); + _.each(obj, function(value, index, list) { + computed = iterator(value, index, list); + if (computed > lastComputed || computed === -Infinity && result === -Infinity) { + result = value; + lastComputed = computed; + } + }); + } return result; }; // Return the minimum element (or element-based computation). _.min = function(obj, iterator, context) { - if (!iterator && _.isArray(obj) && obj[0] === +obj[0] && obj.length < 65535) { - return Math.min.apply(Math, obj); - } - var result = Infinity, lastComputed = Infinity; - each(obj, function(value, index, list) { - var computed = iterator ? iterator.call(context, value, index, list) : value; - if (computed < lastComputed) { - result = value; - lastComputed = computed; + var result = Infinity, lastComputed = Infinity, + value, computed; + if (!iterator && _.isArray(obj)) { + for (var i = 0, length = obj.length; i < length; i++) { + value = obj[i]; + if (value < result) { + result = value; + } } - }); + } else { + iterator = lookupIterator(iterator, context); + _.each(obj, function(value, index, list) { + computed = iterator(value, index, list); + if (computed < lastComputed || computed === Infinity && result === Infinity) { + result = value; + lastComputed = computed; + } + }); + } return result; }; @@ -288,7 +325,7 @@ var rand; var index = 0; var shuffled = []; - each(obj, function(value) { + _.each(obj, function(value) { rand = _.random(index++); shuffled[index - 1] = shuffled[rand]; shuffled[rand] = value; @@ -307,21 +344,14 @@ return _.shuffle(obj).slice(0, Math.max(0, n)); }; - // An internal function to generate lookup iterators. - var lookupIterator = function(value) { - if (value == null) return _.identity; - if (_.isFunction(value)) return value; - return _.property(value); - }; - // Sort the object's values by a criterion produced by an iterator. _.sortBy = function(obj, iterator, context) { - iterator = lookupIterator(iterator); + iterator = lookupIterator(iterator, context); return _.pluck(_.map(obj, function(value, index, list) { return { value: value, index: index, - criteria: iterator.call(context, value, index, list) + criteria: iterator(value, index, list) }; }).sort(function(left, right) { var a = left.criteria; @@ -338,10 +368,10 @@ var group = function(behavior) { return function(obj, iterator, context) { var result = {}; - iterator = lookupIterator(iterator); - each(obj, function(value, index) { - var key = iterator.call(context, value, index, obj); - behavior(result, key, value); + iterator = lookupIterator(iterator, context); + _.each(obj, function(value, index) { + var key = iterator(value, index, obj); + behavior(result, value, key); }); return result; }; @@ -349,32 +379,32 @@ // Groups the object's values by a criterion. Pass either a string attribute // to group by, or a function that returns the criterion. - _.groupBy = group(function(result, key, value) { - _.has(result, key) ? result[key].push(value) : result[key] = [value]; + _.groupBy = group(function(result, value, key) { + if (_.has(result, key)) result[key].push(value); else result[key] = [value]; }); // Indexes the object's values by a criterion, similar to `groupBy`, but for // when you know that your index values will be unique. - _.indexBy = group(function(result, key, value) { + _.indexBy = group(function(result, value, key) { result[key] = value; }); // Counts instances of an object that group by a certain criterion. Pass // either a string attribute to count by, or a function that returns the // criterion. - _.countBy = group(function(result, key) { - _.has(result, key) ? result[key]++ : result[key] = 1; + _.countBy = group(function(result, value, key) { + if (_.has(result, key)) result[key]++; else result[key] = 1; }); // Use a comparator function to figure out the smallest index at which // an object should be inserted so as to maintain order. Uses binary search. _.sortedIndex = function(array, obj, iterator, context) { - iterator = lookupIterator(iterator); - var value = iterator.call(context, obj); + iterator = lookupIterator(iterator, context, 1); + var value = iterator(obj); var low = 0, high = array.length; while (low < high) { var mid = (low + high) >>> 1; - iterator.call(context, array[mid]) < value ? low = mid + 1 : high = mid; + if (iterator(array[mid]) < value) low = mid + 1; else high = mid; } return low; }; @@ -390,7 +420,18 @@ // Return the number of elements in an object. _.size = function(obj) { if (obj == null) return 0; - return (obj.length === +obj.length) ? obj.length : _.keys(obj).length; + return obj.length === +obj.length ? obj.length : _.keys(obj).length; + }; + + // Split a collection into two arrays: one whose elements all satisfy the given + // predicate, and one whose elements all do not satisfy the predicate. + _.partition = function(obj, predicate, context) { + predicate = lookupIterator(predicate, context); + var pass = [], fail = []; + _.each(obj, function(value, key, obj) { + (predicate(value, key, obj) ? pass : fail).push(value); + }); + return [pass, fail]; }; // Array Functions @@ -401,7 +442,7 @@ // allows it to work with `_.map`. _.first = _.head = _.take = function(array, n, guard) { if (array == null) return void 0; - if ((n == null) || guard) return array[0]; + if (n == null || guard) return array[0]; if (n < 0) return []; return slice.call(array, 0, n); }; @@ -411,14 +452,14 @@ // the array, excluding the last N. The **guard** check allows it to work with // `_.map`. _.initial = function(array, n, guard) { - return slice.call(array, 0, array.length - ((n == null) || guard ? 1 : n)); + return slice.call(array, 0, Math.max(0, array.length - (n == null || guard ? 1 : n))); }; // Get the last element of an array. Passing **n** will return the last N // values in the array. The **guard** check allows it to work with `_.map`. _.last = function(array, n, guard) { if (array == null) return void 0; - if ((n == null) || guard) return array[array.length - 1]; + if (n == null || guard) return array[array.length - 1]; return slice.call(array, Math.max(array.length - n, 0)); }; @@ -427,7 +468,7 @@ // the rest N values in the array. The **guard** // check allows it to work with `_.map`. _.rest = _.tail = _.drop = function(array, n, guard) { - return slice.call(array, (n == null) || guard ? 1 : n); + return slice.call(array, n == null || guard ? 1 : n); }; // Trim out all falsy values from an array. @@ -436,23 +477,26 @@ }; // Internal implementation of a recursive `flatten` function. - var flatten = function(input, shallow, output) { + var flatten = function(input, shallow, strict, output) { if (shallow && _.every(input, _.isArray)) { return concat.apply(output, input); } - each(input, function(value) { - if (_.isArray(value) || _.isArguments(value)) { - shallow ? push.apply(output, value) : flatten(value, shallow, output); + for (var i = 0, length = input.length; i < length; i++) { + var value = input[i]; + if (!_.isArray(value) && !_.isArguments(value)) { + if (!strict) output.push(value); + } else if (shallow) { + push.apply(output, value); } else { - output.push(value); + flatten(value, shallow, strict, output); } - }); + } return output; }; // Flatten out an array, either recursively (by default), or just one level. _.flatten = function(array, shallow) { - return flatten(array, shallow, []); + return flatten(array, shallow, false, []); }; // Return a version of the array that does not contain the specified value(s). @@ -460,68 +504,71 @@ return _.difference(array, slice.call(arguments, 1)); }; - // Split an array into two arrays: one whose elements all satisfy the given - // predicate, and one whose elements all do not satisfy the predicate. - _.partition = function(array, predicate) { - var pass = [], fail = []; - each(array, function(elem) { - (predicate(elem) ? pass : fail).push(elem); - }); - return [pass, fail]; - }; - // Produce a duplicate-free version of the array. If the array has already // been sorted, you have the option of using a faster algorithm. // Aliased as `unique`. _.uniq = _.unique = function(array, isSorted, iterator, context) { + if (array == null) return []; if (_.isFunction(isSorted)) { context = iterator; iterator = isSorted; isSorted = false; } - var initial = iterator ? _.map(array, iterator, context) : array; - var results = []; + if (iterator) iterator = lookupIterator(iterator, context); + var result = []; var seen = []; - each(initial, function(value, index) { - if (isSorted ? (!index || seen[seen.length - 1] !== value) : !_.contains(seen, value)) { - seen.push(value); - results.push(array[index]); + for (var i = 0, length = array.length; i < length; i++) { + var value = array[i]; + if (iterator) value = iterator(value, i, array); + if (isSorted ? !i || seen !== value : !_.contains(seen, value)) { + if (isSorted) seen = value; + else seen.push(value); + result.push(array[i]); } - }); - return results; + } + return result; }; // Produce an array that contains the union: each distinct element from all of // the passed-in arrays. _.union = function() { - return _.uniq(_.flatten(arguments, true)); + return _.uniq(flatten(arguments, true, true, [])); }; // Produce an array that contains every item shared between all the // passed-in arrays. _.intersection = function(array) { - var rest = slice.call(arguments, 1); - return _.filter(_.uniq(array), function(item) { - return _.every(rest, function(other) { - return _.contains(other, item); - }); - }); + if (array == null) return []; + var result = []; + var argsLength = arguments.length; + for (var i = 0, length = array.length; i < length; i++) { + var item = array[i]; + if (_.contains(result, item)) continue; + for (var j = 1; j < argsLength; j++) { + if (!_.contains(arguments[j], item)) break; + } + if (j === argsLength) result.push(item); + } + return result; }; // Take the difference between one array and a number of other arrays. // Only the elements present in just the first array will remain. _.difference = function(array) { - var rest = concat.apply(ArrayProto, slice.call(arguments, 1)); - return _.filter(array, function(value){ return !_.contains(rest, value); }); + var rest = flatten(slice.call(arguments, 1), true, true, []); + return _.filter(array, function(value){ + return !_.contains(rest, value); + }); }; // Zip together multiple lists into a single array -- elements that share // an index go together. - _.zip = function() { - var length = _.max(_.pluck(arguments, 'length').concat(0)); - var results = new Array(length); + _.zip = function(array) { + if (array == null) return []; + var length = _.max(arguments, 'length').length; + var results = Array(length); for (var i = 0; i < length; i++) { - results[i] = _.pluck(arguments, '' + i); + results[i] = _.pluck(arguments, i); } return results; }; @@ -542,10 +589,8 @@ return result; }; - // If the browser doesn't supply us with indexOf (I'm looking at you, **MSIE**), - // we need this function. Return the position of the first occurrence of an - // item in an array, or -1 if the item is not included in the array. - // Delegates to **ECMAScript 5**'s native `indexOf` if available. + // Return the position of the first occurrence of an item in an array, + // or -1 if the item is not included in the array. // If the array is large and already in sort order, pass `true` // for **isSorted** to use binary search. _.indexOf = function(array, item, isSorted) { @@ -553,26 +598,23 @@ var i = 0, length = array.length; if (isSorted) { if (typeof isSorted == 'number') { - i = (isSorted < 0 ? Math.max(0, length + isSorted) : isSorted); + i = isSorted < 0 ? Math.max(0, length + isSorted) : isSorted; } else { i = _.sortedIndex(array, item); return array[i] === item ? i : -1; } } - if (nativeIndexOf && array.indexOf === nativeIndexOf) return array.indexOf(item, isSorted); for (; i < length; i++) if (array[i] === item) return i; return -1; }; - // Delegates to **ECMAScript 5**'s native `lastIndexOf` if available. _.lastIndexOf = function(array, item, from) { if (array == null) return -1; - var hasIndex = from != null; - if (nativeLastIndexOf && array.lastIndexOf === nativeLastIndexOf) { - return hasIndex ? array.lastIndexOf(item, from) : array.lastIndexOf(item); + var idx = array.length; + if (typeof from == 'number') { + idx = from < 0 ? idx + from + 1 : Math.min(idx, from + 1); } - var i = (hasIndex ? from : array.length); - while (i--) if (array[i] === item) return i; + while (--idx >= 0) if (array[idx] === item) return idx; return -1; }; @@ -588,9 +630,9 @@ var length = Math.max(Math.ceil((stop - start) / step), 0); var idx = 0; - var range = new Array(length); + var range = Array(length); - while(idx < length) { + while (idx < length) { range[idx++] = start; start += step; } @@ -602,7 +644,7 @@ // ------------------ // Reusable constructor function for prototype setting. - var ctor = function(){}; + var Ctor = function(){}; // Create a function bound to a given object (assigning `this`, and arguments, // optionally). Delegates to **ECMAScript 5**'s native `Function.bind` if @@ -610,17 +652,18 @@ _.bind = function(func, context) { var args, bound; if (nativeBind && func.bind === nativeBind) return nativeBind.apply(func, slice.call(arguments, 1)); - if (!_.isFunction(func)) throw new TypeError; + if (!_.isFunction(func)) throw TypeError('Bind must be called on a function'); args = slice.call(arguments, 2); - return bound = function() { + bound = function() { if (!(this instanceof bound)) return func.apply(context, args.concat(slice.call(arguments))); - ctor.prototype = func.prototype; - var self = new ctor; - ctor.prototype = null; + Ctor.prototype = func.prototype; + var self = new Ctor; + Ctor.prototype = null; var result = func.apply(self, args.concat(slice.call(arguments))); if (Object(result) === result) return result; return self; }; + return bound; }; // Partially apply a function by creating a version that has had some of its @@ -643,27 +686,34 @@ // are the method names to be bound. Useful for ensuring that all callbacks // defined on an object belong to it. _.bindAll = function(obj) { - var funcs = slice.call(arguments, 1); - if (funcs.length === 0) throw new Error('bindAll must be passed function names'); - each(funcs, function(f) { obj[f] = _.bind(obj[f], obj); }); + var i, length = arguments.length, key; + if (length <= 1) throw Error('bindAll must be passed function names'); + for (i = 1; i < length; i++) { + key = arguments[i]; + obj[key] = _.bind(obj[key], obj); + } return obj; }; // Memoize an expensive function by storing its results. _.memoize = function(func, hasher) { - var memo = {}; - hasher || (hasher = _.identity); - return function() { - var key = hasher.apply(this, arguments); - return _.has(memo, key) ? memo[key] : (memo[key] = func.apply(this, arguments)); + var memoize = function(key) { + var cache = memoize.cache; + var address = hasher ? hasher.apply(this, arguments) : key; + if (!_.has(cache, address)) cache[address] = func.apply(this, arguments); + return cache[key]; }; + memoize.cache = {}; + return memoize; }; // Delays a function for the given number of milliseconds, and then calls // it with the arguments supplied. _.delay = function(func, wait) { var args = slice.call(arguments, 2); - return setTimeout(function(){ return func.apply(null, args); }, wait); + return setTimeout(function(){ + return func.apply(null, args); + }, wait); }; // Defers a function, scheduling it to run after the current call stack has @@ -681,12 +731,12 @@ var context, args, result; var timeout = null; var previous = 0; - options || (options = {}); + if (!options) options = {}; var later = function() { previous = options.leading === false ? 0 : _.now(); timeout = null; result = func.apply(context, args); - context = args = null; + if (!timeout) context = args = null; }; return function() { var now = _.now(); @@ -694,12 +744,12 @@ var remaining = wait - (now - previous); context = this; args = arguments; - if (remaining <= 0) { + if (remaining <= 0 || remaining > wait) { clearTimeout(timeout); timeout = null; previous = now; result = func.apply(context, args); - context = args = null; + if (!timeout) context = args = null; } else if (!timeout && options.trailing !== false) { timeout = setTimeout(later, remaining); } @@ -716,13 +766,14 @@ var later = function() { var last = _.now() - timestamp; - if (last < wait) { + + if (last < wait && last > 0) { timeout = setTimeout(later, wait - last); } else { timeout = null; if (!immediate) { result = func.apply(context, args); - context = args = null; + if (!timeout) context = args = null; } } }; @@ -732,9 +783,7 @@ args = arguments; timestamp = _.now(); var callNow = immediate && !timeout; - if (!timeout) { - timeout = setTimeout(later, wait); - } + if (!timeout) timeout = setTimeout(later, wait); if (callNow) { result = func.apply(context, args); context = args = null; @@ -744,19 +793,6 @@ }; }; - // Returns a function that will be executed at most one time, no matter how - // often you call it. Useful for lazy initialization. - _.once = function(func) { - var ran = false, memo; - return function() { - if (ran) return memo; - ran = true; - memo = func.apply(this, arguments); - func = null; - return memo; - }; - }; - // Returns the first function passed as an argument to the second, // allowing you to adjust arguments, run code before and after, and // conditionally execute the original function. @@ -764,16 +800,23 @@ return _.partial(wrapper, func); }; + // Returns a negated version of the passed-in predicate. + _.negate = function(predicate) { + return function() { + return !predicate.apply(this, arguments); + }; + }; + // Returns a function that is the composition of a list of functions, each // consuming the return value of the function that follows. _.compose = function() { - var funcs = arguments; + var args = arguments; + var start = args.length - 1; return function() { - var args = arguments; - for (var i = funcs.length - 1; i >= 0; i--) { - args = [funcs[i].apply(this, args)]; - } - return args[0]; + var i = start; + var result = args[start].apply(this, arguments); + while (i--) result = args[i].call(this, result); + return result; }; }; @@ -786,6 +829,22 @@ }; }; + // Returns a function that will only be executed before being called N times. + _.before = function(times, func) { + var memo; + return function() { + if (--times > 0) { + memo = func.apply(this, arguments); + } + else func = null; + return memo; + }; + }; + + // Returns a function that will be executed at most one time, no matter how + // often you call it. Useful for lazy initialization. + _.once = _.partial(_.before, 2); + // Object Functions // ---------------- @@ -803,7 +862,7 @@ _.values = function(obj) { var keys = _.keys(obj); var length = keys.length; - var values = new Array(length); + var values = Array(length); for (var i = 0; i < length; i++) { values[i] = obj[keys[i]]; } @@ -814,7 +873,7 @@ _.pairs = function(obj) { var keys = _.keys(obj); var length = keys.length; - var pairs = new Array(length); + var pairs = Array(length); for (var i = 0; i < length; i++) { pairs[i] = [keys[i], obj[keys[i]]]; } @@ -843,45 +902,60 @@ // Extend a given object with all the properties in passed-in object(s). _.extend = function(obj) { - each(slice.call(arguments, 1), function(source) { - if (source) { - for (var prop in source) { - obj[prop] = source[prop]; - } + if (!_.isObject(obj)) return obj; + var source, prop; + for (var i = 1, length = arguments.length; i < length; i++) { + source = arguments[i]; + for (prop in source) { + obj[prop] = source[prop]; } - }); + } return obj; }; // Return a copy of the object only containing the whitelisted properties. - _.pick = function(obj) { - var copy = {}; - var keys = concat.apply(ArrayProto, slice.call(arguments, 1)); - each(keys, function(key) { - if (key in obj) copy[key] = obj[key]; - }); - return copy; + _.pick = function(obj, iterator, context) { + var result = {}, key; + if (obj == null) return result; + if (_.isFunction(iterator)) { + iterator = createCallback(iterator, context); + for (key in obj) { + var value = obj[key]; + if (iterator(value, key, obj)) result[key] = value; + } + } else { + var keys = concat.apply([], slice.call(arguments, 1)); + obj = Object(obj); + for (var i = 0, length = keys.length; i < length; i++) { + key = keys[i]; + if (key in obj) result[key] = obj[key]; + } + } + return result; }; // Return a copy of the object without the blacklisted properties. - _.omit = function(obj) { - var copy = {}; - var keys = concat.apply(ArrayProto, slice.call(arguments, 1)); - for (var key in obj) { - if (!_.contains(keys, key)) copy[key] = obj[key]; + _.omit = function(obj, iterator, context) { + if (_.isFunction(iterator)) { + iterator = _.negate(iterator); + } else { + var keys = _.map(concat.apply([], slice.call(arguments, 1)), String); + iterator = function(value, key) { + return !_.contains(keys, key); + }; } - return copy; + return _.pick(obj, iterator, context); }; // Fill in a given object with default properties. _.defaults = function(obj) { - each(slice.call(arguments, 1), function(source) { - if (source) { - for (var prop in source) { - if (obj[prop] === void 0) obj[prop] = source[prop]; - } + if (!_.isObject(obj)) return obj; + for (var i = 1, length = arguments.length; i < length; i++) { + var source = arguments[i]; + for (var prop in source) { + if (obj[prop] === void 0) obj[prop] = source[prop]; } - }); + } return obj; }; @@ -903,7 +977,7 @@ var eq = function(a, b, aStack, bStack) { // Identical objects are equal. `0 === -0`, but they aren't identical. // See the [Harmony `egal` proposal](http://wiki.ecmascript.org/doku.php?id=harmony:egal). - if (a === b) return a !== 0 || 1 / a == 1 / b; + if (a === b) return a !== 0 || 1 / a === 1 / b; // A strict comparison is necessary because `null == undefined`. if (a == null || b == null) return a === b; // Unwrap any wrapped objects. @@ -911,29 +985,27 @@ if (b instanceof _) b = b._wrapped; // Compare `[[Class]]` names. var className = toString.call(a); - if (className != toString.call(b)) return false; + if (className !== toString.call(b)) return false; switch (className) { - // Strings, numbers, dates, and booleans are compared by value. + // Strings, numbers, regular expressions, dates, and booleans are compared by value. + case '[object RegExp]': + // RegExps are coerced to strings for comparison (Note: '' + /a/i === '/a/i') case '[object String]': // Primitives and their corresponding object wrappers are equivalent; thus, `"5"` is // equivalent to `new String("5")`. - return a == String(b); + return '' + a === '' + b; case '[object Number]': - // `NaN`s are equivalent, but non-reflexive. An `egal` comparison is performed for - // other numeric values. - return a != +a ? b != +b : (a == 0 ? 1 / a == 1 / b : a == +b); + // `NaN`s are equivalent, but non-reflexive. + // Object(NaN) is equivalent to NaN + if (a != +a) return b != +b; + // An `egal` comparison is performed for other numeric values. + return a == 0 ? 1 / a == 1 / b : a == +b; case '[object Date]': case '[object Boolean]': // Coerce dates and booleans to numeric primitive values. Dates are compared by their // millisecond representations. Note that invalid dates with millisecond representations // of `NaN` are not equivalent. - return +a == +b; - // RegExps are compared by their source patterns and flags. - case '[object RegExp]': - return a.source == b.source && - a.global == b.global && - a.multiline == b.multiline && - a.ignoreCase == b.ignoreCase; + return +a === +b; } if (typeof a != 'object' || typeof b != 'object') return false; // Assume equality for cyclic structures. The algorithm for detecting cyclic @@ -942,25 +1014,29 @@ while (length--) { // Linear search. Performance is inversely proportional to the number of // unique nested structures. - if (aStack[length] == a) return bStack[length] == b; + if (aStack[length] === a) return bStack[length] === b; } // Objects with different constructors are not equivalent, but `Object`s // from different frames are. var aCtor = a.constructor, bCtor = b.constructor; - if (aCtor !== bCtor && !(_.isFunction(aCtor) && (aCtor instanceof aCtor) && - _.isFunction(bCtor) && (bCtor instanceof bCtor)) - && ('constructor' in a && 'constructor' in b)) { + if ( + aCtor !== bCtor && + // Handle Object.create(x) cases + 'constructor' in a && 'constructor' in b && + !(_.isFunction(aCtor) && aCtor instanceof aCtor && + _.isFunction(bCtor) && bCtor instanceof bCtor) + ) { return false; } // Add the first object to the stack of traversed objects. aStack.push(a); bStack.push(b); - var size = 0, result = true; + var size, result; // Recursively compare objects and arrays. - if (className == '[object Array]') { + if (className === '[object Array]') { // Compare array lengths to determine if a deep comparison is necessary. size = a.length; - result = size == b.length; + result = size === b.length; if (result) { // Deep compare the contents, ignoring non-numeric properties. while (size--) { @@ -969,20 +1045,16 @@ } } else { // Deep compare objects. - for (var key in a) { - if (_.has(a, key)) { - // Count the expected number of properties. - size++; - // Deep compare each member. - if (!(result = _.has(b, key) && eq(a[key], b[key], aStack, bStack))) break; - } - } - // Ensure that both objects contain the same number of properties. + var keys = _.keys(a), key; + size = keys.length; + // Ensure that both objects contain the same number of properties before comparing deep equality. + result = _.keys(b).length == size; if (result) { - for (key in b) { - if (_.has(b, key) && !(size--)) break; + while (size--) { + // Deep compare each member + key = keys[size]; + if (!(result = _.has(b, key) && eq(a[key], b[key], aStack, bStack))) break; } - result = !size; } } // Remove the first object from the stack of traversed objects. @@ -1000,7 +1072,7 @@ // An "empty" object has no enumerable own-properties. _.isEmpty = function(obj) { if (obj == null) return true; - if (_.isArray(obj) || _.isString(obj)) return obj.length === 0; + if (_.isArray(obj) || _.isString(obj) || _.isArguments(obj)) return obj.length === 0; for (var key in obj) if (_.has(obj, key)) return false; return true; }; @@ -1013,7 +1085,7 @@ // Is a given value an array? // Delegates to ECMA5's native Array.isArray _.isArray = nativeIsArray || function(obj) { - return toString.call(obj) == '[object Array]'; + return toString.call(obj) === '[object Array]'; }; // Is a given variable an object? @@ -1022,9 +1094,9 @@ }; // Add some isType methods: isArguments, isFunction, isString, isNumber, isDate, isRegExp. - each(['Arguments', 'Function', 'String', 'Number', 'Date', 'RegExp'], function(name) { + _.each(['Arguments', 'Function', 'String', 'Number', 'Date', 'RegExp'], function(name) { _['is' + name] = function(obj) { - return toString.call(obj) == '[object ' + name + ']'; + return toString.call(obj) === '[object ' + name + ']'; }; }); @@ -1032,12 +1104,12 @@ // there isn't any inspectable "Arguments" type. if (!_.isArguments(arguments)) { _.isArguments = function(obj) { - return !!(obj && _.has(obj, 'callee')); + return _.has(obj, 'callee'); }; } // Optimize `isFunction` if appropriate. - if (typeof (/./) !== 'function') { + if (typeof /./ !== 'function') { _.isFunction = function(obj) { return typeof obj === 'function'; }; @@ -1050,12 +1122,12 @@ // Is the given value `NaN`? (NaN is the only number which does not equal itself). _.isNaN = function(obj) { - return _.isNumber(obj) && obj != +obj; + return _.isNumber(obj) && obj !== +obj; }; // Is a given value a boolean? _.isBoolean = function(obj) { - return obj === true || obj === false || toString.call(obj) == '[object Boolean]'; + return obj === true || obj === false || toString.call(obj) === '[object Boolean]'; }; // Is a given value equal to null? @@ -1071,7 +1143,7 @@ // Shortcut function for checking if an object has a given property directly // on itself (in other words, not on a prototype). _.has = function(obj, key) { - return hasOwnProperty.call(obj, key); + return obj != null && hasOwnProperty.call(obj, key); }; // Utility Functions @@ -1090,11 +1162,13 @@ }; _.constant = function(value) { - return function () { + return function() { return value; }; }; + _.noop = function(){}; + _.property = function(key) { return function(obj) { return obj[key]; @@ -1104,19 +1178,18 @@ // Returns a predicate for checking whether an object has a given set of `key:value` pairs. _.matches = function(attrs) { return function(obj) { - if (obj === attrs) return true; //avoid comparing an object to itself. - for (var key in attrs) { - if (attrs[key] !== obj[key]) - return false; - } + if (obj == null) return _.isEmpty(attrs); + if (obj === attrs) return true; + for (var key in attrs) if (attrs[key] !== obj[key]) return false; return true; - } + }; }; // Run a function **n** times. _.times = function(n, iterator, context) { var accum = Array(Math.max(0, n)); - for (var i = 0; i < n; i++) accum[i] = iterator.call(context, i); + iterator = createCallback(iterator, context, 1); + for (var i = 0; i < n; i++) accum[i] = iterator(i); return accum; }; @@ -1130,7 +1203,9 @@ }; // A (possibly faster) way to get the current timestamp as an integer. - _.now = Date.now || function() { return new Date().getTime(); }; + _.now = Date.now || function() { + return new Date().getTime(); + }; // List of HTML entities for escaping. var entityMap = { @@ -1146,8 +1221,8 @@ // Regexes containing the keys and values listed immediately above. var entityRegexes = { - escape: new RegExp('[' + _.keys(entityMap.escape).join('') + ']', 'g'), - unescape: new RegExp('(' + _.keys(entityMap.unescape).join('|') + ')', 'g') + escape: RegExp('[' + _.keys(entityMap.escape).join('') + ']', 'g'), + unescape: RegExp('(' + _.keys(entityMap.unescape).join('|') + ')', 'g') }; // Functions for escaping and unescaping strings to/from HTML interpolation. @@ -1165,19 +1240,7 @@ _.result = function(object, property) { if (object == null) return void 0; var value = object[property]; - return _.isFunction(value) ? value.call(object) : value; - }; - - // Add your own custom functions to the Underscore object. - _.mixin = function(obj) { - each(_.functions(obj), function(name) { - var func = _[name] = obj[name]; - _.prototype[name] = function() { - var args = [this._wrapped]; - push.apply(args, arguments); - return result.call(this, func.apply(_, args)); - }; - }); + return _.isFunction(value) ? object[property]() : value; }; // Generate a unique integer id (unique within the entire client session). @@ -1208,22 +1271,24 @@ '\\': '\\', '\r': 'r', '\n': 'n', - '\t': 't', '\u2028': 'u2028', '\u2029': 'u2029' }; - var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + var escaper = /\\|'|\r|\n|\u2028|\u2029/g; + + var escapeChar = function(match) { + return '\\' + escapes[match]; + }; // JavaScript micro-templating, similar to John Resig's implementation. // Underscore templating handles arbitrary delimiters, preserves whitespace, // and correctly escapes quotes within interpolated code. _.template = function(text, data, settings) { - var render; settings = _.defaults({}, settings, _.templateSettings); // Combine delimiters into one regular expression via alternation. - var matcher = new RegExp([ + var matcher = RegExp([ (settings.escape || noMatch).source, (settings.interpolate || noMatch).source, (settings.evaluate || noMatch).source @@ -1233,19 +1298,18 @@ var index = 0; var source = "__p+='"; text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { - source += text.slice(index, offset) - .replace(escaper, function(match) { return '\\' + escapes[match]; }); + source += text.slice(index, offset).replace(escaper, escapeChar); + index = offset + match.length; if (escape) { source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; - } - if (interpolate) { + } else if (interpolate) { source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; - } - if (evaluate) { + } else if (evaluate) { source += "';\n" + evaluate + "\n__p+='"; } - index = offset + match.length; + + // Adobe VMs need the match returned to produce the correct offest. return match; }); source += "';\n"; @@ -1255,10 +1319,10 @@ source = "var __t,__p='',__j=Array.prototype.join," + "print=function(){__p+=__j.call(arguments,'');};\n" + - source + "return __p;\n"; + source + 'return __p;\n'; try { - render = new Function(settings.variable || 'obj', '_', source); + var render = Function(settings.variable || 'obj', '_', source); } catch (e) { e.source = source; throw e; @@ -1269,15 +1333,18 @@ return render.call(this, data, _); }; - // Provide the compiled function source as a convenience for precompilation. - template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + // Provide the compiled source as a convenience for precompilation. + var argument = settings.variable || 'obj'; + template.source = 'function(' + argument + '){\n' + source + '}'; return template; }; - // Add a "chain" function, which will delegate to the wrapper. + // Add a "chain" function. Start chaining a wrapped Underscore object. _.chain = function(obj) { - return _(obj).chain(); + var instance = _(obj); + instance._chain = true; + return instance; }; // OOP @@ -1291,42 +1358,44 @@ return this._chain ? _(obj).chain() : obj; }; + // Add your own custom functions to the Underscore object. + _.mixin = function(obj) { + _.each(_.functions(obj), function(name) { + var func = _[name] = obj[name]; + _.prototype[name] = function() { + var args = [this._wrapped]; + push.apply(args, arguments); + return result.call(this, func.apply(_, args)); + }; + }); + }; + // Add all of the Underscore functions to the wrapper object. _.mixin(_); // Add all mutator Array functions to the wrapper. - each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(name) { + _.each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(name) { var method = ArrayProto[name]; _.prototype[name] = function() { var obj = this._wrapped; method.apply(obj, arguments); - if ((name == 'shift' || name == 'splice') && obj.length === 0) delete obj[0]; + if ((name === 'shift' || name === 'splice') && obj.length === 0) delete obj[0]; return result.call(this, obj); }; }); // Add all accessor Array functions to the wrapper. - each(['concat', 'join', 'slice'], function(name) { + _.each(['concat', 'join', 'slice'], function(name) { var method = ArrayProto[name]; _.prototype[name] = function() { return result.call(this, method.apply(this._wrapped, arguments)); }; }); - _.extend(_.prototype, { - - // Start chaining a wrapped Underscore object. - chain: function() { - this._chain = true; - return this; - }, - - // Extracts the result from a wrapped and chained object. - value: function() { - return this._wrapped; - } - - }); + // Extracts the result from a wrapped and chained object. + _.prototype.value = function() { + return this._wrapped; + }; // AMD registration happens at the end for compatibility with AMD loaders // that may not enforce next-turn semantics on modules. Even though general @@ -1340,4 +1409,4 @@ return _; }); } -}).call(this); +}.call(this)); diff --git a/node_modules/columnify/node_modules/wcwidth.js/package.json b/node_modules/columnify/node_modules/wcwidth.js/package.json index 104b70763..9542cc97d 100644 --- a/node_modules/columnify/node_modules/wcwidth.js/package.json +++ b/node_modules/columnify/node_modules/wcwidth.js/package.json @@ -41,7 +41,7 @@ "shasum": "44298a7c899c17501990fdaddd76ef6bd081be75", "tarball": "http://registry.npmjs.org/wcwidth.js/-/wcwidth.js-0.0.4.tgz" }, - "_from": "wcwidth.js@~0.0.4", + "_from": "wcwidth.js@>=0.0.4-0 <0.1.0-0", "_npmVersion": "1.3.11", "_npmUser": { "name": "mycoboco", |