@seniorsistemas/senior-sam
Version:
Senior HCM SAM para Node.js
47 lines • 1.52 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.BaseModel = void 0;
class BaseModel {
toJsonString() {
let json = JSON.stringify(this);
Object.keys(this)
.filter(key => key[0] === '_')
.forEach(key => {
json = json.replace(key, key.substring(1));
});
Object.values(this).forEach(value => {
if (typeof value === 'object') {
Object.keys(value)
.filter(key => key[0] === '_')
.forEach(key => {
json = json.replace(key, key.substring(1));
});
}
});
json = this.replaceArray(json);
return json;
}
replaceArray(json) {
const jsonObj = JSON.parse(json);
Object.values(jsonObj).forEach(value => {
if (this.isArray(value)) {
const jsonArray = JSON.parse(JSON.stringify(value));
for (let i = 0; i < jsonArray.length; i++) {
console.log(jsonArray[i]);
Object.keys(jsonArray[i]).forEach(key => {
json = json.replace(key, key.substring(1));
});
}
}
});
return json;
}
toJson() {
return JSON.parse(this.toJsonString());
}
isArray(what) {
return '' + what === '[object Object]';
}
}
exports.BaseModel = BaseModel;
//# sourceMappingURL=BaseModel.js.map