AFTC.js
A collection of usefull everyday utilities / functions.
Any and all donations to help keep active development and the lights on are more than welcome. Find AFTC.JS useful? Please Donate...
npm i aftc-modules
What's new
Added loadCss(href,onComplete)
Added alias loadScript for loadJs
Reduced core to it's bare minimum
Why? This is because of the direction JS development is going, if I am building a webpack project I often only want: log, logTo, onReady and argsToObject. And so a new core was born! Using webpack? You should be using aftc-modules unless I haven't migrated a feature over yet.
Added fadeTo and fadeFromTo to AFTC.Color()
let color = new AFTC.Color();
color.setRGB(0,255,0); // set starting color
let colors1 = color.fadeTo(255,0,0,10);
// Or do it with fromTo
let colors2 = color.fadeFromTo(0,0,0,255,0,0,10);
A single request animation frame function stack which can be used to control multiple classes / whole applications renderers etc via methods add(fn) remove(fn) stop() start() dispose()
let AnimStack = new AnimationFrameStack();
animStack.add(fn1);
animStack.stop();
adnimStack.remove(fn2);
animStack.start();
You can view all pens at https://codepen.io/AllForTheCode/pens/public/?grid_type=list
Quick and easy script loading and attachement to the DOM.
Attach some visual debug divs to an element which you can logTo, returns an array of elements so you can:
let v = attachDebug(10,document.body);
debugTo(v[0],"hello world 1");
debugTo(v[9],"hello world 10");
Installation
npm i aftc.js
or via cdn:
- https://cdn.jsdelivr.net/npm/aftc.js@latest/dist/aftc.min.js
- https://cdn.jsdelivr.net/npm/aftc.js@latest/dist/aftc.core.min.js
Use aftc.min.js in your html include or vendor merged packages.
Use aftc-modules.js in your ES6 projects for tree shacking.
File descirptions
Then include the version you wish to use, your options are:
-
aftc.min.js (44KB) - Have it all!
-
aftc.core.min.js (3.71KB) - onReady, log, Log, getElement shortcuts, getRandomInt/float etc.
NOTE: You can always customise your build of the AFTC.JS, see the Build Guide below.
Build Guide
gulp build
Step by step
- Open aftc.js directory in VSCode
- Open "gulpfile.js" and edit / comment out or uncomment any of the imports that you want or don't want
// The extras, the modules, the ooo or to some, the bloat
// Nice to have, but not essential
var aftc_modules = [
"./dist/aftc.core.js", // The AFTC Core (required)
"./src/AFTC/AFTC.Audio.js", // Enables new AFTC.Audio() and playSound()
"./src/AFTC/AFTC.Animate.js", // Enables new AFTC.Animate()
"./src/AFTC/AFTC.Canvas.js", // Enables new AFTC.Canvas();
// "./src/AFTC/AFTC.CheckboxHideShow.js", // Up for review - to be updated or removed
"./src/AFTC/AFTC.Color.js", // Enables new AFTC.Color();
"./src/AFTC/AFTC.Visibility.js", // Enables hide(), show(), fade(), fadeIn() & fadeOut()
// "./src/AFTC/AFTC.ResizeManager.js", // Up for review - to be updated or removed
"./src/AFTC/AFTC.XHR.js", // Everyone needs some IO, I know I do...
];
- Open terminal in VSCode by pressing CTRL + '
- Type into terminal
gulp build
https://github.com/DarceyLloyd/AFTC.js.git
NPMJS Has issues with Docs from GITHUB from this point, want to see the docs better please visit the github pageQuick links: addClass(elementOrId,classname)
addEvent(obj,type,fn,useCapture)
AFTC.Animate()
AFTC.Animate(elementId, onComplete)
AFTC.Audio({options})
AFTC.Color({params})
AFTC.Point(x,y)
AFTC.Rectangle(x, y, w, h)
AFTC.Velocity(vx,vy)
AFTC.XHR({options})
argsToObject(fArgs, obj, strict)
arrayContains(needle,haystack)
arrayEmpty(arr)
arrayGetMin(arr)
arrayRemoveIndex(arr,index)
arrayShuffle(arr)
arrayShuffle2(arr)
arrayToSingleLineString(arr)
boolToString(bool)
boolToYesNo(bool)
centerAbsoluteElement(elementId)
cleanJSONString(s)
cls()
convertToArray(val)
cutStringTo(input, len)
cycle(pos, max)
degToRad(input)
escapeHTML(input)
exitFullScreen()
getAllStringsBetween(str,start,end)
getAnchor(url)
getArrayOfRandomNumbers(arraySize,min,max)
getArrayOfRandomStrings(arraySize,strLength)
getBooleanFrom(input)
getBrowser()
getCookie(name)
getDateTime(local)
getDaysBetween(startDateTime, endDateTime)
getElementByClassName(className)
getElementById(id)
getElementByName(name)
getElementByTagName(tagName)
getElementOffsetTop(elementId)
getElementsByClassName(className)
getElementsByName(name)
getElementsByTagName(tagName)
getFileExtension(input)
getFileExtension2(input)
getFunctionName(fn)
getIEVersion()
getLastPartOfUrl(url)
getMaxFromArray(arr)
getOS(testUserAgent)
getRandomColor()
getRandomFloat(min,max)
getRandomInt(min,max)
getRandomThatsNot(min,max,not)
getSQLDateTime()
getStringBetween(input,start,end)
getUID(length)
getUKDateFromDate(dte)
getUkDateFromDbDateTime(input)
getUkDateTimeFromDbDateTime(input)
getUSDateFromDate(dte)
getWeightedRandom(odds, iterations)
goFullScreen(element)
guid()
hasClass(elementOrId, cls)
hexToRgb(hex)
iOS()
isAlphaNumeric(input)
isAndroid()
isArray(input)
isBoolean(input)
isChecked(elementId)
isChrome()
isDOM(obj)
isEdge()
isElement(o)
isElement2(element)
isEven(n)
isFireFox()
isIE()
isInString(find,source)
isMobile()
isNumberKey(evt)
isNumeric(n)
isOdd(n)
isOpera()
isSafari()
isStringInArray(needle,haystack)
leftTrim(str, by)
limitLengthInWords(str, maxWords)
log(*)
logTo(element,str,append)
onReady(fn)
openDebugWindow(html)
parseArrayToFloat(arr)
parseArrayToInt(arr)
parseJSONToSelect(j, selectElementIdOrElement, label, value)
querySelector(query)
radToDeg(input)
randomString(length)
redirect(url)
removeAllSelectOptions(elementId)
removeClass(elementOrId,className)
removeFileFromPath(path)
rgb2Hex(r,g,b)
rgbToHex(r,g,b)
scrollToElement(elementId, duration, offset)
setCookie(name, value)
setHTML(elementOrId,html);
String.prototype.endsWith(str)
String.prototype.startsWith(str)
stringToBool(str)
toArray(v)
toHex(num)
trimStringBy(input, trimBy)
validateEmail(email)
Browse on codepenhttps://codepen.io/AllForTheCode/pens/public/?grid_type=list
argsToObject(fArgs, obj, strict)
Quick and easy args to object
More information
Parameters:
Name | Type | Description |
---|---|---|
args | object | arguments (from the function structure, typically code will always be 'arguments' |
obj | object | object to parse into |
strict | boolean | console.warn any args that have been supplied that don't exist in args |
Returns: null
- argsTo Alias's:
- Usage examples:https://codepen.io/AllForTheCode/pen/PaqbKN
getElementById(id)
Gets an element from the DOM by ID. NOTE
More information
Parameters:
Name | Type | Description |
---|---|---|
id | string | The ID of the DOM element you wish to find |
Returns: html element
- getId - byId Alias's:
- Usage examples:https://codepen.io/AllForTheCode/pen/PedyNO
querySelector(query)
Gets an element from the DOM via DOM Query. NOTE
More information
Parameters:
Name | Type | Description |
---|---|---|
query | string | The DOM Query / css element path you wish to find |
Returns: html element
- query Alias's:
- Usage examples:https://codepen.io/AllForTheCode/pen/MGqPrN
getElementsByName(name)
Gets an array of element from the DOM that have a specific name. NOTE
More information
Parameters:
Name | Type | Description |
---|---|---|
name | string | The name of the DOM element you wish to find |
Returns: array of html elements
- Usage examples:https://codepen.io/AllForTheCode/pen/gzdBdz
getElementByName(name)
Gets the first element from the DOM that has a specific name. NOTE
More information
Parameters:
Name | Type | Description |
---|---|---|
name | string | The name of the DOM element you wish to find |
Returns: html elements
- Usage examples:https://codepen.io/AllForTheCode/pen/gzdBdz
getElementsByClassName(className)
Gets an array of html elements from the DOM that have a specific class name. NOTE
More information
Parameters:
Name | Type | Description |
---|---|---|
className | string | The class the DOM element(s) use you wish to find |
Returns: array of html elements
- Usage examples:https://codepen.io/AllForTheCode/pen/odPQxE
getElementByClassName(className)
Gets the first html element from the DOM that has a specific class name. NOTE
More information
Parameters:
Name | Type | Description |
---|---|---|
className | string | The class name the DOM element uses you wish to find |
Returns: html elements
- Usage examples:https://codepen.io/AllForTheCode/pen/odPQxE
getElementsByTagName(tagName)
Gets an array of html elements from the DOM that has a specific tag name. NOTE
More information
Parameters:
Name | Type | Description |
---|---|---|
tagName | string | the tag name you wish to find |
Returns: array of html elements
getElementByTagName(tagName)
Gets the first html element from the DOM that has a specific tag name. NOTE
More information
Parameters:
Name | Type | Description |
---|---|---|
tagName | string | the tag name you wish to find |
Returns: html element
log(*)
Shortcut for console.log with some formatting capabilities, you can also log to html elements see logTo()
log("Hello World");
log("a = " + a);
log("myVar1 = " + myVar1 + " myVar2 = " + myVar2);
log(MyObject);
log(MyClass);
More information
Parameters:
Name | Type | Description |
---|---|---|
* | input | what you want to console.log |
- log - trace Alias's:
- Usage examples:https://codepen.io/AllForTheCode/pen/pVOOZV - https://codepen.io/AllForTheCode/pen/NMLLJX
logTo(element or elementId,string,append:boolean=true)
Shortcut for console.log with some formatting capabilities, you can also log to html elements see logTo()
logTo("MyElement","Hello World",false); // clears element and inserts
logTo("MyElement","Hello World"); // appends
let myElement = document.getElementById("MyElementId");
logTo(myElement,"Hello World"); // appends
More information
Parameters:
Element or ElementId | String | Append |
---|---|---|
HTML Element or String | String to be inserted into element | To append string or not to elements contents |
cls()
Clears the console if supported
More information
- clearLog(); Alias's:
- Usage examples:https://codepen.io/AllForTheCode/pen/pVOOZV - https://codepen.io/AllForTheCode/pen/NMLLJX
arrayRemoveIndex(arr,index)
remove a specified index from an array
More information
Parameters:
Name | Type | Description |
---|---|---|
arr | array | the array you wish to remove an index on |
index | number | the array index you wish to remove |
Returns: array
- Usage examples:https://codepen.io/AllForTheCode/pen/mLzyGP
isStringInArray(needle,haystack)
Check to see if a string is in an array
More information
Parameters:
Name | Type | Description |
---|---|---|
needle | string | what you want to search for in each array index |
haystack | string | the array you want to search |
- Usage examples:https://codepen.io/AllForTheCode/pen/QrZrBM
arrayContains(needle,haystack)
Check to see if your array contains something you want to find
More information
Parameters:
Name | Type | Description |
---|---|---|
needle | string | what you want to search for in each array index |
haystack | string | the array you want to search |
- isInArray Alias's:
- Usage examples:https://codepen.io/AllForTheCode/pen/VxExVw
arrayEmpty(arr)
clears/empties an array for garbage collection
More information
Parameters:
Name | Type | Description |
---|---|---|
array | arr | the array to clear / empty |
- arrayClear Alias's:
- Usage examples:https://codepen.io/AllForTheCode/pen/ELdRYJ
getMaxFromArray(arr)
returns the maximum value in an array
More information
Parameters:
Name | Type | Description |
---|---|---|
array | arr | the array you wish to find the maximum value in |
- arrayGetMax - arrayMax Alias's:
- Usage examples:https://codepen.io/AllForTheCode/pen/GdYGjW
arrayGetMin(arr)
returns the minimum value in an array
More information
Parameters:
Name | Type | Description |
---|---|---|
arr | array | the array you wish to find the minimum value in |
- getMinFromArray - arrayMin Alias's:
- Usage examples:https://codepen.io/AllForTheCode/pen/bMmKBa
arrayShuffle(arr)
shuffles an array (method 1)
More information
Parameters:
Name | Type | Description |
---|---|---|
arr | array | the array to shuffle |
- shuffle - arrayShuffle Alias's:
- Usage examples:https://codepen.io/AllForTheCode/pen/wjYjmo
arrayShuffle2(arr)
shuffles an array (method 2)
More information
Parameters:
Name | Type | Description |
---|---|---|
arr | array | the array to shuffle |
- shuffle2 - arrayShuffle2 Alias's:
- Usage examples:https://codepen.io/AllForTheCode/pen/wjYjmo
arrayToSingleLineString(arr)
Converts an array to a single line string (usefull for debug)
More information
Parameters:
Name | Type | Description |
---|---|---|
arr | array | the convert |
- arrayToString Alias's:
- Usage examples:https://codepen.io/AllForTheCode/pen/XqoVEe
convertToArray(val)
takes an input and returns it as index[0] of an array
More information
Parameters:
Name | Type | Description |
---|---|---|
val | * | value to make into array an array |
- valueToArray Alias's:
- Usage examples:https://codepen.io/AllForTheCode/pen/QrzazK
redirect(url)
no more typing self.location.href, just use redirect(url)
More information
Parameters:
Name | Type | Description |
---|---|---|
url | string | the url you wish to redirect to |
- Usage examples:https://codepen.io/AllForTheCode/pen/RyEpPY
goFullScreen(element)
Go full screen, on an element if specified or whole browser if left out
More information
Parameters:
Name | Type | Description |
---|---|---|
element | element | optional - html element that you want to go full screen on, leave out for whole browser |
- Usage examples:https://codepen.io/AllForTheCode/pen/ELGWpE
exitFullScreen()
Exits full screen mode
More information
- Usage examples:https://codepen.io/AllForTheCode/pen/ELGWpE
radToDeg(input)
converts radians to degrees
More information
Parameters:
Name | Type | Description |
---|---|---|
input | number | the radians you wish converted to degrees |
- rad2deg Alias's:
- Usage examples:https://codepen.io/AllForTheCode/pen/wjRpBZ
degToRad(input)
converts degrees to radians
More information
Parameters:
Name | Type | Description |
---|---|---|
number | input | the value you wish converted to radians |
- deg2rad Alias's:
- Usage examples:https://codepen.io/AllForTheCode/pen/jxXYbE
toHex(num)
Converts a number to hex
More information
Parameters:
Name | Type | Description |
---|---|---|
num | number | decimal base 10 |
Returns: hexidecimal value
- Usage examples:https://codepen.io/AllForTheCode/pen/ELGoKX
boolToString(bool)
converts boolean to a string of true or false
More information
Parameters:
Name | Type | Description |
---|---|---|
bool | boolean | the boolean you wish to convert |
- Usage examples:https://codepen.io/AllForTheCode/pen/PeXEbg
boolToYesNo(bool)
converts a boolean to yes or no
More information
Parameters:
Name | Type | Description |
---|---|---|
bool | boolean | the boolean you wish to convert |
- Usage examples:https://codepen.io/AllForTheCode/pen/zjypZz
stringToBool(str)
Converts a string to a boolean (y,yes,"1",no etc)
More information
Parameters:
Name | Type | Description |
---|---|---|
str | string | the string you wish to convert |
- Usage examples:https://codepen.io/AllForTheCode/pen/vjvpmQ
getBooleanFrom(input)
converts an input to a boolean
More information
Parameters:
Name | Type | Description |
---|---|---|
* | input | the variable you wish to convert to a boolean |
- Usage examples:https://codepen.io/AllForTheCode/pen/XqoVea
parseArrayToFloat(arr)
parses all values in array to float
More information
Parameters:
Name | Type | Description |
---|---|---|
array | arr | array to process |
- arrayToFloat Alias's:
- Usage examples:https://codepen.io/AllForTheCode/pen/erbyVR
parseArrayToInt(arr)
parses all values in array to float
More information
Parameters:
Name | Type | Description |
---|---|---|
array | arr | array to process |
- arrayToInt Alias's:
- Usage examples:https://codepen.io/AllForTheCode/pen/yjGpqM
toArray(v)
takes an input and returns it as index[0] of an array
More information
Parameters:
Name | Type | Description |
---|---|---|
* | arg | value to insert into array |
- convertToArray - valueToArray Alias's:
- Usage examples:https://codepen.io/AllForTheCode/pen/QrzazK
rgb2Hex(r,g,b)
rgb to hex
More information
Parameters:
Name | Type | Description |
---|---|---|
number | r | red |
number | g | green |
number | b | blue |
rgbToHex(r,g,b)
rgb to hex
More information
Parameters:
Name | Type | Description |
---|---|---|
number | r | red |
number | g | green |
number | b | blue |
hexToRgb(hex)
hexToRgb
More information
Parameters:
Name | Type | Description |
---|---|---|
string | hex | hex color |
setCookie(name, value, expiryTimeInDays)
Sets a cookie by name with a value
More information
Parameters:
Name | Type | Description |
---|---|---|
name | string | name of the cookie |
value | string | value of the cookie |
expiryTimeInDays | number | Specify the number of days the cookie will expire in. |
- Usage examples:https://codepen.io/AllForTheCode/pen/RyBMwq
getCookie(name)
Gets the value of a cookie by name
More information
Parameters:
Name | Type | Description |
---|---|---|
name | string | name of the cookie to get |
- Usage examples:https://codepen.io/AllForTheCode/pen/RyBMwq
addClass(elementOrId,classname)
Add a css class to a html element
More information
Parameters:
Name | Type | Description |
---|---|---|
elementOrId | elementORstring | The elemnt or id of the html element to add a css class to |
className | string | the class name to add |
- Alias's:
- Usage examples:https://codepen.io/AllForTheCode/pen/BxvYmW
removeClass(elementOrId,className)
shortcut to remove a class from a html element
More information
Parameters:
Name | Type | Description |
---|---|---|
elementOrId | elementORstring | The elemnt or id of the html element to add a css class to |
className | string | the class name to remove |
- Alias's:
- Usage examples:https://codepen.io/AllForTheCode/pen/gzZvKL
hasClass(elementOrId, cls)
Check to see if an element has a class attached to it
More information
Parameters:
Name | Type | Description |
---|---|---|
elementOrId | string | The elemnt or id of the html element |
cls | string | class to look for |
- Usage examples:https://codepen.io/AllForTheCode/pen/dewdwY
getDaysBetween(startDateTime, endDateTime)
Gets the number of whole days between a start and end date
More information
Parameters:
Name | Type | Description |
---|---|---|
startDateTime | DateTime | start date |
endDateTime | DateTime | end date |
- getNoOfDaysBetween - getDaysBetweenDates Alias's:
- Usage examples:https://codepen.io/AllForTheCode/pen/pVqaGZ
getUKDateFromDate(dte)
Formats a date in the UK format
More information
Parameters:
Name | Type | Description |
---|---|---|
dte | Date |
- Usage examples:https://codepen.io/AllForTheCode/pen/RyEMwp
getUSDateFromDate(dte)
Formats a date in the US format
More information
Parameters:
Name | Type | Description |
---|---|---|
dte | Date | date |
- Usage examples:https://codepen.io/AllForTheCode/pen/XqoEWL
getUkDateFromDbDateTime(input)
get a uk date from a mysql db date value
More information
Parameters:
Name | Type | Description |
---|---|---|
input | MySQLDateTimeString | MySQL DB DateTime |
- Usage examples:https://codepen.io/AllForTheCode/pen/BxvePW
getUkDateTimeFromDbDateTime(input)
get a uk date from a mysql db date time value
More information
Parameters:
Name | Type | Description |
---|---|---|
input | MySQLDateTimeString | MySQL DB DateTime |
- Usage examples:https://codepen.io/AllForTheCode/pen/MGZdBB
getSQLDateTime()
gets the date time now for sql insert
More information
- Usage examples:https://codepen.io/AllForTheCode/pen/wjRbEe
getDateTime(local)
gets the date time at a specified local
More information
Parameters:
Name | Type | Description |
---|---|---|
local | string | options are us or do not supply for en-gb |
- Usage examples:https://codepen.io/AllForTheCode/pen/GdPaYj
openDebugWindow(html)
open a popup window with the html you wish to display in it
More information
Parameters:
Name | Type | Description |
---|---|---|
html | string | the html you wish to display in the popup window |
- stringToWindow - htmlToWindow Alias's:
- Usage examples:https://codepen.io/AllForTheCode/pen/ELGWpE
isMobile()
Detects if the device you are using is a mobile or not
More information
- Usage examples:https://codepen.io/AllForTheCode/pen/KRbLdm
isAndroid()
Detects if the device you are using is android or not
More information
- Usage examples:https://codepen.io/AllForTheCode/pen/RyEmgN
iOS()
Detects if the device you are using is iOS or not
More information
- Usage examples:https://codepen.io/AllForTheCode/pen/ELGzXO
isFireFox()
Detects FireFox
More information
- Usage examples:https://codepen.io/AllForTheCode/pen/mLaYMe
isChrome()
Detects Chrome
More information
- Usage examples:https://codepen.io/AllForTheCode/pen/xjmNLM
isEdge()
Detects Edge
More information
- Usage examples:https://codepen.io/AllForTheCode/pen/aGPrLP
isSafari()
Detects Safari
More information
- Usage examples:https://codepen.io/AllForTheCode/pen/gzZJXr
isIE()
Detects IE
More information
- Usage examples:https://codepen.io/AllForTheCode/pen/MGZdOG
isOpera()
Detects Opera
More information
- Usage examples:https://codepen.io/AllForTheCode/pen/dewEJb
getIEVersion()
Gets version of IE
More information
- Usage examples:https://codepen.io/AllForTheCode/pen/BxveJp
getBrowser()
Detects browser
More information
- Usage examples:https://codepen.io/AllForTheCode/pen/GdPaQZ
getOS(testUserAgent)
Attempts to get the os from the user agent or the test user agent
More information
Parameters:
Name | Type | Description |
---|---|---|
string | testUserAgent | test user agent string |
- Usage examples:https://codepen.io/AllForTheCode/pen/erbaVj
setHTML(elementOrId,html);
Quick shortcut for outputting html to an element
setHTML("header","Welcome");
More information
Parameters:
Name | Type | Description |
---|---|---|
elementOrId | stringIdOrHtmlElement | the element or the element id you wish to set the html of |
html | string | the html string to insert into your element |
- html Alias's:
- Usage examples:https://codepen.io/AllForTheCode/pen/KRbLER
getElementOffsetTop(elementId)
Gets an elements top offset
More information
Parameters:
Name | Type | Description |
---|---|---|
elementId | string | the element ID you wish to get the top offset of |
- Usage examples:https://codepen.io/AllForTheCode/pen/GdPaLr
centerAbsoluteElement(elementId)
Center element that is absolute positioned
More information
Parameters:
Name | Type | Description |
---|---|---|
elementId | string | element or id of element to center |
- Usage examples:https://codepen.io/AllForTheCode/pen/ZRGabV
scrollToElement(elementId, duration, offset)
Scroll to element on page
More information
Parameters:
Name | Type | Description |
---|---|---|
elementId | string | ID of element you wish to scroll to |
duration | float | Duration in seconds |
offset | number | How much to offset scroll by |
- Usage examples:https://codepen.io/AllForTheCode/pen/eKNeVq
addEvent(obj,type,fn,useCapture)
Shortcut for adding events with old browser compatibility
More information
Parameters:
Name | Type | Description |
---|---|---|
obj | object | The object you wish to attach the event listener to |
type | string | The event type (e.type) mousedown, mouseup, click etc |
fn | function | The function to call when the event is triggered |
useCapture | boolean | Whether the event should be executed in the capturing or in the bubbling phase |
- Usage examples:https://codepen.io/AllForTheCode/pen/VxExLg
onReady(fn)
A replacement for using body onload and no need for jQuery's $(document).ready
More information
Parameters:
Name | Type | Description |
---|---|---|
fn | function | inline function or pass it a function for when your page is loaded and ready to be used |
- ready Alias's:
- Usage examples:https://codepen.io/AllForTheCode/pen/GdYxVa
isChecked(elementId)
Checks to if checkbox is checked or not
More information
Parameters:
Name | Type | Description |
---|---|---|
elementId | string | element id of the form element to check |
- Usage examples:https://codepen.io/AllForTheCode/pen/KRbjpx
isNumberKey(evt)
Checks if evt supplied (use on form input events via onkeyup or onkeydown)
More information
Parameters:
Name | Type | Description |
---|---|---|
evt | event | html onkeyup(event) or onkeydown(event) |
- Usage examples:https://codepen.io/AllForTheCode/pen/vjvqLg
removeAllSelectOptions(elementId)
Removes all the options in a select
More information
Parameters:
Name | Type | Description |
---|---|---|
elementId | string | id of select element |
- Usage examples:https://codepen.io/AllForTheCode/pen/mLaZEm - https://codepen.io/AllForTheCode/pen/rvoEME
parseJSONToSelect(j, selectElementIdOrElement, label, value)
parses a json object of key value pairs to a form select element
More information
Parameters:
Name | Type | Description |
---|---|---|
j | string | the json data |
selectElementIdOrElement | elementOrIdString | the json data |
label | string | of key value pair this is the key |
value | string | of key value pair this is the value |
- Usage examples:https://codepen.io/AllForTheCode/pen/rvoEME
AFTC.Point(x,y)
2D Point
More information
Parameters:
Name | Type | Description |
---|---|---|
x | number | x coordinate |
y | number | y coordinate |
Methods:
Name | Description |
---|---|
position | |
clone | |
delta | |
distance | |
moveTo | |
moveAtAngle | |
applyVelocity | |
angleRadians | |
angleDeg | |
rotate |
- Usage examples:https://codepen.io/AllForTheCode/pen/qYLzzm
AFTC.Rectangle(x, y, w, h)
Rectangle class, allos you to set x, y, width and height or a rectangle
More information
Parameters:
Name | Type | Description |
---|---|---|
x | number | x coordinate |
y | number | y coordinate |
w | number | w width |
h | number | h height |
Methods:
Name | Description |
---|---|
offsetOuter | |
offsetInner | |
setX | |
setY | |
setW | |
setH |
Returns: AFTC.Rectangle
- Usage examples:https://codepen.io/AllForTheCode/pen/JvQRKg
AFTC.Velocity(vx,vy)
AFTC.Velocity class helper
More information
Parameters:
Name | Type | Description |
---|---|---|
vx | number | velocity vector x |
vy | number | velocity vector y |
Methods:
Name | Description |
---|---|
flip | flip |
flipX | flipX |
flipY | flipY |
multiply | multiply |
divide | divide |
- Usage examples:https://codepen.io/AllForTheCode/pen/erxRBo
getFunctionName(fn)
tries to get the function name of a suppled function
More information
Parameters:
Name | Type | Description |
---|---|---|
fn | function | the function wish to get the name of |
- Usage examples:https://codepen.io/AllForTheCode/pen/YLBKRy
isInString(find,source)
check for string in string
More information
Parameters:
Name | Type | Description |
---|---|---|
string | find | The string to look for |
string | source | The string to look in |
- Usage examples:https://codepen.io/AllForTheCode/pen/jxdONK
isEven(n)
check if input is even
More information
Parameters:
Name | Type | Description |
---|---|---|
n | number | variable / value you wish to test |
- Usage examples:https://codepen.io/AllForTheCode/pen/rvPNBR
isOdd(n)
check if input is odd
More information
Parameters:
Name | Type | Description |
---|---|---|
n | number | variable value you wish to test |
- Usage examples:https://codepen.io/AllForTheCode/pen/gzqOOW
isAlphaNumeric(input)
check if an input is an alpha numerical value ([a-z],[A-Z],[0-9] only)
More information
Parameters:
Name | Type | Description |
---|---|---|
string||number | input | variable / value you wish to check |
- Usage examples:https://codepen.io/AllForTheCode/pen/pVGooO
isElement(o)
checks if your variable is an element or not
More information
Parameters:
Name | Type | Description |
---|---|---|
o | * | variable you wish to check |
- Usage examples:https://codepen.io/AllForTheCode/pen/RyvwPK
isElement2(element)
checks to see if your vairable is an element or not
More information
Parameters:
Name | Type | Description |
---|---|---|
element | * | the variable you wish to check |
- Usage examples:https://codepen.io/AllForTheCode/pen/RyvwPK
isDOM(obj)
checks to see if your variable is a DOM object
More information
Parameters:
Name | Type | Description |
---|---|---|
obj | object | variable to check |
- Usage examples:https://codepen.io/AllForTheCode/pen/JvxjYo
isBoolean(input)
checks if a variable is a boolean
More information
Parameters:
Name | Type | Description |
---|---|---|
input | * | variable to check |
- isBool Alias's:
- Usage examples:https://codepen.io/AllForTheCode/pen/JvxjGo
isNumeric(n)
check if variable is numeric
More information
Parameters:
Name | Type | Description |
---|---|---|
n | * | variable to check |
- isNumber Alias's:
- Usage examples:https://codepen.io/AllForTheCode/pen/bMzGEL
isArray(input)
check if variable is an array
More information
Parameters:
Name | Type | Description |
---|---|---|
input | * | variable to check |
- Usage examples:https://codepen.io/AllForTheCode/pen/rvPNeg
cycle(pos, max)
cycles from 0 to max based on pos, will cycle back to 0 if over max
More information
Parameters:
Name | Type | Description |
---|---|---|
pos | number | position of max |
max | number | max number to cycle to |
- Usage examples:https://codepen.io/AllForTheCode/pen/BxMZBZ
getRandomInt(min,max)
returns a random number / int betwen your specified min and max values
More information
Parameters:
Name | Type | Description |
---|---|---|
min | number | the minimum your random number is allowed to go |
max | number | the maximum your random number is allowed to go |
- getRandom Alias's:
- Usage examples:https://codepen.io/AllForTheCode/pen/PeVqLp
getRandomThatsNot(min,max,not)
returns a random int betwen your specified min and max values but never the not value
More information
Parameters:
Name | Type | Description |
---|---|---|
min | number | the minimum your random number is allowed to go |
max | number | the maximum your random number is allowed to go |
- getRandom Alias's:
- Usage examples:https://codepen.io/AllForTheCode/pen/yEBZNq
getRandomFloat(min,max)
returns a random floating point number betwen your specified min and max values
More information
Parameters:
Name | Type | Description |
---|---|---|
min | number | min value |
max | number | max value |
- Usage examples:https://codepen.io/AllForTheCode/pen/gzqaYm
randomString(length)
get a random string of a specified length
More information
Parameters:
Name | Type | Description |
---|---|---|
length | number | the length of the string you wish to generate |
- getRandomString Alias's:
- Usage examples:https://codepen.io/AllForTheCode/pen/QrYjwr
getUID(length)
Generates a random id
More information
Parameters:
Name | Type | Description |
---|---|---|
length | number | length of the unique id to generate |
- getUID - generateUID Alias's:
- Usage examples:https://codepen.io/AllForTheCode/pen/NMoGGY
getArrayOfRandomNumbers(arraySize,min,max)
generate an array of random number between your max and min values
More information
Parameters:
Name | Type | Description |
---|---|---|
arraySize | number | the number of random numbers to generate also the array size that will be returned |
min | number | the minimum your random number is allowed to be |
max | number | the maximum your random number is allowed to be |
- Usage examples:https://codepen.io/AllForTheCode/pen/NMoGdz
getArrayOfRandomStrings(arraySize,strLength)
generate an array of random string of a specified length
More information
Parameters:
Name | Type | Description |
---|---|---|
arraySize | number | the number of random strings to generate also the array size that will be returned |
strLength | number | the length of the strings to be generated |
- Usage examples:https://codepen.io/AllForTheCode/pen/BVNJvB
guid()
generates a guid
More information
- getGUID Alias's:
- Usage examples:https://codepen.io/AllForTheCode/pen/MGLayZ
getWeightedRandom(odds, iterations)
Get a weighted random based on odds and iterations
More information
Parameters:
Name | Type | Description |
---|---|---|
odds | array | array of odds |
iterations | number | number of iterations to run on each number test |
- Usage examples:https://codepen.io/AllForTheCode/pen/RyvWjZ
limitLengthInWords(str, maxWords)
Limit a string in length of words
More information
Parameters:
Name | Type | Description |
---|---|---|
str | string | the original string to limit |
maxWords | number | the number of words you wish to limit to |
Returns: {output
- Usage examples:https://codepen.io/AllForTheCode/pen/xjMdye
cleanJSONString(s)
Attempts to clean a json string
More information
Parameters:
Name | Type | Description |
---|---|---|
s | string | input string |
- Usage examples:https://codepen.io/AllForTheCode/pen/BxMRER
escapeHTML(input)
Attempts to escape a html string
More information
Parameters:
Name | Type | Description |
---|---|---|
input | string | the string you wish to escape |
- Usage examples:https://codepen.io/AllForTheCode/pen/PerGRJ
cutStringTo(input, len)
sets the length of a string from left to right
More information
Parameters:
Name | Type | Description |
---|---|---|
input | string | what string do you want to set the length of? |
length | number | the length you want the string to be |
- cutStringTo - cutString - cutStringLength - setStrLen - trimStringLength Alias's:
- Usage examples:https://codepen.io/AllForTheCode/pen/VxJKEm
trimStringBy(input, trimBy)
Trims the length of a string by a value
More information
Parameters:
Name | Type | Description |
---|---|---|
input | string | The string you want to trim |
trimBy | number | How many characters do you want to trim off the end |
- tTrim Alias's:
- Usage examples:https://codepen.io/AllForTheCode/pen/BxgLvr
leftTrim(str, by)
Trims the left of a string by a specified amount
More information
Parameters:
Name | Type | Description |
---|---|---|
string | str | The string you want to trim |
number | by | How many characters do you want to trim off the end |
- lTrim Alias's:
- Usage examples:https://codepen.io/AllForTheCode/pen/wXayva
getFileExtension(input)
Attempts to get the file extension from a file path string
More information
Parameters:
Name | Type | Description |
---|---|---|
string | str | the file path string |
- Usage examples:https://codepen.io/AllForTheCode/pen/OZeRqv
getFileExtension2(input)
Attempts to get the file extension from a file path string
More information
Parameters:
Name | Type | Description |
---|---|---|
string | str | the file path string |
- Usage examples:https://codepen.io/AllForTheCode/pen/OZeRqv
getLastPartOfUrl(url)
Gets the last part of a URL
More information
Parameters:
Name | Type | Description |
---|---|---|
string | url | url to process |
- Usage examples:https://codepen.io/AllForTheCode/pen/gzNwNv
removeFileFromPath(path)
Attempts to remove the file from a file path string
More information
Parameters:
Name | Type | Description |
---|---|---|
string | path | path |
- Usage examples:https://codepen.io/AllForTheCode/pen/QrXGWY
getAnchor(url)
Get anchor from url
More information
Parameters:
Name | Type | Description |
---|---|---|
string | url | The url to get the anchor from |
- Usage examples:https://codepen.io/AllForTheCode/pen/xxxxxxx
String.prototype.startsWith(str)
ES6 supports the startsWith(), this is for pre ES6 support
More information
Parameters:
Name | Type | Description |
---|---|---|
string | str | string to check |
- Usage examples:https://codepen.io/AllForTheCode/pen/xxxxxxx
String.prototype.endsWith(str)
ES6 supports endsWith(), this is for pre ES6 support
More information
Parameters:
Name | Type | Description |
---|---|---|
string | str | string to check |
- Usage examples:https://codepen.io/AllForTheCode/pen/xxxxxxx
getStringBetween(input,start,end)
Gets a string between two other strings
More information
Parameters:
Name | Type | Description |
---|---|---|
string | input | input string to check |
string | start | start string marker |
string | end | end string marker |
- Usage examples:https://codepen.io/AllForTheCode/pen/xxxxxxx
getAllStringsBetween(str,start,end)
Gets all strings between two other strings (multi match)
More information
Parameters:
Name | Type | Description |
---|---|---|
string | str | input string to check |
string | start | start string marker |
string | end | end string marker |
- Usage examples:https://codepen.io/AllForTheCode/pen/xxxxxxx
validateEmail(email)
Validats an email address
More information
Parameters:
Name | Type | Description |
---|---|---|
string | email address |
- Usage examples:https://codepen.io/AllForTheCode/pen/xjogjy
AFTC.Color({params})
Color allows you to create, convert, lighten or darken colours and more.
var color1 = new AFTC.Color(); // creates a random color
var color2 = new AFTC.Color({r
var color3 = new AFTC.Color({r
log( color3.getHex() ); // Outputs the hex code of color 3
More information
Parameters:
Name | Type | Description |
---|---|---|
object | params | parameters object |
Methods:
Name | Description |
---|---|
lighten(percent,spectrum) | lighten the color by precent and optional spectrum {r |
darken(percent,spectrum) | darken the color by precent and optional spectrum {r |
randomizeColor | randomises the colour |
getRGBString | returns the RGB value of the color |
getRGBAString | returns the RGBA value of the color |
getHexString | returns the HEX value of the color |
getHex | returns the HEX value of the color |
hex | returns the HEX value of the color |
getRGB | returns the RGB value of the color |
rgb | returns the RGB value of the color |
getRGBA | returns the RGBA value of the color |
rgba | returns the RGBA value of the color |
setRGB | returns the RGB value of the color |
setHex | returns the HEX value of the color |
- Usage examples:https://codepen.io/AllForTheCode/pen/mLZRge
getRandomColor()
returns a random RGB object o.r, o.g, o.g
More information
AFTC.Animate(elementId, onComplete)
Quick and easy css animation for nearly every css element style
var anim1 = new AFTC.Animate("box1", onCompleteFunction);
anim1.wait(2); // wait in 2 seconds
anim1.set("backgroundColor","RGBA(255,255,255,0.5)"); // sets background color to white 50% opacity
anim1.anim("fontColor","RGBA(255,0,0,1)",1.5); // animates the font color to red over 1.5 seconds
anim1.set(["html","paddingLeft",left"],["hello","10px","100px"],[1,2,3]); // sets innerHTML, padding-left and left position over 1, 2 and 3 seconds
More information
- Usage examples:see usage example in test/animation.htm - https://codepen.io/AllForTheCode/pen/MXYGob - https://codepen.io/AllForTheCode/pen/MXYPqq - https://codepen.io/AllForTheCode/pen/xzbymv
AFTC.Audio({options})
An audio player with preloading capabilities, looping abilities and loop offset capabilities
More information
Parameters:
Name | Type | Description |
---|---|---|
s | src | String or Array of urls/paths to sound files |
s | cache | To cache or not to cache |
s | volume | 0 to 1 |
s | repeat | -1 forever, 0 play once only, or the number of times to repeat |
s | preload | true or false |
s | offsetLoopBy | the sample offset from the end that you wish to loop by can help remove loop gaps |
s | onUpdate | the function you wish to run when your sound is playing provides and info object |
s | onReady | the function you wish to run when your sound is ready and can play |
s | onComplete | the function you wish to run when your sound has finished playing |
s | hideWarnings | hides notices in console for compatibility issues when not using mp3 etc |
Methods:
Name | Description |
---|---|
play | Play audio |
stop | Stop audio |
pause | Pause audio |
resume | Resume ausio |
- Usage examples:https://codepen.io/AllForTheCode/pen/NzWrvm
AFTC.Color({params})
Color allows you to create, convert, lighten or darken colours and more.
var color1 = new AFTC.Color(); // creates a random color
var color2 = new AFTC.Color({r
var color3 = new AFTC.Color({r
log( color3.getHex() ); // Outputs the hex code of color 3
More information
Parameters:
Name | Type | Description |
---|---|---|
object | params | parameters object |
Methods:
Name | Description |
---|---|
lighten(percent,spectrum) | lighten the color by precent and optional spectrum {r |
darken(percent,spectrum) | darken the color by precent and optional spectrum {r |
randomizeColor | randomises the colour |
getRGBString | returns the RGB value of the color |
getRGBAString | returns the RGBA value of the color |
getHexString | returns the HEX value of the color |
getHex | returns the HEX value of the color |
hex | returns the HEX value of the color |
getRGB | returns the RGB value of the color |
rgb | returns the RGB value of the color |
getRGBA | returns the RGBA value of the color |
rgba | returns the RGBA value of the color |
setRGB | returns the RGB value of the color |
setHex | returns the HEX value of the color |
- Usage examples:https://codepen.io/AllForTheCode/pen/mLZRge
getRandomColor()
returns a random RGB object o.r, o.g, o.g
More information
AFTC.XHR({options})
Quick and easy xhr/ajax
More information
Parameters:
Name | Type | Description |
---|---|---|
s | seelink | please review link |
- Usage examples:https://codepen.io/AllForTheCode/pen/dKodKx
Found this useful? Please Donate...
Any and all donations to help keep active development and the lights on are more than welcome.