Visit Website to learn more.
Master-methods is a javascript add-on library which has some of the additional methods for arrays,objectsnumbers,strings,validations,color conversions and so on.
require('master-methods')
import 'master-methods'
Import the module in the main file of your project.
An array method that returns the average of the numbers in the array.
const arr=[1,2,3]
arr.average() //returns 2;
An array methods count the cardinal value of the given element.
const arr=[1,1,2,3];
arr.count(1) //returns 2;
An array method that extracts the elements from the array with the given count and condition.
- count -Indicates the number of elements to be extracted from the array
- Function -a function that has the condition
- Key (1 or -1)
- 1 selects the elements from the starting of the array.
- -1 selects the elements from the end.
Example:
const myarr=[1,2,3,4];
myarr.getElements(2,x=>x%2==1);//return [1,3];
myarr.getElements(2,-1)//return [3,4]
An array method returns the maximum value in the given array.
const arr=[12,3,4,56];
arr.max()//returns 56;
An array method returns the minimum value in the given array.
const array=[1,2,3,4]
arr.min()//returns 1;
An array method that returns the element which occurs the most in the array.
const arr=[1,2,3,4,5,3]
arr.getmostOccurence()//returns {value:3,occurences:2}
An array method that returns the median of the elements in it.
const arr=[1,2,3]
arr.median()//returns 2;
An array method that removes the undefined and null values in it.
const arr=[1,2,null,true,undefined,"naveeenkumar"]
arr.optimize()//returns [1,2,true,"naveenkumar"]
An array method that removes the element or an array of elements from it.
const array=[1,2,3,4];
array.remove(1) //returns [2,3,4]
array.remove([3,4]) //returns [1,2]
const arr=["naveen","kumar","md"]
arr.remove("naveen")//returns ["kumar","md"]
arr.remove(["naveen","md"])//returns ["kumar"]
Converts the arrays into a object with key and value.
var arr=[1,2,3]
var arr1=[4,5,6]
arr.zip(arr1) //return {1:4,2:5,3:6}
An array method that sorts the array in ascending or descending order.
-
key (optional, default value is 1)
- 1 sorts the array in ascending order.
- -1 sorts the array in descending order.
-
function It has ths condition for sorting.(Optional).
const arr=[1,2,4,3]
arr.sortf()//returns [1,2,3,4]
arr.sortf(-1)//returns [4,3,2,1]
const arr1=["naveen","kumar","md"]
arr1.sortf()//returns ["kumar","md,"naveen"]
An array method that returns the sum of the elements in it.
const arr=[1,2,3]
arr.sum()//returns 6
An array method that deletes the duplicate elements in it.
const arr=[1,3,5,2,3]
arr.ditinct()//returns[1,3,5,2]
const arr=["naveen","naveen"]
arr.distinct()//returns ["naveen]
An array method that returns a shuffled array.
const arr=[1,2,3];
arr.shuffle();//returns [3,2,1] or anything;
A number method that checks whether the number is an armstrong number or not.
const num=1634;
num.isArmstrong()//returns true
const num=1543;
num.isArmstrong()//returns false
A number method that checks whether the number is an composite number or not.
const num=7;
num.isComposite()//returns false;
const num1=14
num.isComposite()//returns true;
A number method that checks whether the number is an Prime number or not.
var num=3
num.isPrime()//returns true
num=4
num.isprime()//returns false;
A number method that converts the value in radian to degree.
const a=0.7853981633974483
a.toDegree()//returns 45
A number method that converts the value in ** degree to radian**.
const a=45;
a.toRadian()//returns 0.7853981633974483
A number method that checks whether a given number is even or not.
var num=2;
num.isEven()//returns true;
num=3;
num.isEven()//returns false;
A number method that checks whether a given number is odd or not.
var num=3
num.isOdd()//returns true
num=4
num.isOdd()//returns false
A number method that returns the number of digits in it.
var num=2334
num.length()//returns 4
A number method that returns the reverse of it.
var num=1234
num.reverse()//returns 4321
num=100
num.reverse()//returns 1
A function which converts colors in rgb into hexadecimal value.
let a=rgbtohex(0,51,255)
a //returns #0033ff;
A function which converts color values from hexadecimal to rgb.
let a=hextorgb(#0033ff)
a //returns rgb(0,51,255) ;
A function returns random color in hexadecimal value.
console.log(randhex())
return #fff43 or any color
A string method that returns the reverse of it.
var str="naveen";
str.sreverse()//returns "neevan"
A string method checks whether the string is undefiend or null or empty.
var str=""
str.isValid() //returns false
str="naveen"
str.isvalid() //return true
A String method returns whether the string is null or undefined.
var str=null
str.isnull() //return true
str="naveen"
str.isnull() //return false
A string method checks whether a given string is empty or not.
var str=""
str.isEmpty()//returns true
str=" "
str.isEmpty()//returns true
A string method that returns the string before the index or before the given string.
index or string
const str="Naveen kumar"
str.truncate(3)//returns "Nav"
str.truncate(" ")//returns "Naveen"
A string method that capitalize the first letter itself.
var about="i am a good boy"
about.capitalize()//returns "I am a good boy"
A string method that swaps the cases in it.
var name="Naveen Kumar"
name.swapcase()//returns "nAVEEN kUMAr"
A string methods that returns the camel case version of it.
var name="naveen kumar"
name.camelCase()//returns naveenKumar
A string method that checks whether it ends with the specified string or not.
const str="naveen kumar"
str.endsWith("kumar")//returns true;
A string method that checks whether it starts with the specified string or not
const str="naveen kumar"
str.startsWith("na")//returns true
A string method that converts all the letters in a string to lower case.
const str="NaveenKumar"
str.casefold()//returns "naveenkumar"
A string method that count the number of occurences of the given string.
const str="Naveen kumar is a good boy"
str.count("a");//returns 3
str.count(" ");//returns 5
str.count("aveen");//returns 1
A string method that check whether the string contains only aphabets and numbers.
const id="naveen9715";
id.isAlnum()//return true
A string method that check whether the string contains only aphabets.
const id="naveen";
id.isAlpha()//return true
A string method that check whether the string contains only numbers.
const id="9715";
id.isNum()//return true
A function that returns the sum of given two numbers.
var x=sum(12,3)//returns 15
A function that returns the difference of given two numbers.
var x=subtract(12,3)//returns 9
A function that returns the product of given two numbers.
var x=product(12,3)//returns 36
A function that returns the quotient of given two numbers.
var x=divide(12,3)//returns 4
A function that returns the modulo of given two numbers.
var x=subtract(12,3)//returns 0
A function that roundoff according to the given number of digits of given two numbers.
var x=roundoff(12.4567,3)//returns 12.457
A function that returns the random number according to the number of digits and between two values.
- Digits -Number of digits
- Min -Start limit
- Max -End limit
console.log(random(2))//returns 77 or something..
console.log(random(3,450,460))//returns 451 or something between 450 and 560
A function that checks whether the given string or number is a palindrome or not.
var str="dad"
isPalindrome(str)//returns true
str=1234321
isPalindrome(str)//returns true
A string method that validates the mail id.
const str="[email protected]"
str.validateMail()//returns true
A string method that validates the password.
const pass="Naveen@1234"
pass.validatePass()//returns "strong"
const pass1="naveen8870499146"
pass1.validatePass()//returns "normal"
const pass2="naveenkumar"
pass2.validatePass()//returns "weak"
A string method that validates the mobile number.
const mobile="+91 8870499146"
mobile.validateMobile()//return true
An object method which return the array of data types present in it.
const obj={a:"naveen",b:23,c:true}
obj.gettypes() //returns ["String","Number","Boolean"]
An object method to return the values of an object.
const obj={a:"naveen",b:23,c:true}
obj.values() //returns ["naveen",23,true]
An object method to return the keys of an object.
const obj={a:"naveen",b:23,c:true}
obj.keys() //returns ['a','b','c']
An object method concat with the given object
const obj={a:1,b:2}
const obj1={c:3,d:4}
obj.concat(obj1)//{a:1,b:2,c:3,d:4}