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 🙏

© 2025 – Pkg Stats / Ryan Hefner

function-feature

v1.1.2

Published

Get V8 function type flags (IsConstructor, IsAsyncFunction, IsGeneratorFunction). Also includes features like getting bind source, Proxy source, function renaming, etc.

Readme

function-feature 🚀

High-performance V8 native function feature detection for Node.js. Supports Node.js 16/18/20/22/24, auto-loads prebuilt binaries, no Nan/N-API dependency required.

Note: Only works in Node.js environments. And prebuilds are only for linux.

Recommended: set "type": "module" in your package.json to use this module with ES6 imports.

For more awesome packages, check out my homepage💛

📦 Installation

npm install function-feature

✨ Import

import {
  getFeatures,
  getBound,
  getOrigin,
  getProxyConfig,
  setName,
  protoToString,
  isClass,
} from 'function-feature';

🧩 API Reference

getFeatures(fn: Function): FunctionFeaturesResult

Analyze a JavaScript function using V8 internals and return its feature flags:

  • isConstructor: Determines if argument is a function object with a [[Construct]] internal method
  • isCallable: Determines if argument is a callable function with a [[Call]] internal method
  • isAsyncFunction: true if the function is an async function
  • isGeneratorFunction: true if the function is a generator function
  • isProxy: true if the function is a Proxy
  • isBound: true if the function has a bound target (created by Function.prototype.bind)
  • isClass: true if the function is a class (either user-defined or native)
  • origin: The original function/object (unwrapped)

Example:

getFeatures(function test(a, b) {});
const result = {
  isConstructor: false,
  isCallable: true,
  isAsyncFunction: false,
  isGeneratorFunction: false,
  isProxy: false,
  isBound: false,
  isClass: false,
  origin: [Function: test]
}

getBound(fn: Function): Function | undefined

Get the original function that satisfies fn = fn0.bind(thisArg, ...args). If not bound, returns itself.

Example:

function test() {}
const bound = test.bind(null);
getBound(bound); // returns test

getOrigin(o: Function | object): Function | object

Get the true origin function/object, tracing through bound and proxy wrappers. For objects, only proxy will be unwrapped.

Example:

const f0 = function () {};
const proxy = new Proxy(f0, {});
const bound = proxy.bind(null);
getOrigin(bound); // returns f0
getOrigin(proxy); // returns f0
getOrigin({}); // returns {}

getProxyConfig(o: object | Function): { target: unknown, handler: unknown } | undefined

Get proxy details (target and handler) if the input is a Proxy object/function. Returns undefined if not a Proxy.

Example:

const target = () => {};
const handler = {};
const proxy = new Proxy(target, handler);
getProxyConfig(proxy); // { target: [Function], handler: {} }
getProxyConfig(target); // undefined

setName(fn: Function, name: string | symbol): Function

Set the name of a function. Only works if the name property is configurable. Class/arrow/native functions cannot be changed.

  • If name is a symbol, uses name.description:
    • If description is undefined, uses ''
    • If description is a string, uses '[description]'

Example:

function foo() {}
setName(foo, 'bar');
console.log(foo.name); // 'bar'
setName(foo, Symbol('baz'));
console.log(foo.name); // '[baz]'

protoToString(fn: Function): string

Equivalent to Function.prototype.toString but uses V8 internals to get the string representation. Safe and not affected by user overrides.

Example:

protoToString(function foo() {});

isClass(fn: Function): boolean

Check if a function is a class (either user-defined or native constructor).

Rules:

  1. Must be a constructor
  2. Gets the original function (unwraps bound functions)
  3. Native constructor (Array, Object, etc.) will return true
  4. Checks function.toString() for class syntax patterns

Example:

isClass(Array); // true
isClass(class A {}); // true
isClass(function () {}); // false

📄 License

MIT