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

evangelist

v0.13.5

Published

Library of helpers that are useful for functional programming

Downloads

29

Readme

🌟 evangelist

build status npm version npm download dependencies coverage status license

What is the Evangelist?

Evangelist is a set of helper methods that are useful and reusable for base functional programming requirements such as function composition, function decoration, event dispatching and emitting, etc.

Plus, as a library, Evangelist is completely tree-shaking-friendly. Your favorite module bundler can easily inline the functionality you need with no extra configuration, instead of bundling the whole Evangelist package.

Quick start

Execute npm install evangelist or yarn add evangelist to install evangelist and its dependencies into your project directory.

Usage of modules

compose(...functionsForComposition)

import compose from 'evangelist/compose';

// compose - slug sample
const lower = x => x.toLowerCase();
const chars = x => x.replace(/[^\w \-]+/g, '');
const spaces = x => x.split(' ');
const dashes = x => x.join('-');

const slug = compose(lower, chars, spaces, dashes);

const message = slug('Hello World!');

// outputs 'slug: hello-world'
console.log(`slug: ${message}`);

curry(targetFunction, ...argumentsToBePrepended)

import curry from 'evangelist/curry';

// curry - sum sample
const sum = (a, b) => a + b;

const sumWith5 = curry(sum, 5);

const result = sumWith5(3);

// outputs 'result: 8'
console.log(`result: ${result}`);

curryRight(targetFunction, ...argumentsToBeAppended)

import curryRight from 'evangelist/curryRight';

// curryRight - sum sample
const dec = (a, b) => a - b;

const decWith5 = curry(dec, 5);

const result = decWith5(3);

// outputs 'result: -2'
console.log(`result: ${result}`);

decorate(functionToDecorate, decoratorFunction)

import decorate from 'evangelist/decorate';

// decorate - calculator sample
let generator = () => 5;
generator = decorate(generator, (func) => func() * 2);
generator = decorate(generator, (func) => func() + 1);

// outputs: 'generated: 11'
console.log(`generated: ${generator()}`);

dispatcher(initialState, mutators) (awaitable)

import dispatcher from 'evangelist/dispatcher';

// dispatcher - state mutation sample
const initialState = { quarter: 1, year: 2018, sum: 1 };

const actionAdd5 = (state, next) => next({ ...state, sum: state.sum + 5 });
const actionDiv2 = (state, next) => next({ ...state, sum: state.sum / 2 });

// outputs 'new state is: {"quarter":1,"year":2018,"sum":3}'
dispatcher(initialState, [ actionAdd5, actionDiv2 ])
    .then(state => console.log(`new state is: ${JSON.stringify(state)}`));

dispatcher(initialState, mutators, subscribers) (awaitable)

import dispatcher from 'evangelist/dispatcher';

// dispatcher - action logger sample
const initialState = { quarter: 1, year: 2018, sum: 1 };

const actionAdd5 = (state, next) => next({ ...state, sum: state.sum + 5 });
const actionDiv2 = (state, next) => next({ ...state, sum: state.sum / 2 });

const logger = (x) => console.log('INFO', x);

/* outputs:
   INFO { action: 'actionAdd5',
     previousState: { quarter: 1, year: 2018, sum: 1 },
     newState: { quarter: 1, year: 2018, sum: 6 } }
   INFO { action: 'actionDiv2',
     previousState: { quarter: 1, year: 2018, sum: 6 },
     newState: { quarter: 1, year: 2018, sum: 3 } }
   new state is: {"quarter":1,"year":2018,"sum":3}'
*/
dispatcher(initialState, [ actionAdd5, actionDiv2 ], [ logger ])
    .then(state => console.log(`new state is: ${JSON.stringify(state)}`));

emitter(events, eventName, eventParameters) (awaitable)

import emitter from 'evangelist/emitter';

// emitter - static pub/sub sample
const subscriberOne = (value) => console.log(`subscriberOne had value ${value}`);
const subscriberTwo = (value) => console.log(`subscriberTwo had value ${value}`);

const events = {
    printToConsole: [ subscriberOne, subscriberTwo ],
};

/* outputs:
   subscriberOne had value 5
   subscriberTwo had value 5
*/
emitter(events, 'printToConsole', [ 5 ]);

emitter(events, eventName, eventParameters, subscribers) (awaitable)

import emitter from 'evangelist/emitter';

// emitter - event logger sample
const subscriberOne = (value) => console.log(`subscriberOne had value ${value}`);
const subscriberTwo = (value) => console.log(`subscriberTwo had value ${value}`);

const logger = (x) => console.log('INFO', x);

const events = {
    printToConsole: [ subscriberOne, subscriberTwo ],
};

/* outputs:
   INFO { event: 'printToConsole',
     subscriber: 'subscriberOne',
     args: [ 5 ] }
   subscriberOne had value 5
   INFO { event: 'printToConsole',
     subscriber: 'subscriberTwo',
     args: [ 5 ] }
   subscriberTwo had value 5
*/
emitter(events, 'printToConsole', [ 5 ], [ logger ]);

iterate(iterable, func) (awaitable)

import iterate from 'evangelist/iterate';
import compose from 'evangelist/compose';

// iterate - url fetcher example
const generator = function* () {
    yield 'http://localhost/samples/1'; // { value: 1 }
    yield 'http://localhost/samples/2'; // { value: 2 }
    yield 'http://localhost/samples/3'; // { value: 3 }
};

const fetchUrl = async function (url) {
    const response = await fetch(url);
    const document = await response.json();

    return document.value;
}

const add5 = async value => await value + 5;
const printToConsole = async value => { console.log(await value); };

/* outputs:
   value is 6
   value is 7
   value is 8
*/
iterate(
    generator(),
    compose(fetchUrl, add5, printToConsole),
);

Todo List

See GitHub Projects for more.

Requirements

  • node.js (https://nodejs.org/)

License

Apache 2.0, for further details, please see LICENSE file

Contributing

See contributors.md

It is publicly open for any contribution. Bugfixes, new features and extra modules are welcome.

  • To contribute to code: Fork the repo, push your changes to your fork, and submit a pull request.
  • To report a bug: If something does not work, please report it using GitHub Issues.

To Support

Visit my patreon profile at patreon.com/eserozvataf