1.0.0 • Published 11 months ago

@fsnjs/truthy v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

Truthy

Exports two type assertion functions and a union type Falsy that that are useful for safely asserting that a variable is or is not null. In the case of not null, the type assertion function isTruthy<T> preserves the type of the variable that is passed into the function. This is useful when applied to filtering null or undefined values.

Examples

Array filtering

['foo', null, undefined, 'bar'].filter(isTruthy).forEach((val) => {
    // `val` will be typed as a non-nullable string
});

RxJS filter

of('foo', null, 'bar')
    .pipe(filter(isTruthy))
    .subscribe((next) => {
        // 'next' will be typed as a a non-nullable string
    });
1.0.0

11 months ago