A collection of utility types and functions
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
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;
}
A bunch of generics for usage in various cases. All documented using jsdoc.
GenericFn
VoidFn
AsyncFn
MaybeAsyncFn
Predicate
Primitives
NullishPritives
Nullable<T>
Optional<T>
Nullish<T>
NonNullable<T>
NonOptional<T>
NonNullish<T>
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>
Some commonly used utility functions
Functions that verify the type of a value at runtime. Type safe.
isNumber()
isString()
isBoolean()
isObject()
isArray()
isNull()
isUndefined()
isNullish()
objectKeys()
objectValues()
objectEntries()
objectFromEntries()
transformObject()
arrayFilter()
Logger()
factory
Functions and type declarations that have yet to be added to this lib
-
Address
-
Currency
-
UUID
- Currency parsers & transformers
- Integer to double precision float parser
- Double precision float to string formatter
- Address parsers & formatter
- Date parsers & formatters
- String transformers
- To Pascal case
- To Kebab case
- Common regular expressions
- Object parsers, validators & transformers
- Object value / key transformer
- Object merge