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

@satyamtechie/ask-ai

v1.0.2

Published

``` npm install @satyamtechie/ask-ai ```

Readme

🚀 Installing

Using npm

npm install @satyamtechie/ask-ai

Once the package is installed, you can import the library using import or require approach:

import { askGemini } from '@satyamtechie/ask-ai'

💡 Example

async function fetchData() {
  try {
    const res = await fetch("https://jsonplaceholder.typicode.www/posts/1"); // Intentional error
    const data = await res.json();
    console.log(data);
  } catch (error) {
    console.log(error.message);

    // Get the function body as a string
    const functionBody = fetchData.toString();

    // Extract the try block content using regular expressions
    const tryBlockRegex = /try\s*\{([\s\S]*?)\}\s*catch/;
    const tryBlockMatch = functionBody.match(tryBlockRegex);

    if (tryBlockMatch && tryBlockMatch[1]) {
      const tryBlockContent = tryBlockMatch[1].trim();

      // Send the error message and the try block content to askGemini
      const response = await askGemini(error.message, tryBlockContent);
      console.log(response);
    } else {
      console.log("Could not extract try block content.");
      const response = await askGemini(error.message);
      console.log(response);
    }
  }
}

fetchData();

Sample Output

fetch failed
The error "fetch failed" is because you have a typo in your URL:  `https://jsonplaceholder.typicode.www/posts/1`  
should be `https://jsonplaceholder.typicode.com/posts/1`.  You have `.www` instead of `.com`.

javascript
async function fetchData() {
  try {
    const res = await fetch("https://jsonplaceholder.typicode.com/posts/1");
    const data = await res.json();
    console.log(data);
  } catch (error) {
    console.error("Fetch failed:", error);
  }
}

fetchData();

This version includes a `catch` block to handle potential errors more gracefully.  If the fetch fails for any reason (network issues, server errors, etc.), the `catch` block will log the error to the console instead of crashing the script.
This is crucial for robust code.  The original code would throw an error and halt execution.  This improved version will handle the failure without causing the entire program to stop.

🚀 fetchData Function

The fetchData function is an asynchronous JavaScript function that demonstrates how to fetch data from an API, handle errors, and use AI assistance (askGemini) to analyze and resolve issues when errors occur.


Functionality

  1. API Request:

    • Tries to fetch data from a sample API (https://jsonplaceholder.typicode.www/posts/1).
    • An intentional error is introduced in the URL (.www) to trigger the error-handling logic.
  2. Error Handling:

    • Captures any errors using a try...catch block.
    • Logs the error message to the console.
  3. Dynamic Code Analysis:

    • Converts the entire function (fetchData) to a string.
    • Extracts the code inside the try block using a regular expression.
    • Sends the error message and extracted code to the askGemini function for AI-assisted debugging.
  4. AI Assistance:

    • The askGemini function (not defined here) is expected to analyze the provided code and error message, returning suggestions or fixes.

🛠 Key Components

  • fetch() – Makes an HTTP request to the API.
  • try...catch – Handles any errors that occur during the fetch operation.
  • fetchData.toString() – Converts the function to a string for analysis.
  • Regular Expression:
    • Pattern: /try\s*\{([\s\S]*?)\}\s*catch/
    • Purpose: Extracts the content inside the try block.
  • askGemini(error.message, tryBlockContent) – Sends the error and code to AI for suggestions.

🚨 Error Handling Example

Given the incorrect URL in the fetch request, the function will likely produce an error like:

TypeError: Failed to fetch

This error, along with the problematic code snippet, is sent to askGemini, which might return helpful debugging advice.


🚀 How to Use

  1. Integrate askGemini Function:
    Ensure that the askGemini function is correctly implemented to handle two parameters:

    • error.message — The error description.
    • tryBlockContent — The code snippet from the try block.
  2. Run the Script:

    node yourScript.js
  3. Review Output:

    • Check the console for:
      • The original error message.
      • The response from Gemini with possible fixes.

🔥 Potential Enhancements

  • Better Code Parsing:
    Use a JavaScript parser (like Babel) instead of regular expressions for more robust code extraction.

  • Enhanced Error Context:
    Include stack traces or additional context when sending data to askGemini.