Usage
If you use prototypes.js in Node, the html prototypes will be based on the Object type. Ex: HTMLSelectElement.prototype.getTextOptSelected -> Object.prototype.getTextOptSelected. They will work the same way, it will only change the specific object it is aimed at.
This prototype orders an array by string, date or number according to the attribute and in both ascending and descending order.
This prototype groups an array by category/attribute. Just work in a new variable.
This prototype merges arrays and groups them based on the value of an attribute that matches between them. Just work in a new variable.
This prototype removes the elements of an array based on their index, respecting the initial order
Strings prototype set.
This prototype makes the first letter uppercase.
This prototype does a line break every x number of characters.
This prototype validates if an email is valid or not.
Numbers prototype set.
This prototype gives the price format "x.xxx", "xx.xxx", etc.
This prototype rounds the number in base 10, "0-5" remains at 0, "6-9" goes to the next number in base 10.
Select elements prototype set.
This prototype gets the text of the selected option.
This prototype gets the specified attribute of the selected option from the select element.
This prototype gets all the attributes of the selected option from the select element.
This prototype gets the values of the selected options from the select multiple element.
This prototype change the value of a select element.
This function assign values to a select multiple.
Table prototype set.
This prototype add a row to an HTML table in a designed position.
Column 1 | Column 2 | Column 3 | Column 4 | Column 5 |
---|---|---|---|---|
Data 1 | Data 2 | Data 3 | Data 4 | Data 5 |
TableRow prototype set.
This prototype delete a row from an HTML table.
Column 1 | Column 2 | Column 3 | Column 4 | Action |
---|---|---|---|---|
Data 1 | Data 2 | Data 3 | Data 4 | |
Data 5 | Data 6 | Data 7 | Data 8 | |
Data 9 | Data 10 | Data 11 | Data 12 |
Input / TextArea elements prototype set.
This function simulates that the user is pressing a key and writes the character in the input.
/**
* This prototype simulates that the user is pressing a key and writes the character in the input
*
* @param {string|number} value value to write to input
*/
HTMLInputElement.prototype.simulateKeyPress = function simulateKeyPress(value){
let event = new Event('keypress');
let text = value.toString();
let index = 0;
setInterval(addCharacter, 100);
function addCharacter() {
if (index < text.length) {
var currentChar = text.charAt(index);
this.value += currentChar;
this.dispatchEvent(event);
index++;
} else {
clearInterval();
}
}
}
HTMLTextAreaElement.prototype.simulateKeyPress = function simulateKeyPress(value){
let event = new Event('keypress');
let text = value.toString();
let index = 0;
setInterval(addCharacter, 100);
function addCharacter() {
if (index < text.length) {
var currentChar = text.charAt(index);
this.value += currentChar;
this.dispatchEvent(event);
index++;
} else {
clearInterval();
}
}
}