Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@jalik/hal

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jalik/hal

Hypertext Application Language toolbox

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
42
increased by23.53%
Maintainers
1
Weekly downloads
 
Created
Source

@jalik/hal

GitHub package.json version Build Status Last commit GitHub issues GitHub npm

H.A.L. (Hypertext Application Language) TypeScript declarations and functions.

Features

  • Create HAL resources
  • Create HAL paginated resources
  • Consume HAL embedded data
  • TypeScript declarations ♥

Installing

npm i -P @jalik/hal
yarn add @jalik/hal

Creating an HAL resource

import { createHalResource } from '@jalik/hal'

const user = {
  username: 'admin'
}

const roles = [
  { name: 'administrator' }
]

// we can add links to roles (optional)
const rolesResources = roles.map((role) => createHalResource(role, undefined, {
  self: { href: `http://localhost/roles/${role.name}` }
}))

const embedded = {
  roles: rolesResources
}

const links = {
  self: { href: 'http://localhost/users/admin' }
}

const resource = createHalResource(user, embedded, links)

Creating an HAL paged resource

import { createHalPagedResource } from '@jalik/hal'

const users = [
  { username: 'admin' },
  { username: 'john' }
]

// we can add links to users (optional)
const usersResources = users.map((user) => createHalResource(user, undefined, {
  self: { href: `http://localhost/users/${user.username}` }
}))

const embedded = {
  users: usersResources
}

const page = {
  number: 3,
  size: 2,
  totalElements: 10,
  totalPages: 5
}

const links = {
  first: 'http://localhost/users?p=1',
  prev: 'http://localhost/users?p=2',
  self: 'http://localhost/users?p=3',
  next: 'http://localhost/users?p=4',
  last: 'http://localhost/users?p=5',
}

const resource = createHalPagedResource(embedded, page, links)

Getting the HAL embedded values

import { getHalEmbedded } from '@jalik/hal'

const doc = {
  username: 'admin',
  _embedded: {
    roles: [
      { name: 'administrator' },
      { name: 'member' }
    ]
  }
}

const embedded = getHalEmbedded(doc)
// embedded = { roles[] }
import { getHalLinks } from '@jalik/hal'

const doc = {
  username: 'admin',
  _links: {
    self: { href: 'http://localhost/users/admin' }
  }
}

const links = getHalLinks(doc)
// links = { self }

Getting the HAL page information

import { getHalPage } from '@jalik/hal'

const doc = {
  _embedded: { users: [] },
  page: {
    number: 1,
    size: 0,
    totalElements: 0,
    totalPages: 1
  }
}

const page = getHalPage(doc)
// page = { number, size, totalElements, totalPages }

Changelog

History of releases is in the changelog on GitHub.

License

The code is released under the MIT License.

Keywords

FAQs

Package last updated on 27 Feb 2024

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc