Socket
Book a DemoInstallSign in
Socket

halster

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

halster

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

latest
Source
npmnpm
Version
1.3.0
Version published
Maintainers
1
Created
Source

halster

NPM version build status Test coverage Downloads

Extract and store hal previous and next links.

Installation

npm install halster

Usage

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

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

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.

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.

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

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

See also

  • burl
  • linkstash

License

MIT

Keywords

hal

FAQs

Package last updated on 20 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