<commit_before># linkstash
[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![Test coverage][coveralls-image]][coveralls-url]
[![Downloads][downloads-image]][downloads-url]

Save [`hal-json`]() `_link` properties and retrieve the latest link in a set.
E.g. after multiple calls for new data in a set you keep pointers to the
oldest and newest data in your set.

## Installation
```bash
npm install linkstash
```

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

var links = linkstash(function(val) {
  return parseInt(val.split('=')[1]);
});

links.set({
  _previous: 'foo.com?until=10',
  _next: 'foo.com?from=100'
});

links.get();
// => {
//  previous: 'foo.com?until=10',
//  next: 'foo.com?from=100'
// }

links.set({
  _previous: 'foo.com?until=100',
  _next: 'foo.com?from=val=190'
});

links.get()
// => {
//  previous: 'foo.com?until=10',
//  next: 'foo.com?from=190'
// }
```

## API
#### var links = linkstash()
Create a new `linkstash` instance. Takes `normalize` function which normalizes
strings to be compared. The function
```js
var linkstash = require('linkstash');

var links = linkstash(function(val) {
  return parseInt(val.splice(10));
});
```

#### links.set()
Pass in a new object with a `previous` and `next` property (either can have an
optional `_` prepended). When setting the values will be parsed through the
earlier set `normalize` function and compared. For `previous` values, the lowest
value remains. For `next` values, the highest value remains.
```js
links({
  previous: 'mysite.com/?until=1234567',
  next: 'mysite.com/?from=7654321'
})

links({
  _previous: 'mysite.com/?until=1234568',
  _next: 'mysite.com/?from=8654321'
})
```

#### links.get()
Get the stored links. Values are returned __without__ prepending `_`.
```js
links.get();
// => {
//   previous: 'mysite.com/?until=1234567',
//   next: 'mysite.com/?from=7654321'
// }
```

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

[npm-image]: https://img.shields.io/npm/v/linkstash.svg?style=flat-square
[npm-url]: https://npmjs.org/package/linkstash
[travis-image]: https://img.shields.io/travis/yoshuawuyts/linkstash.svg?style=flat-square
[travis-url]: https://travis-ci.org/yoshuawuyts/linkstash
[coveralls-image]: https://img.shields.io/coveralls/yoshuawuyts/linkstash.svg?style=flat-square
[coveralls-url]: https://coveralls.io/r/yoshuawuyts/linkstash?branch=master
[downloads-image]: http://img.shields.io/npm/dm/linkstash.svg?style=flat-square
[downloads-url]: https://npmjs.org/package/linkstash<commit_msg>readme: update<commit_after># linkstash
[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![Test coverage][coveralls-image]][coveralls-url]
[![Downloads][downloads-image]][downloads-url]

Save [`hal-json`]() `_link` properties and retrieve the latest link in a set.
E.g. after multiple calls for new data in a set you keep pointers to the
oldest and newest data in your set.

## Installation
```bash
npm install linkstash
```

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

var links = linkstash(function(val) {
  return parseInt(val.split('=')[1]);
});

links.set({
  _previous: 'foo.com?until=10',
  _next: 'foo.com?from=100'
});

links.get();
// => {
//  previous: 'foo.com?until=10',
//  next: 'foo.com?from=100'
// }

links.set({
  _previous: 'foo.com?until=100',
  _next: 'foo.com?from=val=190'
});

links.get()
// => {
//  previous: 'foo.com?until=10',
//  next: 'foo.com?from=190'
// }
```

## API
#### var links = linkstash()
Create a new `linkstash` instance. Takes `normalize` function which normalizes
strings to be compared. The function
```js
var linkstash = require('linkstash');

var links = linkstash(function(val) {
  return parseInt(val.splice(10));
});
```

#### links.set()
Pass in a new object with a `previous` and `next` property (either can have an
optional `_` prepended). When setting the values will be parsed through the
earlier set `normalize` function and compared. For `previous` values, the lowest
value remains. For `next` values, the highest value remains.
```js
links({
  previous: 'mysite.com/?until=1234567',
  next: 'mysite.com/?from=7654321'
})

links({
  _previous: 'mysite.com/?until=1234568',
  _next: 'mysite.com/?from=8654321'
})
```

#### links.get()
Get the stored links. Values are returned __without__ prepending `_`.
```js
links.get();
// => {
//   previous: 'mysite.com/?until=1234567',
//   next: 'mysite.com/?from=7654321'
// }
```

## See also
- [burl][burl]

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

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

[burl]: https://github.com/yoshuawuyts/burl
{'fraction_non_alphanumeric': 0.18786127167630057, 'fraction_numerical': 0.025433526011560695, 'mean_word_length': 4.852311161217587, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 17, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1388851', 'n_tokens_mistral': 2049, 'n_tokens_neox': 1906, 'n_words': 403}