mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-12 03:47:50 +00:00
Remove baseKeys and baseKeysIn.
This commit is contained in:
@@ -1,27 +0,0 @@
|
|||||||
import isPrototype from './isPrototype.js'
|
|
||||||
|
|
||||||
/** Used to check objects for own properties. */
|
|
||||||
const hasOwnProperty = Object.prototype.hasOwnProperty
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The base implementation of `keys` which doesn't treat sparse arrays as dense.
|
|
||||||
*
|
|
||||||
* @private
|
|
||||||
* @param {Object} object The object to query.
|
|
||||||
* @returns {Array} Returns the array of property names.
|
|
||||||
*/
|
|
||||||
function baseKeys(object) {
|
|
||||||
object = Object(object)
|
|
||||||
if (!isPrototype(object)) {
|
|
||||||
return Object.keys(object)
|
|
||||||
}
|
|
||||||
const result = []
|
|
||||||
for (const key in object) {
|
|
||||||
if (hasOwnProperty.call(object, key) && key != 'constructor') {
|
|
||||||
result.push(key)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
export default baseKeys
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
import isObject from '../isObject.js'
|
|
||||||
import isPrototype from './isPrototype.js'
|
|
||||||
|
|
||||||
/** Used to check objects for own properties. */
|
|
||||||
const hasOwnProperty = Object.prototype.hasOwnProperty
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The base implementation of `keysIn` which doesn't treat sparse arrays as dense.
|
|
||||||
*
|
|
||||||
* @private
|
|
||||||
* @param {Object} object The object to query.
|
|
||||||
* @returns {Array} Returns the array of property names.
|
|
||||||
*/
|
|
||||||
function baseKeysIn(object) {
|
|
||||||
const result = []
|
|
||||||
if (object == null) {
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
if (!isObject(object)) {
|
|
||||||
for (const key in Object(object)) {
|
|
||||||
result.push(key)
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
const isProto = isPrototype(object)
|
|
||||||
for (const key in object) {
|
|
||||||
if (!(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
|
|
||||||
result.push(key)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
export default baseKeysIn
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
import getSymbolsIn from './getSymbolsIn.js'
|
import getSymbolsIn from './getSymbolsIn.js'
|
||||||
import baseKeysIn from './baseKeysIn.js'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an array of own and inherited enumerable property names and symbols of `object`.
|
* Creates an array of own and inherited enumerable property names and symbols of `object`.
|
||||||
@@ -9,7 +8,10 @@ import baseKeysIn from './baseKeysIn.js'
|
|||||||
* @returns {Array} Returns the array of property names and symbols.
|
* @returns {Array} Returns the array of property names and symbols.
|
||||||
*/
|
*/
|
||||||
function getAllKeysIn(object) {
|
function getAllKeysIn(object) {
|
||||||
const result = baseKeysIn(object)
|
const result = []
|
||||||
|
for (const key in object) {
|
||||||
|
result.push(key)
|
||||||
|
}
|
||||||
if (!Array.isArray(object)) {
|
if (!Array.isArray(object)) {
|
||||||
result.push(...getSymbolsIn(object))
|
result.push(...getSymbolsIn(object))
|
||||||
}
|
}
|
||||||
|
|||||||
25
defaults.js
25
defaults.js
@@ -1,5 +1,4 @@
|
|||||||
import eq from './eq.js'
|
import eq from './eq.js'
|
||||||
import baseKeysIn from './.internal/baseKeysIn.js'
|
|
||||||
|
|
||||||
/** Used for built-in method references. */
|
/** Used for built-in method references. */
|
||||||
const objectProto = Object.prototype
|
const objectProto = Object.prototype
|
||||||
@@ -28,22 +27,18 @@ const hasOwnProperty = objectProto.hasOwnProperty
|
|||||||
*/
|
*/
|
||||||
function defaults(object, ...sources) {
|
function defaults(object, ...sources) {
|
||||||
object = Object(object)
|
object = Object(object)
|
||||||
let srcIndex = -1
|
sources.forEach((source) => {
|
||||||
const srcLength = sources.length
|
if (source != null) {
|
||||||
while (++srcIndex < srcLength) {
|
source = Object(source)
|
||||||
const source = sources[srcIndex]
|
for (const key in source) {
|
||||||
const props = baseKeysIn(source)
|
const value = object[key]
|
||||||
let propsIndex = -1
|
if (value === undefined ||
|
||||||
const propsLength = props.length
|
(eq(value, objectProto[key]) && !hasOwnProperty.call(object, key))) {
|
||||||
while (++propsIndex < propsLength) {
|
object[key] = source[key]
|
||||||
const key = props[propsIndex]
|
}
|
||||||
const value = object[key]
|
|
||||||
if (value === undefined ||
|
|
||||||
(eq(value, objectProto[key]) && !hasOwnProperty.call(object, key))) {
|
|
||||||
object[key] = source[key]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
return object
|
return object
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import baseKeys from './.internal/baseKeys.js'
|
|
||||||
import getTag from './.internal/getTag.js'
|
import getTag from './.internal/getTag.js'
|
||||||
import isArguments from './isArguments.js'
|
import isArguments from './isArguments.js'
|
||||||
import isArrayLike from './isArrayLike.js'
|
import isArrayLike from './isArrayLike.js'
|
||||||
@@ -54,7 +53,7 @@ function isEmpty(value) {
|
|||||||
return !value.size
|
return !value.size
|
||||||
}
|
}
|
||||||
if (isPrototype(value)) {
|
if (isPrototype(value)) {
|
||||||
return !baseKeys(value).length
|
return !Object.keys(value).length
|
||||||
}
|
}
|
||||||
for (const key in value) {
|
for (const key in value) {
|
||||||
if (hasOwnProperty.call(value, key)) {
|
if (hasOwnProperty.call(value, key)) {
|
||||||
|
|||||||
5
keys.js
5
keys.js
@@ -1,5 +1,4 @@
|
|||||||
import arrayLikeKeys from './.internal/arrayLikeKeys.js'
|
import arrayLikeKeys from './.internal/arrayLikeKeys.js'
|
||||||
import baseKeys from './.internal/baseKeys.js'
|
|
||||||
import isArrayLike from './isArrayLike.js'
|
import isArrayLike from './isArrayLike.js'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -30,7 +29,9 @@ import isArrayLike from './isArrayLike.js'
|
|||||||
* // => ['0', '1']
|
* // => ['0', '1']
|
||||||
*/
|
*/
|
||||||
function keys(object) {
|
function keys(object) {
|
||||||
return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object)
|
return isArrayLike(object)
|
||||||
|
? arrayLikeKeys(object)
|
||||||
|
: Object.keys(Object(object))
|
||||||
}
|
}
|
||||||
|
|
||||||
export default keys
|
export default keys
|
||||||
|
|||||||
3
size.js
3
size.js
@@ -1,4 +1,3 @@
|
|||||||
import baseKeys from './.internal/baseKeys.js'
|
|
||||||
import getTag from './.internal/getTag.js'
|
import getTag from './.internal/getTag.js'
|
||||||
import isArrayLike from './isArrayLike.js'
|
import isArrayLike from './isArrayLike.js'
|
||||||
import isString from './isString.js'
|
import isString from './isString.js'
|
||||||
@@ -38,7 +37,7 @@ function size(collection) {
|
|||||||
if (tag == mapTag || tag == setTag) {
|
if (tag == mapTag || tag == setTag) {
|
||||||
return collection.size
|
return collection.size
|
||||||
}
|
}
|
||||||
return baseKeys(collection).length
|
return Object.keys(collection).length
|
||||||
}
|
}
|
||||||
|
|
||||||
export default size
|
export default size
|
||||||
|
|||||||
Reference in New Issue
Block a user