- UUID_NIL
- EnumGenerator
- getCurrentEpochTime
- CacheMgr
- copy
- deepCopy
- clone
- defaultsGenerator
- EventManager
- isNumber
- isFunction
- isString
- isBoolean
- isArray
- argumentsToArray
- removeDuplicates
- Ajax
Null value for uuid. Database type is uuid/guid. Value is '00000000-0000-0000-0000-000000000000'
Type: string
Generates a Enum class
attr
EnumInput Valid enum data
const enumObj = Utilify.EnumGenerator({ 1: 'Yes', 2: 'No' });
enumObj[1] // 'Yes'
enumObj['Yes'] // 1
Returns JSEnum JavaScript compatible enum class.
Returns current epoch time in int.
Returns number current time in epoch format
Cache manager, stores data in memory.
CacheMgr.set('key1', 1000);
CacheMgr.get('key1'); // 1000
CacheMgr.remove('key1');
Sets cache value
key
string Key of the valueval
T Cached value
CacheMgr.set('key', 1000);
Returns T Cached value.
Gets cached value
key
string Key of the value
CacheMgr.get('key');
Returns any Cached value.
Removes given cached value
key
string Key of the value
CacheMgr.remove('key');
Returns undefined undefined.
Removes all cached values.
CacheMgr.clearAll();
Returns undefined undefined.
Copies all properties from data to copy object.
deepCopy({}, {a:10}); // {a:10}
Returns Object copied object.
Deep clones all properties from data to copy object.
deepCopy({}, {a:{b:{c:10}}}); // {a:{b:{c:10}}}
Returns Object copied object.
Returns clonned object from given object
data
T Source object.
clone({}, {a:{b:{c:10}}}); // {a:{b:{c:10}}}
Returns T copied object.
Generator function for defaults in a class constructor.
attr
Object Default Object attribute (optional, default{}
)
var def = Utilify.defaultsGenerator({
id: 0,
name: 'abc'
});
var vals = def({ name: 'sid' });
Custom event manager. Scope based.
var arr = EventManager.listenTo(obj1, 'Util', respFunc);
EventManager.trigger(obj1, 'Util', data);
EventManager.off(obj1, 'Util', respFunc);
Adds an event listener on given context with given event name and callback.
Adds an event listener on given context with given event name and callback but removes when once executed.
Triggers given event on given context with data.
Removes an event listener if no callback provided, all events will be removed on context with given event.
context
Object The contexteventName
string The event namecallback
Function The callback (optional)
Returns true if parameter is number.
item
any parameter to check.
var myVar = 10; isNumber(myVar); // true
Returns boolean
Returns true if parameter is function.
item
any parameter to check.
var myVar = "str"; isFunction(myVar); // false
Returns boolean
Returns true if parameter is string.
item
any parameter to check.
var myVar = "str"; isString(myVar); // true
Returns boolean
Returns true if parameter is boolean.
item
any parameter to check.
var myVar = 10; isBoolean(myVar); // false
Returns boolean
Returns true if parameter is an array.
item
any parameter to check.
var myVar = []; isArray(myVar); // true
Returns boolean
Converts type arguments into array, with same values
args
argument The arguments
function myFunc1() {
myFunc2.apply(this, argumentsToArray(arguments).push(10));
}
Returns Array<any> Array type arguments
Removes duplicates elements in array.
arr
Array<T> Array with items of type T, having duplicate items
removeDuplicates([10,10,20,20,20,30]); // [10,20,30]
Returns Array<T> Array without duplicate items.
PUT Request, generally used for adding new record in the database. Uses XMLHttpRequest to make an xhr call.
url
string URL for given request.data
Object object payload to be sent to server.onSuccess
Function Optional, success callback for put operation.onFail
Function Optional, error callback for put operation.
Ajax.put('//google.com').then(...).catch(...);
Returns Promise<any> Promise with response
GET Request, generally used to fetch items. Uses XMLHttpRequest to make an xhr call.
url
string URL for given request.onSuccess
Function Optional, success callback for put operation.onFail
Function Optional, error callback for put operation.
Ajax.get('//google.com/users').then(...).catch(...);
Returns Promise<any> Promise with response
POST Request, generally used to update items in the database. Uses XMLHttpRequest to make an xhr call.
url
string URL for given request.data
Object object payload to be sent to server.onSuccess
Function Optional, success callback for put operation.onFail
Function Optional, error callback for put operation.
Ajax.post('//google.com/users').then(...).catch(...);
Returns Promise<any> Promise with response
DELETE Request, generally used to remove/delete items from the database. Uses XMLHttpRequest to make an xhr call.
url
string URL for given request.data
Object object payload to be sent to server.onSuccess
Function Optional, success callback for put operation.onFail
Function Optional, error callback for put operation.
Ajax.delete('//google.com/users').then(...).catch(...);
Returns Promise<any> Promise with response