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.0.0 to 1.1.0

.npmignore

135

index.js

@@ -21,3 +21,4 @@ 'use strict';

Hash.prototype.load = function load() {
Hash.prototype.load =
function load() {
if (this.window.location.hash === this.last) {

@@ -30,7 +31,5 @@ return;

var seen = {};
var i;
var key;
for (i = 0; i < parts.length; i++) {
for (var i = 0; i < parts.length; i++) {
var keyval = parts[i].split('=');
key = unescape(keyval[0]);
var key = unescape(keyval[0]);
var str = unescape(keyval[1]) || '';

@@ -47,12 +46,19 @@ if (this.cache[key] !== str) {

}
this.prune(seen);
};
Hash.prototype.prune =
function prune(except) {
if (!except) {
except = {};
}
var cacheKeys = Object.keys(this.cache);
for (i = 0; i < cacheKeys.length; i++) {
key = cacheKeys[i];
if (!seen[key]) {
for (var i = 0; i < cacheKeys.length; i++) {
var key = cacheKeys[i];
if (!except[key]) {
if (this.bound[key]) {
this.bound[key].reset();
} else {
this.cache[key] = undefined;
this.values[key] = undefined;
delete this.cache[key];
delete this.values[key];
}

@@ -63,5 +69,5 @@ }

Hash.prototype.save = function save() {
var hash = '';
Hash.prototype.save =
function save() {
var parts = [];
var keys = Object.keys(this.cache);

@@ -81,8 +87,8 @@ for (var i = 0; i < keys.length; i++) {

}
parts.push(part);
}
if (hash !== '') {
hash += '&' + part;
} else {
hash += '#' + part;
}
var hash = parts.join('&');
if (hash) {
hash = '#' + hash;
}

@@ -93,3 +99,4 @@

Hash.prototype.bind = function bind(key) {
Hash.prototype.bind =
function bind(key) {
if (this.bound[key]) {

@@ -103,11 +110,14 @@ throw new Error('key already bound');

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

@@ -124,6 +134,9 @@ return bound.set(val);

this.valToString = valueToString;
this.listener = null;
this.listeners = [];
this.notify = this.notifyNoop;
}
HashKeyBinding.prototype.load = function load() {
HashKeyBinding.prototype.load =
function load() {
var str = this.hash.cache[this.key];

@@ -141,3 +154,4 @@ if (str !== undefined) {

HashKeyBinding.prototype.save = function save() {
HashKeyBinding.prototype.save =
function save() {
this.hash.values[this.key] = this.value;

@@ -152,3 +166,15 @@ var str = this.valToString(this.value);

HashKeyBinding.prototype.notify = function notify() {
HashKeyBinding.prototype.notifyNoop =
function notifyNoop() {
return this;
};
HashKeyBinding.prototype.notifyOne =
function notifyOne() {
this.listener(this.value);
return this;
};
HashKeyBinding.prototype.notifyAll =
function notifyAll() {
for (var i = 0; i < this.listeners.length; i++) {

@@ -160,3 +186,4 @@ this.listeners[i].call(this, this.value);

HashKeyBinding.prototype.setParse = function setParse(parse, toString) {
HashKeyBinding.prototype.setParse =
function setParse(parse, toString) {
this.parse = parse || parseValue;

@@ -170,3 +197,4 @@ this.load();

HashKeyBinding.prototype.setToString = function setToString(toString) {
HashKeyBinding.prototype.setToString =
function setToString(toString) {
this.valToString = toString;

@@ -179,32 +207,50 @@ if (this.value !== undefined) {

HashKeyBinding.prototype.addListener = function addListener(listener) {
HashKeyBinding.prototype.addListener =
function addListener(listener) {
if (this.listeners.length) {
this.listeners.push(listener);
} else if (this.listener) {
this.listeners = [this.listener, listener];
this.listener = null;
this.notify = this.notifyAll;
} else {
this.listener = listener;
this.notify = this.notifyOne;
}
if (this.value !== undefined) {
listener(this.value);
this.notify();
}
this.listeners.push(listener);
return this;
};
HashKeyBinding.prototype.setDefault = function setDefault(def) {
HashKeyBinding.prototype.setDefault =
function setDefault(def) {
var value = null;
if (typeof def === 'string') {
def = this.parse(def);
value = this.parse(def);
} else {
value = def;
}
this.def = def;
this.def = value;
if (this.value === undefined) {
this.value = def;
this.value = this.def;
this.save();
}
return this;
};
HashKeyBinding.prototype.onChange = function onChange() {
HashKeyBinding.prototype.onChange =
function onChange() {
this.load();
return this;
};
HashKeyBinding.prototype.get = function get() {
HashKeyBinding.prototype.get =
function get() {
return this.value;
};
HashKeyBinding.prototype.reset = function reset() {
HashKeyBinding.prototype.reset =
function reset() {
if (this.value !== this.def) {

@@ -214,11 +260,16 @@ this.value = this.def;

}
return this;
};
HashKeyBinding.prototype.set = function set(val) {
HashKeyBinding.prototype.set =
function set(val) {
var value = null;
if (typeof val === 'string') {
val = this.parse(val);
value = this.parse(val);
} else {
value = val;
}
if (this.value !== val) {
this.value = val;
if (this.value !== value) {
this.value = value;
this.notify();

@@ -225,0 +276,0 @@ this.save();

{
"name": "hashbind",
"version": "1.0.0",
"version": "1.1.0",
"description": "Dual Binding Library For window.location.hash",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "npm run lint",
"lint": "standard ."
},

@@ -23,3 +24,6 @@ "repository": {

},
"homepage": "https://github.com/jcorbin/hashbind"
"homepage": "https://github.com/jcorbin/hashbind",
"devDependencies": {
"uber-standard": "^4.0.1"
}
}
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