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

niojs

v1.1.5

Published

nio

Downloads

4

Readme

nio.js

Work with streams in JavaScript

Build Status Code Climate npm version Bower version

Getting Started

There are a few ways to make use of nio.js, follow the instructions for the one that applies to your situation

Browser Application (with bower)

  1. Install from bower

    bower install nio.js
  2. Add the script to your HTML

    <script src="./bower_components/nio.js/dist/nio.min.js"></script>
  3. Use it! - See the Examples Section

Browser Application (without bower)

  1. Download the source file: https://raw.githubusercontent.com/nioinnovation/nio.js/v1/dist/nio.min.js

  2. Add the script to your HTML

    <script src="./nio.min.js"></script>
  3. Use it! - See the Examples Section

Node Application

  1. Install from npm

    npm install niojs
  2. Require nio

    var nio = require('niojs')
  3. Use it! - See the Examples Section

Examples

Log data from a few rooms on a socket.io server

nio.source.socketio(
 'http://yoursocketserver.com:8080',
 ['socket', 'rooms', 'go', 'here'],
 120 // optional - will immediately stream cached data within the last 120 seconds
).pipe(nio.log())

API Documentation

Stream Methods

The following methods allow you to filter/manipulate/work with streams of data. You can pipe streams (via .pipe(...)) into these methods, which will then return their own streams.

nio.pass(func)

Perform a function on the data but pass it through unchanged. Changes to the data inside of the function will not be realized in the output stream. Use nio.func() to do that.

Example:

nio.source.generate({
   test_a: 1,
   test_b: 2
}).pipe(nio.pass(function(chunk) {
   console.log("My value is " + chunk.test_a);
}));

Output:

My value is 1

Note that you did not have to return anything from the function, the original chunk was already emitted from the pass function.

nio.func(func)

Perform a function on the data and emit the results of the function.

Example:

nio.source.generate({
   test_a: 1,
   test_b: 2
}).pipe(nio.func(function(chunk) {
   return chunk.test_b + 5;
})).pipe(nio.log("Final value"));

Output:

Final value 7

Note that this time we did return something from the function. The output of the function is what will be emitted to the stream.

nio.log(prefix="")

Log the data of the stream to the JavaScript console, with an optional prefix

nio.filter(func)

Only emit the data if the function evaluates to true

nio.has(property)

Only emit the data if it contains an attribute property.

nio.is(property, value)

Only emit the data if it contains an attribute property and if its value is value.

nio.get(property)

Emit the value of property on the data, if it exists.

Source Methods

The following methods allow you to connect to data sources or generate data in a stream

nio.source.socketio(host, rooms)

Connect to a socket.io server and subscribe to a list of rooms.

nio.source.generate(data, maxTimes=1, rate=100)

Generate an asynchronous data stream at a regular interval.

  • data (function or object): If data is a function, it can receive one argument which would be the iteration number (starting at 0) of the current execution. If it is an object, that object will be emitted.
  • maxTimes (int): How many times the data will get generated. Defaults to 1. Setting this to a negative number will cause it to run indefinitely.
  • rate (int): The rate (in milliseconds) of how often to generate the data.

Example #1:

nio.source.generate({val: 1})
 .pipe(nio.log("output"));

Output #1:

output {val: 1}

Example #2:

nio.source.generate({val: 1}, 3)
 .pipe(nio.log("output"));

Output #2:

output {val: 1}
output {val: 1}
output {val: 1}

Example #3:

nio.source.generate(function(iter) {
 return {val: iter};
}, 3).pipe(nio.log("output"));

Output #3:

output {val: 0}
output {val: 1}
output {val: 2}