npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@b-social/halboy

v0.8.6

Published

a hypermedia parser and navigator

Downloads

1

Readme

halboy.js

CircleCI npm version

A library for all things hypermedia.

  • Create hypermedia resources
  • Marshal to and from plain JS objects
  • Navigate JSON+HAL APIs

API

Resources

With Halboy you can create resources, and pull information from them.

import { Resource } from 'halboy'

const discountResource =
  new Resource()
    .addLink('self', '/discounts/1256')
    .addProperty('discountPercentage', 10)

const itemResources = [
  new Resource()
    .addLink('self', '/items/534')
    .addProperty('price', 25.48)
]

const resource =
    new Resource()
      .addLink('self', '/orders/123')
      .addLink('creator', '/users/rob')
      .addResource('discount', discountResource)
      .addResource('items', itemResources)
      .addProperty('state', 'dispatching')

resource.getLink('self')
// { href: '/orders/123' }

resource.getHref('self')
// '/orders/123'

resource.getProperty('state')
// 'dispatching'

resource
  .getResource('creator')
  .getProperty('discountPercentage')
// 10

resource
  .getResource('items')[0]
  .getProperty('price')
// 25.48

Marshalling

You can create HAL resources from plain JS objects, and vice versa.

import { Resource } from 'halboy'

const itemResources = [
  new Resource()
    .addLink('self', '/items/534')
    .addProperty('price', 25.48)
]

const resource =
    new Resource()
      .addLink('self', '/orders/123')
      .addLink('creator', '/users/rob')
      .addResource('items', itemResources)
      .addProperty('state', 'dispatching')

resource.toObject()
// {
//   _links: {
//     self: { href: '/orders/123' },
//     creator: { href: '/users/rob' }
//   },
//   _embedded: {
//     items: [{
//       _links: {
//         self: { href: '/items/534' }
//       },
//       price: 25.48
//     }]
//   },
//   state: 'dispatching'
// }

Resource.fromObject(resource.toObject())
  .getHref('self')
// '/orders/123'

Navigation

Provided you're calling a HAL+JSON API, you can discover the API and navigate through its links. When you've found what you want, you call navigator.resource() and you get a plain old HAL resource, which you can inspect using any of the methods above.

import { Navigator } from 'halboy'

//  GET / - 200 OK
//  {
//   "_links": {
//     "self": {
//       "href": "/"
//     },
//     "users": {
//       "href": "/users"
//     },
//     "user": {
//       "href": "/users/{id}",
//       "templated": true
//     }
//   }
// }

const discoveryResult = await Navigator.discover('https://api.example.com/')
const usersResult = await discoveryResult.get('users')

usersResult.status()
// 200

usersResult.location()
// 'https://api.example.com/users'

const robResult = await discoveryResult.get('user', {id :'rob'})

robResult.location()
// 'https://api.example.com/users/rob'

const sueResult = await discoveryResult.post('user', {
  id: 'sue',
  name: 'Sue',
  title: 'Dev'
})

sueResult.location()
// 'https://api.example.com/users/sue'

sueResult
  .resource()
  .getProperty('title')
// 'Dev'