Skip to content

zakodium/utils

Repository files navigation

@zakodium/utils

NPM version npm download test coverage license

Small utilities by zakodium for zakodium.

Installation

npm install @zakodium/utils

Usage

import { assertDefinedNotNull } from '@zakodium/utils';

const value: object | string | boolean | number | null | undefined = JSON.parse(someJsonString);

assertDefinedNotNull(value); // throws if value is null or undefined

// value type is object | string | boolean | number

List of utilities

Assertions

With types mutations.

  • function assert(value: unknown, message?: string | (() => string)): asserts value;
  • function assertUnreachable(value: never): never;
  • function assertDefined<T>(value: T): asserts value is Exclude<T, undefined>;
  • function assertDefinedNotNull<T>(value: T): asserts value is Exclude<T, null | undefined>;

Casting

  • function is<Output>(value: unknown, condition: boolean): value is Output;
  • function cast<Output>(value: unknown): asserts value is Output;

Features that could be added later

License

MIT

About

Small utilities by Zakodium for Zakodium

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors