object-sizeof
Advanced tools
Comparing version 1.0.9 to 1.0.10
47
index.js
@@ -15,24 +15,33 @@ // Copyright 2014 Andrei Karpushonak | ||
function sizeof(object) { | ||
if (_.isObject(object)) { | ||
if (Buffer.isBuffer(object)) { | ||
return object.length; | ||
if (_.isObject(object)) { | ||
if (Buffer.isBuffer(object)) { | ||
return object.length; | ||
} | ||
else { | ||
var bytes = 0; | ||
_.forOwn(object, function (value, key) { | ||
bytes += sizeof(key); | ||
try { | ||
bytes += sizeof(value); | ||
} catch (ex) { | ||
if(ex instanceof RangeError) { | ||
// circular reference detected, final result might be incorrect | ||
// let's be nice and not throw an exception | ||
bytes = 0; | ||
} | ||
} | ||
}); | ||
return bytes; | ||
} | ||
} else if (_.isString(object)) { | ||
return object.length * ECMA_SIZES.STRING; | ||
} else if (_.isBoolean(object)) { | ||
return ECMA_SIZES.BOOLEAN; | ||
} else if (_.isNumber(object)) { | ||
return ECMA_SIZES.NUMBER; | ||
} else { | ||
return 0; | ||
} | ||
else { | ||
var bytes = 0; | ||
_.forOwn(object, function (value, key) { | ||
bytes += sizeof(key) + sizeof(value); | ||
}); | ||
return bytes; | ||
} | ||
} else if (_.isString(object)) { | ||
return object.length * ECMA_SIZES.STRING; | ||
} else if (_.isBoolean(object)) { | ||
return ECMA_SIZES.BOOLEAN; | ||
} else if (_.isNumber(object)) { | ||
return ECMA_SIZES.NUMBER; | ||
} else { | ||
return 0; | ||
} | ||
} | ||
module.exports = sizeof; |
The MIT License (MIT) | ||
Copyright © 2014, Andrei Karpushonak aka @miktam, http://avrora.io | ||
Copyright © 2014, Andrei Karpushonak aka @miktam | ||
@@ -5,0 +5,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: |
{ | ||
"name": "object-sizeof", | ||
"version": "1.0.9", | ||
"version": "1.0.10", | ||
"description": "Sizeof of a JavaScript object in bytes", | ||
@@ -11,3 +11,3 @@ "main": "index.js", | ||
"type": "git", | ||
"url": "git://github.com/avrora/sizeof.git" | ||
"url": "git://github.com/miktam/sizeof.git" | ||
}, | ||
@@ -24,3 +24,3 @@ "keywords": [ | ||
"dependencies": { | ||
"lodash": "^4.3.0" | ||
"lodash": "^4.6.1" | ||
}, | ||
@@ -27,0 +27,0 @@ "devDependencies": { |
## object-sizeof | ||
[![Build Status](https://travis-ci.org/avrora/sizeof.svg?branch=master)](https://travis-ci.org/avrora/sizeof) [![Dependency Status](https://david-dm.org/avrora/sizeof.svg)](https://david-dm.org/avrora/sizeof) | ||
[![Build Status](https://travis-ci.org/miktam/sizeof.svg?branch=master)](https://travis-ci.org/miktam/sizeof) [![Dependency Status](https://david-dm.org/miktam/sizeof.svg)](https://david-dm.org/miktam/sizeof) | ||
@@ -51,2 +51,2 @@ [![NPM](https://nodei.co/npm/object-sizeof.png?downloads=true&downloadRank=true)](https://nodei.co/npm/object-sizeof/) | ||
Copyright (c) 2015, Andrei Karpushonak aka @miktam, http://avrora.io | ||
Copyright (c) 2015, Andrei Karpushonak aka @miktam |
@@ -63,2 +63,9 @@ "use strict"; | ||
}) | ||
it('report an error for circular dependency objects', function() { | ||
var firstLevel = {a: 1}; | ||
var secondLevel = {b: 2, c: firstLevel}; | ||
firstLevel.second = secondLevel; | ||
should.exist(sizeof(firstLevel)); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6863
105
Updatedlodash@^4.6.1