This package has been deprecated

Author message:

No longer supported. Use frl-ts-utils package instead.

frlluc-utils
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

TS utils

Build Status Coverage Status npm version Dependency status Dev Dependency Status License

This little project contains a few quality-of-life utils.

A. Installation

If you are using npm, then simply run the npm install frlluc-utils CLI command to get the latest version.

If you are using yarn, then go with the yarn add frlluc-utils command.

B. Types

There are a few util types and interfaces:

  • Optional<T> - represents a union type of T and undefined.

  • Nullable<T> - represents a union type of T and null.

  • Const<T> - represents a deep readonly T type.

  • IConstArray<T> - an interface that extends the ReadonlyArray<Const<T>> interface.

  • IConstMap<K, V> - an interface that extends the ReadonlyMap<Const<K>, Const<V>> interface.

  • IConstSet<T> - an interface that extends the ReadonlySet<Const<T>> interface.

C. Functions

Let's assume we have two classes, Foo and Bar, where Bar extends Foo.

There are two util functions:

  • reinterpretCast<T> - allows to force cast an object to the specified type.
    Be very careful with this function, because you can do stuff like this:
const bar = new Bar();
// yep, this works!
const result = reinterpretCast<string>(bar);
  • dynamicCast<T> - allows to safely cast an object to the specified type of which it is an instanceof, otherwise returns null.
const bar = new Bar();
// returns bar as a Foo object
const foo = dynamicCast(Foo, bar);
// returns null
const str = dynamicCast(String, bar);

Package Sidebar

Install

npm i frlluc-utils

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

8.17 kB

Total Files

15

Last publish

Collaborators

  • calionvarduk