lodash.memoize
Advanced tools
Comparing version 2.4.1 to 3.0.0
178
index.js
/** | ||
* Lo-Dash 2.4.1 (Custom Build) <http://lodash.com/> | ||
* Build: `lodash modularize modern exports="npm" -o ./npm/` | ||
* Copyright 2012-2013 The Dojo Foundation <http://dojofoundation.org/> | ||
* Based on Underscore.js 1.5.2 <http://underscorejs.org/LICENSE> | ||
* Copyright 2009-2013 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors | ||
* Available under MIT license <http://lodash.com/license> | ||
* lodash 3.0.0 (Custom Build) <https://lodash.com/> | ||
* Build: `lodash modern modularize exports="npm" -o ./` | ||
* Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/> | ||
* Based on Underscore.js 1.7.0 <http://underscorejs.org/LICENSE> | ||
* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors | ||
* Available under MIT license <https://lodash.com/license> | ||
*/ | ||
var isFunction = require('lodash.isfunction'), | ||
keyPrefix = require('lodash._keyprefix'); | ||
var isFunction = require('lodash.isfunction'); | ||
/** Used for native method references */ | ||
/** Used as the `TypeError` message for "Functions" methods. */ | ||
var FUNC_ERROR_TEXT = 'Expected a function'; | ||
/** Used for native method references. */ | ||
var objectProto = Object.prototype; | ||
/** Native method shortcuts */ | ||
/** Used to check objects for own properties. */ | ||
var hasOwnProperty = objectProto.hasOwnProperty; | ||
/** | ||
* Creates a cache object to store key/value pairs. | ||
* | ||
* @private | ||
* @static | ||
* @name Cache | ||
* @memberOf _.memoize | ||
*/ | ||
function MapCache() { | ||
this.__data__ = {}; | ||
} | ||
/** | ||
* Removes `key` and its value from the cache. | ||
* | ||
* @private | ||
* @name delete | ||
* @memberOf _.memoize.Cache | ||
* @param {string} key The key of the value to remove. | ||
* @returns {boolean} Returns `true` if the entry was removed successfully, else `false`. | ||
*/ | ||
function mapDelete(key) { | ||
return this.has(key) && delete this.__data__[key]; | ||
} | ||
/** | ||
* Gets the cached value for `key`. | ||
* | ||
* @private | ||
* @name get | ||
* @memberOf _.memoize.Cache | ||
* @param {string} key The key of the value to get. | ||
* @returns {*} Returns the cached value. | ||
*/ | ||
function mapGet(key) { | ||
return key == '__proto__' ? undefined : this.__data__[key]; | ||
} | ||
/** | ||
* Checks if a cached value for `key` exists. | ||
* | ||
* @private | ||
* @name has | ||
* @memberOf _.memoize.Cache | ||
* @param {string} key The key of the entry to check. | ||
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. | ||
*/ | ||
function mapHas(key) { | ||
return key != '__proto__' && hasOwnProperty.call(this.__data__, key); | ||
} | ||
/** | ||
* Adds `value` to `key` of the cache. | ||
* | ||
* @private | ||
* @name set | ||
* @memberOf _.memoize.Cache | ||
* @param {string} key The key of the value to cache. | ||
* @param {*} value The value to cache. | ||
* @returns {Object} Returns the cache object. | ||
*/ | ||
function mapSet(key, value) { | ||
if (key != '__proto__') { | ||
this.__data__[key] = value; | ||
} | ||
return this; | ||
} | ||
/** | ||
* Creates a function that memoizes the result of `func`. If `resolver` is | ||
* provided it will be used to determine the cache key for storing the result | ||
* based on the arguments provided to the memoized function. By default, the | ||
* first argument provided to the memoized function is used as the cache key. | ||
* The `func` is executed with the `this` binding of the memoized function. | ||
* The result cache is exposed as the `cache` property on the memoized function. | ||
* provided it determines the cache key for storing the result based on the | ||
* arguments provided to the memoized function. By default, the first argument | ||
* provided to the memoized function is coerced to a string and used as the | ||
* cache key. The `func` is invoked with the `this` binding of the memoized | ||
* function. | ||
* | ||
* **Note:** The cache is exposed as the `cache` property on the memoized | ||
* function. Its creation may be customized by replacing the `_.memoize.Cache` | ||
* constructor with one whose instances implement the ES `Map` method interface | ||
* of `get`, `has`, and `set`. See the | ||
* [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-properties-of-the-map-prototype-object) | ||
* for more details. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @category Functions | ||
* @category Function | ||
* @param {Function} func The function to have its output memoized. | ||
* @param {Function} [resolver] A function used to resolve the cache key. | ||
* @param {Function} [resolver] The function to resolve the cache key. | ||
* @returns {Function} Returns the new memoizing function. | ||
* @example | ||
* | ||
* var fibonacci = _.memoize(function(n) { | ||
* return n < 2 ? n : fibonacci(n - 1) + fibonacci(n - 2); | ||
* var upperCase = _.memoize(function(string) { | ||
* return string.toUpperCase(); | ||
* }); | ||
* | ||
* fibonacci(9) | ||
* // => 34 | ||
* upperCase('fred'); | ||
* // => 'FRED' | ||
* | ||
* var data = { | ||
* 'fred': { 'name': 'fred', 'age': 40 }, | ||
* 'pebbles': { 'name': 'pebbles', 'age': 1 } | ||
* }; | ||
* | ||
* // modifying the result cache | ||
* var get = _.memoize(function(name) { return data[name]; }, _.identity); | ||
* get('pebbles'); | ||
* // => { 'name': 'pebbles', 'age': 1 } | ||
* upperCase.cache.set('fred, 'BARNEY'); | ||
* upperCase('fred'); | ||
* // => 'BARNEY' | ||
* | ||
* get.cache.pebbles.name = 'penelope'; | ||
* get('pebbles'); | ||
* // => { 'name': 'penelope', 'age': 1 } | ||
* // replacing `_.memoize.Cache` | ||
* var object = { 'user': 'fred' }; | ||
* var other = { 'user': 'barney' }; | ||
* var identity = _.memoize(_.identity); | ||
* | ||
* identity(object); | ||
* // => { 'user': 'fred' } | ||
* identity(other); | ||
* // => { 'user': 'fred' } | ||
* | ||
* _.memoize.Cache = WeakMap; | ||
* var identity = _.memoize(_.identity); | ||
* | ||
* identity(object); | ||
* // => { 'user': 'fred' } | ||
* identity(other); | ||
* // => { 'user': 'barney' } | ||
*/ | ||
function memoize(func, resolver) { | ||
if (!isFunction(func)) { | ||
throw new TypeError; | ||
if (!isFunction(func) || (resolver && !isFunction(resolver))) { | ||
throw new TypeError(FUNC_ERROR_TEXT); | ||
} | ||
var memoized = function() { | ||
var cache = memoized.cache, | ||
key = resolver ? resolver.apply(this, arguments) : keyPrefix + arguments[0]; | ||
key = resolver ? resolver.apply(this, arguments) : arguments[0]; | ||
return hasOwnProperty.call(cache, key) | ||
? cache[key] | ||
: (cache[key] = func.apply(this, arguments)); | ||
} | ||
memoized.cache = {}; | ||
if (cache.has(key)) { | ||
return cache.get(key); | ||
} | ||
var result = func.apply(this, arguments); | ||
cache.set(key, result); | ||
return result; | ||
}; | ||
memoized.cache = new memoize.Cache; | ||
return memoized; | ||
} | ||
// Add functions to the `Map` cache. | ||
MapCache.prototype['delete'] = mapDelete; | ||
MapCache.prototype.get = mapGet; | ||
MapCache.prototype.has = mapHas; | ||
MapCache.prototype.set = mapSet; | ||
// Assign cache to `_.memoize`. | ||
memoize.Cache = MapCache; | ||
module.exports = memoize; |
@@ -1,3 +0,3 @@ | ||
Copyright 2012-2013 The Dojo Foundation <http://dojofoundation.org/> | ||
Based on Underscore.js 1.5.2, copyright 2009-2013 Jeremy Ashkenas, | ||
Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/> | ||
Based on Underscore.js 1.7.0, copyright 2009-2015 Jeremy Ashkenas, | ||
DocumentCloud and Investigative Reporters & Editors <http://underscorejs.org/> | ||
@@ -22,2 +22,2 @@ | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
{ | ||
"name": "lodash.memoize", | ||
"version": "2.4.1", | ||
"description": "The Lo-Dash function `_.memoize` as a Node.js module generated by lodash-cli.", | ||
"homepage": "http://lodash.com/custom-builds", | ||
"version": "3.0.0", | ||
"description": "The modern build of lodash’s `_.memoize` as a module.", | ||
"homepage": "https://lodash.com/", | ||
"icon": "https://lodash.com/icon.svg", | ||
"license": "MIT", | ||
"keywords": ["functional", "lodash", "lodash-modularized", "server", "util"], | ||
"keywords": "lodash, lodash-modularized, stdlib, util", | ||
"author": "John-David Dalton <john.david.dalton@gmail.com> (http://allyoucanleet.com/)", | ||
"contributors": [ | ||
"John-David Dalton <john.david.dalton@gmail.com> (http://allyoucanleet.com/)", | ||
"Benjamin Tan <demoneaux@gmail.com> (https://d10.github.io/)", | ||
"Blaine Bublitz <blaine@iceddev.com> (http://www.iceddev.com/)", | ||
"Kit Cambridge <github@kitcambridge.be> (http://kitcambridge.be/)", | ||
"Mathias Bynens <mathias@qiwi.be> (http://mathiasbynens.be/)" | ||
"Mathias Bynens <mathias@qiwi.be> (https://mathiasbynens.be/)" | ||
], | ||
"bugs": "https://github.com/lodash/lodash-cli/issues", | ||
"repository": { "type": "git", "url": "https://github.com/lodash/lodash-cli.git" }, | ||
"repository": "lodash/lodash", | ||
"scripts": { "test": "echo \"See https://travis-ci.org/lodash/lodash-cli for testing details.\"" }, | ||
"dependencies": { | ||
"lodash.isfunction": "~2.4.1", | ||
"lodash._keyprefix": "~2.4.1" | ||
"lodash.isfunction": "^3.0.0" | ||
} | ||
} |
@@ -1,15 +0,20 @@ | ||
# lodash.memoize v2.4.1 | ||
# lodash.memoize v3.0.0 | ||
The [Lo-Dash](http://lodash.com/) function [`_.memoize`](http://lodash.com/docs#memoize) as a [Node.js](http://nodejs.org/) module generated by [lodash-cli](https://npmjs.org/package/lodash-cli). | ||
The [modern build](https://github.com/lodash/lodash/wiki/Build-Differences) of [lodash’s](https://lodash.com/) `_.memoize` exported as a [Node.js](http://nodejs.org/)/[io.js](https://iojs.org/) module. | ||
## Author | ||
## Installation | ||
| [![twitter/jdalton](http://gravatar.com/avatar/299a3d891ff1920b69c364d061007043?s=70)](https://twitter.com/jdalton "Follow @jdalton on Twitter") | | ||
|---| | ||
| [John-David Dalton](http://allyoucanleet.com/) | | ||
Using npm: | ||
## Contributors | ||
```bash | ||
$ {sudo -H} npm i -g npm | ||
$ npm i --save lodash.memoize | ||
``` | ||
| [![twitter/blainebublitz](http://gravatar.com/avatar/ac1c67fd906c9fecd823ce302283b4c1?s=70)](https://twitter.com/blainebublitz "Follow @BlaineBublitz on Twitter") | [![twitter/kitcambridge](http://gravatar.com/avatar/6662a1d02f351b5ef2f8b4d815804661?s=70)](https://twitter.com/kitcambridge "Follow @kitcambridge on Twitter") | [![twitter/mathias](http://gravatar.com/avatar/24e08a9ea84deb17ae121074d0f17125?s=70)](https://twitter.com/mathias "Follow @mathias on Twitter") | | ||
|---|---|---| | ||
| [Blaine Bublitz](http://www.iceddev.com/) | [Kit Cambridge](http://kitcambridge.be/) | [Mathias Bynens](http://mathiasbynens.be/) | | ||
In Node.js/io.js: | ||
```js | ||
var memoize = require('lodash.memoize'); | ||
``` | ||
See the [documentation](https://lodash.com/docs#memoize) or [package source](https://github.com/lodash/lodash/blob/3.0.0-npm-packages/lodash.memoize) for more details. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7513
1
156
21
1
+ Addedlodash.isfunction@3.0.9(transitive)
- Removedlodash._keyprefix@~2.4.1
- Removedlodash._keyprefix@2.4.2(transitive)
- Removedlodash.isfunction@2.4.1(transitive)
Updatedlodash.isfunction@^3.0.0