class Objects
package thx
Helper methods for generic objects.
Static methods
staticassign (to:{}, from:{}, ?replacef:String ‑> Dynamic ‑> Dynamic ‑> Dynamic):{}
Copies the values from the fields of from to to. If to already contains those fields, then it replaces
those values with the return value of the function replacef.
If not set, replacef always returns the value from the from object.
staticclone<T> (src:T, cloneInstances:Bool = false):T
Clone the current object by creating a new object and using copyTo to clone each field.
staticcompare (a:{}, b:{}):Int
Compares two objects assuming that the object with less fields will come first.
If both objects have the same number of fields, each field value is compared
using thx.Dynamics.compare.
staticcopyTo (src:{}, dst:{}, cloneInstances:Bool = false):{}
copyTo copies the fields from src to dst using Reflect.setField() and Dynamics.clone().
Anonymous objects are entered into and copied recursively.
staticinline fields (o:{}):Array<String>
fields returns an array of string containing the field names of the argument object.
staticgetPath (o:{}, path:String):Dynamic
Gets a value from an object by a string path. The path can contain object keys and array indices separated by ".". Returns null for a path that does not exist.
E.g. { key1: { key2: [1, 2, 3] } }.getPath("key1.key2.2") -> returns 3 E.g. { key1: { key2: [1, 2, 3] } }.getPath("key1.key2[2]") -> returns 3
staticgetPathOr (o:{}, path:String, alt:Dynamic):Dynamic
Gets a value from an object by a string path. The path can contain object keys and array indices separated
by ".". Returns alt for a path that does not exist.
E.g. { key1: { key2: [1, 2, 3] } }.getPath("key1.key2.2") -> returns 3
E.g. { key1: { key2: [1, 2, 3] } }.getPath("key1.key2.5", 7) -> returns 7statichasPath (o:{}, path:String):Bool
Determines whether an object has fields represented by a string path. The path can contain object keys and array indices separated by ".".
E.g. { key1: { key2: [1, 2, 3] } }.hasPath("key1.key2.2") -> returns true
statichasPathValue (o:{}, path:String):Bool
Like hasPath, but will return false for null values, even if the key exists.
E.g. { key1 : { key2: null } }.hasPathValue("key1.key2") -> returns false
staticparsePath<T> (o:{}, path:String, parse:Dynamic ‑> VNel<String, T>):VNel<String, T>
Null-safe getPath that attempts to parse the result using the provided parse
function. thx.fp.Dynamics has several functions that match this pattern.
staticremovePath (o:{}, path:String):{}
Delete an object's property, given a string path to that property.
E.g. { foo : 'bar' }.removePath('foo') -> returns {}
staticsetPath<T> (o:{}, path:String, val:T):{}
Sets a value in an object by a string path. The path can contain object keys and array indices separated by ".". Returns the original object, for optional chaining of other object methods.
Inner objects and arrays will be created as needed when traversing the path.
E.g. { key1: { key2: [1, 2, 3] } }.setPath("key1.key2.2", 4) -> returns { key1: { key2: [ 1, 2, 4 ] } }
staticstring (o:{}):String
Returns a string representation of the object containing each field and value.
The function is recursive so it might generate infinite loops if used with circular references.
statictoMap (o:{}):Map<String, Dynamic>
objectToMap transforms an anonymous object into an instance of Map<String, Dynamic>.
statictuples (o:{}):Array<Tuple2<String, Dynamic>>
Converts an object into an Array
staticinline values (o:{}):Array<Dynamic>
values returns an array of dynamic values containing the values of each field in the argument object.