Reldens/Utils is a package to contain mostly shortcuts and small features that will be used across the project in both sides, server and client.
The current features on this package are:
- ErrorManager: right now is just a throw error + trace, the implementation must be finished.
- Logger: a shortcut to log in different levels, also an unfinished implementation.
- EventsManager: an extended 3rd party module to handle sync and async events with lists.
- IteractionArea: a class to calculate the interaction area between objects.
On the Shortcuts list we have:
- hasOwn(object, property): to check if an object has an specific property.
- isTrue(object, property, strictValidation): to check if the object has the property and return it's value if is present, and if "strict" is passed check as "true".
- isArray: not much so say here, it uses Array.isArray(obj).
- convertObjectsArrayToObjectByKeys(dataArray, keyProperty): this create a new object, loop the array and use the keyProperty to populate the object with the property value from the array item.
- sortObjectKeysBy(object, sortField): this will sort the object keys using an specific object property to compare values.
- propsAssign(from, to, props): this will assign a list of properties from one object into another.
- toJson(jsonString, defaultReturn): a secure convert without getting errors.
- parseJson(jsonString): a try/catch on JSON.parse.
- get(object, prop, defaultReturn): will return the property value if the property exists on the object or the default specified.
- getByPriority(object, propsArray): this will return the first property value present on the object.
- serializeFormData(formData): will return an object with all the formData as key/value.
- removeFromArray(valuesArray, removeValues): will remove all the values from an array.
- getCurrentDate(): will return a date in an specific format '2022-02-20 19:39:14'.