location-hash-stream

2.0.0 • Public • Published

location-hash-stream

Build Status npm install npm version js-standard-style License

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 a Boolean specifying whether the emitted location hash should be stripped of its leading # character. Defaults to false.
  • stream.getHash() -> Retrieve the current hash string, respects the stripHash parameter.

license

MIT

Package Sidebar

Install

npm i location-hash-stream

Weekly Downloads

1

Version

2.0.0

License

MIT

Last publish

Collaborators

  • jarofghosts