UNPKG

@runejs/common

Version:

Common logging, networking, compression, and other miscellaneous functionality for RuneJS.

32 lines 1.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.setObjectProps = void 0; function setObjectProps(object, objectProps, ignoreFieldNameCase = false) { if (!objectProps) { return; } const dataKeys = objectProps instanceof Map ? Array.from(objectProps.keys()) : Object.keys(objectProps !== null && objectProps !== void 0 ? objectProps : {}); const objectKeys = Object.keys(object); dataKeys.forEach(key => { const existingKey = objectKeys.find(k => { if (ignoreFieldNameCase) { return k.toLowerCase() === key.toLowerCase(); } else { return k === key; } }); if (existingKey) { const value = objectProps instanceof Map ? objectProps.get(key) : objectProps[key]; if (typeof object[existingKey] === 'number' || /^\d*$/.test(value)) { object[existingKey] = Number(value); } else { object[existingKey] = value; } } }); } exports.setObjectProps = setObjectProps; //# sourceMappingURL=objects.js.map