@ubloimmo/front-util

A collection of utility types and functions
Getting stated
Installation
Install the package with your manager of choice.
# npm
npm install @ubloimmo/front-util
# yarn
yarn add @ubloimmo/front-util
# bun
bun add @ubloimmo/front-util
Usage
Import an utility type...
import type { GenericFn, Nullish } from "@ubloimmo/front-util";
const addTwoNumbers: GenericFn<[number, number], number> = (a, b) => a + b;
const joinStrings: GenericFn<string[], string> = (...strings) => {
return strings.join();
}
...or a function.
import type { Nullish } from "@ubloimmo/front-util";
import { isNumber } from "@ubloimmo/front-util";
const isMoreThanTen = (a: Nullish<number>) => {
if (isNumber(a)) return a > 10;
return false;
}
Exported values
Utility types
A bunch of generics for usage in various cases. All documented using jsdoc.
Function types
GenericFn
VoidFn
AsyncFn
MaybeAsyncFn
Predicate
Primitives
Primitives
NullishPritives
Union types
Nullable<T>
Optional<T>
Nullish<T>
NonNullable<T>
NonOptional<T>
NonNullish<T>
Object generics
KeyOf<TObject, TRestriction>
DeepKeyOf<TObject, TRestriction>
DeepRequired<T>
DeepNullish<T>
DeepNonNullish<T>
DeepNullable<T>
DeepNonNullable<T>
DeepOptional<T>
DeepNonOptional<T>
DeepPickLax<T, TKey>
DeepPick<TObject, TKey>
Utility functions
Some commonly used utility functions
Predicates
Functions that verify the type of a value at runtime. Type safe.
isNumber()
isString()
isBoolean()
isObject()
isArray()
isNull()
isUndefined()
isNullish()
Object functions
objectKeys()
objectValues()
objectEntries()
objectFromEntries()
transformObject()
Array functions
Logger
Currently missing
Functions and type declarations that have yet to be added to this lib
Product-wide scalars
Common transformers & normalizers