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

@bemoje/fn

v2.0.0

Published

Higher-order function utilities for argument binding, context manipulation, spying, and method wrapping.

Readme

@bemoje/fn

Higher-order function utilities for argument binding, context manipulation, spying, and method wrapping.

TypeScript Module

Exports

  • bindArg: Binds a specified argument to the provided function, returning a new function that requires only the remaining arguments at call time.
  • bindArgs: Binds specified arguments to the provided function, returning a new function that requires only the remaining arguments at call time.
  • dethisify: Converts a function from a class method by by making the first argument take the place of the 'this' context. The reverse of
  • functionSpy: Wraps a function so that the given
  • setLength: Set the length of a function.
  • setName: Set the name of a function.
  • setNameAndLength: Preserves the name and length of a function or class constructor
  • thisProxy: Returns a function that redirects or 'proxies' the 'this' context of the input function to a property of a given key.
  • thisify: Converts a function to a class method by making the 'this' context the first argument.
  • transformReturnValue: Wraps a function to transform its return value using a transform function.
  • wrapMethods: Wrap methods, getters and setters of an object with custom logic.

Installation

npm install @bemoje/fn

Usage

Bind Arguments

Partially apply arguments at specific positions:

import { bindArg, bindArgs } from '@bemoje/fn'

function greet(greeting: string, name: string, punctuation: string) {
  return `${greeting}, ${name}${punctuation}`
}

const greetHello = bindArg(greet, 0, 'Hello')
greetHello('World', '!') // 'Hello, World!'

const greetHelloWorld = bindArgs(greet, { 0: 'Hello', 1: 'World' })
greetHelloWorld('!') // 'Hello, World!'

Convert Between this and First Argument

import { thisify, dethisify } from '@bemoje/fn'

// Convert a standalone function into a method
function getFullName(target: { first: string; last: string }) {
  return `${target.first} ${target.last}`
}

const method = thisify(getFullName)
// Now usable as: obj.getFullName = method

// Convert a method into a standalone function
const standalone = dethisify(method)
standalone({ first: 'John', last: 'Doe' }) // 'John Doe'

Redirect this Context

import { thisProxy } from '@bemoje/fn'

function getName(this: { name: string }) {
  return this.name
}

// Redirect `this` to a property key
const proxied = thisProxy(getName, 'inner')
// When called on { inner: { name: 'test' } }, returns 'test'

Function Spy

Wrap functions with before/after hooks:

import { functionSpy, type IFunctionSpyStrategy } from '@bemoje/fn'

const timingStrategy: IFunctionSpyStrategy<unknown, number> = {
  onInvoke(_ctx, _args) {
    return performance.now()
  },
  onReturn(startTime, retval) {
    console.log(`Took ${performance.now() - startTime}ms`)
    return retval
  },
}

const timed = functionSpy(myFunction, timingStrategy)

Transform Return Values

import { transformReturnValue } from '@bemoje/fn'

function getItems() {
  return [3, 1, 2]
}

const getSorted = transformReturnValue(getItems, (arr) => arr.sort())
getSorted() // [1, 2, 3]

Wrap Object Methods

import { wrapMethods } from '@bemoje/fn'

wrapMethods(myObject, {
  filter: (_target, key, _type, _des) => key !== 'skip',
  onMethod: (_target, key, original) => {
    return function (...args) {
      console.log(`Calling ${String(key)}`)
      return original.apply(this, args)
    }
  },
})

Function Metadata

import { setName, setLength, setNameAndLength } from '@bemoje/fn'

const fn = () => {}
setName('myFn', fn) // fn.name === 'myFn'
setLength(3, fn) // fn.length === 3