node.js-util-functions

1.3.6 • Public • Published

node.js-util-functions

node.js-util-functions is a useful package that will allow you to interact in different ways in node.js.


const nuf = require('node.js-util-functions');

Some functions:

Detect if a object is Number:

if(nuf.isNumber('1')){ // You can use (1) and ('1')
  console.log('Is number.')
} else {
  console.log('Is not number.')
}

Detect if a object is String:

if(nuf.isString('1234')){ // false
//...
} else if(nuf.isString('Hello world')) { // true
// ...
}

Detect if a number is prime:

if(nuf.isPrime(20)) { //false
// ...
} else if (nuf.isPrime(17)) { // true
// ...
}

Calculate the percentage of a number:

console.log(nuf.percentage(50, 1)) // 0.50
console.log(nuf.percentage(50, 200)) // 100

Detect if a string has capitalized letters:

if(nuf.isCapitalized('hello')) // false
if(nuf.isCapitalized('HELLO')) // true

Detect if a string is fully capitalized:

if(nuf.isFullyCapitalized('HElLo')) // false
if(nuf.isFullyCapitalized('HELLO')) // true

Round a entire number:

nuf.entireRound(12423, 1) // 12420
nuf.entireRound(12423, 2) // 12400
nuf.entireRound(12423, 3) // 12000
nuf.entireRound(12423, 4) // 10000

Generate a random string:

nuf.randomString(10, true, false, false) // lsLKgcvqmb
// 10: length: Number
// true: Include upperCase: Boolean
// false: Include numbers: Boolean
// false: Include symbols: Boolean

Obtain the average of multiple numbers:

nuf.average([1, 5, 6]) // 4
nuf.average([7,5,6,8,8,10,5]) // 7

Obtain the ratio of two numbers:

nuf.ratio(50, 200) // 25
nuf.ratio(77, 122) // 63.11 ...

Sort an array of numbers

nuf.numericSort([2, 4, 1, 3]) // [1, 2, 3, 4]

Package Sidebar

Install

npm i node.js-util-functions

Weekly Downloads

0

Version

1.3.6

License

none

Unpacked Size

7.66 kB

Total Files

14

Last publish

Collaborators

  • alexcddg