location-hash-stream
v2.0.0
Published
duplex streaming interface to the location hash
Downloads
8
Maintainers
Readme
location-hash-stream
streaming interface to the window location hash
example
Emits the location hash whenever it changes. Uses the hashchange event under the hood, so browser support is dictated therein.
const hashStream = require('location-hash-stream')
const stream = hashStream()
hashStream.on('data', data => console.log(data))
window.location.hash = 'lol'
// logs '#lol'
Writing to the stream sets the location hash.
const hashStream = require('location-hash-stream')
const stream = hashStream()
hashStream.write('hash')
// window.location.hash is now '#hash'
API
hashStream([opts]) -> stream
opts
is an optional configuration object. Available options are:stripHash
aBoolean
specifying whether the emitted location hash should be stripped of its leading#
character. Defaults tofalse
.
stream.getHash()
-> Retrieve the current hash string, respects thestripHash
parameter.
license
MIT