@mlaursen/utils
v0.4.0
Published
A package of utils I generally find myself using in projects
Maintainers
Readme
@mlaursen/utils
A package of utils I generally find myself using in projects.
Installation
npm install @mlaursen/utilsalphaNumericSort
Simple Example
const items = ["World", "Hello"];
const sorted = alphaNumericSort(items);
// sorted == ["Hello", "World"]Simple Example
interface Item {
nameField: string;
}
const items: Item[] = [{ nameField: "World" }, { nameField: "Hello" }];
const sorted = alphaNumericSort(items, {
extractor: (item) => item.nameField,
});
// sorted == [{ nameField: "Hello" }, { nameField: "World" }]camelCase
Simple Example
import { camelCase } from "@mlaursen/utils";
camelCase("hello-world"); // "helloWorld"chunk
Simple Example
const chunked = chunk([1, 2, 3, 4], 2);
// [[1, 2], [3, 4]]debounce
Simple Example
const debounced = debounce((search: string): void => {
setSearch(search);
}, 150);kebabCase
Simple Example
import { kebabCase } from "@mlaursen/utils";
kebabCase("HelloWorld"); // "hello-world"pascalCase
Simple Example
import { pascalCase } from "@mlaursen/utils";
pascalCase("hello-world"); // "HelloWorld"throttle
Simple Example
const throttled = throttle((search: string): void => {
setSearch(search);
}, 150);titleCase
Simple Example
import { titleCase } from "@mlaursen/utils";
titleCase("hello-world"); // "Hello World"upperFirst
Simple Example
import { upperFirst } from "@mlaursen/utils";
upperFirst("hello-world"); // "Hello-world"wait
Wait some duration
import { wait } from "@mlaursen/utils/wait";
console.log("start");
await wait(5000);
console.log("it has been five seconds");