# hash.subscribe

> Subscribe your components to the browser Hash, and get change notifications

Latest version **2.2.0** (published 2016-10-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install hash.subscribe
pnpm add hash.subscribe
yarn add hash.subscribe
bun add hash.subscribe
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.2.0 |
| Published | 2016-10-04 |
| First published | 2016-02-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.10.x |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | raiseandfall |
| Maintainers | raiseandfall |
| Keywords | hash, browser, location |

## Links

- npm: https://www.npmjs.com/package/hash.subscribe
- Repository: https://github.com/raiseandfall/hash.subscribe
- Issues: https://github.com/raiseandfall/hash.subscribe/issues
- npm.io page: https://npm.io/package/hash.subscribe

## Dependencies (1)

- [clone](https://npm.io/package/clone.md) ^1.0.2

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 2.2.0 (latest) — 2016-10-04
- 2.1.0 — 2016-08-03
- 2.0.6 — 2016-08-02
- 2.0.5 — 2016-06-07
- 2.0.4 — 2016-02-08
- 2.0.3 — 2016-02-07
- 2.0.2 — 2016-02-05
- 2.0.1 — 2016-02-05
- 2.0.0 — 2016-02-05
- 1.1.0 — 2016-02-04
- 1.0.1 — 2016-02-04
- 1.0.0 — 2016-02-02

## README

# Hash.subscribe 

[![Build
Status](https://travis-ci.org/raiseandfall/hash.subscribe.svg)](https://travis-ci.org/raiseandfall/hash.subscribe)
[![js-semistandard-style](https://img.shields.io/badge/code%20style-semistandard-brightgreen.svg?style=flat-square)](https://github.com/Flet/semistandard)

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](./CHANGELOG.md)

## INSTALL
```shell
$ npm install hash.subscribe
```

## USAGE
```javascript
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
```shell
$ git clone git@github.com:raiseandfall/Hash.subscribe.git && cd Hash.subscribe
$ npm run dev
```

### Run tests independently
```shell
$ npm run test
```

## LICENSE
MIT

---
_Source: https://npm.io/package/hash.subscribe · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
