1.1.11 • Published 3 years ago

@disruptph/json-api-utils v1.1.11

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

@disruptph/json-api-utils

Usage

normalize

import { normalize } from '@disruptph/json-api-utils';

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',
//       }
//     }
//   }
// }

flatten

import { flatten } from '@disruptph/json-api-utils';

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

flatten(data);

// Result:
// {
//   1: {
//     id: '1',
//     type: 'user',
//     name: 'John Doe',
//     age: '25',
//     posts: ['1', '2'],
//   }
// }
1.1.11

3 years ago

1.1.10

3 years ago

1.1.9

3 years ago

1.1.8

3 years ago

1.1.7

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago