🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

object-sizeof

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

object-sizeof - npm Package Compare versions

Comparing version

to
2.2.0

5

indexv2.js

@@ -18,4 +18,7 @@ // Copyright 2023 ChatGPT Jan 9 Version

if (obj instanceof Map) {
// convert the map to an object, including the nested properties
// convert the map to an object
potentialConversion = Object.fromEntries(obj)
} else if (obj instanceof Set) {
// convert the set to an array
potentialConversion = Array.from(obj)
}

@@ -22,0 +25,0 @@ const objectToString = JSON.stringify(potentialConversion)

2

package.json
{
"name": "object-sizeof",
"version": "2.1.0",
"version": "2.2.0",
"description": "Sizeof of a JavaScript object in Bytes",

@@ -5,0 +5,0 @@ "main": "indexv2.js",

## object-sizeof
[![Build Status](https://travis-ci.org/miktam/sizeof.svg?branch=master)](https://travis-ci.org/miktam/sizeof) ![GitHub contributors](https://img.shields.io/github/contributors/miktam/sizeof) [![NPM](https://img.shields.io/npm/dy/object-sizeof)](https://img.shields.io/npm/dy/object-sizeof) [![codecov](https://codecov.io/gh/miktam/sizeof/branch/master/graph/badge.svg?token=qPHxmWpC1K)](https://codecov.io/gh/miktam/sizeof)
[![Build](https://img.shields.io/npm/v/object-sizeof)](https://img.shields.io/npm/v/object-sizeof) [![Build Status](https://travis-ci.org/miktam/sizeof.svg?branch=master)](https://travis-ci.org/miktam/sizeof) ![GitHub contributors](https://img.shields.io/github/contributors/miktam/sizeof) [![NPM](https://img.shields.io/npm/dy/object-sizeof)](https://img.shields.io/npm/dy/object-sizeof) [![codecov](https://codecov.io/gh/miktam/sizeof/branch/master/graph/badge.svg?token=qPHxmWpC1K)](https://codecov.io/gh/miktam/sizeof)

@@ -12,4 +12,5 @@ ### Get size of a JavaScript object in Bytes - Node.js

- Map
- Set
### Get size of a JavaScript object in Bytes - Browser
### Get size of a JavaScript object in Bytes - Browser

@@ -22,5 +23,8 @@ For the browser, the calculation takes an object as an argument. It uses a combination of recursion and a stack to iterate through all of its properties, adding up the number of bytes for each data type it encounters.

Project uses [JavaScript Standard Style](https://standardjs.com/).
Project follows [JavaScript Standard Style](https://standardjs.com/) as a JavaScript style guide.
Code coverage reports done using Codecov.io.
Code is written with the assumptions, that any code added, which is not tested properly, is already or will be buggy.
Hence test coverage, with the BDD style unit tests, stating the intent, and expected behaviour, is a must.
### Get size of a JavaScript object in Bytes - version 1.x

@@ -46,18 +50,5 @@

import sizeof from 'object-sizeof'
// 2B per character, 6 chars total => 12B
console.log(sizeof({ abc: 'def' }))
// 8B for Number => 8B
console.log(sizeof(12345))
const param = {
a: 1,
b: 2,
c: {
d: 4
}
}
// 4 one two-bytes char strings and 3 eighth-bytes numbers => 32B
console.log(sizeof(param))
// const sizeof = require("object-sizeof")
console.log("Object { abc: 'def' } in bytes: " + sizeof({ abc: 'def' })) // "Object { abc: 'def' } in bytes: 13"
console.log("Integer 12345 in bytes: " + sizeof(12345)) // "Integer 12345 in bytes: 8"
```

@@ -64,0 +55,0 @@

@@ -71,2 +71,3 @@ 'use strict'

it('map support', () => {
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map
const mapSmaller = new Map()

@@ -77,5 +78,15 @@ mapSmaller.set('a', 1)

mapBigger.set('b', 2)
console.log(sizeof(mapBigger), sizeof(mapSmaller))
sizeof(mapBigger).should.be.above(sizeof(mapSmaller))
})
it('set support', () => {
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
const smallerSet = new Set()
smallerSet.add(1) // Set(1) { 1 }
const biggerSet = new Set()
biggerSet.add(1) // Set(1) { 1 }
biggerSet.add('some text') // Set(3) { 1, 5, 'some text' }
sizeof(biggerSet).should.be.above(sizeof(smallerSet))
})
})