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

lowdown-v2-r-terradev

v1.0.0

Published

An npm functional programming library project

Downloads

1

Readme

lodown

An npm functional programming library project

In this project, you're going to create your own functional library of code and release this code for use through the npm (Node Package Management) platform.

You'll then use your lodown library to solve problems in the next project.

Setup

  1. Fork this repository to your own GitHub account.

  2. Clone your forked version of the lodown repository to a new Cloud9 workspace.

  3. We'll need a package.json file, which describes for npm our library project and lists any dependant libraries of code. To create a package.json configuration file for our lodown library, from the command-line, run the command:

     npm init
  4. IMPORTANT CONFIGURATION: Fill in the prompts with your own details:

    1. When asked to name your lodown project, give it a unique name by appending your GitHub username to the name of the project (of course, replacing <my-github-username> with your actual GitHub username.), like so:

      lodown-<my-github-username>

    2. When asked for test command, enter:

      istanbul cover _mocha -- test/ -R spec

    3. When asked for your git repository, you will probably be given the correct url as the default, so just select this by pressing return, otherwise, provide your forked GitHub repository's url.

  5. Once you're done creating your package.json file, go to the command line and install the required test libraries by running the following command:

     npm install i -D mocha chai sinon istanbul
  6. Implement your library in the file index.js. Remember that index.js is a Node.js module, so you must export your API using module.exports, for example:

     function each(collection, action) {
         // ...code
     }
     module.exports.each = each;
  7. Write clear docs for each Function using the proper JavaScript documentation format. You should clearly explain how each Function works, the type of each paramater and how each paramater is used, and explain any return value. It should be evident from your docs you clearly understand how each Function works. Bonus points for listing usage examples in your docs. Example:

     /**
      * filter: Designed to filter values in a collection based on a test. 
      * Takes a collection, Array or Object, and passes each value 
      * in the collection through a test Function. The test Function returns 
      * true if the value passes the test, false otherwise. Values that pass 
      * the test are collected and returned in an output Array.
      * 
      * @param {Array or Object} collection: The collection to filter.
      * @param {Function} test: The Function to be applied to each value in 
      * the collection. The test Function must return a Boolean based on some 
      * logic which tests the value given to it.
      * 
      * @return {Array}: An Array containing the filtered collection values. 
      * The Array will contain only the values that passed the test.
      * 
      * Usage: 
      * 
      *      const letters = ['a', 'b', 'b', 'c'];
      *      const onlyBs = filter(letters, function(letter) {
      *          return letter === 'b';
      *      });
      *      console.log(onlyBs); // -> ['b', 'b']
      */
     function filter(collection, test) {
         // ...code
     }
     module.exports.each = each;
  8. Once you're done with all Functions and their docs, release your lodown library to npm (node package manager), following the steps in this video to do so (using your GitHub username to create a unique name for your library):

    publishing-npm-packages

Optional: Unit tests

If you want to learn about and create unit tests for your code, write your tests in the file test/index.spec.js. Check out the chai api for examples on asserting expectations and be careful when asserting/expecting against complex types - you'll have to make use of the .eql api, and not .equal. For example:

    expect(lodown.filter([1, 2, 3], function(value) { return value > 2; } )).to.eql([3]);
  1. To run your tests, run the following command:

     npm test
  2. Check the console output for passes and failures.

  3. Preview (Cloud9) or open the file at coverage/lcov-report/index.html for your coverage report. Make certain all lines of code are traversed in your tests!

Resources:

Docs

  1. https://mochajs.org
  2. http://chaijs.com/api/bdd/
  3. http://sinonjs.org/docs/#spies-api

Reading

  1. http://marcofranssen.nl/using-mocha-chai-sinon-to-test-node-js/
  2. http://stackoverflow.com/questions/19298118/what-is-the-role-of-describe-in-mocha
  3. http://www.vapidspace.com/coding/2014/10/29/code-coverage-metrics-with-mocha-and-istanbul/

Quick Videos

  1. https://egghead.io/lessons/javascript-how-to-write-a-javascript-library-setting-up-unit-testing-with-mocha-and-chai
  2. https://egghead.io/lessons/javascript-how-to-write-a-javascript-library-unit-testing-with-mocha-and-chai