Socket
Socket
Sign inDemoInstall

hash

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    hash

Safely use a JavaScript object as hash


Version published
Maintainers
1
Install size
7.46 kB
Created

Readme

Source
__               __        _

/ /_ ____ / / () / __ / __ `/ / __ \ / / / / / / / // ( ) / / / / ( ) // //_,/// /()/ // v0.2.1 //

hash.js is a simple way to safely use a JavaScript object as hash.

Fast: Usage of a regular object as the hash

Safe: Any key can be used. Keys with names that start with "__" are internally escaped to circumvent the mess that JS implementations induce with "magic" properties like proto, count, parent

Installation

npm install hash

Example in node.js

var hash = require('hash')

var existingDataWithEscapedKeys = { __: 1, b: 2, 'parent%': 3 }

var myHash = new hash(existingDataWithEscapedKeys /* optional */)

myHash.set('a', 123) myHash.set('proto', 'value')

myHash.get('parent') // 3 myHash.get('a') // 123 myHash.get('proto') // 'value'

myHash.has('constructor') // false

myHash.del('a')

myHash.get('a') // undefined

myHash.del('parent')

myHash.getData() // { __: 1, b: 2, 'proto%': 'value' }

myHash.forEach(function iterator (value, key) {

// ...

} /*, optionalThisArg */)

Tested in

node.js IE 5.5+, FF 3+, Chrome 1+, Opera 10+, Safari 4+ Mobile Safari 4.0

Further reads

http://www.devthought.com/2012/01/18/an-object-is-not-a-hash/ http://www.2ality.com/2012/01/objects-as-maps.html

Keywords

FAQs

Last updated on 02 Jul 2018

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc