UNPKG

vsf-utilities

Version:

Utilities functions shared between vsf projects

34 lines 1.18 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const camelCase_1 = __importDefault(require("lodash/camelCase")); /** * change object keys to camelCase */ function toCamelCase(obj = {}) { return Object.keys(obj).reduce((accObj, currKey) => { accObj[camelCase_1.default(currKey)] = obj[currKey]; return accObj; }, {}); } /** * assign price and tax to product with proper keys * @param AssignPriceParams */ function assignPrice({ product, target, price, tax = 0, deprecatedPriceFieldsSupport = true, }) { let priceUpdate = { [target]: price, [`${target}_tax`]: tax, [`${target}_incl_tax`]: price + tax, }; if (deprecatedPriceFieldsSupport) { /** BEGIN @deprecated - inconsitent naming kept just for the backward compatibility */ priceUpdate = Object.assign(priceUpdate, toCamelCase(priceUpdate)); /** END */ } Object.assign(product, priceUpdate); } exports.default = assignPrice; //# sourceMappingURL=assignPrice.js.map