https://github.com/9a8ri3l/sizeof
A utility function that calculates the size or length of various input types.
https://github.com/9a8ri3l/sizeof
array-methods commonjs es6 length number object-length-calculation size string
Last synced: 5 months ago
JSON representation
A utility function that calculates the size or length of various input types.
- Host: GitHub
- URL: https://github.com/9a8ri3l/sizeof
- Owner: 9a8ri3L
- License: mit
- Created: 2024-02-06T16:07:57.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-02-08T17:19:48.000Z (over 1 year ago)
- Last Synced: 2025-04-29T06:25:22.893Z (5 months ago)
- Topics: array-methods, commonjs, es6, length, number, object-length-calculation, size, string
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@g-lib/sizeof
- Size: 52.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README




[](https://app.codacy.com/gh/9a8ri3L/sizeof/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)


# sizeof
### A utility function that calculates the size or the length of various types.
#### install
```
npm i @g-lib/sizeof
``````
yarn add @g-lib/sizeof
``````
pnpm add @g-lib/sizeof
```### Usage:
```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.
### License [MIT](https://choosealicense.com/licenses/mit/)