JSPM

json-api-simple-normalizer

1.0.1
    • ESM via JSPM
    • ES Module Entrypoint
    • Export Map
    • Keywords
    • License
    • Repository URL
    • TypeScript Types
    • README
    • Created
    • Published
    • 0
    • Score
      100M100P100Q17680F
    • License MIT

    Simple normalizer for JSON:API specification objects

    Package Exports

    • json-api-simple-normalizer
    • json-api-simple-normalizer/index.js

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (json-api-simple-normalizer) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

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