@leight/utils
This package contains a lot of small utilities from various other packages, which could be safely used on client/server.
Installation
npm
npm i @leight/utils
API
Each section here is exported from the package.
chain()
Useful when you need to rotate through values, for example true
-> false
-> undefined
.
Initial use case for this method was rotating sort order in tables ("asc"
-> "desc":
-> undefined
).
import {chain} from "@leight/utils";
/**
* Next value: `false`
*/
console.log("Next value", chain(true, [true, false, undefined]));
/**
* Next value: `A`
*/
console.log("Next value", chain("C", ["A", "B", "C"]));
cleanOf()
ℹ️
This method is proxy to fast-clean (opens in a new tab) package.
Takes an object as an input and removed all undefined
properties while preserving null
s.
Second parameter of the method is options object (opens in a new tab) from fast-clean
.
import {cleanOf} from "@leight/utils";
/**
* Only `wipeMe` will be removed.
*/
console.log("cleanOf", cleanOf({
foo: "true",
bar: false,
hello: null,
wipeMe: undefined,
}));