Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/ayonli_jsext/object/index.ts>sanitize

A JavaScript extension package for building strong and modern applications.
Latest
function sanitize
import { sanitize } from "https://deno.land/x/ayonli_jsext@v0.9.72/object/index.ts";

Creates an object base on the original object but without any invalid values (except for null), and trims the value if it's a string.

NOTE: This function only operates on plain objects and arrays.

Examples

Example 1

import { sanitize } from "@ayonli/jsext/object";

const obj = sanitize({
    foo: "Hello",
    bar: "  World  ",
    baz: undefined,
    num: NaN,
});

console.log(obj); // { foo: "Hello", bar: "World" }

Type Parameters

T extends object

Parameters

obj: T
optional
deep = [UNSUPPORTED]
optional
options: { removeNulls?: boolean; removeEmptyStrings?: boolean; removeEmptyObjects?: boolean; removeArrayItems?: boolean; } = [UNSUPPORTED]