dynamodb-utils.js
function toValueFromAttributeTypeAndValue(attributeType, value) {
  switch (attributeType) {
    case 'S':
      return value;
    case 'N':
      return toNumberOrIntegerLike(value);
    case 'BOOL':
      return value === true || value === 'true';
    case 'NULL':
      return null;
    case 'M':
      return toObjectFromDynamoDBMap(value);
    case 'L':
      return value.map(v => toValueFromAttributeValue(v));
    case 'SS':
      return value;
    case 'NS':
      return value.map(v => toNumberOrIntegerLike(v));
    case 'B':
    case 'BS':
      return value;
    default:
      throw new Error(`Unexpected DynamoDB attribute value type (${attributeType})`);
  }
}
function toValueFromAttributeTypeAndValue(attributeType, value) {
  switch (attributeType) {
    case 'S':
      return value;
    case 'N':
      return toNumberOrIntegerLike(value);
    case 'BOOL':
      return value === true || value === 'true';
    case 'NULL':
      return null;
    case 'M':
      return toObjectFromDynamoDBMap(value);
    case 'L':
      return value.map(v => toValueFromAttributeValue(v));
    case 'SS':
      return value;
    case 'NS':
      return value.map(v => toNumberOrIntegerLike(v));
    case 'B':
    case 'BS':
      return value;
    default:
      throw new Error(`Unexpected DynamoDB attribute value type (${attributeType})`);
  }
}
function toValueFromAttributeTypeAndValue ( attributeType , value ) { switch ( attributeType ) { case 'S' : return value ; case 'N' : return toNumberOrIntegerLike ( value ) ; case 'BOOL' : return value === true || value === 'true' ; case 'NULL' : return null ; case 'M' : return toObjectFromDynamoDBMap ( value ) ; case 'L' : return value . map ( v => toValueFromAttributeValue ( v ) ) ; case 'SS' : return value ; case 'NS' : return value . map ( v => toNumberOrIntegerLike ( v ) ) ; case 'B' : case 'BS' : return value ; default : throw new Error ( ` ${ attributeType } ` ) ; } }
Attempts to convert the given DynamoDB AttributeValue value into its original type based on the given DynamoDB
AttributeValue type.
@param {string} attributeType - a DynamoDB AttributeValue type
@param {*} value - a DynamoDB AttributeValue value
@returns {*} a JavaScript value
Attempts to convert the given DynamoDB AttributeValue value into its original type based on the given DynamoDB AttributeValue type .