Home Documentation EJS on NPM

Easy-JS

By: Thomas Boccinfuso

Download Now!

What's built in?

Easy-JS is a javascript library built from newcomers to Javascript programming and it's FREE!

Functions & Examples

getId(id);

By passing in an Id as the parameter, this function will return the element tied to that ID.

Example: getId('frstName');
                
idValue(id);

By passing in an Id as the parameter, this function will return the value of the element tied to that ID.

Example: idValue('frstName');
            
emailRegex(email);

Passing in a string that contains the full email address, the function will compare what you enter vs a Regular exprerssion and return true or false depending if it passes or fails the test.

Example: emailRegex('email@email.com');
            
phoneRegex(phone);

Passing in a string that contains the phone number, the function will compare what you enter vs a Regular exprerssion and return true or false depending if it passes or fails the test.

Example: phoneRegex('###-###-###');
            
addClass(el, className);

Passing in two parameters, first being the id of the element and second being the class name as a string. The function will then apply the class name to that element.

Example: addClass('firstName', 'redBox');
                
removeClass(el, className);

Passing in two parameters, first being the id of the element and second being the class name as a string. The function will then remove the class name to that element.

Example: addClass('salary', 'drop-shadow');
                
hideElement(el);

Pass in an element's Id and this function will hide the element. Only works if the element is currently showing.

Example: showElement('lastName');
                    
showElement(el);

Pass in an element's Id and this function will show the element. Only works if the element is currently hidden.

Example: showElement('firstName');
                        
getName(el);

Pass in the element Id and the function will return the name accociated with that element. (if any)

Example: getName(firstName');
                            
getType(el);

Pass in the element Id and the function will return the type of the element.

Example: getType(firstName');
                                
toJSON(obj);

Pass in a string object to convert to JSON format.

Example: var person={"name":"Bobby"};
          toJSON(person);
 Result:  '{"name": "Bobby"}'
                                
FindByTag(tag);

Pass in an html tag and the function will return a Node List of all the elements within the document.

Example: FindByTag('p');
                                    
FindByClass(className);

Pass in a string of the class name, will return an object of elements with the matching class name.

Example: FindByClass('redBox');
                                        
randomNumber(num1, num2);

Pass in two numbers, the function will return a random integer between both numbers.

Example: randomNumber(1,10);
                                            
timesClicked();

Keeps track of how many times something is clicked. Useful for images, buttons and links.

Example: timesclicked();
                                                
newChild(el, parentNode, text);

Pass in the new tag you want to append, the parentNodeId, and the text you want in that new tag.

Example: newChild('p', 'parentNodeID', 'This is the paragraph text'));
Result:  This the paragraph text
                                                    
tagoCollection(tag);

Pass in a tag, returns a collection of all matching tags.

Example: tagCollection('a');
                
                                                        
newCookie(cookie);

Pass in a string / obj to be placed in a new cookie. USeful for storing form data.

Example: newCookie("username=John Doe");
                    
                                                            
removeDDLItem(id);

Pass in the id of the drop down menu. When the function runs, it will remove the selected item.

Example: removeDDLItem('myDropDown');
                        
                                                                
counter();

Keeps a running counter.

Example: counter();
Result:  1     
Result:  2         
                                                                    
changeText(id, text);

Pass in the id of the element and the new text. When the function runs, it will replace the text of that element.

Example: changeText('firstName', 'This is new text');
                                                                        
changeImg(id, src);

Pass in the id of the element and the new image source. When the function runs, it will replace the image of that element.

Example: changeImg('profilePic', './images/me2017');
                                                                            
genSALT(num);

Pass in the desired salt length. Returns a random character string.

Example: genSALT(12);
Result*: f5%#GDFJ@(9K
* The result will always be different
                                                                                
compare(x, y);

Pass in two parameters and the function will return true if the values are the same. Returns false if they do not match.

Example: compare(1, 2);
Result:  false
                                                                                    
displayDate();

Returns the current Date.

Example: displayDate();
Result:  11 October 2017
                                                                                        
toTop();

Jumps current window to the top of the page.

Example: toTop();
                                                                                            
closeWindow();

Closes the current window.

Example: closeWindow();
                                                                                                
closeWindowAfter(seconds);

Closes the current window after so many seconds.

Example: closeWindowAfter(3000);
Result:  The window will close after 3 seconds.
                                                                                                    
genPassword(number);

Generate a temporary password. Pass in a number, that number determines the length of the password.

Example: genPassword(12);
Result:  !fg%6HsY7*#n                                                                                      
                                                                                                    
getUserBrowser();

Returns the user's browser information.

Example: getUserBrowser();
                                                                                                         
                                                                                                        
keyPressed(e);

Returns what key was pressed by the user.

Example: keyPressed(e);
                                                                                                             
                                                                                                            
isChecked(id);

Checks to see if a checkbox by Id has been checked or not. Returns true or false.

Example: isChecked('chkTopping');
                                                                                                                 
                                                                                                                
arrayTopItem(array);

Loops through an array. Returns the item that appears the most.

Example: let numbers = [1,2,3,4,3,3]
arrayTopItem(numbers);                                                                                                   
Result:  3                                                            
                                                                                                                    
isEqual(x,y);

Compares two values to see if both the value AND type are the same. Returns true or false.

Example: isEqual(1, 1);
Result:  true                                                                                                        
                                                                                                                        
plotPoint(x, y, canvasId);

Plots a point on an HTML canavas. You must pass in the x value and y value, plus the id of the canvas you are working with.

Example: plotPoint(10,20, 'myCanvas');
                                                                                                                             
                                                                                                                            
findDistance(x1,x2,y1,y2);

Finds the distance between 2 points. Takes 4 parameters.

Example: findDistance(1,1,30,500);
Result:  470                                                                                     
                                                                                                                                
drawLine(x1,x2,y1,y2, canvasId);

Draws a line between two points. Takes 5 parameters.

Example: drawLine(1,1,39,149,'canvas');
                                                                                                                                     
                                                                                                                                    
query(id);

Takes an Id with # in front. Works similar to getId(id) function.

Example: query('#firstName');
                                                                                                                                         
                                                                                                                                        
sortNumArray(n,n,n...);

Pass in as many numbers as you wish. This function will return the numbers back from lowest to highest. Useful if you are not yet comfortable with building and working with arrays.

Example: sortNumArray(1,2,3,4,5,1,3);
Result:  1,1,2,3,3,4,5                                                                                                                             
                                                                                                                                          
sortTextArray(n,n,n...);

Pass in as many strings as you wish. This function will return the strings back from lowest to highest. Useful if you are not yet comfortable with building and working with arrays.

Example: sortTextArray('f','d','e');
Result:  d,e,f                                                                                                                             
                                                                                                                                          
isNumber(x);

Checks the parameter to see if is a number. Returns true or false. This function is great to use in conditional logic.

Example: isNumber(3);
Result:  true
Example: isNumber('g');
Result:  false                                                                                                                               
                                                                                                                                        
JsonToString(json);

Pass in either a variable holding a JSON string, or a JSON string literal. This function converts it to a Javascript Object.

Example: JSONToString('{"name":"John"}');
Result:  {"name":"John"}                                                                                                                           
                                                                                                                                          
capitalize(string);

Returns a string with the first character capitalized. Great to use with forms!

Example: capitalize('bob');
Result:  Bob                                                                                                                           
                                                                                                                                        
trim(string);

This function gets rid of any extra whitspace before or after a string. Great to use with forms!

Example: trim('  John  ');
Result:  'John'                                                                                                                           
                                                                                                                                      
splitEmail(email);

Splits the passed email at the '@' symbol. Returns an array containing the first and last half of the email address.

Example: splitEmail('email@email.com');
Result:  ['email','email.com']                                                                                                                           
                                                                                                                                    
filterNumArray(array, value);

Filter an Item out of an array. Pass in the array, and what value.

Example: filterNumArray([1,2,3,4], 3);
Result:  [1,2,4]                                                                                                                           
                                                                                                                                  
toInt(string);

Pass in a string value of a numer and convert it to an integer.

Example: toInt('36');
Result:  36                                                                                                                           
                                                                                                                                
toString(x);

Convert to a string.

Example: toString(1 + 1);
Result:  '1 + 1'                                                                                                                           
                                                                                                                              
wholeNum(number);

Rounds a number to the nearest whole number.

Example: wholeNum(13.3);
Result:  13                                                                                                                           
                                                                                                                            
toDec(number);

Rounds a number to the nearest 2 decimal points.

Example: toDec(27.445);
Result:  27.46                                                                                                                           
                                                                                                                          
currentTime();

Returns the current local time. The returned string will be formatted as follows.

Example: currentTime();
Result:  9:15:47 AM                                                                                                                           
                                                                                                                        
currentDate();

Returns the current local date. The returned string will be formatted as follows.

Example: currentDate();
Result:  10/15/17                                                                                                                           
                                                                                                                      
saveInfo(key, value);

Save a key value pair into session storage. Use the 'getInfo()' function to get the info back. Great for forms with AJAX! Deletes once the browser closes or the web page changes.

Example: saveInfo("firstName", "Jenny");
Result:  "firstName" : "Jenny"                                                                                                                           
                                                                                                                    
getInfo(key);

Get's the value for a key that is stored in session storage. Great for forms with AJAX!

Example: getInfo("firstName");
Result:  Jenny                                                                                                                           
                                                                                                                  
screenSize();

Returns an array with two elements. The user's screen width and height.

Example: screenSize();
Result:  [1920,1080]                                                                                                                           
                                                                                                                  
browserOS();

Returns the Operating System version of the browser.

Example: browserOS();
Result:  Win32                                                                                                                           
                                                                                                                  
browserLang();

Returns the language being used by the browser.

Example: browserLang();
Result:  en-US                                                                                                                           
                                                                                                                  
lbKG(pounds);

Convert pounds to kilograms.

Example: lbKG(12);
Result:  5.443164292842239                                                                                                                           
                                                                                                                  
kgLB(kilograms);

Convert kilograms to pounds.

Example: kgLB(12);
Result:  26.4552                                                                                                                           
                                                                                                                  
ozG(ounces);

Convert ounces to grams.

Example: ozG(12);
Result:  340.1939105290015                                                                                                                           
                                                                                                                  
gOZ(grams);

Convert grams to ounces.

Example: gOZ(12);
Result:  0.423288                                                                                                                           
                                                                                                                  
farToCel(F);

Convert Fahrenheit to Celsius.

Example: farToCel(95);
Result:  35                                                                                                                           
                                                                                                                  
celToFar(C);

Convert Celsius to Fahrenheit.

Example: celToFar(35);
Result:  95                                                                                                                           
                                                                                                                  
MPHtoKPH(mph);

Convert Miles Per Hour to Kilometers Per Hour.

Example: MPGtoKPH(95);
Result:  152.88768000000002                                                                                                                           
                                                                                                                  
KPHtoMPH(kph);

Convert Kilometers Per Hour to Miles Per Hour.

Example: KPHtoMPH(95);
Result:  59.030263262546725                                                                                                                           
                                                                                                                  
boolToNum(bool);

Convert a Boolean value to it's matching numeric value.

Example: boolToNum(false);
Result: 0

numToBool(number);

Convert 1 or 0 to it's matching Boolean value.

Example: numToBool(1);
Result: true

isNull(variable);

Check to see if a variable is Null or not. Returns true or false.

Example: isNull(x);
Result: true

new Control(id);

Select the element by it's Id. Allows you to chain methods listed below.

Example: var x= new Control('firstName');

.FontSize(number);

Chain method to add onto Control. Used to change the font size of the given Id.

Example: x.FontSize(12);

.color(color);

Chain method to add onto Control. Used to change the color of the text in a given Id.

Example: x.color('ff0000');

.bgColor(color);

Chain method to add onto Control. Used to change the background color in a given Id.

Example: x.bgColor('ff0000');

.textAlign(value);

Chain method to add onto Control. Used to align the text. Center/Left/Right

Example: x.textAlign('center');
Result:   Text will be centered.

.textDecoration(value);

Chain method to add onto Control. Used to apply text decorations. Pass in the desired property to apply.

Example: x.textDecoration('underline');
Result: Text will now have an underline.

.FontStyle(style);

Chain method to add onto Control. Used to change style of the font.

Example: x.FontStyle('italic');
Result: The font style changed!

.FontWeight(number);

Chain method to add onto Control. Used to change the font weight.

Example: x.FontWeight("900");

.bgIMG(src);

Chain method to add onto Control. Used to change the background image. Pass in the file path.

Example: x.bgIMG("images/me.jpg");

.addClass(className);

Chain method to add onto Control. Used to add a class to the selected Controlled Id.

Example: x.addClass("red-div");

.removeClass(className);

Chain method to add onto Control. Used to remove a class from the selected Controlled Id.

Example: x.removeClass("red-div");

.hide();

Chain method to add onto Control. Used to hide the Controlled Id from the webpage.

Example: x.hide();

.show();

Chain method to add onto Control. Used to showthe Controlled Id.

Example: x.show();

.Opacity(value);

Chain method to add onto Control. Used to change the opacity of the Controlled Id on the webpage.

Example: x.Opacity(0.5);

.Cursor(style);

Chain method to add onto Control. Used to change the type of cursor on the Controlled Id.

Example: x.Cursor('pointer');

.floatLeft();

Chain method to add onto Control. Used on the Controlled Id to apply a float: 'left' css style.

Example: x.floatLeft();

.floatRight();

Chain method to add onto Control. Used on the Controlled Id to apply a float: 'right' css style.

Example:     x.floatRight();

.Text(text);

Chain method to add onto Control. Used on the Controlled Id to add new text or change the current text.

Example: x.Text('New text');
Result: New text

.DecorationOff();

Chain method to add onto Control. Used to turn any and all text decoration off.

Example: x.DecorationOff();

.width(width);

Chain method to add onto Control. Used to change the width.

Example: x.width(width);

.height();

Chain method to add onto Control. Used to change the height.

Example: x.height();