# halster

> Extract and store `hal` `previous` and `next` links

Latest version **1.3.0** (published 2014-10-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install halster
pnpm add halster
yarn add halster
bun add halster
```

## 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 | 1.3.0 |
| Published | 2014-10-20 |
| First published | 2014-10-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | yoshuawuyts |
| Keywords | hal, links, extract |

## Links

- npm: https://www.npmjs.com/package/halster
- Repository: https://github.com/yoshuawuyts/halster
- Issues: https://github.com/yoshuawuyts/halster/issues
- npm.io page: https://npm.io/package/halster

## Dependencies (2)

- [burl](https://npm.io/package/burl.md) ^1.0.1
- [burl-invert](https://npm.io/package/burl-invert.md) ^2.0.0

## Alternatives

- [localforage](https://npm.io/package/localforage.md) — 6.2M weekly downloads
- [localforage-observable](https://npm.io/package/localforage-observable.md) — 30.8K weekly downloads
- [@y/y](https://npm.io/package/@y/y.md) — 30.1K weekly downloads
- [@metaobjectsdev/render](https://npm.io/package/@metaobjectsdev/render.md) — 3.5K weekly downloads
- [@ledgerhq/coin-algorand](https://npm.io/package/@ledgerhq/coin-algorand.md) — 1.1K weekly downloads

## Recent versions

- 1.3.0 (latest) — 2014-10-20
- 1.2.2 — 2014-10-16
- 1.2.1 — 2014-10-15
- 1.2.0 — 2014-10-15
- 1.1.0 — 2014-10-15
- 1.0.1 — 2014-10-15
- 1.0.0 — 2014-10-15

## README

# halster
[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![Test coverage][coveralls-image]][coveralls-url]
[![Downloads][downloads-image]][downloads-url]

Extract and store `hal` `previous` and `next` links.

## Installation
```bash
npm install halster
```

## Usage
```js
var halster = require('halster');

var links = halster({
  default: function() {
    return 'http://mysite.com/api';
  },
  previous: function(val) {
    return 'http://mysite.com/api?until=' + val;
  },
  next: function(val) {
    return 'http://mysite.com/api?from=' + val;
  },
  normalize: function(val) {
    return val.splice(13)[1];
  }
});

links.set({
  _links: {
    previous: {
      url: 'until=12345677'
    },
    next: {
      url: 'from=12345677'
    }
  }
});

links.get({previous: true});
// => 'http://mysite.com/api?until=12345677'
```

## API
#### var links = halster()
Create a new halster instance. Takes an object of arguments. `default` is the
default link to use if no `previous` or `next` were given. If `previous` or
`default` are given the links are passed down to [`burl`][burl] and handled
there. The `normalize` link functions the same as in `burl`, converting urls
into integers that can be compared to determine the newest / oldest link.
Optionally you can also set `invert: true` to flip `next` and `previous`.
```js
var halster = require('halster');

var links = halster({
  default: function() {
    return 'http://mysite.com/api';
  },
  previous: function(val) {
    return 'http://mysite.com/api?until=' + val;
  },
  next: function(val) {
    return 'http://mysite.com/api?from=' + val;
  },
  normalize: function(val) {
    return val.splice(13)[1];
  }
});
```

#### .set()
Pass in an object with a `links` / `_links` property and save the correct link
within halster.
```js
links.set({
  _links: {
    previous: {
      url: 'until=12345677'
    },
    next: {
      url: 'from=12345677'
    }
  }
});
```

#### .get()
Get an url. Can be passed an object with either `next` or `previous` set to true
for the corresponding link. If no argument is provided the default link will be
returned.
```js
links.get({previous: true});
// => 'http://mysite.com/api?until=12345677'

links.get();
// => 'http://mysite.com/api'
```

## See also
- [burl][burl]
- [linkstash][linkstash]

## License
[MIT](https://tldrlegal.com/license/mit-license)

[npm-image]: https://img.shields.io/npm/v/halster.svg?style=flat-square
[npm-url]: https://npmjs.org/package/halster
[travis-image]: https://img.shields.io/travis/yoshuawuyts/halster.svg?style=flat-square
[travis-url]: https://travis-ci.org/yoshuawuyts/halster
[coveralls-image]: https://img.shields.io/coveralls/yoshuawuyts/halster.svg?style=flat-square
[coveralls-url]: https://coveralls.io/r/yoshuawuyts/halster?branch=master
[downloads-image]: http://img.shields.io/npm/dm/halster.svg?style=flat-square
[downloads-url]: https://npmjs.org/package/halster

[burl]: https://github.com/yoshuawuyts/burl
[linkstash]: https://github.com/yoshuawuyts/linkstash

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