1.0.0 • Published 6 years ago

@tiaanduplessis/sizeof v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

@tiaanduplessis/sizeof

package version package downloads standard-readme compliant package license make a pull request

Get approximate size of literal or variable in bytes

Table of Contents

Install

This project uses node and npm.

$ npm install @tiaanduplessis/sizeof
$ # OR
$ yarn add @tiaanduplessis/sizeof

Usage

const sizeof = require('@tiaanduplessis/sizeof')

sizeof(1) // 8
sizeof('hello') // 10
sizeof(true) // 4

sizeof({
  foo: 1,
  bar: 1,
  baz: {
    yes: true,
    foo: {
      hello: 'world'
    }
  }
}) // 30

const m = new Map()
const s = new Set()

m.set('foo', 'foo').set('bar', 9)
s.add('true').add('false').add(1)

sizeof({
  foo: 'true',
  m,
  s
}) // 48

Contribute

  1. Fork it and create your feature branch: git checkout -b my-new-feature
  2. Commit your changes: git commit -am 'Add some feature'
  3. Push to the branch: git push origin my-new-feature
  4. Submit a pull request

License

MIT