objectypes
Version:
A type-safe library to transform and validate objects
17 lines (16 loc) • 848 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.extractValueFromJSONObject = void 0;
const ramda_1 = require("ramda");
function extractValueFromJSONObject(propertyMetadata, jsonObject) {
var _a;
const { name, propertyKey } = propertyMetadata;
const objectPropertyName = name !== null && name !== void 0 ? name : propertyKey;
if (!objectPropertyName.includes('.')) {
return (_a = jsonObject[objectPropertyName]) !== null && _a !== void 0 ? _a : jsonObject[propertyKey];
}
const namePath = objectPropertyName.split('.');
const valueFromPath = (0, ramda_1.path)(namePath, jsonObject);
return valueFromPath !== null && valueFromPath !== void 0 ? valueFromPath : (0, ramda_1.path)([propertyKey], jsonObject);
}
exports.extractValueFromJSONObject = extractValueFromJSONObject;