diff options
author | Florian Dold <florian.dold@gmail.com> | 2017-08-14 05:01:11 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2017-08-14 05:02:09 +0200 |
commit | 363723fc84f7b8477592e0105aeb331ec9a017af (patch) | |
tree | 29f92724f34131bac64d6a318dd7e30612e631c7 /node_modules/concordance/lib/getObjectKeys.js | |
parent | 5634e77ad96bfe1818f6b6ee70b7379652e5487f (diff) |
node_modules
Diffstat (limited to 'node_modules/concordance/lib/getObjectKeys.js')
-rw-r--r-- | node_modules/concordance/lib/getObjectKeys.js | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/node_modules/concordance/lib/getObjectKeys.js b/node_modules/concordance/lib/getObjectKeys.js new file mode 100644 index 000000000..4b0c3e368 --- /dev/null +++ b/node_modules/concordance/lib/getObjectKeys.js @@ -0,0 +1,36 @@ +'use strict' + +function getObjectKeys (obj, excludeListItemAccessorsBelowLength) { + const keys = [] + let size = 0 + + // Sort property names, they should never be order-sensitive + const nameCandidates = Object.getOwnPropertyNames(obj).sort() + // Comparators should verify symbols in an order-insensitive manner if + // possible. + const symbolCandidates = Object.getOwnPropertySymbols(obj) + + for (let i = 0; i < nameCandidates.length; i++) { + const name = nameCandidates[i] + + let accept = true + if (excludeListItemAccessorsBelowLength > 0) { + const index = Number(name) + accept = (index % 1 !== 0) || index >= excludeListItemAccessorsBelowLength + } + + if (accept && Object.getOwnPropertyDescriptor(obj, name).enumerable) { + keys[size++] = name + } + } + + for (let i = 0; i < symbolCandidates.length; i++) { + const symbol = symbolCandidates[i] + if (Object.getOwnPropertyDescriptor(obj, symbol).enumerable) { + keys[size++] = symbol + } + } + + return { keys, size } +} +module.exports = getObjectKeys |