#
omit
function omit(...params): output as object
Description:
Creates copy of object without elements, that didn't pass a filter.
#
params
params = [
object: Object,
filter: (key: string, value: any, i: number) => true | false | any
]
#
Example
const object = {
_privatedKey: "some value",
coins: undefined,
level: 2
};
const isPrivate = (key) => key.startsWith("_");
const isExits = (value) => value !== undefined && value !== null;
const filter = (key, value) => !isPrivate(key) && isExits(value);
const output = omit(object, filter);
// {level: 2};
#
Real example
const userData = client.users.cache.get(userId);
const available = ["coins", "berry"];
return Util.omit(userData, (key) => available.includes(key));