0.1.2 • Published 9 years ago
hashstate v0.1.2
hashstate
Location hash manager for the web inspired by YUI3.
Installation
cortex install hashstate --saveUsage
var hashState = require('hashstate')(options);- options
Object=- prefixString='!'Prefix to prepend when setting the hash fragment. Default to'!'- splitString=','String to split the key-value pairs. - assignString='='String to join key and value of a key-value pair. - windowWindow=
The instance of hashState is an EventEmitter.
.stringify(object)
Returns String , excluding options.prefix.
hashState.stringify({a: 1, b: 'c'}); // 'a=1,b=c'.parse(string)
Parses the given string and returns Object the parsed object according to options.split and options.assign.
// Will deal with the leading '#!'
hashState.parse('#!a=1,b=c'); // {a: '1', b: 'c'}
hashState.parse('!a=1,b=c'); // {a: '1', b: 'c'}
hashState.parse('#a=1,b=c'); // {a: '1', b: 'c'}
hashState.parse('a=1,b=c'); // {a: '1', b: 'c'}.setHash(hash, options)
- hash
Stringhash string. - options
Object- muteBooleaniftrue, calling this method will not emit a'hashchange'event.
Changes the current location hash, which will add a new history entry.
.replaceHash(hash, options)
- hash
Stringhash string. - options
Object- muteBooleaniftrue, calling this method will not emit a'hashchange'event.
Changes location hash and replaces the current history entry instead of adding a new entry.
.getHash()
Returns the current hash string, excluding the leading '#' and options.prefix.
Event: hashchange
- e
Object- newHash
Stringthe new(current) hash string. - oldHash
Stringthe old hash string.
- newHash
Emitted when hash changes.
hashState.on('hashchange', function(e){
console.log('hashchange:', e.newHash);
});