@jali-ms/util v0.0.1
Jali Util Package
This package provides JavaScript language level utilities for the Jali microservice platform. jali-ms.io
Utilities include:
- function argument
Error
types - argument validator functions
iteration
functions that covers mostArray
iteration functions and more.- TypeScript user-defined type guard functions for fundamental JavaScript types.
Getting Started
Install the package:
npm install --save @jali-ms/util
Usage
As a utility package many kinds of functions are provided by a few modules. Major function types are mentioned below. For detailed information see the Jali docs.
Module @jali-ms/util/errors
Provides Error
types and function argument verifiers.
Errors
A family of argument errors are available, with the class
ArgumentError
as the base type in addition to the InvalidStateError
,
which it thrown when object functions are called when in a state not
supported by the operation.
Argument Verifiers
A group of validation errors that throw the appropriate Error
when an
argument is invalid. Many verifiers provide runtime verification for
static type checks provided by TypeScript
.
Module @jali-ms/util/iterables
Provides element iteration for any object that implements the iterable pattern.
Example
import Iterables from '@jali-ms/util/iterables';
const sequence = (function*() { yield 1; yield 2; yield 3; })();
const filtered = Iterables.filter(sequence, e => e % 2 === 0);
console.log(Iterables.find(sequence)); // Displays: 2
Module @jali-ms/util/type-guards
Provides type verification functions especially useful for type coercion
in TypeScript
.
Example
import TypeGuards from '@jali-ms/util/type-guards';
function processException(err: any): void {
if (TypeGuards.isError(err)) {
console.log(`An error has occurred: ${err.message}`);
}
else {
console.log(`An error has occurred: ${err.toString()}`);
}
}
Contribute
This package is part of the monorepo jali-srcs. Please refer to that GitHub repository on how to contribute to the Jali project.