-
Notifications
You must be signed in to change notification settings - Fork 4
Data
OGX.Data
is a static helper class to manipulate, convert data. There is no need to create an instance of this class.
OGX.Data.merge(__master, __slave, __overwrite, __copy, __strict);
OGX.Data.weld(__master, __slave, __overwrite, __copy);
OGX.Data.diff(__master, __slave, __strict);
OGX.Data.adiff(__arrayA, __arrayB);
OGX.Data.same(__objectA, __objectB, __deep);
OGX.Data.intersect(__arrA, __arrB);
OGX.Data.trim(__obj);
OGX.Data.props(__obj, __array);
OGX.Data.clone(__obj);
OGX.Data.isFloat(__val);
OGX.Data.isInt(__val);
OGX.Data.isSizeExp(__string);
OGX.Data.toSizeExp(__string_or_number);
OGX.Data.addDec(__n);
OGX.Data.pad(__n, __length, __direction, __string);
OGX.Data.stringToVal(__string);
OGX.Data.dateToLocale(__date|__string, __options);
OGX.Data.getBestSize(__dimension, __value);
OGX.Data.eval(__obj, __prop, __val);
OGX.Data.clipboard(__string);
OGX.Data.get2DTransform(__element);
The
merge
method merges two objects into one, by appending to the master object the slave's properties . If the__override
flag is set totrue
and the same properties are found in both objects, the slave's properties/values will override the master's. The__copy
flag, if set totrue
, returns a copy of the master object, leaving the master object untouched. If the__strict
flag is set totrue
, only existing properties of the master slave will be updated.
let new_object = OGX.Data.merge(objectA, objectB, true, true, false);
Note that merge will only consider a single level/depth of properties. For deep merging, use the
weld
method.
Similar to
merge
but with deep update asmerge
only supports a single depth. Theweld
method does not support the__strict
flag.
let new_object = OGX.Data.weld(objectA, objectB, true, true);
Retrieve an object composed of the values that are different between a master and a slave object
let diff = OGX.Data.diff(objectA, objectB, true);
Retrieves intersection from 2 array. Note that this only supports simple arrays, not arrays of objects
let inter = OGX.Data.intersect([1,2,3], [1,4,5]);
Recursively trims all values of type string, of all properties of a object, recursively. Array supported.
let o = {first_name:' Some ', last_name:' Guy', children:[{first_name:' Mike', last_name:' Whaterver ', children: ...}, {...}]}
OGX.Data.trim(o);
//{first_name:'Some', last_name:'Guy', children:[{first_name:'Mike', last_name:'Whaterver', children: ...}, {...}]}
Use this method to check if an object has the required properties. Returns
true
orfalse
.
let bool = OGX.Data.props(objectA, ['age', 'gender', 'weight']);
A deep cloning method, shortcut to stringify/parse via JSON.
let new_object = OGX.Data.clone(objectA);
Test if a variable is a float
const bool = OGX.Data.isFloat(myvar);
Test if a variable is an integer
const bool = OGX.Data.isInt(myvar);
Test if a variable is a size expression
const bool = OGX.Data.isSizeExp(myvar);
Converts a dimension to a size expression,
min
andmax
are optional
const exp = OGX.Data.toSizeExp(myvar, min, max);
Convert a number to a string then pads up to 2 decimals
console.log(OGX.Data.addDec(654)); // '654.00'
Pad a string with a given character until a certain overall length is reached
console.log(OGX.Data.pad('654', 5, -1, '0'); // '00654'
console.log(OGX.Data.pad('654', 5, 1, '0'); // '65400'
Auto convert a string to appropriate type.
let val = OGX.Data.stringToVal(__string);
OGX.Data.stringToVal('true'); //return true
OGX.Data.stringToVal('false'); //return false
OGX.Data.stringToVal('1'); //return 1
Converts a date or a parse-ale string into a locale date as string
let str = OGX.dateToLocale('2021-02-28', {options});
//"Sunday, February 28, 2021"
Options by default are
{ weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' }
Computes the most appropriate size given a screen dimension and a
size expression
. For more information about Size Expressions, visit the dedicated page.
let size = OGX.Data.getBestSize(1100, '100px|300|500|70%|100%+');
//70%
let size = OGX.Data.getBestSize(1100, '100px|300|500|70%|100%-');
//100
Note that
size expressions
are supported byWindow
andPopup
Compares two objects for complete similarities and returns true or false. Set the last parameter to
true
if you want to deep compare all properties
OGX.Data.same({whatever:true}, {whatever:100}, false); //false
Sets or returns the value of the property of an object, when the property is a path to a property
OGX.Data.eval({id:'123', geo:{zip:'A1A 1A1'}}, 'geo.zip'); //returns 'A1A 1A1'
OGX.Data.eval({id:'123', geo:{zip:'A1A 1A1'}}, 'geo.zip', 'Z9Z 9Z9'); //sets geo.zip to 'Z9Z 9Z9'
Copy to clipboard given string
OGX.Data.clipboard('my copied text');
Retrieves the current 2D transformation from
DOMMatrix
as an object{x: int, y: int, r: number}
OGX.Data.get2DTransform(myElement);
- Welcome
- Changelog
- Structure
- Configuration
- Getting started
- CLI
- Poly
- Core
- Templating
- Routing
- Controllers
- Components
- Extra Components
- Helpers
- Styling
- Debugging