UNPKG

dynamapping

Version:

replaces keys dynamically within the values for a raw, flat object

28 lines 926 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.fixValueIfChanged = void 0; function isValidJsonString(jsonString) { try { JSON.parse(jsonString); return true; } catch (error) { return false; } } function fixNonStrings(value) { // a valid stringification is assumed to be an object, boolean or number if (isValidJsonString(value)) return JSON.parse(value); return value; } // takes in a raw object (of depth 1) and replaces any session variables there. function fixValueIfChanged(value, newValue) { // console.log(`newValue=${newValue}`) // if ((typeof newValue) === 'object') console.log(`newValue stringified=${JSON.stringify(newValue)}`) if (value !== newValue) return fixNonStrings(newValue); return value; } exports.fixValueIfChanged = fixValueIfChanged; //# sourceMappingURL=fixValueIfChanged.js.map