0.10.0 • Published 5 years ago

jsonapi-serializer-lite v0.10.0

Weekly downloads
3
License
MIT
Repository
github
Last release
5 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

5 years ago

0.8.0

9 years ago

0.7.1

9 years ago

0.7.0

10 years ago

0.6.1

10 years ago

0.6.0

10 years ago

0.5.0

10 years ago

0.4.0

10 years ago

0.3.0

10 years ago

0.2.1

10 years ago

0.2.0

10 years ago

0.1.0

10 years ago