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

@fnet/invoke

v0.1.4

Published

The `@fnet/invoke` module provides a simple utility for dynamically invoking methods on an object. It facilitates calling a specific method without having pre-defined knowledge of its name or the arguments it requires. This tool proves beneficial in scena

Downloads

9

Readme

@fnet/invoke

The @fnet/invoke module provides a simple utility for dynamically invoking methods on an object. It facilitates calling a specific method without having pre-defined knowledge of its name or the arguments it requires. This tool proves beneficial in scenarios where methods need to be invoked dynamically based on runtime data or configurations.

How It Works

@fnet/invoke operates by taking a target object along with the name of a method you wish to call and any necessary arguments. It will then execute the specified method with the provided arguments. This process is performed asynchronously, and the result of the invocation is returned, allowing you to handle it further in your application.

Key Features

  • Dynamic Method Invocation: Execute any method on an object even if the method name is determined at runtime.
  • Asynchronous Handling: Supports asynchronous operations, allowing the handling of promises returned by methods.
  • Argument Passing: Easily pass any required arguments to the method using an array structure.
  • Error Management: Provides comprehensive error handling to ensure any issues during invocation are reported clearly.

Conclusion

The @fnet/invoke module is a straightforward utility for flexibly calling methods on objects without the need for static method names or argument lists. This makes it a functional tool in environments where method names and their parameters need to be determined during execution rather than at compile time.

@fnet/invoke Developer Guide

Overview

The @fnet/invoke library provides a simple mechanism for dynamically invoking methods on target objects. This library is useful when you need to execute a method without prior knowledge of the method's name or its argument list. By leveraging this functionality, you can develop flexible and dynamic applications that adapt to various target structures.

Installation

To install the @fnet/invoke library, use npm or yarn. Choose one of the following commands according to your package manager preference:

npm install @fnet/invoke

or

yarn add @fnet/invoke

Usage

To utilize the @fnet/invoke library, import it into your JavaScript or TypeScript project and use the invoke function to call a method on your target object dynamically.

Example 1: Basic Usage

Here's a straightforward example of how to use @fnet/invoke:

import invoke from '@fnet/invoke';

// Example target object
const targetObject = {
  hello(name) {
    return `Hello, ${name}!`;
  }
};

// Invoke the 'hello' method with arguments
invoke({ 
  method: 'hello', 
  args: ['World'], 
  target: targetObject 
}).then(result => {
  console.log(result); // Outputs: "Hello, World!"
}).catch(error => {
  console.error('Error:', error.message);
});

Example 2: Handling Method Absence

In situations where the method might not exist on the target object, @fnet/invoke will throw an error. You can handle this gracefully using a try-catch block:

import invoke from '@fnet/invoke';

const targetObject = {
  greet() {
    return 'Greetings!';
  }
};

try {
  const result = await invoke({ 
    method: 'nonExistentMethod', 
    target: targetObject 
  });
  console.log(result);
} catch (error) {
  console.error('Caught Error:', error.message); // Outputs: "Unsupported or invalid method: 'nonExistentMethod'"
}

Examples

Below are additional examples showcasing the library's key capabilities:

Example 3: Providing Arguments

You can pass arguments as an array to invoke methods requiring them:

const mathOperations = {
  sum(a, b) {
    return a + b;
  }
};

invoke({ 
  method: 'sum', 
  args: [5, 10], 
  target: mathOperations 
}).then(result => {
  console.log(result); // Outputs: 15
});

Example 4: Using with Async Methods

The library supports asynchronous methods, ensuring dynamic invocation remains seamless with async/await:

const targetObject = {
  async fetchData(id) {
    // Simulate async operation
    return Promise.resolve(`Data for ID: ${id}`);
  }
};

invoke({
  method: 'fetchData',
  args: [42],
  target: targetObject
}).then(result => {
  console.log(result); // Outputs: "Data for ID: 42"
});

Acknowledgement

This library is maintained by its author with contributions from the open-source community. Your feedback and contributions are always welcome, ensuring the library continues to improve.

Input Schema

$schema: https://json-schema.org/draft/2020-12/schema
type: object
properties:
  method:
    type: string
    description: The name of the method to invoke on the target object.
  args:
    type: array
    items:
      type: any
    description: An array of arguments to pass to the method.
    default: []
  target:
    type: object
    description: The target object containing the method to be invoked.
required:
  - method
  - target