• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Fdawgs / ydh-myydh-crud-api / 4417510579

pending completion
4417510579

push

github

GitHub
chore(main): release 11.0.7 (#1221)

259 of 259 branches covered (100.0%)

Branch coverage included in aggregate %.

527 of 527 relevant lines covered (100.0%)

14.21 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/plugins/clean-object/index.js
1
/* eslint-disable security/detect-object-injection */
2
const fp = require("fastify-plugin");
6✔
3

4
/**
5
 * @author Frazer Smith
6
 * @author Felix Meyer-Wolters
7
 * @description Removes key value pairs from an object where the value is null or undefined.
8
 * Adapted from Felix's answer at https://stackoverflow.com/a/38340730
9
 * @param {object=} object - Object to be parsed and cleaned.
10
 * @returns {object} cleaned object.
11
 */
12
function cleanObject(object = {}) {
1✔
13
        const obj = object;
179✔
14
        Object.keys(obj).forEach((key) => {
179✔
15
                if (obj[key] && typeof obj[key] === "object") {
527✔
16
                        cleanObject(obj[key]); // recursive
135✔
17
                } else if (obj[key] === null || obj[key] === undefined) {
392✔
18
                        delete obj[key];
4✔
19
                }
20
        });
21
        return obj;
179✔
22
}
23

24
/**
25
 * @author Frazer Smith
26
 * @description Plugin that decorates Fastify instance with `cleanObject` function,
27
 * which removes key value pairs from an object where the value is null or undefined.
28
 * @param {object} server - Fastify instance.
29
 */
30
async function plugin(server) {
31
        server.decorate("cleanObject", cleanObject);
32✔
32
}
33

34
module.exports = fp(plugin, {
6✔
35
        fastify: "4.x",
36
        name: "clean-object",
37
});
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc