Reference Source

Utils Module

Utils is a lightweight and versatile JavaScript utility class designed to provide commonly used functions for web development. It is a collection of various helper functions that can be used in a variety of projects.

Installation

ES Module

import { Utils } from './utils.mjs';

IIFE (Immediately Invoked Function Expression)

<script src="utils.js"></script>;
// ...
window.UtilsBundle.Utils;

CommonJS (CJS) Module

const { Utils } = require('./utils.cjs.js');

You can then call any of the functions available in the Utils class.

API

decimalRand(pNum1, pNum2, pPlaces)

rand(pNum1, pNum2)

getPercentage(pValue, pTotalValue)

clamp(pNumber, pMin, pMax)

lerp(pStart, pEnd, pAmount)

flooredLerp(pStart, pEnd, pAmount)

round(pNumber, pPlace)

normalize(pVal, pMin, pMax)

within(pVal, pMin, pMax)

formatIntegerWithCommas(pNum)

toRadians(pDegrees)

toDegrees(pRadians)

pick(pArray)

removeProperties(pObject, pExclude)

prob(pChance)

getInverseDirection(pDir)

getAngleFromDirection(pDir)

generateID(pIDLength)

decimalToHex(pDecimal, pChars)

addIntensity(pColor, pPercent)

rgbToHex(pR, pG, pB)

hexToRgb(pHex)

rgbToDecimal(pR, pG, pB)

hexToDecimal(pHex)

grabColor(pSwitch, pG, pB)

getRandomColor()

getRandomColorBetween(pColor1, pColor2, pAmount = 0.5)

transitionColor(pInstance, pStartColor='#000', pEndColor='#fff', pDuration=1000, pIterativeCallback, pEndCallback)

cancelTransitionColor(pID)

getPointRotated(pRect, pTheta, pPoint)v

getPointsOfRotatedRect(pRect, pTheta)

Global Dependency

Utils relies on the VYLO variable being globally accessible.