A JS library for most commonly used utils

- Currency Utils
- URL Utils
- Common Utils
- Geo Location Utils
- History
- Storage Utils
- Date Utils
yarn add utileo
or
npm i utileo --save-dev
| Method |
Params |
Description |
| format |
amount, isFloat |
To display any and all amount-values, if isFloat is true, amount formatted to 2 decimal places |
| parse |
amount |
To parse amount-value back to number-only |
| beforeAPIRequest |
amount |
Before-submitting on any API-requests |
| Method |
Params |
Description |
| validateName |
string |
Check if all characters in the string are alphabets |
| validateOnlyNumber |
string/number |
Check if it is a number |
| titleCase |
string |
Convert a string to title case |
| camelize |
string |
Convert hello-world style strings to helloWorld style strings |
| removeSpacesAndLowerCase |
string |
Converting to lower case and remove spaces in a string. Ex:My Name - myname |
| replaceSpaceWithUnderscore |
string |
Converting space to underscore in a string. Ex:My Name - My_Name |
| replaceSpecialCharsWithUnderscore |
string |
Replace special chars like @,$ to _ . Ex:abc@123%a$ - abc_123_a_ |
| addKeyToObject |
object |
Adds key to objects |
| getIndex |
arr,object |
Find index of an Item from Array of objects. |
| toNumber |
value |
Convert a string to number |
| partition |
arr, criteria |
Partition array into two arrays based on criteria |
| isArray |
value |
Check for an Array |
| isObject |
value |
Check for an Object |
| isFunction |
value |
Check for a function |
| isIOS |
none |
Check device type is IOS or not |
| Method |
Params |
Description |
| get |
key |
Get value from localstorage by key name |
| set |
key, value |
Set value to localstorage |
| has |
key |
Check key available in localstorage |
| remove |
key |
Remove key from localstorage |
| removeAll |
- |
Remove all items from localstorage |
| Method |
Params |
Description |
| getLatLong |
timeout |
get lat and long |
| Method |
Params |
Description |
| getURLParameter |
qrString, paramName |
get parameter value |
| Method |
Params |
Description |
| formatDate |
date |
Returns an object of day, month, year |
| getCurrentDate |
- |
Returns current date |
| getDateByDashFormat |
date |
Returns date with DD-MM-YYYY format |
| getDateBySlashFormat |
date |
Returns date with DD/MM/YYYY format |
| timestampToDate |
timestamp |
Converting timestamp to date Ex : 1560211200000 to Tue Jun 11 2019 |
| getDateFromString |
string |
Converting string to date Ex : '6-11-2019' to Tue Jun 11 2019 |
import { CurrencyUtils, CommonUtils, StorageUtils, GeoLocationUtils, URLUtils, History, DateUtils } from 'utileo';
CurrencyUtils.format('10000')
CurrencyUtils.format('10000.1234',true)
CurrencyUtils.parse('1,00,000')
CommonUtils.validateName('only alphabets')
CommonUtils.validateOnlyNumber('1233')
CommonUtils.titleCase('main menu')
CommonUtils.camelize('main-menu')
CommonUtils.toNumber('1234')
CommonUtils.isArray([1,2,3]);
CommonUtils.isObject({"name": "abc", "age": 12})
CommonUtils.isFunction(CommonUtils.isObject);
var users = [
{'user': 'barney', 'age': 36, 'active': false},
{'user': 'fred', 'age': 40, 'active': true},
{'user': 'pebbles', 'age': 1, 'active': false}
];
var groups = CommonUtils.partition(users, function (user) {
return user.active;
});
CommonUtils.getIndex(users,{'user': 'barney', 'age': 36, 'active': false});
CommonUtils.addKeyToObject(users);
StorageUtils.get('phoneNumber')
StorageUtils.set('phoneNumber',9899224433)
StorageUtils.has('phoneNumber')
StorageUtils.remove('token')
StorageUtils.removeAll()
let latLong = GeoLocationUtils.getLatLong()
let latitude = latLong.lat
let longitude = latLong.long
var appVisa = URLUtils.getURLParameter(window.location.href, 'visa')
History.replace("/")
History.goBack()
History.push("/")
const currDate = DateUtils.getCurrentDate();
const dateObj = DateUtils.formatDate(currDate);
DateUtils.getDateByDashFormat(currDate);
DateUtils.getDateBySlashFormat(currDate);
DateUtils.timestampToDate(1560211200000);
DateUtils.getDateFromString('2/10/2017');
Here Contributors
MIT @bharatpe