Photo credit: jjjj56cp on Visualhunt.com / CC BY-NC-SA
Savana is a JavaScript framework that assists in developing web applications using DOM manipulation methods helpers and simple concepts of client-side development.
This library relies on Fetch API. And this API is supported in the following browsers.
39+ ✔ | 42+ ✔ | 29+ ✔ | 10.1+ ✔ | Nope ✘ |
Insert in your end body.
<body>
...
</body>
<script src="/dist/savana.min.js"></script>
Or import the folder ./savanajs to your project
import $savanajs from "./savanajs"
Just below we see the documentation and examples of use of framework
Methods of manager of arrays.
Arguments
Argument | Type | Options |
---|---|---|
array * |
string | |
value * |
string or number | |
position |
string | last, first |
Add value in last position of array
$savana.array.add([1,2,3], 4); // [1,2,3,4]
$savana.array.add([1,2,3], 4, "last"); // [1,2,3,4]
Add value in first position of array
$savana.array.add([1,2,3], 4, "first"); // [4,1,2,3]
Add value in position of array
$savana.array.add([1,2,3], 4, 1); // [1,4,2,3]
Arguments
Argument | Type | Options |
---|---|---|
array * |
string | |
value * |
string or number |
Remove the value of array
$savana.array.remove(['a','b','c'], 'b'); // ['a','c']
Arguments
Argument | Type | Options |
---|---|---|
array * |
string | |
index * |
*number |
Remove the index position of array
$savana.array.removeAt(['a','b','c'], 1); // ['a','c']
Arguments
Argument | Type | Options |
---|---|---|
array * |
string | |
value * |
string or number |
Get index position of array
$savana.array.getIndex(['a','b','c'], 'b'); // 1
Arguments
Argument | Type | Options |
---|---|---|
array * |
string | |
value * |
string or number or NULL | |
position |
string | last, first |
Get the value of array
$savana.array.search(['a','b','c'], 'b'); // b
Arguments
Argument | Type | Options |
---|---|---|
array * |
string | |
index |
number |
Get the value by index of array
$savana.array.searchAt(['a','b','c'], 1); // b
Arguments
Argument | Type | Options |
---|---|---|
arr1 * |
array | |
arr2 |
array |
Intersection of two given sets A and B is a set which consists of all the elements which are common to both A and B.
$savana.array.intersection(['a','b','c'], ['b']); // ['b']
$savana.array.intersection([1,2,3,4,5], [3,4]); // [3,4]
Methods of manager of cookies.
Arguments
Argument | Type | Options |
---|---|---|
name * |
string |
Get the value of array
$savana.cookie.get('fullname'); // John Carter
Arguments
Argument | Type | Options |
---|---|---|
name * |
string |
Verify if cookie exists
$savana.cookie.exists('fullname'); // true or false
Arguments
Argument | Type | Options |
---|---|---|
name * |
string | |
path |
string | |
domain |
string |
Remove cookie
$savana.cookie.remove("exemple"); // true or false
$savana.cookie.remove("exemple", "/home", "subdomain.site.com"); // true or false
Remove all cookies
$savana.cookie.removeAll(); // true or false
Arguments
Argument | Type | Options |
---|---|---|
name * |
string | |
value * |
string or number | |
time * |
number | In hours |
path |
string | |
domain |
string |
Save cookie
$savana.cookie.set("exemple", "hello", 2); // true
$savana.cookie.set("exemple2", "hello", 2, "/home", "subdomain.site.com"); // true
Methods of manager of date.
Get the timestamp
$savana.date.timestamp(); //123456879
Get the defference between dates
$savana.date.daysDifferenceBetweenDates(new Date(2016, 10, 20), new Date(2016, 10, 30)); // 10
Methods of manager of get.
Arguments
Argument | Type | Options |
---|---|---|
value * |
string |
Get number of strings
$savana.get.getNumberOfString('hello10hello') // 10
Arguments
Argument | Type | Options |
---|---|---|
value * |
string, number or Object |
Get the quantity of letters
$savana.get.count('hello') // 5
Get the quantity items of array
$savana.get.count([]) // 0
Get the quantity items of object
$savana.get.count({}) // 0
Methods of manager of validations.
Arguments
Argument | Type | Options |
---|---|---|
email * |
string |
Validation of email
$savana.is.email('[email protected]'); // true
Arguments
Argument | Type | Options |
---|---|---|
number * |
number |
Validation of number
$savana.is.number(10); // true
Arguments
Argument | Type | Options |
---|---|---|
url * |
string |
Validation of URL
$savana.is.url('https://github.com'); // true
Arguments
Argument | Type | Options |
---|---|---|
value * |
function |
Validation of function
$savana.is.function(function(){}); // true
Arguments
Argument | Type | Options |
---|---|---|
value * |
object |
Validation of object
$savana.is.object({}); // true
Arguments
Argument | Type | Options |
---|---|---|
value * |
string or number |
Validation of CPF
$savana.is.CPF('12345678909'); // true
Arguments
Argument | Type | Options |
---|---|---|
value * |
string |
Validation of String
$savana.is.CPF('hello'); // true
Validation of Browser IE
$savana.is.IE(); // true
Arguments
Argument | Type | Options |
---|---|---|
value * |
null |
Validation of String
$savana.is.NULL(1); // false
$savana.is.NULL(null); // true
Arguments
Argument | Type | Options |
---|---|---|
value * |
undefined |
Validation of Undefined
$savana.is.undefined(1); // false
$savana.is.undefined(undefined); // true
Arguments
Argument | Type | Options |
---|---|---|
value * |
string |
Validation of NAN
$savana.is.NAN(1); // false
$savana.is.NAN('1'); // true
Methods of manager of validations.
Arguments
Argument | Type | Options |
---|---|---|
value * |
number | |
dec_point * |
string | , |
thousands_sep * |
string | . |
Format money
$savana.money.format('10',',','.'); // 10,00
Arguments
Argument | Type | Options |
---|---|---|
value * |
string |
Convert price value to float
$savana.money.priceToFloat("R$ 100,00"); // 100.00
Arguments
Argument | Type | Options |
---|---|---|
value * |
string or number | |
discount * |
number |
Calculate Billet Value
$savana.money.bill(2000, 10); // {total: "1.800,00", descount: "200,00"};
$savana.money.bill("R$ 2.000,00", 10); // {total: "1.800,00", descount: "200,00"};
Arguments
Argument | Type | Options |
---|---|---|
value * |
string or number | |
quantity_installment * |
number | |
min_installment * |
number |
Calculate of installment
$savana.money.installment("R$ 380.50", 10, 50);
//{parc: "7x", parc_number: 7, price: "54,36", price_number: 54.36, juros: null})
$savana.money.installment(380.50, 10, 50);
//{parc: "7x", parc_number: 7, price: "54,36", price_number: 54.36, juros: null})
Arguments
Argument | Type | Options |
---|---|---|
value * |
string or number | |
quantity_installment * |
number | |
min_installment * |
number | |
interest * |
number |
Calculate of financing
$savana.money.financing("R$ 500,00", 10, 100, 2);
// {parc: "5x", parc_number: 5, price: "106,08", price_number: 106.08, juros: "2% a.m"});
$savana.money.money.financing(500.00, 10, 100, 2));
//{parc: "5x", parc_number: 5, price: "106,08", price_number: 106.08, juros: "2% a.m"});
Arguments
Argument | Type | Options |
---|---|---|
oldValue * |
string or number | |
newValue * |
string or number |
Calculate the value percental Difference
$savana.money.percentalDifference("R$ 100,00","R$ 50,00");
// {discount: 50, discount_format: "50%"}
$savana.money.percentalDifference(100.00, 50.00);
// {discount: 50, discount_format: "50%"}
Arguments
Argument | Type | Options |
---|---|---|
oldValue * |
string or number | |
newValue * |
string or number |
Calculate the value percentage discount
$savana.money.percentageDiscount("R$ 100,00","R$ 50,00");
/*
{
discount_format: "450,00",
discount_format_number: 450,
discount_format_value: "50,00",
discount_value: 50,
increase_format: "550,00",
increase_format_number: 550
}
*/
$savana.money.percentageDiscount(100.00, 50.00);
/*
{
discount_format: "450,00",
discount_format_number: 450,
discount_format_value: "50,00",
discount_value: 50,
increase_format: "550,00",
increase_format_number: 550
}
*/
Methods of manager of objects.
Arguments
Argument | Type | Options |
---|---|---|
objectValue1 * |
Object | |
objectValue2 * |
Object |
Extends a object
$savana.obj.extends({'firstname': 'John'}, {'lastname': 'Miller'});
// {'firstname': 'John','lastname': 'Miller'}
Arguments
Argument | Type | Options |
---|---|---|
objectValue * |
Object |
Create a object
$savana.obj.create({'firstname': 'John'});
// {'firstname': 'John'}
Arguments
Argument | Type | Options |
---|---|---|
objectValue * |
Object | |
itemDelete * |
string |
Remove a object item
$savana.obj.remove({'firstname': 'John','lastname': 'Miller'}, 'lastname');
// {'firstname': 'John'}
Arguments
Argument | Type | Options |
---|---|---|
objectValue * |
Object | |
itemDelete * |
string |
Get value by key
$savana.obj.search({'firstname': 'John','lastname': 'Miller'}, 'lastname');
// Miller
Arguments
Argument | Type | Options |
---|---|---|
objectValue * |
Object |
Get keys
$savana.obj.getKeys({'firstname': 'John','lastname': 'Miller'});
// ['firstname','lastname']
Arguments
Argument | Type | Options |
---|---|---|
objectValue * |
Object |
Get values
$savana.obj.getValues({'firstname': 'John','lastname': 'Miller'});
// ['John','Miller']
Arguments
Argument | Type | Options |
---|---|---|
objectValue * |
Object |
Convert Object to Array
$savana.obj.toArray({'firstname': 'John'});
// [["firstname", "John"]]
Methods of manager of strings.
Arguments
Argument | Type | Options |
---|---|---|
value * |
string or array |
Verify if exists the value
$savana.string.contain(['a','b','c'], 'd'); // true or false
Arguments
Argument | Type | Options |
---|---|---|
value * |
string or array | |
start * |
number | |
end * |
number |
Letter limite
$savana.string.limitLetter('hello world', 0, 10); // hello worl...
Arguments
Argument | Type | Options |
---|---|---|
value * |
string or array | |
end * |
number |
Letter limite
$savana.string.limitWord('hello world', 1); // hello ...
Arguments
Argument | Type | Options |
---|---|---|
value * |
string |
Spaces remove
$savana.string.trim(' Hello '); // Hello
Methods of manager of convertions.
Arguments
Argument | Type | Options |
---|---|---|
value * |
string |
Convert string to HTML
$savana.to.HTML('<p>Hello World</p>');
Arguments
Argument | Type | Options |
---|---|---|
value * |
string |
Convert string to JSON
$savana.to.JSON('{"name": "Hello"}'); // {"name": "Hello"}
Arguments
Argument | Type | Options |
---|---|---|
value * |
number or object |
Convert string to JSON
$savana.to.string({"name": "Hello"}); // {"name": "Hello"}
Arguments
Argument | Type | Options |
---|---|---|
value * |
string |
Convert string to XML
$savana.to.XML('<p>Hello World</p>');
Arguments
Argument | Type | Options |
---|---|---|
value * |
string |
Convert string to rewrite
$savana.to.rewrite('Hello World caça está'); // hello-world-caca-esta
Arguments
Argument | Type | Options |
---|---|---|
value * |
string |
Convert string to uppercase
$savana.to.upper('hello world'); // HELLO WORLD
Arguments
Argument | Type | Options |
---|---|---|
value * |
string |
Convert string to lowercase
$savana.to.lower('HELLO WORLD'); // hello world
Methods of manager of urls.
Arguments
Argument | Type | Options |
---|---|---|
url * |
string |
Redirect to url
$savana.url.redirect('http://www.google.com');
Arguments
Argument | Type | Options |
---|---|---|
parameter * |
string | |
url * |
string |
Get parameter
$savana.url.getParams('v','http://www.google.com?v=hello'); // hello
Get the url current
$savana.url.getCurrent();
Get the url infos
$savana.url.getInfos();
Methods of manager of storage browser.
Arguments
Argument | Type | Options |
---|---|---|
name * |
string | |
value * |
string or array |
Create
$savana.webStorage.create('test', [{"name": "John","lastname": "Miller"}]);
$savana.webStorage.create('test2', "John")
Arguments
Argument | Type | Options |
---|---|---|
name * |
string |
Select
$savana.webStorage.select('test'); // [{"name": "John","lastname": "Miller"}]
$savana.webStorage.select('test2'); // John
Arguments
Argument | Type | Options |
---|---|---|
name * |
string | |
index |
number |
Delete storage or item of storage
$savana.webStorage.delete('test');
$savana.webStorage.delete('test', 0);
Methods of manager of urls.
Get the browser current
$savana.what.browser(); // Chrome, Firefox, Safari, Opera, Edge, EI7...EI12
Get the device in use
$savana.what.device(); // mobile, tablet ou desktop
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
We use SemVer for versioning. For the versions available, see the tags on this repository.
This project is licensed under the MIT License - see the LICENSE.md file for details