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

kokua

v1.3.3

Published

Hypermedia Representor Using Hyper+JSON

Downloads

25

Readme

Kōkua - Hypermedia Representor

Kōkua (Hawaiian) - help, aid, assistance

NPM Version Build Test Coverage

Kōkua is an implementation of the Representor pattern, written in modern Javascript/Node. It allows developers to represent hypermedia messages in a flexible media type, purpose-designed for the task: Hyper and automatically outputs messages in a variety of popular Hypermedia formats such as:

  1. HAL (application/hal+json)
  2. Siren (application/vnd.siren+json)
  3. Collection+JSON (application/vnd.collection+json)
  4. UBER (application/vnd.uber+json)
  5. JSON API (application/vnd.api+json)
  6. etc.

Usage

Convert a Hyper document to other formats

  const kokua = require("kokua");
  let halDoc = kokua(hyperDoc, kokua.mt('hal'));

where the first argument to a kokua() call is a JSON document formatted as a Hyper document, and the second argument is the name of a supported media-type that we want the message to be translated to.

Convert a document in another format to Hyper

  const kokua = require("kokua");
  let uberDoc = kokua.parse(halDoc, kokua.mt('hal'));

where the first argument to a kokua.parse() call is a JSON document formatted in a media type, supported by Kokua, and the second argument is the name of a supported media-type that we want the message to be translated from.

Please see the official specification for Hyper media type, for more details about the format.

Advanced Example


  const hyperDoc = const hyper = {
    "h:head": {"curies": {"ea": "http://example.com/docs/rels/"}},
    "h:ref": {"self": "/orders", "next": "/orders?page=2"},
    "currentlyProcessing": 14, "shippedToday": 20,
    "ea:order": [
      {
        "h:ref": {
          "self": "/orders/123",
          "ea:basket": "/baskets/98712",
          "ea:customer": "/customers/7809"
        },
        "total": 30, "currency": "USD", "status": "shipped"
      },
      {
        "h:ref": {
          "self": "/orders/123",
          "ea:basket": "/baskets/98712",
          "ea:customer": "/customers/124234"
        },
        "total": 123, "currency": "USD", "status": "pending"
      }
    ]
  };

  const kokua = require("kokua");
  let halDoc = kokua(hyperDoc, kokua.mt('hal'));
  let sirenDoc = kokua(hyperDoc, kokua.mt('siren'));

Implementation Status

  1. Hyper to HAL: 100%
    • Reverse: 0%
  2. Hyper to Siren: 100%
    • Reverse: 100%
  3. Hyper to UBER: 0%
    • Reverse: 0%
  4. Hyper to Collection+JSON: 0%
    • Reverse: 0%
  5. Hyper to JSONAPI: 0%
    • Reverse: 0%

Quick-n-dirty benchmark

> node benchmark.js
Time to convert HAL 10,000 times:  2.572 ms
Time to convert Siren 10,000 times:  1.42 ms

Plugin Development

If you are interested in developing a new plugin to implement translation to a hypermedia format that is not yet implemented, please refer to README-PLUGINDEV