0.10.0 • Published 4 years ago

jsonapi-serializer-lite v0.10.0

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

jsonapi-serializer-lite

Usage

const jsl = require('jsl');

jsl.serialize(data, options)

List of options default values:

{
  type: 'resource',
  id: 'id',
  attributes: [],
  relationships: []
}
const toBeSerialized = {
  id: 'unique_id',
  fullName: 'Fabrício',
  description: 'JSON API',
  newEvent: '1'
};

jsl.serialize(toBeSerialized, {
  type: 'users',

  attributes: [
    'fullName',
    'description',
    'anniversary'
  ],

  relationships: [
    { rel: 'newEvent', type: 'events' }
  ]
});

Returns:

{
  data: {
    id: 'unique_id',
    type: 'users',
    attributes: {
      'full-name': 'Fabrício',
      description: 'JSON API',
      anniversary: null
    },
    relationships: {
      'new-event': {
        data: {
          id: '1',
          type: 'events'
        }
      }
    }
  }
}

jsl.deserialize(jsonapiObject, options)

List of options default values:

{
  flat: true,
  convertCase: 'camelCase'  // one of: camelCase, kebabCase, snakeCase
}
const jsonapiObject = {
  data: {
    attributes: {
      'full-name': 'Fabrício',
      description: 'JSON API'
    },
    relationships: {
      'created-by': {
        data: {
          type: 'people',
          id: '1'
        }
      },
      'modified-by': {
        data: {
          type: 'people',
          id: '1'
        }
      }
    }
  }
};

jsl.deserialize(jsonapiObject, { flat: false });

Returns:

{
  attributes: {
    fullName: 'Fabrício',
    description: 'JSON API'
  },
  relationships: {
    createdBy: '1',
    modifiedBy: '1'
  }
}
0.10.0

4 years ago

0.8.0

8 years ago

0.7.1

8 years ago

0.7.0

8 years ago

0.6.1

8 years ago

0.6.0

8 years ago

0.5.0

8 years ago

0.4.0

8 years ago

0.3.0

8 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.1.0

8 years ago