GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - raiseandfall/hash.subscribe: Subscribe anything to the browser Hash location changes.

BranchesTags
Open more actions menu

Latest commit

 

History

47 Commits
47 Commits

Folders and files

NameName
Last commit message
Last commit date
.editorconfig
.editorconfig
 
 
.gitignore
.gitignore
 
 
.jshintrc
.jshintrc
 
 
.python-version
.python-version
 
 
.travis.yml
.travis.yml
 
 
CHANGELOG.md
CHANGELOG.md
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
index.js
index.js
 
 
package.json
package.json
 
 
tests.js
tests.js
 
 

Repository files navigation

Hash.subscribe

Build Status js-semistandard-style Downloads

A browser hash listener system using query string style parameters ( #foo=bar&baz=qux ), based on the subscribe design pattern.

Features:

  • Browser Hash initialization
  • Subscribe to Hash specific parameters
  • Set specific Hash parameter
  • Mute / Unmute subscription

CHANGELOG

INSTALL

$ npm install hash.subscribe

USAGE

var Hash = require('hash.subscribe');

// Init browser hash
Hash.init('foo=bar');

// Set parameters (object)
Hash.setHash({
  foo: ['bar'],
  baz: ['qux']
});

// Set hash (string)
Hash.setHash('foo=bar&baz=qux');

// Update one key value
Hash.updateHashKeyValue('foo', ['bar1', 'bar2']);

// Delete one param
Hash.deleteParam('baz');

// Subscribe to parameter(s)
Hash.subscribe(['foo', 'baz'], function(params) {
  if (params.foo.changed) {
    console.log('Param Foo has changed : ' + params.foo.values);
  }
});

// More examples in the test file...

API

init(hash)

Parameter:

  • hash - String | Object - default hash to initialize the page with

getHash(keepHash)

Get current hash
Parameter:

  • keepHash - Boolean - whether or not to keep the hash character in the return string
    Returns: String

getParams

Get current hash parameters
Returns: Object

getParam(key)

Get values of one hash parameter
Parameter:

  • key - string - parameter name
    Returns: Array

setHash(hash)

Updates current hash
Parameter:

  • hash - String | Object - new hash

updateHashKeyValue(key, value)

Updates one hash key
Parameters:

  • key - String - hash key to update
  • value - Array - new value(s) for key

deleteParam(params)

Deletes hash param(s)
Parameter:

  • params - String | Array - param(s) name(s) to delete

subscribe([hashParameters], callback)

Subscribe to specific parameters
Parameters:

  • hashParameters - Array - Array of parameters names you want to subscribe to
  • callback - Function - Callback function called when a parameter has changed

mute()

Mutes subscription to Hash

unmute()

Resume subscription to Hash

destroy()

Destroys current hash value

CONTRIBUTE

Development task

$ git clone [email protected]:raiseandfall/Hash.subscribe.git && cd Hash.subscribe
$ npm run dev

Run tests independently

$ npm run test

LICENSE

MIT

About

Subscribe anything to the browser Hash location changes.

www.npmjs.com/package/hash.subscribe

Topics

hashnpmnpm-packageurl-hash

Resources

Readme
MIT license
Activity

Stars

3 stars

Watchers

2 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.