
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Work with streams in JavaScript
There are a few ways to make use of nio.js, follow the instructions for the one that applies to your situation
Install from bower
bower install nio.js
Add the script to your HTML
<script src="./bower_components/nio.js/dist/nio.min.js"></script>
Use it! - See the Examples Section
Download the source file: https://raw.githubusercontent.com/nioinnovation/nio.js/v1/dist/nio.min.js
Add the script to your HTML
<script src="./nio.min.js"></script>
Use it! - See the Examples Section
Install from npm
npm install niojs
Require nio
var nio = require('niojs')
Use it! - See the Examples Section
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())
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.
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.
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.
Log the data of the stream to the JavaScript console, with an optional prefix
Only emit the data if the function evaluates to true
Only emit the data if it contains an attribute property
.
Only emit the data if it contains an attribute property
and if its value is value
.
Emit the value of property
on the data, if it exists.
The following methods allow you to connect to data sources or generate data in a stream
Connect to a socket.io server and subscribe to a list of rooms.
Generate an asynchronous data stream at a regular interval.
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.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}
FAQs
nio
The npm package niojs receives a total of 9 weekly downloads. As such, niojs popularity was classified as not popular.
We found that niojs demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.