Jamsek-m / prog-lib-rxjs

Utility library providing RxJS operators.

Home Page:https://www.npmjs.com/package/@mjamsek/rxjs-utils

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RxJS Utils

npm (scoped) GitHub license

Utility library providing RxJS operators.

Installation

Run command: npm install --save @mjamsek/rxjs-utils

Documentation

Type assertions

Assert type

assertType<T>() asserts observable is of type T. Usage:

observable$.pipe(
    assertType<string>(),
);

Assert void

assertVoid() asserts observable is of type void. Usage:

observable$.pipe(
    assertVoid(),
);

Assert non null

nonNull() asserts observable value is not null. Usage:

observable$.pipe(
    nonNull(),
);

Type filter

ofTypeOnly<T>() runs a type guard check on observable to filter values that are not of type T. Usage:

function isString(x: unknown): x is string {
    return typeof x === "string";
}

observable$.pipe(
    ofTypeOnly<string>(isString),
);

You can also create reusable filters, by using createTypeFilter function:

const enforceString = createTypeFilter(isString);

observable$.pipe(
    enforceString(),
);

Enforce type

enforceType<T>() runs a type guard check on observable to enforce it is of type T. Usage:

function isString(x: unknown): x is string {
    return typeof x === "string";
}

observable$.pipe(
    enforceType<string>(isString),
);

You can also create reusable enforcers, by using createTypeEnforcer function:

const enforceString = createTypeEnforcer(isString);

observable$.pipe(
    enforceString(),
);

Bugs & Features

Any issues, requests for a new feature, etc. can be filled using GitHub Issues.

License

MIT

About

Utility library providing RxJS operators.

https://www.npmjs.com/package/@mjamsek/rxjs-utils

License:MIT License


Languages

Language:TypeScript 69.9%Language:JavaScript 30.1%