Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

o-stream

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

o-stream

Intuitive node streams in typescript.

  • 0.1.8
  • npm
  • Socket score

Version published
Weekly downloads
25K
decreased by-65.48%
Maintainers
1
Weekly downloads
 
Created
Source

O-Stream

Provides an intuitive interface for node streams, in typescript.

Useful for creating streams and gulp plugins (there is an example).

Install

npm install --save o-stream

Or dev:
npm install --save-dev o-stream

Basic Usage

Simple transform stream:

import ObjectStream, { EnteredArgs } from "o-stream"

let incrementStream = ObjectStream.transform<number, number>({
    onEntered: (args: EnteredArgs<number, number>) => {
        args.output.push(args.object + 1);
    }
});

stream.write(4);

let actual = stream.read(); // 5

Output on stream end:

import ObjectStream, { EnteredArgs, EndedArgs } from "o-stream"

let sum = 0;
let sumStream = ObjectStream.transform<number, number>({
    onEntered: (args: EnteredArgs<number, number>) => {
        sum += args.object;
    },
    onEnded: (args: EndedArgs<number>) => {
        args.output.push(sum);
    }
});

sumStream.write(100);
sumStream.write(5);
sumStream.write(-10);
sumStream.end();

let actualSum = sumStream.read(); // 95

Async:

import ObjectStream, { EnteredAsyncArgs, EndedAsyncArgs } from "o-stream"

let sum = 0;
let sumStream = ObjectStream.transform<number, number>({
    onEnteredAsync: (args: EnteredAsyncArgs<number, number>) => {
        sum += args.object;
        args.done();
    },
    onEndedAsync: (args: EndedAsyncArgs<number>) => {
        args.output.push(sum);
        args.done();
    }
});

let num1 = 4;
let num2 = 6;
let num3 = -1;
let expected = num1 + num2 + num3;

sumStream.write(num1);
sumStream.write(num2);
sumStream.write(num3);
sumStream.end();

let actual = sumStream.read();

expect(actual).toBe(expected);

Create a stream from an array:

import ObjectStream from "o-stream"

let stream = ObjectStream.fromArray([1, 2, 3, 5, 8, 13]);

Gulp plugin example - create file with the input files names:

import ObjectStream, { EnteredArgs, EndedArgs, Transform } from "o-stream";
let gutil = require("gulp-util");

export default function plugin(outFilePath: string, options?: Options): Transform {

    let generator = new ExportsGenerator(options);
    let myPaths: string[] = [];

    return ObjectStream.transform({
        onEntered: (args: EnteredArgs<any, any>) => {
            myPaths.push(args.object.relative);
        },
        onEnded: (args: EndedArgs<any>) => {
            let file = new gutil.File({
                cwd: "",
                base: "",
                path: outFilePath,
                contents: new Buffer(myPaths.join("\n"))
            })

            args.output.push(file);
        }
    });
}

Keywords

FAQs

Package last updated on 13 Mar 2017

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc