biswarup-npm
Version:
biswarup-npm ========= [![npm Version][NPM VERSION BADGE]][NPM PAGE] [![Node.js][NODE VERSION BADGE]][NODE PAGE] [![GitHub License][LICENSE BADGE]][LICENSE PAGE] [![CI Status][CI BADGE]][CI PAGE]
46 lines (35 loc) • 1.15 kB
JavaScript
function helloNpm() {
return "hello NPM"
}
// sleep function.
const sleep = async (milliseconds) => {
await new Promise(resolve => setTimeout(resolve, milliseconds));
}
// rendomInt with range.
function randomInt(min = 0, max = 99999999) {
return Math.floor(Math.random() * (max - min + 1) + min);
}
// rendomFloat with range.
function randomFloat(min = 0, max = 99999999) {
return (Math.random() * (max - min + 1) + min);
}
// validate email function.
function validateEmail(email) {
const regex = /^\S+@\S+\.\S+$/;
return regex.test(email);
};
// capitalize function first latter "uppercase".
function capitalize(str) {
const arr = str.trim().toLowerCase().split(" ");
for (let i = 0; i < arr.length; i++) {
arr[i] = arr[i].charAt(0).toUpperCase() + arr[i].slice(1);
}
return arr.join(" ");
};
// camel Case convertion function.
function camelize(str) {
return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function(word, index) {
return index === 0 ? word.toLowerCase() : word.toUpperCase();
}).replace(/\s+/g, '');
}
module.exports = { helloNpm, sleep, randomInt, randomFloat, validateEmail, capitalize, camelize };