To install, run:

haxelib install anon 0.0.1 

See using Haxelib in Haxelib documentation for more information.

Anon travis

Runtime type check and value extractor for dynamic objects


Sometimes we just cannot make sure the data type during compile time, usually when the input data comes from external source. For example:

var obj:{myInt:Int} = Json.parse('{"myString":"hello, world"}');
trace(obj.myInt + 10); // fail

// for the best security, we need to check it manually
if(obj.myInt == null || !, Int)) throw "Invalid data";

However, thanks to Haxe macros, we don't need to write these check codes manually. This library helps you generate the validation codes and also make sure the resulting object contains only the fields you need.


var source:Dynamic = {a:1, b:"2"};
var r:{a:Int} = Anon.extract(source); // r is {a:1}

var source:Dynamic = {a:1, b:"2"};
var r:{a:Int, ?c:Int} = Anon.extract(source); // r is {a:1, c:null}

var source:Dynamic = {a:1, b:"2"};
var r:{a:Int, c:Int} = Anon.extract(source); // error: the field `c` does not exist
2 years ago

All libraries are free

Every month, more than thousand developers use haxelib to find, share, and reuse code — and assemble it in powerful new ways. Enjoy Haxe; It is great!

Explore Haxe

Haxe Manual

Haxe Code Cookbook

Haxe API documentation

You can try Haxe in the browser!

Join us on Github!

Haxe is being developed on GitHub. Feel free to contribute or report issues to our projects.

Haxe on Github