1.0.6 • Published 5 years ago
tonic-js v1.0.6
Tonic JS
Tonic JS is a general purpose javascript library aimed at improving the speed at which javascript is written. It has a ton of methods that you can use for : -
- DOM manipulation
- String accessibility
- Array methods
- Minimizing syntax
- Animations
Usage
First run the command : -
npm i tonic-js
Then you will be able to use the module.
The syntax will look as follows :-
const tonic = require('tonic')
tonic.<method>(<parameter>)Methods
Tonic offers a variety of methods :-
String methods
kebabCase
parameters: string to be convertedsyntax: kebabCase('hello world')output: hello-world
titleCase
parameters: string to be convertedsyntax: titleCase('hello world')output: Hello World
snakeCase
parameters: string to be convertedsyntax: snakeCase('hello world')output: hello_world
longestWord
parameters: stringsyntax: longestWord("Hello Mountains")output: Mountains
Array methods
contains
aim: Know if an array contains a valueparameters: array, valuesyntax: contains(1,2,3, 3)output:true
strings
aim: Get all strings of an arrayparameters: arraysyntax: strings("Hey", 6, 3)output: Hey
unique
aim: Get all unique values of arrayparameters: arraysyntax: unique("Hey", "Hey", 3, 5, 5, 7)output: Hey,3,5,7
numbers
aim: Get all numbers of an arrayparameters: arraysyntax: numbers("Hey", 6, 3)output: 6,3
DOM mainpulation
tn
aim: Select items from DOMparameters: querysyntax: tn("h1")output: \Text\
hasClass
aim: Check if an item has a classparameters: element, class, callback (optional)syntax: hasClass(tn("h1") (this selects the "h1" element), ".hello") You can also put an additional callbackoutput: false
removeClass
aim: Remove a classparameters: element, classsyntax: removeClass(tn("h1") (this selects the "h1" element), "hello") You can also put an additional callbackoutput: "hello" class is removed from \ element
addClass
aim: Add a classparameters: element, classsyntax: addClass(tn("h1") (this selects the "h1" element), "hello")output: "hello" class is added to the \ element
setCss
aim: Change CSS propertiesparameters: element, css property, changed valuesyntax: setCss(tn("h1") (This selects the "h1" element), "background-color", "red")output: Background becomes red for \ element
setText
aim: Change text of an elementparameters: element, textsyntax: setText(tn("h1") (This selects the "h1" element), "Hello World")output: Text becomes "Hello World" for \ element
click
aim: Add a click event listenerparameters: element, callbacksyntax: click(tn("h1") (This selects the "h1" element),function() {console.log("Hello World")})output: "Hello World" gets logged when \ element is clicked
keypress
aim: Add a keypress event listenerparameters: element, callbacksyntax: keypress(window ,function() {console.log("Hello World")})output: "Hello World" gets logged when a key is pressed (since we added the event listener to the window)
Animation
blink
aim: add a fade-in and fade-out animationparameters: element, timeoutsyntax: blink(tn("h1") (This selects the "h1" element), 300)output: Blink animatino set for \ on load after 300 milliseconds (the timeout)
fadeIn
aim: add a fade-in animationparameters: element, timeoutsyntax: fadeIn(tn("h1") (This selects the "h1" element), 300)output: \ element fades in on load after 300 milliseconds (the timeout)
fadeOut
aim: add a fade-out animationparameters: element, timeoutsyntax: fadeOut(tn("h1") (This selects the "h1" element), 300)output: \ element fades out on load after 300 milliseconds (the timeout)
Minimizing Syntax
repeat
aim: Run aforloop till a certain countparameters: times to repeat, callbacksyntax: repeat(9, function(index) {console.log(index)})explaination: When you run this function, it loops a variable until it reaches the max limit. It also passes the variable as a parameter so that it can be used for array manipulationoutput: \ element fades out on load after 300 milliseconds (the timeout)