A utility function that calculates the size or the length of various types.
npm install @g-lib/sizeof!GitHub Release
!NPM License
!GitHub forks
!GitHub stars

!GitHub Downloads (all assets, all releases)
!GitHub commits since latest release
!GitHub contributors
!npm bundle size (scoped)
#### install
```
npm i @g-lib/sizeof
``
yarn add @g-lib/sizeof
``
pnpm add @g-lib/sizeof
`ts
import sizeof from "@g-lib/sizeof";
// or
const sizeof = require("@g-lib/sizeof");
console.log(sizeof({ foo: "bar", bar: "baz" })); // 2
console.log(sizeof([1, 2, 3])); // 3
console.log(sizeof(new Map().set("foo", true))); // 1
console.log(sizeof(new Set().add("foo").add("bar"))); // 2
console.log(sizeof(2024)); // 4
console.log(sizeof(100e15)); // 18
console.log(sizeof(Symbol("foo"))); // 3
console.log(
sizeof(function foo(a: any, b: any) {
return a + b;
})
); // 0
console.log(
sizeof(function bar() {
return "bar";
})
); // 3
console.log(
sizeof(
new (function Foo(this: any) {
this.name = "Foo";
this.age = 30;
} as any)()
)
); // 2
console.log(
sizeof(
new (class Foo extends Map
constructor(public name: string) {
super();
}
})("")
)
); // 0
console.log(
sizeof(
new (class Bar {
constructor(public name: string) {}
})("")
)
); // 1
``
#### Contributing is always welcomed.