primitive-pool

2.0.0 • Public • Published

primitive-pool unstable Build Status

Get object for a primitive value. Useful to make WeakMap store strings/numbers and other primitives.

Usage

npm install primitive-pool

import p from 'primitive-pool'

let map = new WeakMap()

map.set(p('abc'), 123)
map.get(p('abc')) // 123

map.set(p(null), 789)
map.get(p(null)) // 789

map.set(p(123), 'abc')
map.get(p(123)) // 'abc'

// non-primitives are stored as is
let a = {}
map.set(p(a), 'xyz')
map.get(a) // 'xyz'

Alternative can be done via weak refs.

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i primitive-pool

      Weekly Downloads

      3,574

      Version

      2.0.0

      License

      MIT

      Unpacked Size

      3.96 kB

      Total Files

      6

      Last publish

      Collaborators

      • dfcreative
      • dy