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

@lordofdestiny/streams-ts

v1.1.1

Published

Streams library for TS

Downloads

7

Readme

streams-ts

badge

TypeScript implementation of the Streams API for Node.js. Inspired by the Java 8 Stream API and Rust's Iterator trait.

Library is still in development and not yet ready for production use. It's mostly feature complete, but there are still some missing methods and some methods, like cycle and reverse.

Library is written in TypeScript and compiled to ES6. You can use it in both Node.js and the browser, with both TypeScript and JavaScript.

All methods are lazy and return a new Stream object. Even so, focus of the library was more on the API design and less on performance.

Library is heavily tested with Jest.

Examples

import {Stream} from '@lordofdestiny/streams-ts';

const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

const result = Stream.from(arr)
    .filter(x => x % 2 === 0)
    .map(x => x * 2)
    .toArray();

console.log(result); // [4, 8, 12, 16, 20]

const result2 = Stream.from(arr)
    .filter(x => x % 2 === 0)
    .map(x => x * 2)
    .reduce((acc, x) => acc + x);

console.log(result2); // 60

const result3 = Stream.from(arr)
    .filter(x => x % 2 === 0)
    .map(x => x * 2)
    .findFirst((_) => true);

console.log(result3); // 4

/* We need to make an explicit cast because
   TypeScript can't infer the type of the chunked stream
 */
const stream4 = Stream.from(arr).chunk(2) as Stream<[number, number]>;
const result4 = stream4.toMap();

console.log(result4); // Map { 1 => 2, 3 => 4, 5 => 6, 7 => 8, 9 => 10 }

For more examples, check the tests or the documentation.

Installation

This library is hosted on NPM as well as GitHub Packages.

You can install it with: npm i @lordofdestiny/streams-ts

Building

If you decide to clone the repository, you can build the library with:

npm run build

This will generate the build files in the dist directory.

If you want, you can also build the library in watch mode:

npm run build:watch

Running tests

If you decide to clone the repository, you can run tests with:

npm test

Or you can run tests with watch mode:

npm run test:watch

You can also generate coverage report with:

npm run coverage

This opens a browser with coverage report.

Documentation

Official documentation is avilable at here

You can also generate documentation from the source code by using:

npm run docs

After that, you can open docs/index.html in your browser or by running

npm run docs:open

You can check the tests for more examples.

Clean build results

Build results

npm run clean:build

Documentation

npm run clean:docs

Coverage

npm run clean:coverage