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

@prexjs/wrappy

v1.0.3

Published

Lightweight TypeScript utility that wraps functions while preserving their own properties and callback decorations.

Readme

@prexjs/wrappy

A lightweight TypeScript utility that wraps functions while preserving their own properties and callback decorations.

npm version npm downloads License: MIT TypeScript

@prexjs/wrappy wraps functions without losing their own enumerable properties and ensures callback decorations survive wrapping when a wrapper function returns a different callback.

Features

  • Wrap functions without losing their own enumerable properties.
  • Preserve callback properties when a wrapper returns a different callback function.
  • Support TypeScript generics for function signatures and return types.
  • Provide both named and default exports.
  • Lightweight implementation with no runtime dependencies.

Installation

Install using your preferred package manager:

# npm
npm install @prexjs/wrappy

# pnpm
pnpm add @prexjs/wrappy

# Yarn
yarn add @prexjs/wrappy

# Bun
bun add @prexjs/wrappy

Quick start

import { wrappy } from '@prexjs/wrappy';

function original(value: string): string {
  return `Hello, ${value}!`;
}

const wrapped = wrappy(original);

console.log(wrapped('World')); // 'Hello, World!'

Both default and named imports are supported:

import wrappy, { wrappy as namedWrappy } from '@prexjs/wrappy';

Examples

Preserve function properties

Properties attached to the original function are copied to the wrapper:

import { wrappy } from '@prexjs/wrappy';

function callback() {
  // Callback logic
}

Object.assign(callback, {
  label: 'request-callback',
  customFlag: true,
});

function wrapper(fn: typeof callback) {
  return fn;
}

const wrapped = wrappy(wrapper);

console.log((wrapped as typeof wrapper & { label?: string }).label);
// 'request-callback'

The wrapper copies enumerable own string-keyed properties from the original function using Object.keys().

Preserve callback properties

When the wrapped function returns a different function, enumerable own properties from the final argument are copied to the returned function:

import { wrappy } from '@prexjs/wrappy';

type Callback = (() => void) & {
  label?: string;
};

function wrapper(callback: Callback) {
  const decorated = (() => {
    callback();
  }) as Callback;

  return decorated;
}

const callback = Object.assign(() => {
  console.log('Callback executed');
}, {
  label: 'completion',
});

const wrapped = wrappy(wrapper);
const result = wrapped(callback);

console.log(result.label); // 'completion'

This behavior ensures that metadata or custom tags attached to callbacks remain intact even after the callback is transformed by a wrapper.

Compatibility

@prexjs/wrappy is designed for JavaScript and TypeScript projects. It is distributed with ES Modules (.mjs), CommonJS (.cjs), and TypeScript declarations. It runs in any modern JavaScript runtime without platform-specific dependencies.

License

This project is licensed under the MIT License. See LICENSE for the full license text.

Related projects

  • prex.js — prex.js monorepo and ecosystem.