1.0.0 β€’ Published 5 months ago

taskwizard v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
5 months ago

A versatile package containing useful code snippets for simple tasks

🏠 Homepage

Table of Contents

Prerequisites

  • node >=10

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); //"value1".

const hasKey2 = cache.has("key2");
console.log(hasKey2); //true.

cache.set("key3", "value3");
console.log(cache.get("key1")) //undefined

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); // Expected: An array of absolute file paths.

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); // { success: true/false, status: HTTP status code, buffer: Buffer content }.

Calculate Percentage Bar

import { calculatePercentageBar } from "taskwizard";

const options = { currentValue: 75, totalValue: 100, numBars: 10 };
// You can customize the bars however you want add options:
// { fillEmoji: "πŸ’›", emptyEmoji: "🀍" }
const percentageBar = calculatePercentageBar(options);
console.log(percentageBar); // β–°β–°β–°β–°β–°β–°β–°β–±β–± 75%

Compact Number

import { compactNumber } from "taskwizard";

const numberToFormat = 12300;
const formattedNumber = compactNumber(numberToFormat);
console.log(formattedNumber) //12.3k

Format Time from Seconds

import { formatTimeFromSeconds } from "taskwizard";

const seconds = 3780;
const formattedTime = formatTimeFromSeconds(seconds);
console.log(formattedTime); // 1 hour 3 minutes

Get Country Information

import { getInfoFlag, isValidCode, isValidEmoji, isValidFlagName, isValidFlag, getLanguagesFromCode, getLanguagesFromEmoji } from "taskwizard";

const flag = "πŸ‡ΊπŸ‡Έ";
const countryInfo = getInfoFlag(flag);
console.log(countryInfo); // Expected: Information related to the country.

const countryCode = "us";
const isValidCountryCode = isValidCode(countryCode);
console.log(isValidCountryCode); // Expected: true or false.

const isValidCountryEmoji = isValidEmoji(flag);
console.log(isValidCountryEmoji); // Expected: true or false.

const countryName = "United States of America";
const isValidFlagName = isValidFlagName(countryName);
console.log(isValidFlagName); // Expected: true or false.

const isValidFlagValue = isValidFlag(flag);
console.log(isValidFlagValue); // Expected: true or false.

const languagesFromCode = getLanguagesFromCode(countryCode);
console.log(languagesFromCode); // Expected: An array of languages.

const languagesFromEmoji = getLanguagesFromEmoji("πŸ‡¨πŸ‡΄");
console.log(languagesFromEmoji); // Expected: An array of languages.

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); // 31

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