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

js-streams

v1.0.3

Published

**An implementation of Java 8 stream API of Java Script.**

Downloads

3

Readme

Install

$ npm install js-streams

Import

let js_stream = require('js-streams')

Optional

An object that wrapped a single value and provides checks to validate it's presence.

#isPresent()

Check if the value is present.

js_stream.Optional.empty().isPresent() // false
js_stream.Optional.forValue(undefined).isPresent() // false
js_stream.Optional.forValue(5).isPresent() // true
js_stream.Optional.forValue(null).isPresent() // false
js_stream.Optional.forNullableValue(null).isPresent() // true

#get()

Get the wrapped value. Throws an exception if isPresent() returns False.

js_stream.Optional.empty().get() // throws Error
js_stream.Optional.forValue(5).get() // 5
js_stream.Optional.forValue(js_stream.Optional.forValue(5)).get() // 5

#ifPresent(function, function)

A method to consume the internal value if it is present.

js_stream.Optional
    .forValue(5)
    .ifPresent(
        function(value) {
            // value is 5
        }
    )

Seconds callback is invoked when the value is not present.

js_stream.Optional
    .forValue(5)
    .ifPresent(
        null,
        function() {
            // no value present
        }
    )

Stream

A wrapper for either an array or single value. Has method for filtering and finding values using Optional values as return value.

Create a stream

js_stream.Stream.forValue().get() // []
js_stream.Stream.forValue(1).get() // [1]
js_stream.Stream.forValue([1, 2, 3]).get() // [1, 2, 3]

Create a stream

js_stream.Stream.forValue().get() // []
js_stream.Stream.forValue(1).get() // [1]
js_stream.Stream.forValue([1, 2, 3]).get() // [1, 2, 3]

#isEmpty()

js_stream.Stream.forValue().isEmpty() // true
js_stream.Stream.forValue(1).isEmpty() // false

#filter()

Filter the contents of the stream using a predicate function and returns a new stream with the results.

js_stream.Stream.forValue([1, 2]).filter( function(v){return v==2}).get() // [2]

#first()

Returns an Optional value of the first entry in the stream or an empty Optional if the stream was empty.

js_stream.Stream.forValue([1, 2]).first().isPresent() // true
js_stream.Stream.forValue([1, 2]).first().get() // 1
js_stream.Stream.forValue([]).first().isPresent() // false

#find()

Returns an Optional value of the first match found for the supplied predicate.

js_stream.Stream.forValue([1, 2])
    .find(
        function(v){ return v==2 }
        )
    .isPresent() // true

js_stream.Stream.forValue([1, 2])
    .find(
        function(v){ return v==2; }
        )
    .get() // 2

js_stream.Stream.forValue([1])
    .find(
        function(v){return v==2}
    )
    .isPresent() // false

#map()

Calls a defined callback function on each element of an stream, and returns an Stream that contains the results.

js_stream.Stream.forValue([1, 2])
    .map(
        function(v){ return v*2 }
        )
    .get() // [2, 4]

#forEach()

Calls a defined callback function on each element of the stream.

js_stream.Stream.forValue([1, 2])
    .forEach(
        function(v){ // do something }
    )