0.0.6 • Published 7 years ago

sqs-object v0.0.6

Weekly downloads
1
License
MIT
Repository
-
Last release
7 years ago

sqs-object

npm license CircleCI

Convert JavaScript objects to SQS Meta attributes as vice verse.

Installation

$ > npm install sqs-object --save

Usage

const sqsObject = require('sqs-object');

Mapping

First define a mapping between the JavaScript object and the SQS Meta Attributes like this:

const mapping = [
  {
    objectKey: 'id',
    sqsKey: 'ID',
    sqsType: 'Number'
  },
  {
    objectKey: 'name',
    sqsKey: 'Name',
    sqsType: 'String'
  },
  {
    objectKey: 'age',
    sqsKey: 'Age',
    sqsType: 'Number'
  }
];

Object to Meta Attributes

const meta = sqsObject.Meta({
  id: 12,
  name: 'Paul',
  age: 45
}, mapping);
{
  "ID": {
    "DataType": "Number",
    "StringValue": "12"
  },
  "Name": {
    "DataType": "String",
    "StringValue": "Paul"
  },
  "Age": {
    "DataType": "Number",
    "StringValue": "45"
  }
}

Meta Attributes to Object

const object = sqsObject.Object({
  ID: {
    DataType: 'Number',
    StringValue: '12'
  },
  Name: {
    DataType: 'String',
    StringValue: 'Paul'
  },
  Age: {
    DataType: 'Number',
    StringValue: '45'
  }
}, mapping);
{
  "id": 12,
  "name": "Paul",
  "age": 45
}

License

Feel free to use the code, it's released using the MIT license.

Contributors