UNPKG

@nova-odm/auto-marshaller

Version:

A data marshaller that converts JavaScript types into Amazon DynamoDB AttributeValues

50 lines (49 loc) 1.7 kB
"use strict"; var _a; Object.defineProperty(exports, "__esModule", { value: true }); exports.NumberValue = void 0; var NUMBER_VALUE_TAG = 'DynamoDbNumberValue'; var EXPECTED_TAG = "[object ".concat(NUMBER_VALUE_TAG, "]"); /** * A number that may contain greater precision than can safely be stored in * JavaScript's `number` data type. Numerical values are represented internally * as strings (the format used by DynamoDB's JSON-based data representation * schema). */ var NumberValue = /** @class */ (function () { function NumberValue(value) { this[_a] = NUMBER_VALUE_TAG; this.value = value.toString().trim(); } /** * Convert the value to its desired JSON representation. Called by * `JSON.stringify`. */ NumberValue.prototype.toJSON = function () { return this.valueOf(); }; /** * Convert the value to its desired string representation. Called * automatically when objects are coerced into strings. */ NumberValue.prototype.toString = function () { return this.value; }; /** * Convert the value to its desired literal representation. Called * automatically when objects appear in arithmetic expressions. */ NumberValue.prototype.valueOf = function () { return Number(this.value); }; /** * Evaluate whether the provided value is a NumberValue object. */ NumberValue.isNumberValue = function (arg) { return (typeof NumberValue === 'function' && arg instanceof NumberValue) || Object.prototype.toString.call(arg) === EXPECTED_TAG; }; return NumberValue; }()); exports.NumberValue = NumberValue; _a = Symbol.toStringTag;