mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 02:17:48 +00:00
120 lines
3.6 KiB
JavaScript
120 lines
3.6 KiB
JavaScript
/**
|
|
* lodash 3.1.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.8.3 <http://underscorejs.org/LICENSE>
|
|
* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|
* Available under MIT license <https://lodash.com/license>
|
|
*/
|
|
var baseCopy = require('lodash._basecopy'),
|
|
isNative = require('lodash.isnative'),
|
|
keys = require('lodash.keys');
|
|
|
|
/** Native method references. */
|
|
var getOwnPropertySymbols = isNative(getOwnPropertySymbols = Object.getOwnPropertySymbols) && getOwnPropertySymbols,
|
|
preventExtensions = isNative(Object.preventExtensions = Object.preventExtensions) && preventExtensions;
|
|
|
|
/** Used as `baseAssign`. */
|
|
var nativeAssign = (function() {
|
|
// Avoid `Object.assign` in Firefox 34-37 which have an early implementation
|
|
// with a now defunct try/catch behavior. See https://bugzilla.mozilla.org/show_bug.cgi?id=1103344
|
|
// for more details.
|
|
//
|
|
// Use `Object.preventExtensions` on a plain object instead of simply using
|
|
// `Object('x')` because Chrome and IE fail to throw an error when attempting
|
|
// to assign values to readonly indexes of strings in strict mode.
|
|
var object = { '1': 0 },
|
|
func = preventExtensions && isNative(func = Object.assign) && func;
|
|
|
|
try { func(preventExtensions(object), 'xo'); } catch(e) {}
|
|
return !object[1] && func;
|
|
}());
|
|
|
|
/**
|
|
* The base implementation of `_.assign` without support for argument juggling,
|
|
* multiple sources, and `customizer` functions.
|
|
*
|
|
* @private
|
|
* @param {Object} object The destination object.
|
|
* @param {Object} source The source object.
|
|
* @returns {Object} Returns `object`.
|
|
*/
|
|
var baseAssign = nativeAssign || function(object, source) {
|
|
return source == null
|
|
? object
|
|
: baseCopy(source, getSymbols(source), baseCopy(source, keys(source), object));
|
|
};
|
|
|
|
/**
|
|
* Creates an array of the own symbols of `object`.
|
|
*
|
|
* @private
|
|
* @param {Object} object The object to query.
|
|
* @returns {Array} Returns the array of symbols.
|
|
*/
|
|
var getSymbols = !getOwnPropertySymbols ? constant([]) : function(object) {
|
|
return getOwnPropertySymbols(toObject(object));
|
|
};
|
|
|
|
/**
|
|
* Converts `value` to an object if it is not one.
|
|
*
|
|
* @private
|
|
* @param {*} value The value to process.
|
|
* @returns {Object} Returns the object.
|
|
*/
|
|
function toObject(value) {
|
|
return isObject(value) ? value : Object(value);
|
|
}
|
|
|
|
/**
|
|
* Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
|
|
* (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
|
|
*
|
|
* @static
|
|
* @memberOf _
|
|
* @category Lang
|
|
* @param {*} value The value to check.
|
|
* @returns {boolean} Returns `true` if `value` is an object, else `false`.
|
|
* @example
|
|
*
|
|
* _.isObject({});
|
|
* // => true
|
|
*
|
|
* _.isObject([1, 2, 3]);
|
|
* // => true
|
|
*
|
|
* _.isObject(1);
|
|
* // => false
|
|
*/
|
|
function isObject(value) {
|
|
// Avoid a V8 JIT bug in Chrome 19-20.
|
|
// See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
|
|
var type = typeof value;
|
|
return type == 'function' || (!!value && type == 'object');
|
|
}
|
|
|
|
/**
|
|
* Creates a function that returns `value`.
|
|
*
|
|
* @static
|
|
* @memberOf _
|
|
* @category Utility
|
|
* @param {*} value The value to return from the new function.
|
|
* @returns {Function} Returns the new function.
|
|
* @example
|
|
*
|
|
* var object = { 'user': 'fred' };
|
|
* var getter = _.constant(object);
|
|
*
|
|
* getter() === object;
|
|
* // => true
|
|
*/
|
|
function constant(value) {
|
|
return function() {
|
|
return value;
|
|
};
|
|
}
|
|
|
|
module.exports = baseAssign;
|