Repository URL to install this package:
|
Version:
6.0.4 ▾
|
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var is_1 = require("../is");
var preAllocate_1 = require("../array/preAllocate");
/**
* @name keysIn
* @version 1.0.0 uncommented, used preAllocate
* @version 0.0.1 just comment
* @since 5.0.0
*
* @param {Object|Array} obj object to call `for in` on
* @param {boolean} [guard=false] only accept `hasOwnProperty`
* @return {Array} keys from obj
*
* {@link https://github.com/ramda/ramda/blob/master/src/keysIn.js ramda-keys-in}
* @see {@link ramda-keys-in}
* @see array/preAllocate
* @see util/hasOwnProperty
*
* @tests keys
*
* @example
*
* keysIn([1, 2]) //=> [0, 1]
* keysIn({one: 1, two: 2}) //=> ['one', 'two']
*
*/
function keysIn(obj, guard) {
var result = preAllocate_1.default(obj);
var index = 0;
// eslint-disable-next-line
// for (const key in obj) hasOwnProperty(obj, key) && (result[index++] = key)
for (var key in obj) {
/**
* when we have a guard, check ownProperty, otherwise just assign
*
* also written as pseudo:
* ```
* if (guard)
* if (hasOwnProperty) assign
* else result[index++] = key
* ```
*/
if (guard !== true || is_1.hasOwnProperty(obj, key)) {
result[index++] = key;
}
}
return result;
}
exports.default = keysIn;
//# sourceMappingURL=keysIn.js.map