0.0.8 • Published 4 years ago
util-funcs v0.0.8
Util-Funcs - is a simple package with functions that can be useful to you!
I will be adding functions that are useful to us for faster development constantly!
Instalation:
$ npm install util-funcs
$ yarn add util-funcs
Statements:
const utils = require("util-funcs");
Docs:
Strings, Numbers and Arrays manipulators/converters Methods:
- .randomString(length, type, caseInsensitive, capsLock)
- .randomNumber(min, max, float)
- .toArray(string)
- .stringFind(string, character)
Milisecond Converter Methods:
- .secondInMs(value)
- .minuteInMs(value)
- .hourInMs(value)
- .dayInMs(value)
- .weekInMs(value)
- .monthInMs(value, optional:monthDays)
- .yearInMs(value)
- .time(value, configs)
Methods Help:
Strings, Numbers and Arrays manipulators/converters Methods:
/*
All parameters are optional.
The default value for the {length} parameter is 10, the {type} parameter is 0, the {caseInsensitive} parameter is false, and the {capsLock} parameter is also false.
*/
utils.randomString();
//---> EXAMPLE RETURN: 'gtrulhgpcy'
utils.randomString(15);
//---> EXAMPLE RETURN: 'ygrabmdmxqancya'
/*
Define the type of string that will be returned by setting the parameter {type}.
*/
utils.randomString(15, 1);
//---> EXAMPLE RETURN: '488585235480207'
utils.randomString(15, 2);
//---> EXAMPLE RETURN: '77vygfta7znl9c3'
utils.randomString(15, 3);
//---> EXAMPLE RETURN: '@&9f5iu3,l$´h4w'
/*
Here is a list with the valid values of the parameter {type}:
0 = Only Letters
1 = Only Numbers
2 = Alpha-Numeric
3 = Alpha-Numeric with special characters
*/
/*
If you want the string to contain uppercase and lowercase letters, set the parameter {caseInsensitive} to true, otherwise, set to false.
*/
utils.randomString(15, 2, true);
//---> EXAMPLE RETURN: '0MPhVKj4161umyI'
utils.randomString(15, 2, false);
//---> EXAMPLE RETURN: 'giejlqirg0c07j4'
/*
If you want all letters to be capital letters only, set the parameter {capsLock} to true, otherwise, set to false.
*/
utils.randomString(15, 2, false, true);
//---> EXAMPLE RETURN: '3GOXHUOGF891HMI'
utils.randomString(15, 2, false, false);
//---> EXAMPLE RETURN: 'ago347ca7oq9inf'
// With this function, you can return a random value with minimum and maximum.
utils.randomNumber(5, 20);
//---> EXAMPLE RETURN: 15.045860685796184
// If you do not want to return float numbers, set the parameter {float} to false.
utils.randomNumber(5, 20, false);
//---> EXAMPLE RETURN: 13
utils.randomNumber(5, 20, true);
//---> EXAMPLE RETURN: 19.529826353635208
// This function transforms a string into an array. It removes: Spaces, periods (.) and commas (,).
utils.toArray('hi');
//---> { content: [ 'hi' ], length: 1 }
utils.toArray('I am a frog, ribbet!');
//---> { content: [ 'I', 'am', 'a', 'frog', 'ribbet!' ], length: 5 }
// You can check if there are any characters in the string, see the examples:
utils.stringFind('hi', 'i');
//---> true
utils.stringFind('hi', 'hi')
//---> true
// This method uses Regular Expressions to find and check if the character exists, so if you try to search: 'ih', in 'hi', it will return false.
utils.stringFind('hi', 'ih')
//---> false
// However, if you try to check 'ih' in 'giht', it will return true.
utils.stringFind('Wait... what is "giht?"', 'ih')
//---> true
Milisecond Converter Methods:
utils.secondInMs(1);
//---> 1000
utils.minuteInMs(1);
//---> 60000
utils.hourInMs(1)
//---> 3600000
utils.dayInMs(1)
//---> 86400000
utils.weekInMs(1)
//---> 604800000
utils.monthInMs(1)
//---> 2592000000
//Do you can put the month days(30, or 31).
utils.monthInMs(1, 30)
//---> 2592000000
utils.monthInMs(1, 31)
//---> 2678400000
utils.yearInMs(1)
//---> 31536000000
// The {configs} paramether is optional, if do you not use, he is set to 'all'.
utils.time(31536000000)
//---> 1 years, 12 months, 52 weeks, 365 days, 8760 hours, 525600 minutes, 31536000 seconds
// You can use pre-set keys to filter years, months, weeks, days, hours, minutes and seconds!
// Examples:
utils.time(31536000000, 'days')
//---> 365 days
utils.time(31536000000, 'years')
//---> 1 years
// The existing pre-set keys are: 'seconds', 'minutes', 'hours', 'days', 'weeks', 'months', 'years' and 'all'.