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

simple-charm

v0.3.5

Published

live-code with event emitters

Downloads

31

Readme

simple charm

live-code with streaming data!

installation

npm install simple-charm

usage:

in one file (index.js):

var charm = require('simple-charm')
  , spawn = require('child_process').spawn

function pathTo (filename) { 
  return require('path').join(__dirname, filename)
}

// one-script prints 1 to process.stdout, over and over
var process  = spawn('node', [pathTo('one-script.js')])

// `charm` em with app.js
var app = pathTo('/app.js')
// make sure to pass an absolute path
charm(app, process.stdout, 'data')

in another file (app.js):

module.exports = function (oneStream) {
  function addTwo (x) { return x+2 }
  var threeStream = oneStream.map(addTwo)
  threeStream.log()
}

now you can node index.js and, while it's running, live-code app.js!

you can even make syntax errors - it will catch them without stopping your streams!

here, oneStream is a Kefir stream, made out of our event emitter and accompanying event. map, filter, scan, whatever, and log as you go.

use this to mix-and-match various types of emitters - sockets, serial connections, any node stream, what have you

see examples/ for working with multiple streams, returning stuff back to inde.js (e.g. for logging), etc.

why

livecoding is really great

long history in lisp and all that, still a core priority in clojure and clojurescript

in javascript, event emitters are at the core of most asynchronous operations. i personally deal with streaming biosensor data, which sometimes comes over a bluetooth connection (serial) and sometimes through a websocket. in both cases, i need to parse and process the data.

live-coding with emitters

simple-charm lets you live-code with event emitters in node

it turns the events from an emitter into Kefir streams - a flexible, discretized data sturcture that lets you map, filter, buffer, etc... across many values over time.

then, you write a script that processes the stream. you can change this script in real time, and your emitter's values will be sent through updated versions, without a hitch.

may it serve you well

api

single stream:

charm(path, emitter, event)

or multiple streams:

charm(path, [emitter, event], [emitter2, event2], ...)

path refers to some file that exposes a function. the arguments to this function will be Kefir streams, one for each [emitter, event] pair passed to charm.

see examples/multiple-streams/ for an example with multiple in-streams

this function returns a Kefir stream as well - a stream of return values from the function in app.js every time app.js is saved and hot-reloaded, the new return value is emitted into to this stream.

see examples/logging/ for one use case of this

debugging

be sure to pass charm the absolute path of your script. see example.

LICENSE

BSD-2-Clause