Repository URL to install this package:
|
Version:
6.0.4 ▾
|
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var NON_ENUMERABLE_1 = require("../native/NON_ENUMERABLE");
var is_1 = require("../is");
var uniq_1 = require("../array/uniq");
var concatMutate_1 = require("../array/concatMutate");
var keys_1 = require("./keys");
var getOwnPropertyNames = Object.getOwnPropertyNames;
var getOwnPropertySymbols = Object.getOwnPropertySymbols;
/**
* @todo @@perf
*/
function forProto(obj, fn, max) {
if (max === void 0) { max = 11; }
var current = obj;
var index = 0;
// would be result for `mapProto`
// let result = []
while ((current = Object.getPrototypeOf(current))) {
if (index++ > max)
break;
fn(current, index);
}
// return result
}
/**
* @desc properties, property symbols, object keys
* ^ all again for prototype
* @memberOf util
* @since 3.0.0
* @version 5.0.0-beta.4 only used in gc (as of 5.0.0-beta.4)
*
* @param obj object to get properties & symbols from
* @return properties
*
* @see deps/gc
* @see deps/utils/nonEnumerableTypes
* @see http://2ality.com/2011/07/js-properties.html
* @TODO https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptors
* `const getOwnPropertyDescriptors = Object.getOwnPropertyDescriptors`
*
* @example
* var obj = {key: true}
* allProperties(obj)
* //=> ['key']
*
* @example
* class One {
* method() {}
* }
* class Two extends One {
* eh() {}
* }
* allProperties(new Two())
* //=> ['eh', 'method']
*
*/
function allProperties(obj) {
return getOwnPropertyNames(obj)
.concat(getOwnPropertySymbols(obj))
.concat(keys_1.default(obj));
// .concat(keys(obj)) ?
// const result = []
// for (const prop in obj) result.push(prop)
// return result
// flatten(getOwnPropertyNames, getOwnPropertySymbols)
// const proto = getPrototypeOf(obj)
// return [].concat(
// getOwnPropertyNames(obj),
// getOwnPropertySymbols(obj)
// // ObjectKeys(obj),
// // proto ? allProperties(proto) : []
// )
}
// @TODO @HACK @FIXME - needs to be in another file
var NON_ASSIGNABLE = NON_ENUMERABLE_1.default.concat(['length', 'name']);
function walkAllProperties(obj, max) {
if (max === void 0) { max = 1; }
var props = allProperties(obj);
forProto(obj, function (proto) { return concatMutate_1.default(props, allProperties(proto)); }, max);
return props.filter(function (key) { return !NON_ASSIGNABLE.includes(key); }).filter(uniq_1.default);
}
var BUILT_IN_METHODS = NON_ASSIGNABLE.concat(['apply', 'bind', 'call']);
var BUILT_IN_FILTER = function (key) {
return (!BUILT_IN_METHODS.includes(key) &&
!is_1.isSymbol(key) &&
(key && !key.startsWith('$')));
};
function walkAllCustomProperties(obj, max) {
if (max === void 0) { max = 1; }
var props = allProperties(obj);
// const iteratee = proto => {
// props = props.concat(allProperties(proto))
// }
// forProto(obj, iteratee, max)
return props.filter(BUILT_IN_FILTER).filter(uniq_1.default);
}
exports.default = walkAllCustomProperties;
//# sourceMappingURL=props.js.map