UNPKG

infinity-forge

Version:
43 lines 1.45 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.applyDecimalFields = applyDecimalFields; function normalizeDecimal(value) { if (typeof value !== 'string' && typeof value !== 'number') return value; var stringValue = String(value).trim(); if (!stringValue) return value; var normalized = stringValue.includes(',') ? stringValue.replace(/\./g, '').replace(',', '.') : stringValue; var parsed = Number(normalized); return Number.isNaN(parsed) ? value : parsed; } function getByPath(obj, path) { return path.split('.').reduce(function (acc, key) { return acc === null || acc === void 0 ? void 0 : acc[key]; }, obj); } function setByPath(obj, path, value) { var keys = path.split('.'); var current = obj; keys.forEach(function (key, index) { if (index === keys.length - 1) { current[key] = value; } else { if (!current[key] || typeof current[key] !== 'object') { current[key] = {}; } current = current[key]; } }); } function applyDecimalFields(payload, decimalFields) { decimalFields.forEach(function (path) { var value = getByPath(payload, path); if (value !== undefined) { setByPath(payload, path, normalizeDecimal(value)); } }); return payload; } //# sourceMappingURL=format-decimal-fields.js.map