@mjamsek/rxjs-utils
TypeScript icon, indicating that this package has built-in type declarations

0.0.7 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i @mjamsek/rxjs-utils

Weekly Downloads

1

Version

0.0.7

License

MIT

Unpacked Size

28.4 kB

Total Files

10

Last publish

Collaborators

  • mjamsek