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

entrust

v0.0.21

Published

delegatee-last structure for curried functions

Downloads

37

Readme

entrust

Delegatee-last curried functions for great justice

Greenkeeper badge

You can use entrust to easily transform methods into a curried, delegatee-last (data-last) form. If you are used to functional programming (FP) paradigms, this makes FP in JS much easier.

Example:

// native map looks like: array.map(fn)
// entrust map looks like: e1(`map`, fn, array)
import {e1} from 'entrust'
const map = e1(`map`) // this takes a function first, and then the data
map(x => x * 2, [1,2,3]) // [2,4,6]

Here's an example of how to apply the same approach to a tertiary function, like reduce:

import {e2} from 'entrust'
// native reduce looks like: array.reduce(fn, initial)
const reduce = e2(`reduce`) // e2(`reduce`, fn, initial, array)
const sum = reduce((a, b) => a + b, 0)
sum([1,2,3]) // 6
sum([1,2,3,4]) // 10
sum([1,2,3,4,5]) // 15

NB: This approach is used extensively in the f-utility module. You may want to take a look at it here.

entrust is built using katsu-curry's curry implementation. However, if you would like to use a different curry implementation, this is easily accomplished using the custom API. This specific technque is used to generate entrust's "debug-mode" export: entrust/debug.js.

API

Table of Contents

custom

generate a customized version of entrust's API

Parameters

Examples

import {custom} from 'entrust'
import curry from 'lodash/fp/curry'
const {e0} = custom(curry)

Returns object raw+ an augmented version of the raw API

eN

invoke a delegated method with arguments as an array. enforces specific arity

Parameters

  • n number 0 - 10
  • method string a function name on your delegatee
  • args Array arguments to pass to your delegatee's method
  • delegatee any something with methods

Examples

import {eN} from 'entrust'
eN(0, `toUpperCase`, [], `cool`) // `COOL`
eN(1, `map`, [(x) => x * 2], [1,2,3]) // [2,4,6]
eN(2, `reduce`, [(a, b) => (a + b), 0], [1,2,3]) // 6

Returns any the result of delegating to the method with some arguments

eD

invoke a delegated method with arguments as an array. enforces specific arity Yells at you if you give arguments that don't match the expected arity.

Parameters

  • n number 0 - 10
  • method string a function name on your delegatee
  • args Array arguments to pass to your delegatee's method
  • delegatee any something with methods

Examples

import {eD} from 'entrust'
eD(0, `toUpperCase`, [], `cool`) // `COOL`
eD(1, `map`, [(x) => x * 2], [1,2,3]) // [2,4,6]
eD(2, `reduce`, [(a, b) => (a + b), 0], [1,2,3]) // 6
eD(2, `reduce`, [(a, b) => (a + b)], [1, 2, 3]) // throws error

Returns any the result of delegating to the method with some arguments

e0

Parameters

Examples

import {e0} from 'entrust'
const toLowerCase = e0(`toLowerCase`)
toLowerCase(`COOL`) // cool

Returns any

e1

Parameters

  • fn string a function name
  • a any some parameter
  • x Object an object

Examples

import {e1} from 'entrust'
const split = e1(`split`)
split(`:`, `c:o:o:l`) // [`c`,`o`,`o`,`l`]

Returns any

e10

Parameters

  • fn string a function name
  • a any some parameter
  • b any some parameter
  • c any some parameter
  • d any some parameter
  • e any some parameter
  • f any some parameter
  • g any some parameter
  • h any some parameter
  • i any some parameter
  • j any some parameter
  • x Object an object

Returns any

e2

Parameters

  • fn string a function name
  • a any some parameter
  • b any some parameter
  • x Object an object

Examples

import {e2} from 'entrust'
const replace = e2(`replace`)
replace(`old`, `new`, `oldnew`) // newnew

Returns any

e3

Parameters

  • fn string a function name
  • a any some parameter
  • b any some parameter
  • c any some parameter
  • x Object an object

Returns any

e4

Parameters

  • fn string a function name
  • a any some parameter
  • b any some parameter
  • c any some parameter
  • d any some parameter
  • x Object an object

Returns any

e5

Parameters

  • fn string a function name
  • a any some parameter
  • b any some parameter
  • c any some parameter
  • d any some parameter
  • e any some parameter
  • x Object an object

Returns any

e6

Parameters

  • fn string a function name
  • a any some parameter
  • b any some parameter
  • c any some parameter
  • d any some parameter
  • e any some parameter
  • f any some parameter
  • x Object an object

Returns any

e7

Parameters

  • fn string a function name
  • a any some parameter
  • b any some parameter
  • c any some parameter
  • d any some parameter
  • e any some parameter
  • f any some parameter
  • g any some parameter
  • x Object an object

Returns any

e8

Parameters

  • fn string a function name
  • a any some parameter
  • b any some parameter
  • c any some parameter
  • d any some parameter
  • e any some parameter
  • f any some parameter
  • g any some parameter
  • h any some parameter
  • x Object an object

Returns any

e9

Parameters

  • fn string a function name
  • a any some parameter
  • b any some parameter
  • c any some parameter
  • d any some parameter
  • e any some parameter
  • f any some parameter
  • g any some parameter
  • h any some parameter
  • i any some parameter
  • x Object an object

Returns any