https://github.com/bendrucker/observ-path
Observable interface to the browser path with history support
https://github.com/bendrucker/observ-path
Last synced: 3 months ago
JSON representation
Observable interface to the browser path with history support
- Host: GitHub
- URL: https://github.com/bendrucker/observ-path
- Owner: bendrucker
- License: mit
- Created: 2015-09-24T19:32:07.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2019-08-19T21:59:06.000Z (almost 7 years ago)
- Last Synced: 2025-10-26T10:58:38.993Z (9 months ago)
- Language: JavaScript
- Homepage:
- Size: 7.81 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# observ-path [](https://travis-ci.org/bendrucker/observ-path) [](https://greenkeeper.io/)
> Observable interface to the browser path with history support
## Install
```
$ npm install --save observ-path
```
## Usage
```js
var Path = require('observ-path')
var path = Path('/the/initial/path')
path(console.log)
//=> path changed
path.set('/the/new/path')
//=> path updated and history entry added
```
## API
#### `Path([value])` -> `function`
Returns an observable `path`.
##### value
Type: `string`
Default: `''`
The initial path, defaulting to `document.location.pathname` in the browser and `''` in Node.
#### `path([fn])` -> `function` / `string`
##### fn
Type: `function`
A function to call when the path changes. If no function is provided, the current value is returned.
#### `path.set(value)` -> `undefined`
##### value
*Required*
Type: `string`
The new path value to set.
## License
MIT © [Ben Drucker](http://bendrucker.me)