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

underscorer

v1.0.4

Published

Underscorer is a functioner and chainer for underscore

Downloads

10

Readme

Underscorer

npm version bower version Dependencies Downloads Gitter(https://badges.gitter.im/Join Chat.svg)

Underscorer is a functioner :smile: and chainer :smirk: for underscore

What is the meaning of underscorer?

First you must understand the meaning of functioner and chainer.

As you know, the er suffix in English can be used to describe the subject who performs a task, e.g. employer for the person who employs. Similarly, the functioner is the one who creates a function and chainer chains them together like functional languages.

Underscorer is a functioner and chainer for underscore

Install

$ npm install underscorer
$ bower install underscorer
$ meteor add underscorer

Benchmarks

You can see Benchmarks

Usage

Node.js

var _r = require('underscorer');

Browser

<script src="underscore.js"></script>
<script src="underscorer.js"></script>

Functioning

In underscore, the _.last function returns the last item of passed array

_.last([3, 4, 1, 5]); // 5

Underscorer replaces it by _r.laster (last + er) function. It creates a function which whenever called, returns the last item of array. Because underscorer is a functioner.

var fn = _r.laster()
fn([3, 4, 1, 5]); // 5
fn([5, 2, 6, 1]); // 1

Chaining

Suppose that you want to calculate the sum of squares of values which are stored in the last item of another list.

var l = [{a: 1, b: 4}, {a: 3}, {a: 3, c: 4}];
_.reduce(_.map(_.values(_.last(l)),function (i) {return i * i;}),function(a, b){ return a + b});

The underscorer isn't just a simple functioner but also a chainer. That is, you can chain functions together.

var fn = _r
    .laster()
    .valueser()
    .maper(function (i) { return i * i; })        // maper!? I know :D
                                                  // ... but this is map + er
    .reduceer(function (a, b) { return a + b; }); 

fn([{a: 1, b: 4}, {a: 3}, {a: 3, c: 4}]);         // 25
fn([{i: 1, j: 8}, {k: 1, l: 2}]);                 // 5

Obtained functions can be reused anywhere. Call them multiple times or use them within other chains.

var fnBase = _r
    .laster()
    .valueser();
    
var fnPow2 = fnBase.maper(function (i) {
    return i * i;
});

var fnPow3 = fnBase.maper(function (i) {
    return i * i * i;
});

fnBase([{i: 1, j: 2}, {k: 5}, {k: 3, l: 2}]); // [ 3, 2 ]
fnPow2([{i: 1, j: 2}, {k: 5}, {k: 3, l: 2}]); // [ 9, 4 ]
fnPow3([{i: 1, j: 2}, {k: 5}, {k: 3, l: 2}]); // [ 27, 8 ]

Underscorer as a function

Underscore support object-oriented style of coding too. It allows passing the list/object/iteratee as an underscore object and so saves passing it to the last, values, etc. in the functional style. Similarly, the underscorer gets the list argument using _r function.

// underscore
_([1, 2, 3]).last(); // 3

// underscorer
_r([1, 2, 3]).laster(); // function
_r([1, 2, 3]).laster()(); // 3
// chaining
_r([[2, 4], [4, 5], [5, 6]])
    .laster()
    .maper(function(i){return i * i})();          // [ 25, 36 ]
// forking chains
var fn = _r([[2, 4], [4, 5], [5, 6]]).laster();   // function
fn.maper(function(i){return i * i})();            // [ 25, 36 ]
fn.maper(function(i){return i * i * i})();        // [ 125, 216 ]

API

All functions of underscore + er suffix :)

For example: laster, firster, sampleer, and sortByer. And Functions that supported in underscore chain: poper, pusher, reverseer, shifter, sorter, spliceer, unshifter, concater, joiner , and sliceer.

Note: underscore extend, default, pop, push, reverse, shift, sort, splice, unshift functions are mutable. Similarly underscorer.

var x = [1, 2, 3];
var y = _r(x).pusher(4)(); // mutable
x               // [1, 2, 3, 4]
x === y         // true