react / wstein / node_modules / jest-cli / node_modules / lodash.template / node_modules / lodash.restparam / index.js
80676 views/**1* lodash 3.6.1 (Custom Build) <https://lodash.com/>2* Build: `lodash modern modularize exports="npm" -o ./`3* Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>4* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>5* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors6* Available under MIT license <https://lodash.com/license>7*/89/** Used as the `TypeError` message for "Functions" methods. */10var FUNC_ERROR_TEXT = 'Expected a function';1112/* Native method references for those with the same name as other `lodash` methods. */13var nativeMax = Math.max;1415/**16* Creates a function that invokes `func` with the `this` binding of the17* created function and arguments from `start` and beyond provided as an array.18*19* **Note:** This method is based on the [rest parameter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters).20*21* @static22* @memberOf _23* @category Function24* @param {Function} func The function to apply a rest parameter to.25* @param {number} [start=func.length-1] The start position of the rest parameter.26* @returns {Function} Returns the new function.27* @example28*29* var say = _.restParam(function(what, names) {30* return what + ' ' + _.initial(names).join(', ') +31* (_.size(names) > 1 ? ', & ' : '') + _.last(names);32* });33*34* say('hello', 'fred', 'barney', 'pebbles');35* // => 'hello fred, barney, & pebbles'36*/37function restParam(func, start) {38if (typeof func != 'function') {39throw new TypeError(FUNC_ERROR_TEXT);40}41start = nativeMax(start === undefined ? (func.length - 1) : (+start || 0), 0);42return function() {43var args = arguments,44index = -1,45length = nativeMax(args.length - start, 0),46rest = Array(length);4748while (++index < length) {49rest[index] = args[start + index];50}51switch (start) {52case 0: return func.call(this, rest);53case 1: return func.call(this, args[0], rest);54case 2: return func.call(this, args[0], args[1], rest);55}56var otherArgs = Array(start + 1);57index = -1;58while (++index < start) {59otherArgs[index] = args[index];60}61otherArgs[start] = rest;62return func.apply(this, otherArgs);63};64}6566module.exports = restParam;676869