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

tarkjs

v1.0.6

Published

Collection of promise oriented functions and classes.

Downloads

6

Readme

tarkjs

Collection of promise oriented functions and classes.

travis-ci Test Coverage Code Climate esdocs npm version npm downloads Known Vulnerabilities Dependencies devDependencies Status MIT license

Installation

Install with npm: npm i -S tarkjs

Usage

ES6 imports.

import * as tarkjs from 'tarkjs'

There is no default export.

Custom Events and Stores

EventBus

The EventBus is a custom event dispatcher that process events to handlers in the order they were added asynchronously. The events are cancelable by the handlers and the dispatch, stopping propagation to the next handler. The return value of each handler is kept in an accumulator and the original dispatch will resolve with those values.

import { EventBus, changeNotifier } from 'tarkjs'

const eventBus = new EventBus()

// Create an object that send events when it's properties are set.
const notifier = changeNotifier({message: 'hello'}, eventBus)

// attach an handler
eventBus.addEventHandler('message_value_changed', (e) => {
    console.log(e.payload.newValue)
})

// send a value changed event
notifier.message = 'hi'

// Send any event 
eventBus.addEventHandler('custom_event', ({event, payload, acc, i, end}) => {
    // code...
})

eventBus.dispatch({event: 'custom_event', payload: 'hello'})

// Accumulate
[1, 2, 3].forEach(i => eventBus.addEventHandler('accumulate', () => i))
const { promise } = eventBus.dispatch({event: 'accumulate'})
promise.then((value) => value.reduce((p,n) => p+n))
Regex handler

Give a regex as event to EventBus#addEventHandler to handle any events that match the pattern.

Notifiers
PromiseStore

Store the result and dispatch events of promise resolve and rejection from promise creator functions.

import { PromiseStore, fetchRequest } from 'tarkjs'

// Actions must return a promise.
const store = new PromiseStore({simple_fetch: (url) => fetchRequest(url)})

// Subscribe get all the events of an action.
store.subscribe('simple_fetch', (e) => {
    const { fulfilled } = store.actionStore.simple_fetch.STATES
    if (e.event === fulfilled)
        console.log(e.payload)
})

// The values are stored in the actionStore 
if (!store.actionStore.simple_fetch.store.pending)
    store.actions.simple_fetch('some_text.txt')
SocketStore

A web socket that store a number of messages in a deque and dispatch events to subscribers.

import { SocketStore } from 'tarkjs'

const socket = new SocketStore('ws://somesocket/', {
    transformMessage: (data) => JSON.parse(data),
    capacity: 10,
    socketName: 'somesocket'
})

socket.subscribe((e) => {
    console.log(e.payload.data)
})

socket.onOpen = () => socket.send(JSON.stringify({payload: 'Hello socket'}))

socket.start()

Documentation

Full documentation