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.

staticcombine (first:{}, second:{}):{}

Shallow, untyped merge of two anonymous objects.

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.

staticdeepCombine (first:{}, second:{}):{}

Deep, typed merge of two objects.

staticdeflate (o:{}, flattenArrays:Bool = true):{}

staticinline exists (o:{}, name:String):Bool

exists returns true if o contains a field named name.

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

staticgetPathOption (o:{}, path:String):Option<Dynamic>

Null-safe getPath

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 7

statichasPath (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

staticinflate (o:{}):{}

staticinline isEmpty (o:{}):Bool

isEmpty returns true if the object doesn't have any field.

staticmerge (first:{}, second:{}):Dynamic

Shallow, typed merge of two anonymous objects.

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 ] } }

staticshallowCombine (first:{}, second:{}):{}

Shallow, untyped merge of two anonymous objects.

staticshallowMerge (first:{}, second:{}):Dynamic

Shallow, typed merge of two anonymous objects.

staticinline size (o:{}):Int

size returns how many fields are present in the object.

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> where the left value (_0) of the tuple is the field name and the right value (_1) is the field value.

staticinline values (o:{}):Array<Dynamic>

values returns an array of dynamic values containing the values of each field in the argument object.

staticwith<T> (o:T, field:Dynamic, value:Dynamic):Dynamic