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

fwrap

v1.0.0

Published

A high-performance utility for runtime function name obfuscation, identity spoofing, and recursive bottom-up object graph freezing.

Readme

fwrap

npm version Node.js License Socket Badge Donate

Lightweight utilities for anonymizing function names and deeply processing object graphs.


Installation

NodeJS

npm install fwrap

Browser (via ESM)

<script type="module">
  import fwrap, { fwrapObj } from 'https://esm.sh/fwrap';
</script>

Quick Start

import fwrap, { fwrapObj } from 'fwrap';

// Anonymize a single function
const fn = fwrap(function mySecret() {});
console.log(fn.name); // ''

// Anonymize all functions in an object graph and freeze it
const api = fwrapObj({
    getUser: function getUser() { /* ... */ },
    saveUser: function saveUser() { /* ... */ },
});

console.log(api.getUser.name); // ''
console.log(Object.isFrozen(api));  // true

API

fwrap(fn, obj?, key?, opts?)

Strips the name property from a function by redefining it as ''.

When called standalone it returns the anonymized function. When obj and key are provided it mutates obj[key] in-place and returns undefined. On failure (e.g. a non-configurable name) it returns the original function unchanged rather than throwing.

| Parameter | Type | Default | Description | |---|---|---|---| | fn | Function | — | The function to anonymize. | | obj | Object | null | null | Optional parent object for in-place mutation. | | key | string | symbol | null | null | Property key on obj to reassign. | | opts.configurable | boolean | true | Whether name can be redefined later. | | opts.writable | boolean | false | Whether name can be assigned directly. | | opts.enumerable | boolean | false | Whether name appears in enumeration. |

Returns: Function | void

// Standalone
const anon = fwrap(function named() {});
console.log(anon.name); // ''

// In-place
const obj = { greet: function greet() {} };
fwrap(obj.greet, obj, 'greet');
console.log(obj.greet.name); // ''

// With descriptor overrides
const fn = fwrap(function named() {}, null, null, { writable: true });

fwrapCustom(fn, obj?, key?, opts?)

Identical to fwrap but accepts a value override, allowing any name to be set rather than always stripping it to ''.

| Parameter | Type | Default | Description | |---|---|---|---| | fn | Function | — | The function to rename. | | obj | Object | null | null | Optional parent object for in-place mutation. | | key | string | symbol | null | null | Property key on obj to reassign. | | opts.value | string | '' | The custom name to assign. | | opts.configurable | boolean | true | Whether name can be redefined later. | | opts.writable | boolean | false | Whether name can be assigned directly. | | opts.enumerable | boolean | false | Whether name appears in enumeration. |

Returns: Function | void

const fn = fwrapCustom(function original() {}, null, null, { value: 'alias' });
console.log(fn.name); // 'alias'

fwrapObj(obj, isFreeze?, _opts?, _seen?)

Recursively scans an object or array to anonymize all function names, then optionally deep-freezes it.

  • Skips non-writable, non-configurable, and accessor (getter/setter) properties to avoid errors with third-party or native objects.
  • Handles circular references safely via an internal WeakSet.
  • Freezes bottom-up so child structures are immutable before their parents.

| Parameter | Type | Default | Description | |---|---|---|---| | obj | Object | Array | — | The target structure to process. | | isFreeze | boolean | true | Whether to deeply freeze the structure after processing. | | _opts | Object | {} | Descriptor overrides forwarded to every fwrap call. | | _seen | WeakSet | new WeakSet() | Internal circular-reference tracker; do not pass manually. |

Returns: Object | Array

// Deep freeze + anonymize (default)
const config = fwrapObj({
    load: function load() {},
    nested: {
        parse: function parse() {},
    },
});

console.log(config.load.name);          // ''
console.log(config.nested.parse.name);  // ''
console.log(Object.isFrozen(config));   // true

// Anonymize without freezing
const mutable = fwrapObj({ fn: function fn() {} }, false);
console.log(Object.isFrozen(mutable)); // false

// Pass descriptor overrides to all wrapped functions
const api = fwrapObj({ fn: function fn() {} }, true, { writable: true });

Behavior Notes

Descriptor defaults. By default name is set with configurable: true, writable: false, enumerable: false — matching native function behavior. Direct assignment (fn.name = 'x') will silently fail in sloppy mode or throw in strict mode; Object.defineProperty can still re-set it.

Failure safety. Both fwrap and fwrapCustom catch any defineProperty error and return the original function unchanged, so they are always safe to call regardless of the target's property descriptors.

Read-only and accessor properties. fwrapObj skips any property where writable === false, configurable === false, or a getter/setter is present. This prevents errors when processing objects from third-party modules or native APIs.

Circular references. fwrapObj tracks visited objects in a WeakSet and silently skips any already-seen reference, preventing infinite recursion.


Funding & Support 🤍

If you find this utility useful in securing your application structures, consider supporting development:


License

Licensed under the Apache License, Version 2.0; a robust, permissive license that includes an explicit grant of patent rights and provides protection against contributor liability.

Copyright © 2026 Aries Harbinger. See the LICENSE file for full details.