Former-commit-id: aff34ccd5d3c6e3e78aeb5832e694171fca35412
Lo-Dash v1.0.0-rc.3
An alternative to Underscore.js, delivering consistency, customization, performance, and extra features.
Download
-
Lo-Dash builds:
Development and Production -
Underscore compatibility builds:
Development and Production -
CDN copies of ≤ v1.0.0-rc.3’s builds are available on cdnjs thanks to CloudFlare:
Lo-Dash dev, Lo-Dash prod, Underscore compat-dev, and Underscore compat-prod -
For optimal file size, create a custom build with only the features you need
Dive in
We’ve got API docs, benchmarks, and unit tests.
For a list of upcoming features, check out our roadmap.
Screencasts
For more information check out these screencasts over Lo-Dash:
- Introducing Lo-Dash
- Lo-Dash optimizations and custom builds
- Lo-Dash’s origin and why it’s a better utility belt
- Unit testing in Lo-Dash
- Lo-Dash’s approach to native method use
- CascadiaJS: Lo-Dash for a better utility belt
Features
- AMD loader support (RequireJS, curl.js, etc.)
- _(…) supports intuitive chaining
- _.bindKey for binding “lazy” defined methods
- _.cloneDeep for “deep” cloning arrays and objects
- _.contains accepts a
fromIndexargument - _.forEach is chainable and supports exiting iteration early
- _.forIn for iterating over an object’s own and inherited properties
- _.forOwn for iterating over an object’s own properties
- _.isPlainObject checks if values are created by the
Objectconstructor - _.merge for a “deep” _.extend
- _.partial for partial application without
thisbinding - _.pick and _.omit accepts
callbackandthisArgarguments - _.template supports ES6 template delimiters and utilizes sourceURLs for easier debugging
- _.contains, _.size, _.toArray, and more… accept strings
Support
Lo-Dash has been tested in at least Chrome 524, Firefox 118, IE 6-10, Opera 9.25-12, Safari 3-6, Node.js 0.4.8-0.8.18, Narwhal 0.3.2, RingoJS 0.8, and Rhino 1.7RC5.
Custom builds
Custom builds make it easy to create lightweight versions of Lo-Dash containing only the methods you need. To top it off, we handle all method dependency and alias mapping for you.
- Backbone builds, with only methods required by Backbone, may be created using the
backbonemodifier argument.
lodash backbone
- CSP builds, supporting default Content Security Policy restrictions, may be created using the
cspmodifier argument. Thecspmodifier is an alais of themodernmodifier. Chrome extensions will require sandboxing or the use of either themobile,modern, orunderscorebuild.
lodash csp
- Legacy builds, tailored for older environments without ES5 support, may be created using the
legacymodifier argument.
lodash legacy
- Modern builds, tailored for newer environments with ES5 support, may be created using the
modernmodifier argument.
lodash modern
- Mobile builds, without method compilation and most bug fixes for old browsers, may be created using the
mobilemodifier argument.
lodash mobile
- Strict builds, with
_.bindAll,_.defaults, and_.extendin strict mode, may be created using thestrictmodifier argument.
lodash strict
- Underscore builds, tailored for projects already using Underscore, may be created using the
underscoremodifier argument.
lodash underscore
Custom builds may be created using the following commands:
- Use the
categoryargument to pass comma separated categories of methods to include in the build.
Valid categories (case-insensitive) are “arrays”, “chaining”, “collections”, “functions”, “objects”, and “utilities”.
lodash category=collections,functions
lodash category="collections, functions"
- Use the
exportsargument to pass comma separated names of ways to export theLoDashfunction.
Valid exports are “amd”, “commonjs”, “global”, “node”, and “none”.
lodash exports=amd,commonjs,node
lodash exports="amd, commonjs, node"
- Use the
iifeargument to specify code to replace the immediately-invoked function expression that wraps Lo-Dash.
lodash iife="!function(window,undefined){%output%}(this)"
- Use the
includeargument to pass comma separated method/category names to include in the build.
lodash include=each,filter,map
lodash include="each, filter, map"
- Use the
minusargument to pass comma separated method/category names to remove from those included in the build.
lodash underscore minus=result,shuffle
lodash underscore minus="result, shuffle"
- Use the
plusargument to pass comma separated method/category names to add to those included in the build.
lodash backbone plus=random,template
lodash backbone plus="random, template"
- Use the
templateargument to pass the file path pattern used to match template files to precompile.
lodash template="./*.jst"
- Use the
settingsargument to pass the template settings used when precompiling templates.
lodash settings="{interpolate:/\{\{([\s\S]+?)\}\}/g}"
- Use the
moduleIdargument to specify the AMD module ID of Lo-Dash, which defaults to “lodash”, used by precompiled templates.
lodash moduleId="underscore"
All arguments, except legacy with csp, mobile, modern, or underscore, may be combined.
Unless specified by -o or --output, all files created are saved to the current working directory.
The following options are also supported:
-c,--stdout......... Write output to standard output-d,--debug........... Write only the non-minified development output-h,--help............. Display help information-m,--minify......... Write only the minified production output-o,--output......... Write output to a given path/filename-p,--source-map.. Generate a source map for the minified output-s,--silent......... Skip status updates normally logged to the console-V,--version....... Output current version of Lo-Dash
The lodash command-line utility is available when Lo-Dash is installed as a global package (i.e. npm install -g lodash).
Installation and usage
In browsers:
<script src="lodash.js"></script>
Using npm:
npm install lodash
npm install -g lodash
npm link lodash
To avoid potential issues, update npm before installing Lo-Dash:
npm install npm -g
In Node.js and RingoJS v0.8.0+:
var _ = require('lodash');
// or as a drop-in replacement for Underscore
var _ = require('lodash/lodash.underscore');
Note: If Lo-Dash is installed globally, run npm link lodash in your project’s root directory before requiring it.
In RingoJS v0.7.0-:
var _ = require('lodash')._;
In Rhino:
load('lodash.js');
In an AMD loader like RequireJS:
require({
'paths': {
'underscore': 'path/to/lodash'
}
},
['underscore'], function(_) {
console.log(_.VERSION);
});
Release Notes
v1.0.0-rc.3
Compatibility Warnings
- Made
_#join,_#pop, and_#shiftwrapper methods return unwrapped values - Made “Functions” methods wrapper counterparts return wrapped values
- Removed
_.chainand_#chainmethods
Changes
- Added _.cloneDeep alias of
_.clone(…, true) - Added
_.onceto thebackbonebuild method dependencies - Ensured
backbonebuilds implement Underscore’s chaining behavior - Ensured the
settings=…build option doesn’t clobber the defaultmoduleId - Ensured Lo-Dash’s
npmpackage installation avoids erroring when no other modules have been globally installed - Made compiled templates loaded via AMD use the Lo-Dash module for their
_references - Removed the “Collections” method
_.forEachdependency from “Arrays” method_.intersection - Optimized
_.isArrayand_.isFunctionfallbacks as well as
_.intersection,_.isDate,_.isRegExp,_.reduce,_.reduceRight,_.union, and_.uniq
v1.0.0-rc.2
- Specified more method chaining behaviors
- Updated
underscorebuild compatibility to v1.4.3
v1.0.0-rc.1
Compatibility Warnings
- Made
_(…)intuitively chain without needing to call_#chain - Made
_.isEqualequateargumentsobjects to similarObjectobjects - Made
_.clonecopy the enumerable properties ofargumentsobjects and objects
created by constructors other thanObjectare cloned to plainObjectobjects
Changes
- Ensure Lo-Dash runs in the JS engine embedded in Adobe products
- Ensured
_.reduceand_.reduceRightpass the correct number ofcallbackarguments - Ensured
_.throttlenulls thetimeoutId - Made deep
_.clonemore closely follow the structured clone algorithm and copy array properties assigned byRegExp#exec - Optimized compiled templates in Firefox
- Optimized
_.forEach,_.forOwn,_.isNumber, and_.isString - Simplified
iteratorTemplate
The full changelog is available here.
BestieJS
Lo-Dash is part of the BestieJS “Best in Class” module collection. This means we promote solid browser/environment support, ES5 precedents, unit testing, and plenty of documentation.
