🕵️♀️ Light-weight observable implementation and functional utilities in TypeScript
Installations
npm install observable-fns
Score
99.5
Supply Chain
99.1
Quality
75.4
Maintenance
100
Vulnerability
100
License
Developer
andywer
Developer Guide
Module System
Unable to determine the module system for this package.
Min. Node Version
Typescript Support
No
Node Version
12.16.3
NPM Version
6.14.11
Statistics
45 Stars
68 Commits
1 Forks
3 Watching
4 Branches
1 Contributors
Updated on 21 Nov 2024
Bundle Size
10.55 kB
Minified
2.91 kB
Minified + Gzipped
Languages
TypeScript (97.71%)
JavaScript (2.29%)
Total Downloads
Cumulative downloads
Total Downloads
18,153,359
Last day
-11%
29,049
Compared to previous day
Last week
6.5%
177,243
Compared to previous week
Last month
2.5%
704,952
Compared to previous month
Last year
71%
7,656,031
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
7
🕵️♀️ observable-fns
Light-weight Observable implementation and common toolbelt functions. Based on zen-observable
, re-implemented in TypeScript. Zero dependencies, tree-shakeable.
The aim is to provide a lean Observable implementation with a small footprint that's fit to be used in libraries as an alternative to the huge RxJS.
Find all the provided functions and constructors in the 👉 API Documentation
🧩 Composable functional streams
🚀 map(), filter() & friends support async handlers
🔩 Based on popular zen-observable
, re-implemented in TypeScript
🌳 Zero dependencies, tree-shakeable
Installation
npm install observable-fns
Observable?
An observable is basically a stream of asynchronously emitted values that you can subscribe to. In a sense it is to the event emitter what the promise is to the callback.
The main difference to a promise is that a promise only resolves once, whereas observables can yield values repeatedly. They can also fail with an error, like a promise, and they come with a completion event to indicate that no more values will be send.
For a quick introduction on how to use observables, check out the zen-observable readme.
1import { Observable, multicast } from "observable-fns"
2
3function subscribeToServerSentEvents(url) {
4 // multicast() will make the observable "hot", so multiple
5 // subscribers will share the same event source
6 return multicast(new Observable(observer => {
7 const eventStream = new EventSource(url)
8
9 eventStream.addEventListener("message", message => observer.next(message))
10 eventStream.addEventListener("error", error => observer.error(error))
11
12 return () => eventStream.close()
13 }))
14}
15
16subscribeToServerSentEvents("http://localhost:3000/events")
17 .filter(event => !event.isStale)
18 .subscribe(event => console.log("Server sent event:", event))
Usage
You can import everything you need directly from the package:
1import { Observable, flatMap } from "observable-fns"
If you write front-end code and care about bundle size, you can either depend on tree-shaking or explicitly import just the parts that you need:
1import Observable from "observable-fns/observable" 2import flatMap from "observable-fns/flatMap"
Functions like filter()
, flatMap()
, map()
accept asynchronous handlers – this can be a big win compared to the usual methods on Observable.prototype
that only work with synchronous handlers.
Those functions will also make sure that the values are consistently emitted in the same order as the input observable emitted them.
1import { Observable, filter } from "observable-fns" 2 3const existingGitHubUsersObservable = Observable.from(["andywer", "bcdef", "charlie"]) 4 .pipe( 5 filter(async name => { 6 const response = await fetch(`https://github.com/${name}`) 7 return response.status === 200 8 }) 9 )
API
See docs/API.md for an overview of the full API.
License
MIT
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
6 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-pfrx-2q88-qq97
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/14 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 22 are checked with a SAST tool
Score
2.3
/10
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More