PHP 8.2.30
Preview: memoize.js Size: 2.43 KB
/opt/alt/alt-nodejs9/root/lib/node_modules/npm/node_modules/cli-table2/node_modules/lodash/function/memoize.js

var MapCache = require('../internal/MapCache');

/** Used as the `TypeError` message for "Functions" methods. */
var FUNC_ERROR_TEXT = 'Expected a function';

/**
 * Creates a function that memoizes the result of `func`. If `resolver` is
 * 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 [`Map`](http://ecma-international.org/ecma-262/6.0/#sec-properties-of-the-map-prototype-object)
 * method interface of `get`, `has`, and `set`.
 *
 * @static
 * @memberOf _
 * @category Function
 * @param {Function} func The function to have its output memoized.
 * @param {Function} [resolver] The function to resolve the cache key.
 * @returns {Function} Returns the new memoizing function.
 * @example
 *
 * var upperCase = _.memoize(function(string) {
 *   return string.toUpperCase();
 * });
 *
 * upperCase('fred');
 * // => 'FRED'
 *
 * // modifying the result cache
 * upperCase.cache.set('fred', 'BARNEY');
 * upperCase('fred');
 * // => 'BARNEY'
 *
 * // 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 (typeof func != 'function' || (resolver && typeof resolver != 'function')) {
    throw new TypeError(FUNC_ERROR_TEXT);
  }
  var memoized = function() {
    var args = arguments,
        key = resolver ? resolver.apply(this, args) : args[0],
        cache = memoized.cache;

    if (cache.has(key)) {
      return cache.get(key);
    }
    var result = func.apply(this, args);
    memoized.cache = cache.set(key, result);
    return result;
  };
  memoized.cache = new memoize.Cache;
  return memoized;
}

// Assign cache to `_.memoize`.
memoize.Cache = MapCache;

module.exports = memoize;

Directory Contents

Dirs: 0 × Files: 26

Name Size Perms Modified Actions
1.26 KB lrw-r--r-- 2021-09-28 11:28:34
Edit Download
1.04 KB lrw-r--r-- 2021-09-28 11:28:34
Edit Download
41 B lrw-r--r-- 2021-09-28 11:28:34
Edit Download
1.13 KB lrw-r--r-- 2021-09-28 11:28:34
Edit Download
1.64 KB lrw-r--r-- 2021-09-28 11:28:35
Edit Download
1.57 KB lrw-r--r-- 2021-09-28 11:28:34
Edit Download
1.99 KB lrw-r--r-- 2021-09-28 11:28:34
Edit Download
41 B lrw-r--r-- 2021-09-28 11:28:35
Edit Download
1.41 KB lrw-r--r-- 2021-09-28 11:28:34
Edit Download
1.24 KB lrw-r--r-- 2021-09-28 11:28:34
Edit Download
5.39 KB lrw-r--r-- 2021-09-28 11:28:34
Edit Download
699 B lrw-r--r-- 2021-09-28 11:28:34
Edit Download
742 B lrw-r--r-- 2021-09-28 11:28:34
Edit Download
617 B lrw-r--r-- 2021-09-28 11:28:34
Edit Download
574 B lrw-r--r-- 2021-09-28 11:28:34
Edit Download
2.43 KB lrw-r--r-- 2021-09-28 11:28:34
Edit Download
1.56 KB lrw-r--r-- 2021-09-28 11:28:34
Edit Download
803 B lrw-r--r-- 2021-09-28 11:28:34
Edit Download
650 B lrw-r--r-- 2021-09-28 11:28:34
Edit Download
1.26 KB lrw-r--r-- 2021-09-28 11:28:34
Edit Download
1.23 KB lrw-r--r-- 2021-09-28 11:28:34
Edit Download
1.22 KB lrw-r--r-- 2021-09-28 11:28:34
Edit Download
1.85 KB lrw-r--r-- 2021-09-28 11:28:34
Edit Download
1.15 KB lrw-r--r-- 2021-09-28 11:28:34
Edit Download
2.40 KB lrw-r--r-- 2021-09-28 11:28:35
Edit Download
1.01 KB lrw-r--r-- 2021-09-28 11:28:34
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).