0.0.7 • Published 1 year ago

@mjamsek/rxjs-utils v0.0.7

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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

0.0.7

1 year ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago