@disruptph/json-api-normalizer
TypeScript icon, indicating that this package has built-in type declarations

1.2.10 • Public • Published

@disruptph/json-api-normalizer

This is basically just re-exporting the json-api-normalizer. The only difference is that this package includes a typescript type definition.

Usage

import normalize from '@disruptph/json-api-normalizer';

const jsonApiData = {
  data: {
    id: '1',
    type: 'user'
    attributes: {
      name: 'John Doe',
      age: '25',
    },
    relationships: {
      posts: {
        data: [
          {
            id: '1',
            type: 'post'
          }
        ]
      }
    }
  },
  included: [
    {
      id: '1',
      type: 'post',
      attributes: {
        title: 'Hello World',
      }
    }
  ],
};

normalize(jsonApiData);

// Result:
// {
//   user: {
//     1: {
//       id: '1',
//       type: 'user'
//       attributes: {
//         name: 'John Doe',
//         age: '25',
//       },
//       relationships: {
//         posts: {
//           data: [
//             {
//               id: '1',
//               type: 'post'
//             }
//           ]
//         }
//       }
//     }
//   },
//   business: {
//     1: {
//       id: '1',
//       type: 'post',
//       attributes: {
//         title: 'Hello World',
//       }
//     }
//   }
// }

Readme

Keywords

none

Package Sidebar

Install

npm i @disruptph/json-api-normalizer

Weekly Downloads

4

Version

1.2.10

License

MIT

Unpacked Size

4.41 kB

Total Files

5

Last publish

Collaborators

  • onoya
  • calimbas