1.2.2 • Published 2 months ago

answ3r-utils v1.2.2

Weekly downloads
-
License
ISC
Repository
-
Last release
2 months ago

answ3r Utilities

A simple utilities package that offers many different functions that could be of use to you when writing ExpressJS websites or Discord bots!


Functions / Exports


figlify

Used to turn text into art!

    const utils = require('answ3r-utils');
    await utils.figlify("Hello World!", { randFont: true, font: undefined });

mdConvert

Converts raw text/md to HTML compatible.

    const utils = require('answ3r-utils');
    let text = "# Hello world!";
    let webPageContent = await utils.mdConvert(text);
    res.render('index.ejs', { content: webPageContent }); // ExpressJS Framework Example

generateRandom

Generate a random string of acceptable characters.

    const utils = require('answ3r-utils');
    let random = await utils.generateRandom(12) // How long the string should be
    console.log(random);

sanitize

Make a string of text MySQL compatible to avoid injections.

    const utils = require('answ3r-utils');
    let text = "oh hello world`; DROP DATABASE main;";
    let cleansed = await utils.sanitize(text, false) // boolean for <script> replacement in HTML
    await con.query(cleansed, function(err, row) {
        if(err) throw err;
    });

saveFile

Download and save a file from a URL. (NodeJS File Downloader)

    const utils = require('answ3r-utils');
    utils.saveFile("https://answ3r.net/assets/logo.png", "answ3rlogo", "png", "./public/images", false); // boolean is to clone files or not

getDate

Get the date and convert to string with NodeJS.

    const utils = require('answ3r-utils');
    let date = await utils.getDate();
    console.log(date);

fetchTime

Fetch the current time from a certain time zone.

    const utils = require('answ3r-utils');
    let time = await utils.fetchTime("America/New_York", "MM-DD-YYYY"); // https://github.com/Itz-answ3r/big-ben-bot/blob/main/timezones.json look at values
    console.log(date);

getRandomArray

Get a random element from an array of strings.

    const utils = require('answ3r-utils');
    let array = ["a", "b", "c", "d", "e", "f"];
    let random = await utils.getRandomArray(array);
    console.log(`you got: ${random}!`);

checkIfHex

Check if the provided string is a valid color hex.

    const utils = require('answ3r-utils');
    let hex = "#FFFFFF";
    let check = await utils.checkIfHex(hex);
    if(!check.pass) hex = check.item; // Set to the proper hex value if it's not
    console.log(hex);

dirSize

View the directory size of a folder.

    const utils = require('answ3r-utils');
    let size = await utils.dirSize("./src/images");
    console.log(size);

getDiscountedValue

Get the discounted amount of a total value.

const utils = require('answ3r-utils');
let totalValue = 34.99; // Price
let discount = 30; // 30%
let newValue = await utils.getDiscountedValue(totalValue, discount);
console.log(newValue) // 10.497 (30% of 34.99)

randomColor

Get a random color logged to the console.

const utils = require('answ3r-utils');
utils.randomColor("Wow a random color!!!");

validURL

Check vaild is a url.

const utils = require('answ3r-utils');
utils.validURL('https://answ3r.hu/') //true
utils.validURL('hps://answ3r.hu/') //false

Credits

@answ3r - Creating the package.

1.2.2

2 months ago

1.2.1

1 year ago

1.2.0

1 year ago

1.1.9

1 year ago

1.1.8

1 year ago

1.1.7

1 year ago

1.1.6

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago