Sizeof of a JavaScript object in bytes
npm install size-of-object !GitHub contributors 
Uses the Buffer.from(objectToString) method to convert the object's string representation to a buffer, and then it uses the byteLength property to obtain the buffer size in bytes.
- Map
- Set
- BigInt
- Function
- Typed Arrays (Int8Array, Uint32Array, Float64Array, etc)
An instance of SizeOfError if is impossible to calculate the size of the object.
- JSON serialization error, e.g. circular references.
- Unrecognizable object.
It prevents potential exceptions or infinite loops, improving reliability.
npm install size-of
``typescriptSize of the object: ${sizeObj} bytes
import { sizeOf } from "size-of-object";
const size = sizeOf({ abc: "def" });
console.log();``
This project is licensed under the MIT License.
This project is a fork of object-sizeof, originally created by Andrei Karpushonak aka @miktam and licensed under the MIT License.
The original code has been reworked to comply with the latest TypeScript standards and to improve performance and reliability.
Compared to the original, this version offers:
- No browser support, only work in node focusing on performance by simplifying the code and removing unnecessary checks
- Better types and support for both CommonJS and ESM
- Error are getting thrown instead of returning magic numbers
- Focus on performance by simplifying the code and removing unnecessary checks