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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@siren-js/core

v0.4.0

Published

Cross-platform library of classes for generating and parsing Siren entities

Readme

Siren.js Core

Node Package Build Status standard-readme compliant License Contributing

Cross-platform library of classes for generating and parsing Siren entities.

Table of Contents

Install

npm install @siren-js/core

Usage

Creating an Entity

Here's a simple example of generating an entity:

import * as Siren from '@siren-js/core';

const person = Siren.Entity.of({
  class: ['Person'],
  properties: {
    givenName: 'Neville',
    familyName: 'Longbottom',
    birthDate: '1980-07-30'
  },
  links: [
    {
      rel: ['self'],
      href: 'https://api.example.com/people/69'
    }
  ]
});

Here is a more complete example building out the order entity example from the Siren spec:

const order = {
  orderNumber: 42,
  itemCount: 3,
  status: 'pending',
  customer: {
    userId: 'pj123',
    name: 'Peter Joseph'
  }
};

const orderEntity = Siren.Entity.of({
  class: ['order'],
  properties: {
    orderNumber: order.orderNumber,
    itemCount: order.itemCount,
    status: order.status
  },
  entities: [
    {
      class: ['items', 'collection'],
      rel: ['http://x.io/rels/order-items'],
      href: `http://api.x.io/orders/${order.orderNumber}/items`
    },
    {
      class: ['info', 'customer'],
      rel: ['http://x.io/rels/customer'],
      properties: {
        customerId: order.customer.userId,
        name: order.customer.name
      },
      links: [
        {
          rel: ['self'],
          href: `http://api.x.io/customers/${order.customer.userId}`
        }
      ]
    }
  ],
  actions: [
    {
      name: 'add-item',
      title: 'Add Item',
      method: 'POST',
      href: `http://api.x.io/orders/${order.orderNumber}/items`,
      type: 'application/x-www-form-urlencoded',
      fields: [
        { name: 'orderNumber', type: 'hidden', value: `${order.orderNumber}` },
        { name: 'productCode', type: 'text' },
        { name: 'quantity', type: 'number' }
      ]
    }
  ],
  links: [
    {
      rel: ['self'],
      href: `http://api.x.io/orders/${order.orderNumber}`
    },
    {
      rel: ['previous'],
      href: `http://api.x.io/orders/${order.orderNumber - 1}`
    },
    {
      rel: ['next'],
      href: `http://api.x.io/orders/${order.orderNumber + 1}`
    }
  ]
});

Generating an Entity

Use the stringify function to convert an Entity into Siren JSON (application/vnd.siren+json).

const siren = Siren.stringify(person);
// => "{ "class": ["Person"], ... }"

Parsing Siren

Use the parse function to convert a Siren JSON string to an Entity.

const entity = Siren.parse(siren);
// `entity` is equivalent to `person`

Querying an Entity

The Entity class provides several convenience methods for finding actions or links within the entity:

const addItemAction = orderEntity.findActionByName('add-item');
const customerSubEntities = orderEntity.findEntitiesByRel('customer');
const nextOrderLinks = orderEntity.findLinksByRel('next');

Querying an Action

The Action class also provides convenience methods for finding fields:

const productCodeField = addItemAction.findFieldByName('productCode');

Extensions

Extensions are supported for every type of object. Here's an example using min and max constraints for a Field and hreflang for a Link:

Siren.Entity.of({
  actions: [
    {
      name: 'guess-number',
      href: 'https://api.example.com/guess',
      fields: [
        {
          name: 'guess',
          type: 'number',
          min: 0,
          max: 100
        }
      ]
    }
  ]
  links: [
    {
      rel: ['about'],
      href: 'https://api.example.com/about',
      hreflang: 'en-US'
    }
  ]
});

Contributing

PRs and bug reports welcome! Be sure to read our contribution guidelines.

License

MIT © Siren.js