UNPKG

@env0/dynamo-easy

Version:

DynamoDB client for NodeJS and browser with a fluent api to build requests. We take care of the type mapping between JS and DynamoDB, customizable trough typescript decorators.

28 lines 848 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); function dateFromDb(attributeValue) { if (attributeValue.S) { const date = new Date(attributeValue.S); if (isNaN(date)) { throw new Error('given string is not a valid date string'); } return date; } else { throw new Error('there is no S(tring) value defiend on given attribute value'); } } function dateToDb(modelValue) { // noinspection SuspiciousInstanceOfGuard if (modelValue && modelValue instanceof Date) { return { S: `${modelValue.toISOString()}` }; } else { throw new Error('the given model value must be an instance of Date'); } } exports.dateToStringMapper = { fromDb: dateFromDb, toDb: dateToDb, }; //# sourceMappingURL=date-to-string.mapper.js.map