Webility
The Front-End developers Utility Belt, lightweight, smooth and easy to use.
Examples
Check the project page to see some examples: http://khaledelansari.com/webility/
Installation
Webility got zero dependences, just inject it your project and your hooked!.
-
The old school way:
-
The NPM way:
npm install webility.js
Then include it in your project like the following:
var webility = ;// ES6 way;
APIs Reference
Here's the list of functionalities provided by Webility organized by Object Type:
-
pageready(callback): will check if everything in the document is ready then will the callback function will start.
-
select(cssSelector): a simple & fast DOM selector with some functions chained to it.
-
ID(): Chained to the select function, works in three scenarios:
-
ID(): empty parenthesis will return the current ID of the first selected element.
-
ID("remove"): will remove any ID assigned to the selected element(s).
-
ID("someID"): will add the string as an ID to the selected element(s).
-
-
addclass("classname"): will add the string as a class to the selected element(s).
-
removeclass("classname"): will remove the string from the selected element(s) classes.
-
hasclass("classname"): will check if the selected element(s) has the string in there classes list, it will return
true
if the class exist andfalse
if not.
-
-
browser(): will return the name of the users browser.
-
os(): will return the name of the users Operating System.
-
device(): will return the type of the users device, either Desktop, Tablet or Mobile.
-
browser(): will return the name of the users browser.
-
ismobile(): will return
true
if the user is using a mobile andfalse
if not. -
uuid(): will generate a UUID and if you passed a string it will check if the string is valid UUID or not.
-
get(obj, key, defaultValue): made to check Objects (dictionaries or associative arrays) it takes 3 arguments (inspired by Python):
-
obj (
Object
): the object you want the function to check. -
key (
String
): the key you want to check, if existget()
will return it's value if not it will assign and default value to it. -
defaultValue (
Any
): the value you want to assign to the key in case it doesn't exist, if you don't provide it the defaultValue will benull
.
-
-
isEmpty(): it take one argument either
Array
orObject
and it will returntrue
if empty andfalse
if not. -
sort(): if it's an
Array
,Object
or an Array of Objects just name it this function will sort it, it takes two arguments:-
element: as mentioned above
Array
,Object
or Array of Objects. -
type (
String
): type of the sort, either"ascend"
or"descend"
(default to"ascend"
).
-
-
objToArray(Object): this will convert the object into and array of objects.
-
today(): it will return the date of the currenct day in ISO format (ex: 2016-08-17 10:34:54).
-
toUTC(): it will return the date in UTC in ISO format (ex: 2016-08-17 10:34:54).
-
toLocalTime(): it will return the date Local Time in ISO format (ex: 2016-08-17 10:34:54).
-
getDays(): this function takes two strings of two dates and retruns an
Array
of the days between them. -
dayAfter(): this function takes two arguments first is a
String
of a date and the second one is an IntegerNumber
of the wanted day after that period. -
dateFormat(): coming soon.
-
title(string): will capitalize the first letter of each word in the string (inspired by Python)
-
capitalize(string): will capitalize the first letter of the string only.
-
quote(string): will add a double quotation to the string
// Fast examplewebility;
License
This project is under the MIT license.