dumfunctions
Advanced tools
Comparing version 1.0.0 to 1.0.1
21
main.js
@@ -12,6 +12,2 @@ /** | ||
if (typeof minimum != 'number') return console.error(new Error('Minimum number is not a number.')); | ||
if (typeof maximum != 'number' && maximum != undefined) return console.error(new Error('Maximum number is not a number.')); | ||
return Math.floor(Math.random() * Math.floor(maximum) + minimum); | ||
@@ -28,3 +24,2 @@ }; | ||
async function delay(milliseconds) { | ||
if (typeof milliseconds != 'number') return console.error(new Error('Delay is not a number.')); | ||
return new Promise((resolve) => setTimeout(resolve, milliseconds)); | ||
@@ -41,5 +36,4 @@ } | ||
function title(string, lowercase = false) { | ||
if (typeof string != 'string') return console.log(new Error('Title is not a string.')); | ||
if (lowercase == true) string = string.toLowerCase(); | ||
return string.split(/ +/g).map(word => string = word.slice(0, 1).toUpperCase() + word.slice(1)).join(' '); | ||
if (lowercase == true) string = string?.toLowerCase(); | ||
return string?.toString()?.split(/ +/g)?.map(word => word?.slice(0, 1).toUpperCase() + word?.slice(1)).join(' '); | ||
@@ -56,5 +50,4 @@ } | ||
function capitalize(string, lowercase = false) { | ||
if (typeof string != 'string') return console.log(new Error('Capitalize is not a string.')); | ||
if (lowercase == true) string = string.toLowerCase(); | ||
return string.charAt(0).toUpperCase() + string.slice(1); | ||
if (lowercase == true) string = string?.toLowerCase(); | ||
return string?.toString()?.charAt(0)?.toUpperCase() + string?.toString()?.slice(1); | ||
} | ||
@@ -68,7 +61,7 @@ | ||
function randomColor(type) { | ||
if (type.toLowerCase() == 'rgb') { | ||
if (type?.toString()?.toLowerCase() == 'rgb') { | ||
let r = () => Math.random() * 256 >> 0; | ||
return `rgb(${r()}, ${r()}, ${r()})`; | ||
} | ||
if (type.toLowerCase() == 'hex') { | ||
if (type?.toString()?.toLowerCase() == 'hex') { | ||
let hex = '0123456789ABCDEF'; | ||
@@ -81,3 +74,3 @@ let color = ''; | ||
} | ||
else return console.error(new Error('type is not recognised.')) | ||
else return undefined; | ||
} | ||
@@ -84,0 +77,0 @@ |
{ | ||
"name": "dumfunctions", | ||
"version": "1.0.0", | ||
"description": "A package for JS functions that should be in the main language.", | ||
"version": "1.0.1", | ||
"description": "A package for JS functions that should be in the main language but aren't.", | ||
"main": "main.js", | ||
@@ -6,0 +6,0 @@ "scripts": { |
3223
79