{"library":"object-sizeof","title":"Object Size Calculator","description":"The `object-sizeof` library provides an approximation of the memory footprint of a JavaScript object in bytes. Currently at stable version 2.6.5, the package sees active maintenance with minor releases addressing types and bug fixes, as evidenced by recent updates from v2.6.1 to v2.6.4. It distinguishes itself by employing separate underlying implementations for Node.js (utilizing `Buffer.from` on stringified objects) and browser environments (using a recursive stack-based approach). A key feature is its expanded support for a wide array of built-in and complex types including Map, Set, BigInt, Function, and Typed Arrays. Unlike some alternatives, `object-sizeof` aims for robustness by returning -1 for common error scenarios such as circular references or unrecognizable TypedArray objects, preventing exceptions or infinite loops, rather than throwing errors. It also ships with TypeScript types for improved developer experience.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install object-sizeof"],"cli":null},"imports":["import sizeof from 'object-sizeof';","const sizeof = require('object-sizeof');","sizeof({ a: 1 });"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import sizeof from 'object-sizeof';\n\n// Basic object\nconst obj1 = { id: 1, name: 'Test Object', data: [10, 20, 30] };\nconsole.log(`Size of basic object: ${sizeof(obj1)} bytes`);\n\n// Complex object with various types\nconst complexObj = {\n  str: 'hello world!',\n  num: 123.456,\n  bool: true,\n  arr: [1, 'two', { key: 'value' }],\n  map: new Map([['a', 1], ['b', 2]]),\n  set: new Set([1, 2, 3]),\n  bigInt: BigInt(9007199254740991),\n  func: () => { console.log('I am a function'); },\n  typedArray: new Uint8Array([10, 20, 30, 40])\n};\nconsole.log(`Size of complex object: ${sizeof(complexObj)} bytes`);\n\n// Object with a circular reference (will return -1)\nconst circularObj: any = { a: 1 };\ncircularObj.b = circularObj;\nconsole.log(`Size of circular object: ${sizeof(circularObj)} bytes (expected -1 due to circularity)`);\n\n// Test with a simple number and string\nconsole.log(`Size of number 12345: ${sizeof(12345)} bytes`);\nconsole.log(`Size of string \"hello\": ${sizeof(\"hello\")} bytes`);","lang":"typescript","description":"Demonstrates calculating the approximate size of various JavaScript objects, including primitive types, complex structures like Map, Set, BigInt, Typed Arrays, functions, and showcases handling of circular references.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}