npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@uneksija/comea

v0.3.0

Published

Utilities for simplified observables

Downloads

8

Readme

version size license

Utilities for simplified observables

Usage

Install:

npm install @uneksija/comea

Import:

import { /* functions */ } from 'comea'

Definitions

Observer: A function that receives some data over time and does something with it.

const observer = data => doSomething(data)

Observable: A function that receives an observer and calls it with data.

const observable = next => next(130)
const number$ = next => [1, 2, 3].forEach(next)

The next example will build a timer observable and a logger observer within these concepts:

const timer = next => {
  let i = 0
  next(i)
  setInterval(_ => {
    i++
    next(i)
  }, 1000)
}
const logger = data => console.log('data:', data)

To bind them we call the observable passing the observer as a parameter:

timer(logger)

// data: 0
// data: 1
// data: 2

API

just

just: (value: any) => Observable

Takes a value and returns an observable that emits just that value.

from

from: (values: any[]) => Observable

Takes a list of values and returns an observable that emits each value at a time.

periodic

periodic: (interval: number) => Observable

Takes an interval in milliseconds and returns an observable that emits undefined at that interval.

map

map: (base: Observable, mapper: (value: any) => any) => Observable

Takes an observable and a function, returns an observable that applies the function to the values of the base observable and emits the results.

flatMap

flatMap: (base: Observable, mapper: (value: any) => Observable) => Observable

Like map, applies a function to the values emitted by the base observable but expecting that function to return observables, then returns an observable that flattens the emissions of the generated observables.

constant

constant: (base: Observable, value: any) => Observable

Takes an observable and a constant, returns an observable that emits the constant each time the base observable emits a value.

take

take: (base: Observable, ammount: number) => Observable

Takes an observable and an ammount, returns an observable that emits that many events from the base observable.

filter

filter: (base: Observable, predicate: (value: any) => boolean) => Observable

Takes an observable and a predicate, returns an observable that emits only the values from the base observable for which the predicate evaluates to true.

scan

scan: (base: Observable, reducer: (state: any, value: any) => any, initial: any) => Observable

Takes an observable, a reducer and an initial value, returns an observable that emits the partial applications of the reducer on the values from the base observable. Where the reducer is a function that takes the current state and a value, then returns the next state.

merge

merge: (...observables: Observable[]) => Observable

Takes some observables and returns an observable that emits events from all the base observables.

combine

combine: (combiner: (...values: any) => any, ...observables: Observable[]) => Observable

Takes a combiner and some observables, returns an observable that emits the application of the combiner to the values of the base observables. Where the combiner is a function that receives the values in the same order as the observables were passed.

zip

zip: (merger: (...values: any) => any, ...observables: Observable[]) => Observable

Takes a merger and some observables and returns an observable that emits the application of the merger to the values of the base observables. Where the merger is a function that receives the values in the same order as the observables were passed. The first emission will have the first events from all observables, and so on.

sample

sample: (base: Observable, trigger: Observable) => Observable

Takes two observables, a base and a trigger, the resulting observable will emit the last event from the base each time it receives an event from the trigger.

debounce

debounce: (base: Observable, interval: number) => Observable

Takes an observable and an interval in milliseconds and returns an observable that emits events from the base observable with at least that much interval between emissions, ignoring events emitted during this interval.

delay

delay: (base: Observable, interval: number) => Observable

Takes an observable and an interval in milliseconds and returns an observable that emits events from the base observable delayed by that much time.

endWhen

endWhen: (base: Observable, limiter: Observable) => Observable

Takes two observables, a base and a limiter, and returns an observable that emits events from the base observable until the limiter observable emits an event.

Motivation

License

MIT