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

hal9k

v1.0.1

Published

A pure JavaScript library for creating, modifying and validating HAL conform objects based on draft-kelly-json-hal-08

Downloads

5

Readme

coliquio Build Status

hal9k - coliquio's internal HAL library

A pure JavaScript library for creating, modifying and validating HAL conform objects based on draft-kelly-json-hal-08

Requirements

Installation

npm install hal9k

Example

Basic Resource

const hal9k = require('hal9k');
hal9k.resource()
.link('self', '/order/123')
.state({
    "currency": "USD",
    "status": "shipped",
    "total": 10.20
});

API

hal9k

const hal9k = require('hal9k');

hal9k.fromJSON(json) - Create a resource from JSON

// As object...
hal9k.fromJSON({
 _links: {
   self: { href: '/orders' },
   curies: [{
     name: 'acme',
     href: 'http://docs.acme.com/relations/{rel}',
     templated: true
   }],
   'acme:widgets': { href: '/widgets' }
 }
});

// or as string.
hal9k.fromJSON('{
    "_links": {
        "self": {
            "href": "/orders/523"
        },
        "warehouse": {
            "href": "/warehouse/56"
        },
        "invoice": {
            "href": "/invoices/873"
        }
    },
    "currency": "USD",
    "status": "shipped",
    "total": 10.20
}');

hal9k.isValidHal(json) - Validates resource syntax and structure

Possible inputs
// As json string...
hal9k.isValidHAL('{
    "_links": {
        "self": {
            "href": "/orders/523"
        },
        "warehouse": {
            "href": "/warehouse/56"
        },
        "invoice": {
            "href": "/invoices/873"
        }
    },
    "currency": "USD",
    "status": "shipped",
    "total": 10.20
}');

// as json object...
hal9k.isValidHAL({
    "_links": {
        "self": {
            "href": "/orders/523"
        },
        "warehouse": {
            "href": "/warehouse/56"
        },
        "invoice": {
            "href": "/invoices/873"
        }
    },
    "currency": "USD",
    "status": "shipped",
    "total": 10.20
});

// or as resource object
hal9k.isValidHAL(
    hal9k.resource({
        "currency": "USD",
        "status": "shipped",
        "total": 10.20
    })
    .link('self', '/orders/523')
    .link('warehouse', '/warehouse/56')
    .link('invoice', '/invoices/873')
);
Possible outputs
// valid Hal
{
    warnings: [],
    errors: []
}
// with warnings
{
    warnings: [
        {
            resourceRel: 'root',
            title: 'missing self link',
            description: 'Each Resource Object SHOULD contain a self link.'
        }
    ],
    errors: []
}
// with errors
{
    warnings: [],
    errors: [
        {
            resourceRel: 'yourResource',
            title: 'missing href in link',
            description: 'The "href" property is REQUIRED.'
        }
    ]
}

hal9k.resource(data) - Create a resource object

// creates an empty resource
hal9k.resource();

// resource with state
hal9k.resource({
    "currency": "USD",
    "status": "shipped",
    "total": 10.20
});

The resource object chains

.link(rel, href, optionalParams) - Add links

optionalParams:
href, templated, type, deprecation, name, profile, title, hreflang

hal9k.resource()
.link('self', '/example/href/2');

hal9k.resource()
.link('self', '/example/href', {
    type: 'json',
    deprecation: 'url/to/further/information/concerning/deprecation',
    name: 'sample name'
});

hal9k.resource()
.link('self', {
    href: '/example/href',
    type: 'json',
    deprecation: 'url/to/further/information/concerning/deprecation',
    name: 'sample name'
});

hal9k.resource()
.link('items', [
    '/first_item',
    '/second_item'
]);

.embed(rel, resource) - Embed resources

hal9k.resource()
.link('self', '/example/href/2')
.embed('order', hal9k.resource());

hal9k.resource()
.link('self', '/example/href/2')
.embed('orders', [
    hal9k.resource(),
    hal9k.resource()
]);

.state(data) - Add state

hal9k.resource()
.link('self', '/example/href/2')
.state({
    key1: 'value1',
    key2: 'value2',
    key3: 'value3',
});

.toJSON() - Returns valid HAL-JSON-Object (end of chain)

Input
hal9k.resource({
    "currency": "USD",
    "status": "shipped",
    "total": 10.20
})
.link('self', '/orders/523')
.link('warehouse', '/warehouse/56')
.link('invoice', '/invoices/873')
.toJSON();
Result
{
 "_links": {
   "self": { "href": "/orders/523" },
   "warehouse": { "href": "/warehouse/56" },
   "invoice": { "href": "/invoices/873" }
 },
 "currency": "USD",
 "status": "shipped",
 "total": 10.20
}

.curie(name, href) - Add a link relation abbreviated via CURIE syntax

Input
hal9k.resource()
.link('self', '/orders')
.curie('acme', 'http://docs.acme.com/relations/{rel}')
.link('acme:widgets', '/widgets')
.toJSON();
Result
{
    "_links": {
        "self": {
            "href": "/orders"
        },
        "curies": [{
            "name": "acme",
            "href": "http://docs.acme.com/relations/{rel}",
            "templated": true
        }],
        "acme:widgets": {
            "href": "/widgets"
        }
    }
}

License

See LICENSE.

About

coliquio ist mit über 170.000 registrierten Ärzten aller Fachrichtungen das größte Ärzte-Netzwerk im deutschsprachigen Raum.

coliquios Applikationslandschaft setzt auf eine moderne Microservice-basierte Architektur. Standardisierte API sind daher ein großer und wichtiger Teil unserer Arbeit. HAL (Hypertext Application Language) hilft uns unsere API von innen heraus zu entdecken und erleichtert das schnelle Arbeiten mit den Schnittstellen. Ein wichtiger Faktor um unsere Produktivität zu erhöhen. Diese Library ist nach dem neuesten HAL Draft erstellt worden.

coliquio is today with over 170,000 physicians of all disciplines the largest medical community in the German-speaking world.

coliquios application landscape is based on a modern microservice architecture. Standardized APIs are therefore a large and important part of our business. HAL (Hypertext Application Language) helps us to discover our APIs and facilitate fast working with our interfaces. It's an important factor to increase our productivity. This library has been created according to the latest HAL Draft.

Disclaimer

This is a project for the community, from developers for developers. This is NOT an official coliquio product. I.e. Maintenance and support are provided by the individual developers but not officially by coliquio.