Skip to content

Commit

Permalink
Fixes #38 (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
miktam authored Feb 18, 2020
1 parent 1a5484b commit ccfee89
Show file tree
Hide file tree
Showing 3 changed files with 201 additions and 20 deletions.
9 changes: 4 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ function sizeOfObject (seen, object) {
// Do not recalculate circular references
if (typeof object[key] === 'object' && object[key] !== null) {
if (seen.has(object[key])) {
continue;
continue
}
seen.add(object[key]);
seen.add(object[key])
}

bytes += getCalculator(seen)(key)
Expand All @@ -35,9 +35,8 @@ function sizeOfObject (seen, object) {
return bytes
}


function getCalculator (seen) {
return function(object) {
return function (object) {
if (Buffer.isBuffer(object)) {
return object.length
}
Expand Down Expand Up @@ -71,7 +70,7 @@ function getCalculator (seen) {
* @returns {*}
*/
function sizeof (object) {
return getCalculator(new WeakSet())(object);
return getCalculator(new WeakSet())(object)
}

module.exports = sizeof
208 changes: 195 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "object-sizeof",
"version": "1.5.2",
"version": "1.5.3",
"description": "Sizeof of a JavaScript object in Bytes",
"main": "index.js",
"scripts": {
Expand All @@ -23,7 +23,7 @@
"buffer": "^5.4.3"
},
"devDependencies": {
"mocha": "^6.2.1",
"mocha": "^7.0.1",
"should": "^13.2.3",
"standard": "^14.3.1"
},
Expand Down

0 comments on commit ccfee89

Please sign in to comment.