Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fetching contributors…
Cannot retrieve contributors at this time
93 lines (58 sloc) 1.91 KB


A true string -> value mapping datatype


Thanks to __proto__, you can no longer add arbitrary strings as object keys without fear of malfunctioning in modern browsers; even in objects created via Object.create(null). true-map solves that; providing a storage datatype with that intact.


var map = require('true-map')

var person = map({ firstName: 'hugh', lastName: 'jackson' })

person.has('firstName') //= true
    awesome            : 'hopefully',
    feelingChristmassy : true

person.get('awesome') //= "hopefully"



Creates an empty map, or sets the initial attributes if an object is passed.

var o = map()

// or
var you = map({ wise: true, willUseThisLib: true })

.set(String, Value) OR .set(Object)

Sets an attribute, or shallow-clones an object's attributes to the map.

var o = map()

o.set('x', 3) 
o.set({ y: 4, z: 5 })

o.has('x') //= true


Gets an attribute.

var o = map({ x: 3, y: 4 })

o.get('x') //= 3


Returns true or false; same as key in object for regular objects:

var o = map({ x: 3, y: 4 })

o.has('x') //= true
o.has('z') //= false

.remove(String) alias: .delete(String)

Removes an attribute - same as the delete keyword, but it returns the map itself to allow chaining (there are no non-deletable attributes, so returning true or false is unnecessary)

var o = map({ 
    foo: 'bar',
    baz: 'quux'

o.has('foo') //= false


Where the attributes themselves are stored, with the keys prefixed with '$' to ensure no collision with 'dunder' properties, such as __proto__.


npm install true-map or download Creates a CommonJS module if available, otherwise exports a global named trueMap.

Jump to Line
Something went wrong with that request. Please try again.