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 - npm Package Compare versions

Comparing version 1.1.0 to 2.0.0

42

index.js
'use strict';
var Result = require('rezult');
module.exports = Hash;

@@ -39,3 +41,7 @@

} else {
this.values[key] = parseValue(str);
var res = parseValue(str);
if (!res.err) {
// intentional ignore parse error; best-effort load
this.values[key] = res.value;
}
}

@@ -116,5 +122,5 @@ }

Hash.prototype.set =
function set(key, val) {
function set(key, val, callback) {
var bound = this.bound[key] || this.bind(key);
return bound.set(val);
return bound.set(val, callback);
};

@@ -138,3 +144,8 @@

if (str !== undefined) {
var val = this.parse(str);
var res = this.parse(str);
if (res.err) {
// intentional ignore parse error; best-effort load
return this;
}
var val = res.value;
if (this.value !== val) {

@@ -220,3 +231,3 @@ this.value = val;

if (typeof def === 'string') {
value = this.parse(def);
value = this.parse(def).toValue();
} else {

@@ -255,6 +266,15 @@ value = def;

HashKeyBinding.prototype.set =
function set(val) {
function set(val, callback) {
var value = null;
if (typeof val === 'string') {
value = this.parse(val);
var res = this.parse(val);
if (callback) {
callback(res.err, val, res.value);
if (res.err) {
return undefined;
}
value = res.value;
} else {
value = res.toValue();
}
} else {

@@ -285,11 +305,11 @@ value = val;

if (str === '' || str === 'true') {
return true;
return new Result(null, true);
}
if (str === 'false') {
return false;
return new Result(null, false);
}
if (str === 'null') {
return null;
return new Result(null, null);
}
return str;
return new Result(null, str);
}
{
"name": "hashbind",
"version": "1.1.0",
"version": "2.0.0",
"description": "Dual Binding Library For window.location.hash",

@@ -25,2 +25,5 @@ "main": "index.js",

"homepage": "https://github.com/jcorbin/hashbind",
"dependencies": {
"rezult": "^1.1.0"
},
"devDependencies": {

@@ -27,0 +30,0 @@ "uber-standard": "^4.0.1"

@@ -8,2 +8,5 @@ # [Hash Bind](//jcorbin.github.io/hashbind)

```javascript
var Hash = require('hashbind');
var Result = require('rezult');
var hash = new Hash(window);

@@ -24,3 +27,3 @@

var bound = hash.bind('setting')
.setParse(parseInt)
.setParse(Result.lift(parseInt))
.addListener(function onSettingChange(val) {

@@ -33,3 +36,3 @@ console.log('the setting is', val);

var bound = hash.bind('setting')
.setParse(parseInt)
.setParse(Result.lift(parseInt))
.setDefault('42')

@@ -46,4 +49,14 @@ .addListener(function onSettingChange(val) {

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
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