Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

true-map

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

true-map

A string:val map that works for all keynames - including __proto__

latest
Source
npmnpm
Version
0.1.0
Version published
Maintainers
1
Created
Source

true-map

A true string -> value mapping datatype

Why

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.

Example

var map = require('true-map')

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

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

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

API

map([Object])

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

.get

Gets an attribute.

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

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

.has(String)

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)

Removes an attribute - same as delete, 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.remove('foo').remove('baz')
o.has('foo') //= false

.attributes

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

Install

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

FAQs

Package last updated on 25 Dec 2012

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts