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

Fdawgs / ydh-myydh-crud-api / 3593284982

pending completion
3593284982

Pull #1108

github

GitHub
Merge df2e6346d into f056ffcf3
Pull Request #1108: build(deps): bump @fastify/rate-limit from 7.5.0 to 7.6.0

276 of 276 branches covered (100.0%)

Branch coverage included in aggregate %.

557 of 557 relevant lines covered (100.0%)

16.44 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
const fp = require("fastify-plugin");
6✔
2

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

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

33
module.exports = fp(plugin, {
6✔
34
        fastify: "4.x",
35
        name: "clean-object",
36
});
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