jsHelper: Add helper functions to String and Array objects

Recommend this page to a friend!
     
  Info   Example   View files Files   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 64 All time: 482 This week: 3Up
Version License JavaScript version Categories
jshelper 1.0MIT/X Consortium ...6Validation, Language, Utilities and T..., T..., E...
Description 

Author

This class can add helper functions to String and Array objects.

It can add new prototypes to the String object of functions to replace all occurrences of a given text in a string, delete all spaces from a string and check if a string is empty.

It also adds static functions to check if a variable is set, call a function by name, check if a variable is a string or an object, and create a DOM element with given properties.

It can also add prototypes to the Array object of functions to find a given element in a array and check if the array is empty.

It also adds

Picture of Leo Otero
  Performance   Level  
Name: Leo Otero <contact>
Classes: 1 package by
Country: Spain Spain
Age: ???
All time rank: 17411 in Spain Spain
Week rank: 6 Up2 in Spain Spain Up

Example

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script src="jsHelper.js"></script> <script> var testString = "text"; var testString2 = "my monkey Amelio and I"; var testArray = ["text", 2, 123, 4, "k", ""]; var testArray2 = []; var testObject = { name: function(){alert()}, inventedVar:null }; var leoIsset; var myfunction = "hello"; function hello(name, surname){ console.log("Hello " + name + " " + surname); } // lets try if(!jsHelper.isset(leoIsset) || !jsHelper.isset(testObject.inventedVar)){ console.log("These vars are null or undefined"); } if(jsHelper.isObject(testObject)){ console.log("This is a object"); } if(testArray2.empty()){ console.log("The array is empty :( "); } jsHelper.callFunctionByName(myfunction, [ "Leandro", "Otero" ]); console.log("TestString2 before: " + testString2); console.log("TestString2 after replacement: " + testString2.strReplaceAll(" ","")); console.log("TestString2 after replacement (only with 2): " + testString2.strReplaceAll(" ","",2)); if(testArray[5].empty()){ console.log("The string is empty :("); } if(testArray.in_array(123)){ console.log("Element found in the array :)") } var stringFullTrim = testString2.fullTrim(); console.log(stringFullTrim); window.onload = function(){ var newElement = {name:"a", text: "es un link", attrs: {href:"http://www.google.es",style:"color:red;"}}; jsHelper.createDOMElement(newElement,"box1"); }; </script> </head> <body> <div id ="box1"> </div> </body> </html>

Details

How to use JSHelper

A little explanation

The main purspose of this class (what follow the new sintax of ES6) is provide a list of methods to help developers to program faster. Besides this class add some new features to the prototypes of javascript to make easier to check the variables.

Functions and features

String.prototype.strReplaceAll : It replaces all occurrences of a string for the string that you want. You can specify how many occurrences you want to replace.

String.prototype.empty : It checks if your string is empty.

Array.prototype.in_array : It checks if what you pass as param is in the array.

Array.prototype.empty : It checks if your array is empty.

Object.prototype.getPropertiesName : This function give you the option to use getOwnPropertyNames directly as a function of any object

String.prototype.fullTrim : This function trim all white spaces

Functions

isset : It checks if the variable is not null and not undefined.

callFunctionByName : This function calls to another function by name. You pass a string as name and an array as params if the function has them.

isObject : it checks that what you pass as param is an object.

isString : it checks that what you pass as param is an string.

createDOMElement : This method creates dom element with the properties that you specify and in the element that you want


  Files folder image Files (3)  
File Role Description
Plain text file jsHelper.js Class Class source
Accessible without login Plain text file readme.md Doc. Documentation
Accessible without login Plain text file test.html Example Example

 Version Control Unique User Downloads Download Rankings  
 100%
Total:64
This week:0
All time:482
This week:3Up