Socket
Book a DemoInstallSign in
Socket

linkstash

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

linkstash

Save hal-json _link properties and retrieve the latest link in a set.

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

linkstash

NPM version build status Test coverage Downloads

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

npm install linkstash

Usage

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

Create a new linkstash instance. Takes normalize function which normalizes strings to be compared. The function

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.

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 _.

links.get();
// => {
//   previous: 'mysite.com/?until=1234567',
//   next: 'mysite.com/?from=7654321'
// }

See also

  • burl

License

MIT

Keywords

hal

FAQs

Package last updated on 14 Oct 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts