json-api-simple-normalizer

1.0.1 • Public • Published

json-api-simple-normalizer

Simple normalizer for JSON:API like datasets.

Usage

import { normalize } from 'json-api-simple-normalizer';

const { data } = await fetch('https://www.example.com');
const users = normalize(data);

Examples

Input:

data: {
  id: '1',
  type: 'users',
  attributes: {
    first_name: 'Piotr',
    last_name: 'Klupa',
  },
}

Output:

{
  id: '1',
  type: 'users',
  first_name: 'Piotr',
  last_name: 'Klupa',
}

Input:

data: [
  {
    id: '1',
    type: 'users',
    attributes: {
      first_name: 'Piotr',
      last_name: 'Klupa',
    },
  },
  {
    id: '2',
    type: 'users',
    attributes: {
      first_name: 'Jan',
      last_name: 'Kowalski',
    },
  },
]

Output:

[
  {
    id: '1',
    type: 'users',
    first_name: 'Piotr',
    last_name: 'Klupa',
  },
  {
    id: '2',
    type: 'users',
    first_name: 'Jan',
    last_name: 'Kowalski',
  },
]

Package Sidebar

Install

npm i json-api-simple-normalizer

Weekly Downloads

2

Version

1.0.1

License

MIT

Unpacked Size

6.25 kB

Total Files

4

Last publish

Collaborators

  • piotrekkk