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

f-js

v0.5.2

Published

Dead simple library for functional and reactive programming

Downloads

21

Readme

F.js

Build Status Gitter Stable release Stable release MIT License

Sauce Test Status

F.js is a collection of helper methods used for functional and reactive programming in JavaScript. It provides methods for transforming, filtering, reducing and other operations which work on arrays, HTMLCollections, ES6 generators (and almost all other indexables) and streams of events.

Installing

With bower

bower install f.js --save-dev

And include the main script file into your project:

<script src="bower_components/f.js/dist/F.min.js"></script>

With NPM

npm install f-js --save-dev

And require the f-js module into your files:

var Fjs = require("f-js"),
  F = Fjs.F,
  P = Fjs.P;

Manually downloading the zip file

curl "https://codeload.github.com/colin-dumitru/F.js/zip/0.5.0" > F.js.zip
unzip F.js.zip

And include the main script file into your project:

<script src="F.js-0.5.0/dist/F.min.js"></script>

Documentation

Samples

F.js works with regular Arrays (RUN)

var people = [
  { name: "John", age: 31},
  { name: "Colin", age: 25},
  { name: "Dave", age: 13},
  { name: "Vic", age: 52}
];

var result = F(people)
  .filter(function(person) {
    return person.age < 50;
  })
  .property("name")
  .drop(1)
  .zip(["first", "second"])
  .toArray();

document.write(JSON.stringify(result));

HTML collections (RUN)

var links = document.getElementsByTagName("a"),
    titles = document.getElementsByTagName("h5");

var result = F(links)
  .property("href")
  .dropWhile(function(val) {
    return val.indexOf("http") == -1;
  })
  .zip(
    F(titles)
      .property("innerText")
  )
  .toMap();

document.write(JSON.stringify(result));

And even ES6 generators (RUN)

function *gen() {
  for (var i = 0; i < 10; i++) {
    yield i;
  }
}

var result = F(gen())
  .fold((l, r) => l + r);

document.write(result);

So at it's core, F.js is just another functional library. But the real power comes when you combine reactive programming with streams.

Streams are nothing more than promises which can resolve multiple times. You can either push or consume values from a stream, all done asynchronously. This enables you to write more modular async code, by passing values through streams and not callbacks.

This next example takes a search query from an input element and displays a list of images which match the given query, all done using streams.

Stream example (RUN)

var input = $("#search_query"),
    keyStream = F.eventStream(input, "keydown"),
    wordStream = F.stream(),
    imageStream = F.stream();

F(keyStream)
  .property("keyCode")
  .accumulateUntil(P.equalTo(13)) /* Enter */
  .map(function() {
    return input.val();
  })
  .feedStream(wordStream)
  .pullStream();

F(wordStream)
  .each(text =>
        $.ajax({
                url: url + text,
                dataType: 'jsonp',
                jsonp: 'jsonFlickrApi',
                jsonpCallback: 'jsonFlickrApi'
            })
          .then(imageStream.bindPush()))
  .pullStream();

F(imageStream)
  .each(reset)
  .property("photos", "photo")
  .each(images =>
       F(images)
        .map(render)
        .foreach(display))
  .pullStream();

Got you interested? Visit our wiki pages for more examples and info.