@zishone/dotnotate
Version:
A utility function to convert JSON objects to dotnotation
22 lines • 714 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.dotnotate = void 0;
const bson_1 = require("bson");
const recurse = (source, destination, currentKey) => {
for (const key in source) {
const value = source[key];
const newKey = currentKey ? `${currentKey}.${key}` : key;
if (value && typeof value === 'object' && !Array.isArray(value) && !bson_1.ObjectId.isValid(value)) {
recurse(value, destination, newKey);
}
else {
destination[newKey] = value;
}
}
};
exports.dotnotate = (object) => {
const result = {};
recurse(object, result);
return result;
};
//# sourceMappingURL=dotnotate.js.map