npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

sizeomatic

v1.0.3

Published

Estimate and format the size of JavaScript objects

Downloads

3

Readme

sizeomatic

A module that provides methods for approximating the amount of memory being used by a JavaScript object. The results should not be assumed to be precisely accurate, but rather estimates based on useful approximations. It also exports two methods for converting between bytes and larger units of digital storage - which are accurate.

$ npm install sizeomatic

Type/Size Approximation

| Type | Approximation | |---------|-----------------------| | boolean | 4 bytes | | number | 8 bytes | | string | 2 bytes per character |

Size Abbreviations

| Abbr | Size | |------|----------| | K/k | Kilobyte | | M/m | Megabyte | | G/g | Gigabyte |

Usage

var sizeomatic = require ('sizeomatic');

var bytes = sizeomatic.howManyBytes('125K');
/* result : 128000 */

var notbytes = sizeomatic.pretty(bytes + 1500);
/* result : 126.465K */

var obj =
{
	b : true,
	n : 12345,
	s : "Hello!",
	a : [ "something", "wicked", "this", "way", "comes" ],
	o : { "everything" : "is awesome!" }
};

var size = sizeomatic.getSize(obj);
/* result: 130 (bytes) */

var rsize = sizeomatic.getSize(JSON.stringify(obj));
/* result: 228 (bytes) */

Methods

The following methods are exposed.

howManyBytes

Takes a string representation of an amount of digital storage and returns an integer representation of the number of bytes. The case of the units does not matter, and if you accidentally add a b at the end, it will handle that, too.

console.log(sizeomatic.howManyBytes('125'));
/* 125 */

console.log(sizeomatic.howManyBytes('125B'));
/* 125 */

console.log(sizeomatic.howManyBytes('125Kb'));
/* 128000 */

console.log(sizeomatic.howManyBytes('125kb'));
/* 128000 */

console.log(sizeomatic.howManyBytes('125m'));
/* 131072000 */

console.log(sizeomatic.howManyBytes('125G'));
/* 134217728000 */

getSize

Takes a JavaScript object and returns the approximates size in bytes of memory the object is consuming as an integer.

var obj =
{
	b : true,
	n : 12345,
	s : "Hello!",
	a : [ "something", "wicked", "this", "way", "comes" ],
	o : { "everything" : "is awesome!" }
};

var size = sizeomatic.getSize(obj);
/* result: 130 (bytes) */

var rsize = sizeomatic.getSize(JSON.stringify(obj));
/* result: 228 (bytes) */

Note that a serialized representation will of an object will return a larger value than the original object because it is being treated as a string.

pretty

Takes an integer representation of a number of bytes and formats it to an appropriate size (precise up to three decimal places) suffixed with the appropriate size abbreviation.

console.log(sizeomatic.pretty(125));
/* 125B */

console.log(sizeomatic.pretty(128950));
/* 125.928K */

console.log(sizeomatic.pretty(131672000));
/* 125.572M */

console.log(sizeomatic.pretty(139217728000));
/* 129.657G */

Acknowledgments

I used sizeof as the basis for this module, tweaked it, and added what I wanted.