Skip to content

A lightweight JavaScript library to reduce front-end development time.

License

Notifications You must be signed in to change notification settings

rao123dk/Rao.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rao.js

contributions welcome

HitCount

CDN

CDN for production:-
<script src="https://rawcdn.githack.com/rao123dk/Rao.js/49a0ee053b07522d1ca875c7748e003ac724bc8f/rao.js"> </script>

CDN for development :-
<script src="https://raw.githack.com/rao123dk/Rao.js/master/rao.js"> </script>

Table of Contents

Browser

Detect Client Browser name and version

Code:-

r.browser();

Example:-

console.log(r.browser());
Output :- Chrome 62(Broweser Name, Version)

Detect Device type

Code:-

r.deviceType();

Example:-

console.log(r.deviceType());
Output :- Desktop
Outputs :- Desktop/Mobile/iPad/iPod

JavaScript new feature browser compatibility checker(i.e. ECMAScript 2015/2016/2017)

Code:-

r.ES6()
r.ES7()
r.ES8()

Example:-

console.log(r.ES6());
console.log(r.ES7());
console.log(r.ES8());
Output :- true/false

Reload the current page(Normal)

Code:-

r.reload();

Example:- ♥️ page from the cache ♥️

r.reload();
Output :- Reloads the current page from the cache.

Reload the current page(Hard)

Code:-

r.hardReload();

Example:- ♥️ page from the server ♥️

r.hardReload();
Output :- Reloads the current page from the server.

Array

Check duplicate items

Code:-

r.duplicate(Array_name);

Example:-

const array = ["a", "f", "e", "w", "r", "e", "o", "j", "j","w"];
console.log(r.duplicate(array));
Output :- ["e", "w", "j"]

Remove duplicate items from array

Code:-

r.duplicate(arrayName);

Example:-

var array = ["a", "f", "e", "w", "r", "e", "o", "j", "j","w"];
console.log(r.removeDuplicate(array));
Output :- ["a", "f", "e", "w", "r", "o", "j"]

Check Array or not

Code:-

r.isArray(value);

Example:-

var value = [1,2,3];
console.log(r.isArray(value));
Output :- true

Clean Array i.e. remove undefined,null,'',true,false and NaN from array

Code:-

r.cleanArray(value);

Example:-

var value = [1, false, "", undefined, 2, null, NaN,5];
console.log(r.cleanArray(value));
Output :- [1,2,5]

Remove particular item from Array

Code:-

r.removeFromArray(array, item); // Remove first found item from array
r.removeFromArrayAll(array, item); // Remove all target item in array

Example:-

var numarray = [3,55,66,55,234,61,99,100,55,055];
var strarray = ['dheeraj',"rao", "kumar", "rao","Rao"];
console.log(r.removeFromArray(numarray,3));
Output :- [55,66,55,234,61,99,100,55,055];

console.log(r.removeFromArray(strarray,"rao"));
Output :- ['dheeraj',"kumar", "rao","Rao"];
var numarray = [3,55,66,55,234,61,99,100,55,055];
var strarray = ['dheeraj',"rao", "kumar", "rao","Rao"];
console.log(r.removeFromArrayAll(numarray,55));
Output :- [3, 66, 234, 61, 99, 100, 45]

console.log(r.removeFromArrayAll(strarray,"rao"));
Output :- ["dheeraj", "kumar", "Rao"]

Insert Item at particular position in Array

Code:-

r.insertIntoArray(Array_name, indexAt, Item);

Example:-

var numarray = [3,55,66,55,234,61,99,100,55,055];
r.insertIntoArray(numarray, 4, "Rao.js");
console.log(numarray);
Output :- [3,55,66,55,"Rao.js",234,61,99,100,55,055];

Make Deep copy of array

Code:-

r.deepCopyArray(arrayName);

Example:-

var numarray = [3,55,66,55,234,61,99,100,55,055];
var newArray = r.deepCopyArray(numarray);
numarray.push("Hello");
console.log(newArray);
Output :- [3,55,66,55,234,61,99,100,55,055];

Object

Check Object or not

Code:-

r.isObject(value);

Example:-

var value = {};
console.log(r.isObject(value));
Output :- true
var value = "hello";
console.log(r.isObject(value));
Output :- false

Merge Objects

Code:-

r.mergeObject(object1, object2);

Example:-

var object1 = {  "a" : 10, "c" : 22, d : { "k" : "hello"} };
var object2 = {  "q" : 10 };
console.log(r.mergeObject(object1, object2););
Output :- {a: 10, c: 22, d: {k: "hello"}, q: 10}

JSON

Check JSON data is valid or not

Code:-

r.isJSON(value);

Example:-

console.log(r.isJSON('{"name" : "dheerraj", "Age" : 22}'););
Output:- true
console.log(r.isJSON('{"name" : "dheerraj", Age : 22}'););
Output:- false

Webstorage

Time

Digital watch

Code:-

r.showWatch('#showwatchid',"h","m","s",hour12=true/false);

Example:-

console.log(r.showWatch('#showwatchid',"h","m","s",hour12=true));
Output:- 1:8:58 PM
console.log(r.showWatch('#showwatchid',"h","m","s",hour12=false));
Output:- 13:8:58
console.log(r.showWatch('#showwatchid',"h","m",hour12=true));
Output:- 1:08 PM

Countdown Timer

Code:-

r.countDown(01,01,2018)

Example:-

console.log(r.countDown(01,01,2018)); // Format will be DD/MM/YYYY
Output :- {total: 896620000, days: 10, hours: 9, minutes: 3, seconds: 40}

Difference between two Dates

Code:-

r.dayDiff("Start_date","end_date"));   // Format will be DD/MM/YYYY
r.dayDiffSatSun("Start_date","end_date"));
r.dayDiffHoliday("Start_date","end_date",array_of_list));

Example:-

  1. Get difference between two date {General}
r.dayDiff("Start_date","end_date")); // Format will be DD/MM/YYYY
console.log(r.dayDiff("21/12/2017","30/12/2017"));
Output :- 9
  1. Get difference between two date{ escape Saturday and Sunday i.e. count only working days}
 r.dayDiffSatSun("Start_date","end_date")); // Format will be DD/MM/YYYY
 console.log(r.dayDiffSatSun("21/12/2017","30/12/2017"));
 Output :- 7
  1. Get difference between two date{ escape Saturday, Sunday and holiday festival also}
 	console.log("Coming soon.....");

String

Random string generator(i.e. also password generator)

Code:-

r.randomString(length_of_string)

Example:-

console.log(r.randomString(8));
Output :- g485edgn

Convert Strint into uppercase in diiferent condition

Code:-

r.upper(str,"1");
r.upper(str,"1++");
r.upper(str,">1");

Example:-

var str = "thanks for using Rao.js";
(A) console.log(r.upper(str,"1"));
    Output:- Thanks for using Rao.js
(B) console.log(r.upper(str,"1++"));
    Output:- Thanks For Using Rao.js
(C) console.log(r.upper(str,">1"));
    Output:- Thanks For Using Rao.js

Replace string

Preserve the case of the original word when you are replacing it. For example if you mean to replace the word "Book" with the word "pen", it should be replaced as "Pen". Code:-

r.rao_replace(str, to, with)

Example:-

let org_str = "This is my Book.",
console.log(r.rao_replace(org_str, "Book", "pen"));
Output :- This is my Pen.

Check String or not

Code:-

r.isString(value);

Example:-

var value = "Thanks for using Rao.js";
console.log(r.isString(value));
Output :- true

DOM

Get element by id

Code:-

rao("#id");

Example:-

<input type ="text" id="f_name" value="Dheeraj">
var exp = rao("#f_name");
console.log(exp.val());
Output :- Dheeraj

Get element by Class

Code:-

rao(".class");

Example:-

<input type ="text" class="name" value="Dheeraj">
<input type ="text" class="name" value="rao">
var exp = rao(".name");
console.log(exp[0].val());
Output :- Dheeraj

Get element by attributes

Code:-

rao("input[type='text']");

Example:-

<input type ="text" class="name" value="Rao">
var exp = rao("input[type='text']");
console.log(exp[0].val());
Output :- Rao

Get/Set html

Code:-

var ht = rao('#htm');
ht.html();
ht.html('<p>Thanks for using Rao.js</p>');

Example:-

<div id="htm"> </div>
var ht = rao('#htm');
ht.html("<p>Thanks for using Rao.js</p>"); //Set
Output :- <div id="htm"> <p>Thanks for using Rao.js</p> </div>
ht.html(); //Get
Output :- <p>Thanks for using Rao.js</p>

Get/Set text

Code:-

var tx = rao('#txt');
tx.text();
tx.text('Thanks for using Rao.js');

Example:-

<p id="txt"> </p>
var tx = rao('#htm');
tx.text("Thanks for using Rao.js"); //Set
Output :- <p id="htm">Thanks for using Rao.js</p>
tx.text(); //Get
Output :- Thanks for using Rao.js

Append/Prepend elements

Code:-

rao('#id').append("<div>Hello append</div>");
rao('#id').prepend("<div>Hello prepend</div>");

Example:-

<div class="parent">
  <div id="id"> Hello</div>
</div>
rao('#id').append("<div>Hello append</div>");
Output :-
<div class="parent">
  <div id="id"> Hello</div>
  <div>Hello append</div>
</div>
rao('#id').prepend("<div>Hello prepend</div>");
Output :-
<div class="parent">
  <div>Hello prepend</div>
  <div id="id"> Hello</div>
</div>

Find all child elements of parent element

Code:-

rao('#id').mychild();

Example:-

<div id="todolist">
  <p>Item 1</p>
  <p>Item 2</p>
  <p>Item 3</p>
  <p>Item 3</p>
</div>
rao('#todolist').mychild();
Output :-
  <p>Item 1</p>
  <p>Item 2</p>
  <p>Item 3</p>
  <p>Item 3</p>

Events add/remove

Code:-

rao('#id').on('click', function(){
//code here....
});
rao('#id').off('click');

Example:-

rao('#id').on('click', function(){
 alert("Thanks For using Rao.js");
});
rao('#id').off('click');

Get/set attribute dynamically from/in element

Set own attribute

rao('#sr').attri("attribue","value");
Ex:-
rao('#sr').attri("custom_id","12CU100");
output :-
<span id="sr" custom_id ="12CU100"> </span>

Get attribue

rao('#sr').attri("nameofattribue")
Ex:-
console.log(rao('#sr').attri("class"));
Output:-
It will return classname of element which is is 'sr'

Hide, show and toggle(hide/show) element

Hide

rao('#id').out();

show

rao('#id').in();

toggle

rao('#id').inOut();

Get custom attribute(data-myperonalId) value

console.log(rao("#id").Data("customAttribute"));
ex:-
<span id="myid" data-myperonalId="177466"></span>
console.log(rao("#myid").Data("myperonalId"));

Print current year

This method is helpful for those who manually update copyright year on webiste

rao("#copyrightYear").currentYear();

Add / Remove class to/from element

rao("#id").addClass("newclass");
rao("#id").removeClass("alreadyThere");

Get Random Number between two given numbers

    // r.random(first_digit, last_digit)
   console.log(r.random(10, 111));
   Output :- 29 or different

Thanks!

	console.log("Thanks!");

📧📧 @ -> [email protected]

About

A lightweight JavaScript library to reduce front-end development time.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published