🚀 DAY 5 OF LAUNCH WEEK: Introducing Socket Firewall Enterprise.Learn more →
Socket
Book a DemoInstallSign in
Socket

@disruptph/json-api-utils

Package Overview
Dependencies
Maintainers
2
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@disruptph/json-api-utils

## Usage

Source
npmnpm
Version
1.1.10
Version published
Weekly downloads
0
-100%
Maintainers
2
Weekly downloads
 
Created
Source

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

FAQs

Package last updated on 28 Jun 2021

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