Installations
npm install vamtec
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
16.20.2
NPM Version
8.19.4
Releases
Unable to fetch releases
Download Statistics
Total Downloads
1,070
Last Day
2
Last Week
155
Last Month
242
Last Year
1,070
Bundle Size
41.06 kB
Minified
15.54 kB
Minified + Gzipped
Package Meta Information
Latest Version
1.3.10
Package Id
vamtec@1.3.10
Unpacked Size
24.40 kB
Size
7.77 kB
File Count
7
NPM Version
8.19.4
Node Version
16.20.2
Publised On
27 Jan 2025
Total Downloads
Cumulative downloads
Total Downloads
1,070
Last day
0%
2
Compared to previous day
Last week
604.5%
155
Compared to previous week
Last month
-70.8%
242
Compared to previous month
Last year
0%
1,070
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Vamtec
Vamtec is a utility package designed to simplify and automate the process of managing commonly used file generation tasks in Node.js. It helps you quickly set up and generate Excel, CSV, and PDF files from JSON data. It also ensures that necessary dependencies like xlsx
, json2csv
, and pdfkit
are installed automatically if missing.
Features
- Automatically installs necessary dependencies (
xlsx
,json2csv
,pdfkit
). - Provides functions to generate Excel, CSV, and PDF files from JSON data.
- Supports quick and seamless file generation for web applications or automation tasks.
- Lightweight and easy to integrate into existing projects.
- New Image Upload Module for handling file uploads in multiple ways (automatic folder creation and filename management).
Installation
1npm install vamtec
1. Usage ( AI BOT)
1# ChatAI Library
2
3Vamtec is a Node.js library that provides an easy-to-use interface to interact with generative AI models, enabling seamless text generation and chatbot functionality. It supports customizable chatbot names and intuitive chat sessions.
4
5---
6
7## Features
8
9- Simple and user-friendly API.
10- Text generation powered by the Gemini model.
11- Customizable chatbot names.
12- Supports multiple exit commands (`exit`, `Exit`, `stop`, `Esc`) for ending the chat.
13- Error handling for API requests.
14
15---
16
17## Installation
18
19To install the package, use npm:
20
21```bash
22npm install vamtec
Usage
Importing the Library
1const { Bot } = require('vamtec');
Example Code
Here’s an example of how to use the ChatAI
library:
1const { Bot } = require('vamtec'); 2 3const apiKey = 'your_api_key_here'; // Replace with your actual API key 4const bot = new Bot(apiKey); // Default chatbot name is 'Chatbot' 5 6// Start a chat session 7bot.chat();
Renaming the Chatbot
You can rename the chatbot to a custom name before starting the chat session:
1const { Bot } = require('vamtec'); 2 3const apiKey = 'your_api_key_here'; // Replace with your actual API key 4const bot = new Bot(apiKey); // Set a default name ( "ChatBot" ) during initialization 5 6// Rename the chatbot dynamically 7bot.rename('MyPersonalBot'); 8 9// Start a chat session 10bot.chat();
Supported Exit Commands
During a chat session, you can exit the chat by typing any of the following commands:
exit
Exit
stop
Esc
API Documentation
Class: Bot
Constructor: new Bot(apiKey)
Parameter | Type | Default | Description |
---|---|---|---|
apiKey | string | Required | Your API key for the Gemini AI model. |
name | string | 'Chatbot' | The name of the chatbot (optional). |
Method: rename(newName)
Parameter | Type | Description |
---|---|---|
newName | string | The new name for the chatbot. Must be a non-empty string. |
Method: chat()
Starts an interactive chat session. Type messages, and the bot will respond based on the AI model.
Error Handling
If an API request fails, the error message will be displayed, such as:
1Chatbot: Sorry, an error occurred: Error occurred while making API request: [error message]
Development
To contribute or customize the package:
- Clone the repository.
- Install dependencies:
1npm install
- Run the library in a local test environment.
Example Output
Default Chat Session
1Type one of [exit, Exit, stop, Esc] to end the chat. 2 3You: Hello 4Chatbot: Hi there! How can I assist you today? 5 6You: Tell me a joke. 7Chatbot: Why don't skeletons fight each other? Because they don't have the guts! 8 9You: exit 10Chatbot: Goodbye! 👋
Renamed Chatbot
1Type one of [exit, Exit, stop, Esc] to end the chat. 2 3You: Hi 4MyPersonalBot: Hello! How can I help you? 5 6You: What is the weather today? 7MyPersonalBot: I'm sorry, I can't provide weather updates. Is there anything else you'd like to know? 8 9You: stop 10MyPersonalBot: Goodbye! 👋
Automatically Install Dependencies and Load Modules
1const vamtec = require('vamtec'); // Import the vamtec library 2vamtec.main(); // This will check and install required dependencies like xlsx, json2csv, pdfkit
This will automatically install the required packages and print:
xlsx is already installed.
json2csv is already installed.
pdfkit is already installed.
Modules loaded successfully!
yes...
Using the Functions in Your Express Router
Here’s an example of how to use all three functions (Excel, PDF, and CSV) in an Express route:
Frontend: Reports.js
1 2import React, { useState } from 'react'; 3import axios from 'axios'; 4import { DownloadFile } from 'vamtec-react'; 5 6const App = () => { 7 const [fileFormat, setFileFormat] = useState("excel"); // Default to 'excel' without the dot 8 9 const handleDownload = async () => { 10 try { 11 const response = await axios.get(`http://localhost:5000/download-leave-requests?format=${fileFormat}`, { responseType: 'blob' }); 12 // Map 'excel', 'csv', 'pdf' to their respective extensions 13 const fileExtension = fileFormat === "excel" ? ".xlsx" : fileFormat === "csv" ? ".csv" : ".pdf"; 14 // Call the fileHandling function with correct file name and extension 15 DownloadFile('Download', fileExtension, response.data); // Pass base filename, extension, and data 16 } catch (error) { 17 console.error('Error downloading file', error); 18 } 19 }; 20 21 return ( 22 <div> 23 <h1 className="text-2xl font-bold mb-4">Download Leave Requests</h1> 24 <select value={fileFormat} onChange={(e) => setFileFormat(e.target.value)} className="p-2 border rounded-md w-full mb-4"> 25 <option value="excel">Excel (.xlsx)</option> 26 <option value="csv">CSV (.csv)</option> 27 <option value="pdf">PDF (.pdf)</option> 28 </select> 29 <button onClick={handleDownload} className="bg-blue-500 text-white p-2 rounded mt-4"> 30 Download Leave Requests 31 </button> 32 </div> 33 ); 34}; 35 36export default App;
Backend:server.js
1const express = require('express'); 2const router = express.Router(); 3const vamtec = require('vamtec'); // Import the vamtec library 4const pool = require('../config/db'); // Database connection 5 6// Route to generate reports in different formats 7router.get('/', async (req, res) => { 8 const format = req.query.format || 'excel'; // Default to 'excel' if format is not specified 9 const title = req.query.title || 'Leave Requests'; // Get title from query parameter, default to 'Leave Requests Report' 10 11 try { 12 // Fetch data from the database 13 const { rows: data } = await pool.query('SELECT * FROM LeaveRequests'); 14 15 // Generate the file based on the format specified in the query 16 if (format === 'excel') { 17 vamtec.generateExcel(data, res); // Generate Excel file 18 } else if (format === 'pdf') { 19 vamtec.generatePDF(data, res, title); // Generate PDF file 20 } else if (format === 'csv') { 21 vamtec.generateCSV(data, res); // Generate CSV file 22 } else { 23 res.status(400).send('Invalid format'); 24 } 25 } catch (err) { 26 console.error('Error:', err); 27 res.status(500).send('Internal Server Error'); 28 } 29}); 30 31module.exports = router;
Available Functions
generateExcel(data, res)
: Generates and sends an Excel file (XLSX format) from the provided data.generateCSV(data, res)
: Generates and sends a CSV file from the provided data.generatePDF(data, res, title)
: Generates and sends a PDF file from the provided data with an optional title.
New Image Upload Module
Vamtec now includes an image upload module for managing file uploads. This module allows flexible folder management and filename control for your file uploads.
Installation
1npm install vamtec
Image Upload Setup
Here’s an example of how to use the image upload setup in your Express application:
1const express = require("express"); 2const { img } = require("vamtec"); // Import the image upload setup 3 4const app = express(); 5 6// Case 1: Upload with custom folder and filename configuration 7app.post("/upload", img({ folder: "uploads1", filename: "timestamp" }).single("image"), async (req, res) => { 8 if (!req.file) return res.status(400).send("No file uploaded"); 9 res.json({ message: "File uploaded successfully", fileName: req.file.filename }); 10}); 11 12// Case 2: Upload with folder and filename array configuration 13app.post("/upload", img(["uploads2", "original"]).single("image"), async (req, res) => { 14 if (!req.file) return res.status(400).send("No file uploaded"); 15 res.json({ message: "File uploaded successfully", fileName: req.file.filename }); 16}); 17 18// Case 3: Upload with folder, filename, and field name configuration 19app.post("/upload", img(["uploads3", "original", "image"]).single("image"), async (req, res) => { 20 if (!req.file) return res.status(400).send("No file uploaded"); 21 res.json({ message: "File uploaded successfully", fileName: req.file.filename }); 22}); 23 24app.listen(5000, () => console.log("Server running on http://localhost:5000"));
How it Works:
- Case 1: Uploads a file with a custom folder and filename format (
timestamp
for a timestamp-based filename). - Case 2: Uploads a file with the original filename in the specified folder.
- Case 3: Uploads a file with a custom folder, filename, and field name (useful when you have multiple fields in your form).
This module supports automatic creation of the upload folder if it doesn't exist.
No vulnerabilities found.
No security vulnerabilities found.