@neumatter/utilities
v1.0.3
Published
Utility package for copying case, getting values from option objects, and asserting types.
Downloads
5
Maintainers
Readme
Utilities
Table of Contents
Install
npm i @neumatter/utilities
Usage
Import
import * as utilities from '@neumatter/utilities'
// use utilities
utilities.getCasePattern
:
utilities.getCasePattern(input: string): ByteView
utilities.applyCasePattern
:
utilities.applyCasePattern(input: string, pattern: ByteView): string
utilities.throwIfNotWithin
:
utilities.throwIfNotWithin<T extends any>(
value: T,
availableValues?: Array<T>
): void
utilities.throwIfNoInstanceOf
:
utilities.throwIfNoInstanceOf<T extends any>(
value: T,
availableValues?: Array<typeof T>
): void
utilities.assertObject
:
utilities.assertObject<T extends object>(
input: T,
paramName: string
): void
utilities.assertString
:
utilities.assertString(input: string, paramName: string): void
utilities.assertFunction
:
utilities.assertFunction(input: Function, paramName: string): void
utilities.assertNumber
:
utilities.assertNumber(input: number, paramName: string): void
utilities.assertFiniteNumber
:
utilities.assertFiniteNumber(input: number, paramName: string): void
utilities.getObjectOption
:
utilities.getObjectOption<O extends object, T>(
opts: O,
prop: keyof O,
values?: Array<any>,
fallback: T
): T
utilities.getBooleanOption
:
utilities.getBooleanOption<O extends object>(
opts: O,
prop: keyof O,
fallback: boolean
): boolean
utilities.getStringOption
:
utilities.getStringOption<O extends object>(
opts: O,
prop: keyof O,
values?: Array<string>,
fallback: string
): string
utilities.defaultNumberOption
:
utilities.defaultNumberOption(
val: number,
min: number,
max: number,
fallback: number
): number
utilities.getNumberOption
:
utilities.getNumberOption<O extends object>(
options: O,
property: keyof O,
minimum: number,
maximum: number,
fallback: number
): number
utilities.defaultIntegerOption
:
utilities.defaultIntegerOption(
val: number,
min: number,
max: number,
fallback: number
): number
utilities.getIntegerOption
:
utilities.getIntegerOption<O extends object>(
options: O,
property: keyof O,
minimum: number,
maximum: number,
fallback: number
): number