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

@oggi.ch/pipe

v0.1.2

Published

Pipeline: make a chain of functions that the output will be the input of the next function.

Downloads

4

Readme

@oggi.ch/pipe

Pipeline: make a chain of functions that the output will be the input of the next function.

Install

$ npm install @oggi.ch/pipe
or
$ yarn add @oggi.ch/pipe

Usage

const pipe = require('@oggi.ch/pipe');
pipe(
    initialValue,
    [...functions]
)

Examples

### Example 1

const pipe = require('@oggi.ch/pipe');

const double = a => a * 2;
const sum = (a, b) => a + b;
const minus = (a, b) => a - b;
const div = (a, b) => a / b;
const multiply = a => b => a * b;

const result_1 = pipe(
    6, 
    double,
    console.log,      // ← Debuggable 
    _ => sum(10, _), 
    _ => div(_, 3),
    console.log,     // ← Easy print intermediate result
    Math.floor, 
    multiply(6), 
    _ => minus(_, 3)
);

console.log('Result is', result_1);
-------------------------------------------------------------------------------
12
7.333333333333333
Result is 39

### Example 2

const cleanVowels = str => str.replace(/[aeiou]/ig, "");

const result_2 = pipe(
    "Lorem ipsum dolor sit amet.",
    cleanVowels,
    (_) => _.split(""),
    (_) => _.reverse(),
    (_) => _.join("")
);

console.log('Result is', result_2);
-------------------------------------------------------------------------------
Result is  .tm ts rld msp mrL

### Example 3

const reParser = /^(\S+) (\S+) (\S+) \[([\w:/]+\s[+\-]\d{4})\] "(\S+)\s?(\S+)?\s?(\S+)?" (\d{3}|-) (\d+|-)\s?"?([^"]*)"?\s?"?([^"]*)?"?$/;

const parseLogLines = (logs) => {
    return logs.map(log => {
        const parsed = log.match(reParser);
        return {
            ipAddress: parsed[1],
            datetime: moment(parsed[4], 'DD/MMM/YYYY:HH:mm:ss ZZ'),
            method: parsed[5],
            resource: parsed[6],
            protocol: parsed[7],
            status: parsed[8],
            size: parsed[9],
            referer: parsed[10],
            userAgent: parsed[11]
        }
    });
};

const trim = str => str.trim();
const split = token => str => str.split(token);
const take = key => items => ( items.map(item => item[key]) );
const grep = rule => items => ( items.filter(item => item.indexOf(rule) !== -1) );
const wc = items => items.reduce(totals => totals + 1, 0);

const accesslog = `
127.0.0.1 - - [21/Aug/2017:09:10:51 +0000] "GET / HTTP/1.1" 200 534 "" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.49 Safari/537.36"
127.0.0.1 - - [21/Aug/2017:09:10:53 +0000] "GET /admin HTTP/1.1" 200 534 "" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.49 Safari/537.36"
127.0.0.1 - - [21/Aug/2017:09:10:57 +0000] "GET / HTTP/1.1" 200 14 "" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.49 Safari/537.36"
127.0.0.1 - - [21/Aug/2017:09:10:58 +0000] "GET /admin HTTP/1.1" 200 534 "" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.49 Safari/537.36"
127.0.0.1 - - [21/Aug/2017:09:10:59 +0000] "GET /admin HTTP/1.1" 200 534 "" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.49 Safari/537.36"
`; 

const result_3 = pipe(
    accesslog,
    trim,
    split('\n'),
    parseLogLines,
    take('resource'),
    grep('/admin'),
    wc
);
console.log('Result is', result_3);
-------------------------------------------------------------------------------
Result is 3

### Example 4 (async)

const asyncDouble = a => new Promise((resolve, reject) => {
    setTimeout(() => {
        resolve(a * 2)
    }, 500);
});

const asyncAdd = (a, b) => new Promise((resolve, reject) => {
    setTimeout(() => {
        resolve(a + b)
    }, 100);
});

const result_4 = pipe(
    6,
    asyncDouble,
    (_) => (_ - 1),
    (_) => asyncAdd(_, 7)
);

console.log('Async result is...');
result_4.then(console.log)
-------------------------------------------------------------------------------
Async result is...
18