taskcollab-auto
v1.0.4
Published
A simple package to check if input is null, undefined, or an empty string
Downloads
10
Maintainers
Readme
TaskCollab Auto 📋✨
A simple Node.js utility for adding and managing tasks via REST APIs. Easily send single or bulk tasks to your API endpoint using axios, with built-in logging and error handling powered by chalk.
🚀 Features
- ✅ Add Single Task: Seamlessly post a single task to your API.
- 🚀 Bulk Task Adding: Send multiple tasks in bulk with a delay between each.
- 🎨 Colorful Logging: Task progress and errors are beautifully displayed with chalk.
- 🔑 Token-Based Authentication: Pass your token via headers for secure API access.
📦 Installation
Install the package using npm:
npm install task-collabor with Yarn:
yarn add task-collab🔧 Usage
1. Initialize the Class
"To start using TaskCollab, you need to initialize it with your API endpoint and token:
import TaskCollab from 'task-collab';
// API endpoint and authentication token
const endpoint = 'https://api.example.com/tasks';
const token = 'your_secret_token';
// Create an instance of TaskCollab
const taskCollab = new TaskCollab(endpoint, token);2. Add a Single Task
You can use the addTask() method to add a single task to your API:
const task = {
title: 'New Task',
description: 'This is a new task.'
};
// Add a single task
taskCollab.addTask(task);3. Bulk Add Tasks
The bulkAddTask() method lets you add multiple tasks at once, with a small delay between each request:
const tasks = [
{ title: 'Task 1', description: 'First task.' },
{ title: 'Task 2', description: 'Second task.' },
{ title: 'Task 3', description: 'Third task.' }
];
// Add tasks in bulk
taskCollab.bulkAddTask(tasks);4. Test Your Setup
You can use the test() method to quickly check if your endpoint and token are correctly set:
taskCollab.test(tasks);🧪 Example Output
When you run the methods, you’ll see beautifully colored logs thanks to chalk:
Started adding task...
DATA ADDED SUCCESSFULLY { title: 'New Task', description: 'This is a new task.' }
Successfully added task.
Program Started!
Started for task index ==> 0
DATA ADDED SUCCESSFULLY { title: 'Task 1', description: 'First task.' }
Successfully added task.🛠️ Methods
1. addTask(data)
Posts a single task to the given API endpoint.
- Parameters:
data: An object containing the task details (e.g.,{ title: 'Task', description: 'Details about task' }).
- Example:
const task = { title: 'New Task', description: 'Details about the task' };
taskCollab.addTask(task);2. bulkAddTask(data)
Posts multiple tasks in sequence with a delay between each.
- Parameters:
data: An array of objects, where each object is a task (e.g.,[ { title: 'Task 1' }, { title: 'Task 2' } ]).
- Example:
const tasks = [
{ title: 'Task 1', description: 'First task.' },
{ title: 'Task 2', description: 'Second task.' }
];
taskCollab.bulkAddTask(tasks);3. test(data)
Logs the passed data, the API endpoint, and the token to the console for testing purposes.
- Parameters:
data: Any object or array you want to test with.
- Example:
taskCollab.test(tasks);🛡️ Authentication
This library uses token-based authentication. Simply pass your API token when creating an instance of TaskCollab:
const taskCollab = new TaskCollab('https://api.example.com/tasks', 'your_secret_token');The token is automatically added to the Authorization header for all requests.
⚡ License
Licensed under the MIT License.
