Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hashbind

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hashbind

Dual Binding Library For window.location.hash

  • 2.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
increased by200%
Maintainers
1
Weekly downloads
 
Created
Source

Hash Bind

A dual-binding library for window.location.hash

Example

var Hash = require('hashbind');
var Result = require('rezult');

var hash = new Hash(window);

// Simple usage as a key-value store:
var someVal = hash.get('setting');
hash.set('setting', someVal);

// Better still, bind the value:
var bound = hash.bind('setting')
    .addListener(function onSettingChange(val) {
        console.log('the setting is', val);
    })
    ;

// Maybe you wanted an integer setting:
var bound = hash.bind('setting')
    .setParse(Result.lift(parseInt))
    .addListener(function onSettingChange(val) {
        console.log('the setting is', val);
    })
    ;

// Maybe you wanted a default:
var bound = hash.bind('setting')
    .setParse(Result.lift(parseInt))
    .setDefault('42')
    .addListener(function onSettingChange(val) {
        console.log('the setting is', val);
    })
    ;

// You can still set it by name:
hash.set('setting', 99);

// You can also set it through the bound reference:
bound.set(99);

// If you care to handle parse errors when settingy our values (rather than
have them thrown):
bound.set('XXX', function setDone(err, str, val) {
    // err is null or the parse error
    // str is the string that was parsed
    // val is the value returned by the parser
    console.error(err);
});

MIT Licensed

Keywords

FAQs

Package last updated on 02 Jan 2017

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

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc