react / wstein / node_modules / jest-cli / node_modules / istanbul / node_modules / js-yaml / node_modules / argparse / node_modules / lodash / utility / mixin.js
80742 viewsvar arrayCopy = require('../internal/arrayCopy'),1baseFunctions = require('../internal/baseFunctions'),2isFunction = require('../lang/isFunction'),3isObject = require('../lang/isObject'),4keys = require('../object/keys');56/** Used for native method references. */7var arrayProto = Array.prototype;89/** Native method references. */10var push = arrayProto.push;1112/**13* Adds all own enumerable function properties of a source object to the14* destination object. If `object` is a function then methods are added to15* its prototype as well.16*17* **Note:** Use `_.runInContext` to create a pristine `lodash` function to18* avoid conflicts caused by modifying the original.19*20* @static21* @memberOf _22* @category Utility23* @param {Function|Object} [object=lodash] The destination object.24* @param {Object} source The object of functions to add.25* @param {Object} [options] The options object.26* @param {boolean} [options.chain=true] Specify whether the functions added27* are chainable.28* @returns {Function|Object} Returns `object`.29* @example30*31* function vowels(string) {32* return _.filter(string, function(v) {33* return /[aeiou]/i.test(v);34* });35* }36*37* _.mixin({ 'vowels': vowels });38* _.vowels('fred');39* // => ['e']40*41* _('fred').vowels().value();42* // => ['e']43*44* _.mixin({ 'vowels': vowels }, { 'chain': false });45* _('fred').vowels();46* // => ['e']47*/48function mixin(object, source, options) {49var methodNames = baseFunctions(source, keys(source));5051var chain = true,52index = -1,53isFunc = isFunction(object),54length = methodNames.length;5556if (options === false) {57chain = false;58} else if (isObject(options) && 'chain' in options) {59chain = options.chain;60}61while (++index < length) {62var methodName = methodNames[index],63func = source[methodName];6465object[methodName] = func;66if (isFunc) {67object.prototype[methodName] = (function(func) {68return function() {69var chainAll = this.__chain__;70if (chain || chainAll) {71var result = object(this.__wrapped__),72actions = result.__actions__ = arrayCopy(this.__actions__);7374actions.push({ 'func': func, 'args': arguments, 'thisArg': object });75result.__chain__ = chainAll;76return result;77}78var args = [this.value()];79push.apply(args, arguments);80return func.apply(object, args);81};82}(func));83}84}85return object;86}8788module.exports = mixin;899091