UNPKG

@briswell/bw-domain

Version:

Domain Library for Node.js

35 lines (33 loc) 993 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const lodash_1 = require("lodash"); function stripUndefinedField(obj) { const result = JSON.parse(JSON.stringify(obj)); const deleteEmptyObj = (o) => { Object.keys(o).forEach((key) => { if (lodash_1.isEmpty(o[key])) { delete o[key]; } else if (typeof o[key] === 'object') { deleteEmptyObj(o[key]); } }); }; deleteEmptyObj(result); return result; } exports.stripUndefinedField = stripUndefinedField; /* export function removeTimestampField(obj: Sequelize.Instance<any> | null) { if (obj === null) { return obj; } const plainObj = obj.get({ plain: true }); // 不要フィールドを削除 delete plainObj.createdAt; delete plainObj.createdBy; delete plainObj.updatedAt; delete plainObj.updatedBy; delete plainObj.deletedAt; delete plainObj.deletedBy; return plainObj; } */