Welcome to Taskwizard 🦄
A versatile package containing useful code snippets for simple tasks
Table of Contents
Prerequisites
Installation
npm install taskwizard
Usage
TaskWizard can be imported using CommonJS or ES6 syntax. It also supports TypeScript.
import taskwizard from "taskwizard";
const taskwizard = require("taskwizard");
TaskMap
import { TaskMap } from "taskwizard";
const cacheSize = 2;
const cache = new TaskMap(cacheSize);
cache.set("key1", "value1");
cache.set("key2", "value2");
const valueForKey1 = cache.get("key1");
console.log(valueForKey1);
const hasKey2 = cache.has("key2");
console.log(hasKey2);
cache.set("key3", "value3");
console.log(cache.get("key1"))
Search Files Recursively
import { searchFilesRecursive } from "taskwizard";
const folderPath = "/path/to/folder";
const fileExtensions = [".js", ".ts"];
const files = await searchFilesRecursive(folderPath, fileExtensions);
console.log(files);
Fetch Buffer from URL
import { fetchBuffer } from "taskwizard";
const url = "https://example.com/image.png";
const result = await fetchBuffer(url);
const buffer = result.buffer;
console.log(result);
Calculate Percentage Bar
import { calculatePercentageBar } from "taskwizard";
const options = { currentValue: 75, totalValue: 100, numBars: 10 };
const percentageBar = calculatePercentageBar(options);
console.log(percentageBar);
Compact Number
import { compactNumber } from "taskwizard";
const numberToFormat = 12300;
const formattedNumber = compactNumber(numberToFormat);
console.log(formattedNumber)
Format Time from Seconds
import { formatTimeFromSeconds } from "taskwizard";
const seconds = 3780;
const formattedTime = formatTimeFromSeconds(seconds);
console.log(formattedTime);
Get Country Information
import { getInfoFlag, isValidCode, isValidEmoji, isValidFlagName, isValidFlag, getLanguagesFromCode, getLanguagesFromEmoji } from "taskwizard";
const flag = "🇺🇸";
const countryInfo = getInfoFlag(flag);
console.log(countryInfo);
const countryCode = "us";
const isValidCountryCode = isValidCode(countryCode);
console.log(isValidCountryCode);
const isValidCountryEmoji = isValidEmoji(flag);
console.log(isValidCountryEmoji);
const countryName = "United States of America";
const isValidFlagName = isValidFlagName(countryName);
console.log(isValidFlagName);
const isValidFlagValue = isValidFlag(flag);
console.log(isValidFlagValue);
const languagesFromCode = getLanguagesFromCode(countryCode);
console.log(languagesFromCode);
const languagesFromEmoji = getLanguagesFromEmoji("🇨🇴");
console.log(languagesFromEmoji);
Calculate Difference in Hours
import { diffHours } from "taskwizard";
const date1 = new Date("2023-01-01T12:00:00Z");
const date2 = new Date("2023-01-02T18:30:00Z");
const hoursDifference = diffHours(date2, date1);
console.log(hoursDifference);
Other useful methods are also available for some validations.
- discordColors
- isDiscordEmoji
- isDiscordInviteLink
- isValidEmail
- isHex
Author
👤 NoBody
🤝 Contributing
Contributions, issues and feature requests are welcome!
Feel free to check issues page.
Show your support
Give a ⭐️ if this project helped you!
with ❤️ by NoBody