2.13.0 • Published 3 years ago

sandeep-utileo v2.13.0

Weekly downloads
22
License
ISC
Repository
github
Last release
3 years ago

Utileo NPM version Downloads

A JS library for most commonly used utils

Utileo

Utils

  • Currency Utils
  • URL Utils
  • Common Utils
  • Geo Location Utils
  • History
  • Storage Utils
  • Date Utils

    Getting Started (Installation)

yarn add utileo

or

npm i utileo --save-dev

Currency Formatter Methods

MethodParamsDescription
formatamount, isFloatTo display any and all amount-values, if isFloat is true, amount formatted to 2 decimal places
parseamountTo parse amount-value back to number-only
beforeAPIRequestamountBefore-submitting on any API-requests

Common Util Methods

MethodParamsDescription
validateNamestringCheck if all characters in the string are alphabets
validateOnlyNumberstring/numberCheck if it is a number
titleCasestringConvert a string to title case
camelizestringConvert hello-world style strings to helloWorld style strings
removeSpacesAndLowerCasestringConverting to lower case and remove spaces in a string. Ex:My Name - myname
replaceSpaceWithUnderscorestringConverting space to underscore in a string. Ex:My Name - My_Name
replaceSpecialCharsWithUnderscorestringReplace special chars like @,$ to . Ex:abc@123%a$ - abc_123_a
addKeyToObjectobjectAdds key to objects
getIndexarr,objectFind index of an Item from Array of objects.
toNumbervalueConvert a string to number
partitionarr, criteriaPartition array into two arrays based on criteria
isArrayvalueCheck for an Array
isObjectvalueCheck for an Object
isFunctionvalueCheck for a function
isIOSnoneCheck device type is IOS or not

Storage Util Methods

MethodParamsDescription
getkeyGet value from localstorage by key name
setkey, valueSet value to localstorage
haskeyCheck key available in localstorage
removekeyRemove key from localstorage
removeAll-Remove all items from localstorage

Geo Location Util Method

MethodParamsDescription
getLatLongtimeoutget lat and long

URL Parameter Method

MethodParamsDescription
getURLParameterqrString, paramNameget parameter value

Date Util Methods

MethodParamsDescription
formatDatedateReturns an object of day, month, year
getCurrentDate-Returns current date
getDateByDashFormatdateReturns date with DD-MM-YYYY format
getDateBySlashFormatdateReturns date with DD/MM/YYYY format
timestampToDatetimestampConverting timestamp to date Ex : 1560211200000 to Tue Jun 11 2019
getDateFromStringstringConverting string to date Ex : '6-11-2019' to Tue Jun 11 2019

Usage

import { CurrencyUtils, CommonUtils, StorageUtils, GeoLocationUtils, URLUtils, History, DateUtils } from 'utileo';

//---------------------------------- Currency Utils -------------------------//
CurrencyUtils.format('10000') // 10,000
CurrencyUtils.format('10000.1234',true) // 10,000.12
CurrencyUtils.parse('1,00,000') // 100000 

//---------------------------------- Common Utils -------------------------------------//
CommonUtils.validateName('only alphabets')// true
CommonUtils.validateOnlyNumber('1233')// true
CommonUtils.titleCase('main menu')// Main Menu
CommonUtils.camelize('main-menu')// mainMenu
CommonUtils.toNumber('1234')// 1234
CommonUtils.isArray([1,2,3]);// true
CommonUtils.isObject({"name": "abc", "age": 12})// true
CommonUtils.isFunction(CommonUtils.isObject);// true

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;
});
// groups[0] has [{'user':'fred', 'age': 40, 'active': true}]
// groups[1] has [{'user':'barney', 'age': 36, 'active': false}, {'user': 'pebbles', 'age': 1, 'active': false}]

CommonUtils.getIndex(users,{'user': 'barney', 'age': 36, 'active': false});// 0

CommonUtils.addKeyToObject(users);// key(type) will be added
// [{type: "0", user: "barney", age: 36, active: false}
// {type: "1", user: "fred", age: 40, active: true}
// {type: "2", user: "pebbles", age: 1, active: false}]

//------------------------ Storage Utils -----------------------------//
StorageUtils.get('phoneNumber')// 9899224433
StorageUtils.set('phoneNumber',9899224433)
StorageUtils.has('phoneNumber')// true
StorageUtils.remove('token')
StorageUtils.removeAll()

//----------------------- Geo Location ----------------------------//
let latLong = GeoLocationUtils.getLatLong()// value of lat long
let latitude = latLong.lat
let longitude = latLong.long

//--------------------------------- URL Parameter ---------------------------------------//
var appVisa = URLUtils.getURLParameter(window.location.href, 'visa')// 12n23be3h3bhbbh34

//--------- History --------//
History.replace("/")
History.goBack()
History.push("/")

//------------------------------------------ Date Utils ------------------------------------------------//
const currDate = DateUtils.getCurrentDate();// Wed Jul 14 2020 13:07:57 GMT+0530 (India Standard Time)
const dateObj = DateUtils.formatDate(currDate);// {day: 14, month: 6, year: 2020}
DateUtils.getDateByDashFormat(currDate);// 14-07-2020
DateUtils.getDateBySlashFormat(currDate);// 14/07/2020
DateUtils.timestampToDate(1560211200000);// Tue Jun 11 2019 05:30:00 GMT+0530 (India Standard Time)
DateUtils.getDateFromString('2/10/2017');// Sat Feb 10 2017 00:00:00 GMT+0530 (India Standard Time)

Contributors

Here Contributors

License

MIT @bharatpe

2.13.0

3 years ago

2.12.0

3 years ago

1.8.0

3 years ago

1.7.0

3 years ago

1.6.0

3 years ago

2.11.0

3 years ago

2.3.0

3 years ago

2.2.0

3 years ago

2.5.0

3 years ago

2.10.0

3 years ago

2.7.0

3 years ago

2.6.0

3 years ago

2.9.0

3 years ago

2.8.0

3 years ago

2.1.0

3 years ago

2.0.0

3 years ago

1.5.0

3 years ago

1.4.0

3 years ago

1.3.0

3 years ago

1.2.0

3 years ago

1.1.0

3 years ago

1.0.0

3 years ago