react / wstein / node_modules / jest-cli / node_modules / lodash.template / node_modules / lodash.keys / index.js
80676 views/**1* lodash 3.1.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*/8var getNative = require('lodash._getnative'),9isArguments = require('lodash.isarguments'),10isArray = require('lodash.isarray');1112/** Used to detect unsigned integer values. */13var reIsUint = /^\d+$/;1415/** Used for native method references. */16var objectProto = Object.prototype;1718/** Used to check objects for own properties. */19var hasOwnProperty = objectProto.hasOwnProperty;2021/* Native method references for those with the same name as other `lodash` methods. */22var nativeKeys = getNative(Object, 'keys');2324/**25* Used as the [maximum length](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.max_safe_integer)26* of an array-like value.27*/28var MAX_SAFE_INTEGER = 9007199254740991;2930/**31* The base implementation of `_.property` without support for deep paths.32*33* @private34* @param {string} key The key of the property to get.35* @returns {Function} Returns the new function.36*/37function baseProperty(key) {38return function(object) {39return object == null ? undefined : object[key];40};41}4243/**44* Gets the "length" property value of `object`.45*46* **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792)47* that affects Safari on at least iOS 8.1-8.3 ARM64.48*49* @private50* @param {Object} object The object to query.51* @returns {*} Returns the "length" value.52*/53var getLength = baseProperty('length');5455/**56* Checks if `value` is array-like.57*58* @private59* @param {*} value The value to check.60* @returns {boolean} Returns `true` if `value` is array-like, else `false`.61*/62function isArrayLike(value) {63return value != null && isLength(getLength(value));64}6566/**67* Checks if `value` is a valid array-like index.68*69* @private70* @param {*} value The value to check.71* @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.72* @returns {boolean} Returns `true` if `value` is a valid index, else `false`.73*/74function isIndex(value, length) {75value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1;76length = length == null ? MAX_SAFE_INTEGER : length;77return value > -1 && value % 1 == 0 && value < length;78}7980/**81* Checks if `value` is a valid array-like length.82*83* **Note:** This function is based on [`ToLength`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength).84*85* @private86* @param {*} value The value to check.87* @returns {boolean} Returns `true` if `value` is a valid length, else `false`.88*/89function isLength(value) {90return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;91}9293/**94* A fallback implementation of `Object.keys` which creates an array of the95* own enumerable property names of `object`.96*97* @private98* @param {Object} object The object to query.99* @returns {Array} Returns the array of property names.100*/101function shimKeys(object) {102var props = keysIn(object),103propsLength = props.length,104length = propsLength && object.length;105106var allowIndexes = !!length && isLength(length) &&107(isArray(object) || isArguments(object));108109var index = -1,110result = [];111112while (++index < propsLength) {113var key = props[index];114if ((allowIndexes && isIndex(key, length)) || hasOwnProperty.call(object, key)) {115result.push(key);116}117}118return result;119}120121/**122* Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.123* (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)124*125* @static126* @memberOf _127* @category Lang128* @param {*} value The value to check.129* @returns {boolean} Returns `true` if `value` is an object, else `false`.130* @example131*132* _.isObject({});133* // => true134*135* _.isObject([1, 2, 3]);136* // => true137*138* _.isObject(1);139* // => false140*/141function isObject(value) {142// Avoid a V8 JIT bug in Chrome 19-20.143// See https://code.google.com/p/v8/issues/detail?id=2291 for more details.144var type = typeof value;145return !!value && (type == 'object' || type == 'function');146}147148/**149* Creates an array of the own enumerable property names of `object`.150*151* **Note:** Non-object values are coerced to objects. See the152* [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.keys)153* for more details.154*155* @static156* @memberOf _157* @category Object158* @param {Object} object The object to query.159* @returns {Array} Returns the array of property names.160* @example161*162* function Foo() {163* this.a = 1;164* this.b = 2;165* }166*167* Foo.prototype.c = 3;168*169* _.keys(new Foo);170* // => ['a', 'b'] (iteration order is not guaranteed)171*172* _.keys('hi');173* // => ['0', '1']174*/175var keys = !nativeKeys ? shimKeys : function(object) {176var Ctor = object == null ? null : object.constructor;177if ((typeof Ctor == 'function' && Ctor.prototype === object) ||178(typeof object != 'function' && isArrayLike(object))) {179return shimKeys(object);180}181return isObject(object) ? nativeKeys(object) : [];182};183184/**185* Creates an array of the own and inherited enumerable property names of `object`.186*187* **Note:** Non-object values are coerced to objects.188*189* @static190* @memberOf _191* @category Object192* @param {Object} object The object to query.193* @returns {Array} Returns the array of property names.194* @example195*196* function Foo() {197* this.a = 1;198* this.b = 2;199* }200*201* Foo.prototype.c = 3;202*203* _.keysIn(new Foo);204* // => ['a', 'b', 'c'] (iteration order is not guaranteed)205*/206function keysIn(object) {207if (object == null) {208return [];209}210if (!isObject(object)) {211object = Object(object);212}213var length = object.length;214length = (length && isLength(length) &&215(isArray(object) || isArguments(object)) && length) || 0;216217var Ctor = object.constructor,218index = -1,219isProto = typeof Ctor == 'function' && Ctor.prototype === object,220result = Array(length),221skipIndexes = length > 0;222223while (++index < length) {224result[index] = (index + '');225}226for (var key in object) {227if (!(skipIndexes && isIndex(key, length)) &&228!(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {229result.push(key);230}231}232return result;233}234235module.exports = keys;236237238