UNPKG

dynamodb-toolbox

Version:

Lightweight and type-safe query builder for DynamoDB and TypeScript.

22 lines (21 loc) 870 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.anySchemaFormatter = anySchemaFormatter; const cloneDeep_js_1 = require("../../../utils/cloneDeep.js"); function* anySchemaFormatter(schema, rawValue, options = {}) { const { format = true, transform = true } = options; let transformedValue = undefined; if (transform) { const transformer = schema.props.transform; transformedValue = transformer !== undefined ? transformer.decode(rawValue) : (0, cloneDeep_js_1.cloneDeep)(rawValue); if (format) { yield transformedValue; } else { return transformedValue; } } const formattedValue = transformedValue !== null && transformedValue !== void 0 ? transformedValue : (0, cloneDeep_js_1.cloneDeep)(rawValue); return formattedValue; }