0.0.7 • Published 3 years ago
@mjamsek/rxjs-utils v0.0.7
RxJS Utils
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