Enhance Browser’s JavaScript Engine with Balzac.js Library

Category: Javascript | August 2, 2023
Author:visicode
Views Total:35 views
Official Page:Go to website
Last Update:August 2, 2023
License:MIT

Preview:

Enhance Browser’s JavaScript Engine with Balzac.js Library

Description:

Balzac.js is a lightweight JavaScript library that expands and improves native browser capabilities for web development.

It infuses your JavaScript engine with missing functionalities, completes incomplete features, augments existing HTML elements, and gently overwrites built-in JavaScript objects for an optimized web development experience.

Table Of Contents:

How to use it:

1. Include the minified version of the Balzac.js library on the page.

<script src="balzac.min.js" defer></script>

2. Enhance JavaScript’s Number object.

// checks if a number is between two values, bounds included
number.isBetween(min, max);
// checks if a number is between two values, bounds excluded
number.isBetweenExclusive(min, max);

3. Enhance JavaScript’s Math object.

// returns a numeric expression rounded to a specified number of fractional digits
Math.roundTo(x, decimals);

4. Enhance JavaScript’s String object.

// hecks if a string is all in uppercase letters.
string.isUpperCase();
// checks if a string is all in lowercase letters.
string.isLowerCase();
// returns a string converted to title case (every major word capitalized).
string.toTitleCase();
// returns a string converted to sentence case (first word of every sentence capitalized).
string.toSentenceCase();
// returns a string with leading and trailing white space and line terminator characters removed from each line.
string.trimAll();
// returns a string truncated to the nearest word, with a trailing ellipsis if needed.
string.truncate(max);
// returns an HTML string converted to plain text, with all HTML tags removed.
string.toPlainText();
// returns a string with new lines converted to HTML line breaks.
string.nl2br();
// returns a string with new lines converted to HTML paragraphs.
string.nl2p();

5. Enhance JavaScript’s Date object.

/**
 * Adds duration constants to new Date.DURATION object for converting delays into milliseconds.
 *  SECONDE: 1 second in milliseconds.
 *  MINUTE:  1 minute in milliseconds.
 *  HOUR: 1 hour in milliseconds.
 *  DAY: 1 day in milliseconds.
 */
setTimeout(function, 3 * Date.DURATION.MINUTE);
// checks if a date is between the specified interval, bounds included.
date.isBetween(start, end);
// checks if a date is between the specified interval, bounds excluded.
date.isBetweenExclusive(start, end);
// returns a new Date that adds the specified number of milliseconds to the value of this instance.
date.addMilliseconds(value);
// returns a new Date that adds the specified number of seconds to the value of this instance.
date.addSeconds(value);
// returns a new Date that adds the specified number of minutes to the value of this instance.
date.addMinutes(value);
// returns a new Date that adds the specified number of hours to the value of this instance.
date.addHours(value);
// returns a new Date that adds the specified number of days to the value of this instance.
date.addDays(value);
// returns a new Date that adds the specified number of months to the value of this instance.
date.addMonths(value);
// returns a new Date that adds the specified number of years to the value of this instance.
date.addYears(value);

6. Enhance JavaScript’s RegExp object.

/**
 * Adds predefined input RegExp patterns to new RegExp.PATTERN object.
 *  EMAIL
 *  EMAILS
 *  PHONE:
 *  PASSWORD
 *  PASSPORT
 *  IBAN
 *  POSTCODE
 */
RegExp.PATTERN.EMAIL.test(string);
// checks if user navigator is Google Chrome.
navigator.isChrome;
// checks if user navigator is Microsoft Edge.
navigator.isEdge;
// checks if user navigator is Mozilla Firefox.
navigator.isFirefox;
// checks if user navigator is Opera.
navigator.isOpera;
// checks if user navigator is Apple Safari.
navigator.isSafari;

8. Manipulate browser cookies.

// returns a browser cookie value (undefined if not existing).
string = document.getCookie(name);
// sets a browser cookie.
document.setCookie(name, value, expires);
// deletes a browser cookie.
document.removeCookie(name);

9. Enhance JavaScript’s File object.

/**
 * adds size constants to new File.SIZE object to help converting file sizes from bytes.
 *  KILOBYTE
 *  MEGABYTE
 *  GIGABYTE
 *  TERABYTE
 */
megabytes = document.getElementById('fileInput').files[0].size / File.SIZE.MEGABYTE;

10. Encode/decode HTML.

string = WebUtility.htmlEncode(string);
string = WebUtility.htmlDecode(string);

11. Add a new case attribute to all input elements to force text case (“none”, “lower”, “upper”, “title” or “sentence”).

document.getElementById('input').case;

12. Get the password strength.

/**
 * Returns the password strength from HTMLInputElement.PASSWORD_RATING.EMPTY to HTMLInputElement.PASSWORD_RATING.STRONG.
 *  EMPTY:      Empty.
 *  SHORT:      Less than 8 characters.
 *  WEAK:       One or two of the PASSWORD_RATING.GOOD criteria.
 *  MEDIUM:     Three of the PASSWORD_RATING.GOOD criteria.
 *  GOOD:       At least 1 lowercase letter, 1 uppercase letter, 1 digit and 1 special character.
 *  STRONG:     All PASSWORD_RATING.GOOD criteria and greater than or equal to 12 characters.
 */
document.getElementById('passwordInput').getPasswordRating();

13. Return a static node list containing all HTML output elements associated with the input.

document.getElementById('input').getOutputs();

You Might Be Interested In:


Leave a Reply