functions-tools
v0.1.5
Published
Your fonctions friends
Downloads
21
Readme
Table of contents
Installation
npm i functions-tools
Examples
const ft = require('functions-tools'); //Define the functions-tools module
Fonctions Times
ft.stringifyTime(4800000); // 1h, 20m
ft.stringifyTime(4800000, {lang: "en", long: true, separator: " | "}); // 1 hour | 20 minutes
ft.stringifyTime(4800000, {lang: "en", valueNull: true, format: "Y-MO-W-D-H-M-S-MS"}); // 0y, 0mo, 0w, 0d, 1h, 20m, 0s, 0ms
ft.stringifyTime(4800000, {lang: "en", format: "M-H-MS"}); // 20m, 1h
ft.stringifyTime(4800000, {lang: "en", suppressTag: true}); // 1, 20
ft.parseTime("2d"); // 172800000
ft.parseTime("2d",{ms: false}); // 172800
ft.parseTime("2day 5m 3hour"); // 183900000
ft.parseTime("2day -1d"); // 86400000
ft.parseTime("-2d"); // -172800000
await ft.wait(5000);
// {startTime: 1623327459766, endTime: 1623327464766, durationTime: 5000}
await ft.wait("5s 10s -1s");
// {startTime: 1623327464827, endTime: 1623327478827, durationTime: 14000}
ft.formatTime(Date.now()); // june 10th 2021, 22:46:10
ft.formatTime("10/06/2021"); // june 10th 2021, 00:00:00
ft.formatTime("10/06/2021", {lang: "en", format: "Do MM, YYYY | hh:mm"}); // 06th Oct, 2021 | 00:00
Fonctions Number
ft.numberToRoman(24); // XXIV
ft.romanToNumber("XXIV"); // 24
Fonctions Text
ft.replaceText("Hello {user}", {user: "NewGlace"}) //Hello NewGlace
ft.replaceText("Hello {user} {suffix}", {user: "NewGlace", suffix: "vanilla"}) //Hello NewGlace vanilla
ft.replaceText("Hello {user}", {user: "NewGlace {suffix}", suffix: "vanilla"}) //Hello NewGlace vanilla
Fonctions Array
ft.findArray(["H",["E",["L"],"L"],"O,"," ","W",["O",["R",["L"]]],"D"], "L");
// Map(1) { 0 => [ 1, 1, 0 ] }
ft.findArray(["H",["E",["L"],"L"],"O,"," ","W",["O",["R",["L"]]],"D"], "L", {all: true});
// Map(3) { 0 => [ 1, 1, 0 ], 1 => [ 1, 1, 2 ], 2 => [ 1, 5, 1, 1, 0 ] }
ft.findArray(["H",["E",["L"],"L"],"O,"," ","W",["O",["R",["L"]]],"D"], "P");
// Map(0) {}
ft.randomArray(["A","B","C"]); // B
ft.randomArray(["A","B","C"], {number: 4}); // ["C", "A", "B", "A"]
ft.randomArray(["A","B","C"], {number: 4, double: false}); // ["A", "C", "B"]
//To shuffle an array
const array = [1,2,3,4,5,6,7,8,9,0];
ft.randomArray(array, {number: array.length, double: false});
// [4, 3, 7, 0, 5, 6, 2, 1, 9, 8]
Fonctions multiFunctions
ft.multiFunctions(ft.numberToRoman, [10, 34, 54]);
await ft.multiFunctions(ft.numberToRoman, [10, 34, 54], async: true);
// Promise { [ 'X', 'XXXIV', 'LIV' ] }
ft.multiFunctions(ft.replaceText, [["Hello {x}", {x: "World"}],["Hi {u}", {u: "World"}],["Bye {p}", {p: "World"}]]);
await ft.multiFunctions(ft.replaceText, [["Hello {x}", {x: "World"}],["Hi {u}", {u: "World"}],["Bye {p}", {p: "World"}]], async: true);
//Promise { [ 'Hello World', 'Hi World', 'Bye World' ] }
Discord
Join the Discord