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 🙏

© 2026 – Pkg Stats / Ryan Hefner

xfn

v1.0.0

Published

Extends a function object with configured versions of itself.

Downloads

50

Readme

Extended Function (xfn)

Extends a function object with configured versions of itself.

Installation

Requires Node.js 7.0.0 or above.

npm i xfn

Tutorial

Singular/Plural

xfn simplifies the process of creating singular and plural versions of the same function (e.g. get() and get.all()). The function that you write is the plural version, and xfn creates the singular version. The following example uses each as the name of the plural function:

const xfn = require('xfn')

const getFirstOf = xfn({
  pluralProp: 'each',
  pluralReturn: true,
}, arrs => arrs.map(arr => arr[0]))

const arr = [[1, 2], ['a', 'b']]

getFirstOf(arr) // [1, 2]
getFirstOf.each(arr) // [[1], ['a']]

The first call treats arr as a single array, while the second call treats arr as an array of arrays.

Preset Options

xfn lets you create subfunctions that have certain options preconfigured. For example, you can replace fn(arg, {option: true}) with fn.option(arg).

const getOwnProperty = require('get-own-property')
const xfn = require('xfn')

const get = xfn({
  optionArg: 2, // The index of the parameter that contains the options
  optionProps: {own: {own: true}},
}, (obj, key, {own} = {}) => own ? getOwnProperty(obj, key) : obj[key])

class Cls {
  get inherited () { return 123 }
}

const obj = new Cls()
obj.mine = 456

get(obj, 'mine') // 456
get(obj, 'inherited') // 123
get.own(obj, 'mine') // 456
get.own(obj, 'inherited') // undefined

API

The module exports a single function.

Parameters

  1. Object argument:
    • Optional: pluralArg (positive integer): The zero-based index of the argument that should be singularized if pluralProp is set. Defaults to 0.
    • Optional: pluralFirst (boolean): If true, the pluralProp comes before the optionProps when they are both set. Defaults to false. (For example: a pluralProp of all and an optionProps key of in will result in a property chain of all.in() if true, or in.all() if false.)
    • Optional: pluralProp (string or symbol): If set, the returned function will be a singularized version of fn, and the original fn will be attached to the pluralProp property of the returned function (e.g. if pluralProp is set to 'all' and the returned function is assigned to the variable get, the available functions will be get() and get.all()).
    • Optional: pluralReturn (boolean): Only applies if pluralProp is set. Set to true if fn returns an array of one result per argument. (This will cause the one-element result array to be unwrapped when the singularized function is called.) Set to false if fn returns a result that does not correspond to the number of arguments. Defaults to false.
    • Required if optionProps is set: optionArg (positive integer): The zero-based index of the argument into which the preconfigured options of optionProps should be inserted.
    • Optional: optionProps (object or Map): A collection whose keys are the desired fn property keys and whose values are the option objects that should be merged into the plain object argument at index optionArg.
    • Optional: sbo (object or false): Options to be passed to the sbo module (which adds support for the bind operator), or false if you do not want the sbo module applied.
  2. fn (function): The main function that should be extended on the basis of the arguments in the first parameter.

Return Value

A function object with pluralProp and/or optionProps properties.

Related

This module is part of the fn family of modules.

  • efn: Extracted Function
  • ffn: Filtering Function
  • jfn: Joined Function
  • mfn: Memoized Function
  • ofn: Overloaded Function
  • pfn: Possible Function
  • qfn: Qualified Function
  • vfn: Variadic Function
  • wfn: Wrapper Function