├── run.hxml ├── run.n ├── icon.png ├── bin ├── hxjsondef ├── hxjsondef.n └── example │ ├── test0.json │ ├── test.json │ ├── ASTtest0.hx │ └── ASTtest.hx ├── docs ├── cubes.png ├── favicon.ico ├── index.html ├── hxjsondef.js.map └── hxjsondef.js ├── .gitignore ├── haxelib.json ├── src ├── ast │ ├── ASTTest0.hx │ └── ASTTest.hx ├── MainJS.hx ├── hxjsondef │ └── macro │ │ └── AutomaticJsonDef.hx └── Hxjsondef.hx ├── tools └── Main.hx └── README.md /run.hxml: -------------------------------------------------------------------------------- 1 | -main Main 2 | -cp tools 3 | -cp src 4 | -neko run.n 5 | -debug -------------------------------------------------------------------------------- /run.n: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthijsKamstra/hxjsondef/HEAD/run.n -------------------------------------------------------------------------------- /icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthijsKamstra/hxjsondef/HEAD/icon.png -------------------------------------------------------------------------------- /bin/hxjsondef: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthijsKamstra/hxjsondef/HEAD/bin/hxjsondef -------------------------------------------------------------------------------- /bin/hxjsondef.n: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthijsKamstra/hxjsondef/HEAD/bin/hxjsondef.n -------------------------------------------------------------------------------- /docs/cubes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthijsKamstra/hxjsondef/HEAD/docs/cubes.png -------------------------------------------------------------------------------- /docs/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthijsKamstra/hxjsondef/HEAD/docs/favicon.ico -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | _assets 2 | test.hxml 3 | bin/_test 4 | _temp/hxjsondef.js 5 | _temp/hxjsondef.js.map 6 | _temp/index.html 7 | _temp 8 | -------------------------------------------------------------------------------- /bin/example/test0.json: -------------------------------------------------------------------------------- 1 | { 2 | "glossary": { 3 | "string": "I am a string", 4 | "number": 1234, 5 | "int": 8956, 6 | "float": 123.4, 7 | "boolean": true, 8 | "stringArray": ["one", "two"], 9 | "intArray": [888, 444], 10 | "obj" : { 11 | "para": "A meta-markup language, used to create markup languages such as DocBook.", 12 | "GlossSeeAlso": ["GML", "XML"] 13 | } 14 | 15 | } 16 | } -------------------------------------------------------------------------------- /haxelib.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hxjsondef", 3 | "url" : "https://github.com/MatthijsKamstra/hxjsondef", 4 | "license": "MIT", 5 | "tags": ["js", "web", "html5", "haxe", "javascript", "macro", "html", "json"], 6 | "description": "HxJsonDef helps you quickly define a typedef from some arbitrary .json", 7 | "version": "0.0.7", 8 | "classPath": "src/", 9 | "releasenote": "init", 10 | "contributors": ["MatthijsKamstra"], 11 | "dependencies": { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /bin/example/test.json: -------------------------------------------------------------------------------- 1 | { 2 | "glossary": { 3 | "title": "example glossary", 4 | "GlossDiv": { 5 | "title": "S", 6 | "GlossList": { 7 | "GlossEntry": { 8 | "ID": "SGML", 9 | "SortAs": "SGML", 10 | "GlossTerm": "Standard Generalized Markup Language", 11 | "Acronym": "SGML", 12 | "Abbrev": "ISO 8879:1986", 13 | "GlossDef": { 14 | "para": "A meta-markup language, used to create markup languages such as DocBook.", 15 | "GlossSeeAlso": ["GML", "XML"] 16 | }, 17 | "GlossSee": "markup" 18 | } 19 | } 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /bin/example/ASTtest0.hx: -------------------------------------------------------------------------------- 1 | package; 2 | 3 | /** 4 | * Generated with HxJsonDef (version 0.0.8) on 2017-04-06 10:44:24 5 | * from : test0 6 | * 7 | * AST = Abstract Syntax Tree 8 | * 9 | * Note: 10 | * If you provide a .json there should be no null values 11 | * comments in this document show you the values that need to be changed! 12 | * 13 | * Some (backend)-developers choose to hide empty/null values, you can add them: 14 | * @:optional var _id : Int; 15 | * 16 | * Name(s) that you possibly need to change: 17 | * Obj 18 | * Glossary 19 | * Test0ObjObj 20 | */ 21 | 22 | typedef Obj = 23 | { 24 | var para : String; 25 | var GlossSeeAlso : Array; 26 | }; 27 | 28 | typedef Glossary = 29 | { 30 | var intArray : Array; 31 | var boolean : Bool; 32 | var int : Int; 33 | var obj : Obj; 34 | var float : Float; 35 | var string : String; 36 | var number : Int; 37 | var stringArray : Array; 38 | }; 39 | 40 | typedef Test0ObjObj = 41 | { 42 | var glossary : Glossary; 43 | }; 44 | -------------------------------------------------------------------------------- /src/ast/ASTTest0.hx: -------------------------------------------------------------------------------- 1 | package; 2 | 3 | /** 4 | * Generated with HxJsonDef (version 0.0.8) on 2017-04-06 10:44:23 5 | * from : test0 6 | * 7 | * AST = Abstract Syntax Tree 8 | * 9 | * Note: 10 | * If you provide a .json there should be no null values 11 | * comments in this document show you the values that need to be changed! 12 | * 13 | * Some (backend)-developers choose to hide empty/null values, you can add them: 14 | * @:optional var _id : Int; 15 | * 16 | * Name(s) that you possibly need to change: 17 | * Test0.jsonObjObj 18 | * Obj 19 | * Glossary 20 | */ 21 | 22 | typedef Test0.jsonObjObj = 23 | { 24 | var glossary : Glossary; 25 | }; 26 | 27 | typedef Obj = 28 | { 29 | var para : String; 30 | var GlossSeeAlso : Array; 31 | }; 32 | 33 | typedef Glossary = 34 | { 35 | var intArray : Array; 36 | var boolean : Bool; 37 | var int : Int; 38 | var obj : Obj; 39 | var float : Float; 40 | var string : String; 41 | var number : Int; 42 | var stringArray : Array; 43 | }; 44 | -------------------------------------------------------------------------------- /bin/example/ASTtest.hx: -------------------------------------------------------------------------------- 1 | package; 2 | 3 | /** 4 | * Generated with HxJsonDef (version 0.0.8) on 2017-04-06 10:44:24 5 | * from : test 6 | * 7 | * AST = Abstract Syntax Tree 8 | * 9 | * Note: 10 | * If you provide a .json there should be no null values 11 | * comments in this document show you the values that need to be changed! 12 | * 13 | * Some (backend)-developers choose to hide empty/null values, you can add them: 14 | * @:optional var _id : Int; 15 | * 16 | * Name(s) that you possibly need to change: 17 | * GlossDiv 18 | * GlossDef 19 | * GlossList 20 | * Glossary 21 | * GlossEntry 22 | * TestObjObj 23 | */ 24 | 25 | typedef GlossDiv = 26 | { 27 | var GlossList : GlossList; 28 | var title : String; 29 | }; 30 | 31 | typedef GlossDef = 32 | { 33 | var para : String; 34 | var GlossSeeAlso : Array; 35 | }; 36 | 37 | typedef GlossList = 38 | { 39 | var GlossEntry : GlossEntry; 40 | }; 41 | 42 | typedef Glossary = 43 | { 44 | var GlossDiv : GlossDiv; 45 | var title : String; 46 | }; 47 | 48 | typedef GlossEntry = 49 | { 50 | var GlossDef : GlossDef; 51 | var GlossSee : String; 52 | var SortAs : String; 53 | var ID : String; 54 | var Acronym : String; 55 | var GlossTerm : String; 56 | var Abbrev : String; 57 | }; 58 | 59 | typedef TestObjObj = 60 | { 61 | var glossary : Glossary; 62 | }; 63 | -------------------------------------------------------------------------------- /src/ast/ASTTest.hx: -------------------------------------------------------------------------------- 1 | package; 2 | 3 | /** 4 | * Generated with HxJsonDef (version 0.0.8) on 2017-04-06 10:44:23 5 | * from : test 6 | * 7 | * AST = Abstract Syntax Tree 8 | * 9 | * Note: 10 | * If you provide a .json there should be no null values 11 | * comments in this document show you the values that need to be changed! 12 | * 13 | * Some (backend)-developers choose to hide empty/null values, you can add them: 14 | * @:optional var _id : Int; 15 | * 16 | * Name(s) that you possibly need to change: 17 | * GlossDiv 18 | * Test.jsonObjObj 19 | * GlossEntry 20 | * GlossDef 21 | * GlossList 22 | * Glossary 23 | */ 24 | 25 | typedef GlossDiv = 26 | { 27 | var GlossList : GlossList; 28 | var title : String; 29 | }; 30 | 31 | typedef Test.jsonObjObj = 32 | { 33 | var glossary : Glossary; 34 | }; 35 | 36 | typedef GlossEntry = 37 | { 38 | var GlossDef : GlossDef; 39 | var GlossSee : String; 40 | var SortAs : String; 41 | var ID : String; 42 | var Acronym : String; 43 | var GlossTerm : String; 44 | var Abbrev : String; 45 | }; 46 | 47 | typedef GlossDef = 48 | { 49 | var para : String; 50 | var GlossSeeAlso : Array; 51 | }; 52 | 53 | typedef GlossList = 54 | { 55 | var GlossEntry : GlossEntry; 56 | }; 57 | 58 | typedef Glossary = 59 | { 60 | var GlossDiv : GlossDiv; 61 | var title : String; 62 | }; 63 | -------------------------------------------------------------------------------- /src/MainJS.hx: -------------------------------------------------------------------------------- 1 | package; 2 | 3 | import js.jquery.JQuery; 4 | import js.Browser; 5 | import js.html.TextAreaElement; 6 | 7 | class MainJS { 8 | 9 | var inArea : Dynamic; 10 | var outArea : Dynamic; 11 | 12 | var inTextArea : TextAreaElement; 13 | var outTextArea : TextAreaElement; 14 | 15 | var hxjsondef : Hxjsondef; 16 | 17 | var jsonExample1 : String = '{\n\t"id": 1,\n\t"name": "A green door",\n\t"price": 12.50,\n\t"tags": ["home", "green"]\n}'; 18 | var jsonExample2 : String = '{\n\t"title": "Product",\n\t"description": "A product from Acme\'s catalog",\n\t"type": "object",\n\t"properties": {\n\t\t"id": {\n\t\t\t"description": "The unique identifier for a product",\n\t\t\t"type": "integer"\n\t\t},\n\t\t"name": {\n\t\t\t"description": "Name of the product",\n\t\t\t"type": "string"\n\t\t},\n\t\t"price": {\n\t\t\t"type": "number",\n\t\t\t"minimum": 0,\n\t\t\t"exclusiveMinimum": true\n\t\t},\n\t\t"tags": {\n\t\t\t"type": "array",\n\t\t\t"items": {\n\t\t\t\t"type": "string"\n\t\t\t},\n\t\t\t"minItems": 1,\n\t\t\t"uniqueItems": true\n\t\t}\n\t},\n\t"required": ["id", "name", "price"]\n}'; 19 | 20 | public function new() 21 | { 22 | new JQuery( function():Void 23 | { 24 | // when document is ready 25 | // js.Lib.alert('document ready'); 26 | 27 | // your magic 28 | new JQuery('#btn_convert').click(onClick); 29 | new JQuery('#btn_select').click(onClick); 30 | 31 | new JQuery('#example1').click(onClick); 32 | new JQuery('#example2').click(onClick); 33 | 34 | inArea = new JQuery('#in_json'); 35 | outArea = new JQuery('#out_hxjson'); 36 | 37 | inTextArea = cast (js.Browser.document.getElementById('in_json'), TextAreaElement); 38 | outTextArea = cast (js.Browser.document.getElementById('out_hxjson'), TextAreaElement); 39 | 40 | hxjsondef = new Hxjsondef(); 41 | hxjsondef.fileName = Browser.location.href; 42 | 43 | convert(jsonExample1); 44 | }); 45 | } 46 | 47 | function convert ( str ) 48 | { 49 | inArea.val(str); 50 | outArea.val(hxjsondef.convert('foobar', str)); 51 | 52 | outTextArea.scrollTop = outTextArea.scrollHeight; 53 | outTextArea.select(); 54 | } 55 | 56 | function selectAll():Void { 57 | outTextArea.select(); 58 | } 59 | 60 | private function onClick (e:Dynamic) : Void 61 | { 62 | var id = e.currentTarget.id; 63 | switch (id) { 64 | case "example1": convert(jsonExample1); 65 | case "example2": convert(jsonExample2); 66 | case "btn_convert": convert(inArea.val()); 67 | case "btn_select": selectAll(); 68 | } 69 | e.preventDefault(); 70 | } 71 | 72 | static public function main(){ 73 | var app = new MainJS(); 74 | } 75 | } -------------------------------------------------------------------------------- /src/hxjsondef/macro/AutomaticJsonDef.hx: -------------------------------------------------------------------------------- 1 | package hxjsondef.macro; 2 | 3 | #if macro 4 | 5 | import haxe.macro.Context; 6 | import haxe.macro.Expr; 7 | import haxe.io.Path; 8 | import sys.FileSystem; 9 | import sys.io.File; 10 | import sys.io.FileOutput; 11 | 12 | 13 | using StringTools; 14 | 15 | class AutomaticJsonDef { 16 | 17 | /** 18 | * generate jsons automaticly 19 | * 20 | * @param source file or folder of the json file(s) 21 | * @param bin the folder the .hx file should be generated 22 | * @return 23 | */ 24 | public static function build(source:String, bin:String){ 25 | 26 | var cwd:String = Sys.getCwd(); 27 | var templateSrcFolder = Path.join([cwd, source]); 28 | var templateDstFolder = Path.join([cwd, bin]); 29 | 30 | if(FileSystem.exists(templateSrcFolder)){ 31 | // [mck] just generate that folder... I don't care! 32 | if(!FileSystem.exists(templateDstFolder)) FileSystem.createDirectory(templateDstFolder); 33 | generateFromFolder(templateSrcFolder,templateDstFolder); 34 | } else { 35 | Context.warning('You might be using a different folder structure: this will not work!', Context.currentPos()); 36 | } 37 | } 38 | 39 | public static function generateFromFolder(folder:String,binFolder:String):Void 40 | { 41 | var fileNames = FileSystem.readDirectory(folder); 42 | for (fileName in fileNames) 43 | { 44 | if (!FileSystem.isDirectory(folder + '/' + fileName)) 45 | { 46 | // ignore invisible (OSX) files like ".DS_Store" 47 | if (fileName.startsWith(".")) continue; 48 | 49 | // we need json, ignore the rest 50 | if (!fileName.endsWith(".json")) continue; 51 | 52 | var cleanFileName = fileName.toLowerCase().split('.')[0]; 53 | var tempTemplateFile = binFolder + '/AST' + capString(cleanFileName) + '.hx'; 54 | 55 | var json; 56 | var content = File.getContent(folder + '/' + fileName); 57 | 58 | try{ 59 | // [mck] just checking if it is correct json 60 | json = haxe.Json.parse(content); 61 | } catch (e:Dynamic) { 62 | Sys.println('JSON :: this is not a valid json'); 63 | return ; 64 | } 65 | 66 | var hxjsondef = new Hxjsondef(); 67 | hxjsondef.fileName = cleanFileName; 68 | var str = hxjsondef.convert('${capString(fileName)}Obj', content); 69 | 70 | File.saveContent(tempTemplateFile, str); 71 | } else { 72 | // [mck] untested folder stucture copy from sourcefolder 73 | FileSystem.createDirectory(binFolder + '/' + fileName + '/'); 74 | generateFromFolder(folder + '/' + fileName, binFolder); 75 | } 76 | } 77 | } 78 | 79 | private static function capString(str:String):String 80 | { 81 | var tempstr = ''; 82 | tempstr = str.substring(0,1).toUpperCase() + str.substring(1,str.length); 83 | return tempstr; 84 | } 85 | 86 | } 87 | 88 | #end -------------------------------------------------------------------------------- /tools/Main.hx: -------------------------------------------------------------------------------- 1 | package; 2 | 3 | import sys.io.File; 4 | import sys.io.FileOutput; 5 | import sys.FileSystem; 6 | 7 | using StringTools; 8 | 9 | class Main { 10 | 11 | var filePath = ''; 12 | var isFileSet : Bool = false; 13 | 14 | var path:String; 15 | var fileName:String; 16 | 17 | var hxjsondef : Hxjsondef; 18 | 19 | function new(?args : Array) : Void 20 | { 21 | var args : Array = args; 22 | if(args.length == 1 && args[0].indexOf('.') != -1){ 23 | filePath = args[0]; 24 | isFileSet = isValidJson(filePath); 25 | } 26 | if(args.length == 2 && args[0].indexOf('.') != -1){ 27 | filePath = args[1]+args[0]; 28 | isFileSet = isValidJson(filePath); 29 | } 30 | 31 | if (!isFileSet){ 32 | Sys.println('ERROR :: Sorry I need a .json file to convert'); 33 | showHelp(); 34 | return; 35 | } 36 | 37 | // [mck] validate path? 38 | // [mck] validate if file exists 39 | 40 | var tmpArr = filePath.split('/'); 41 | fileName = validFileName(tmpArr[tmpArr.length-1].split(".")[0]); 42 | path = filePath.substring(0,filePath.lastIndexOf("/")+1); 43 | 44 | hxjsondef = new Hxjsondef(); 45 | hxjsondef.fileName = fileName; 46 | 47 | Sys.println('${Hxjsondef.NAME} (${Hxjsondef.VERSION}) :: convert "${fileName}.json"'); 48 | 49 | // trace( "path: " + path ); 50 | // trace( "fileName: " + fileName ); 51 | 52 | 53 | // trace( "Sys.executablePath(): " + Sys.executablePath() ); 54 | // trace( "Sys.getCwd(): " + Sys.getCwd() ); 55 | // var path = Sys.executablePath(); 56 | // var fin = sys.io.File.getContent(path + fname); 57 | 58 | init(filePath); 59 | 60 | Sys.println('${Hxjsondef.NAME} (${Hxjsondef.VERSION}) :: done "${fileName}.json"\n'); 61 | 62 | } 63 | 64 | 65 | 66 | private function init(file:String):Void 67 | { 68 | var content; 69 | var json; 70 | try{ 71 | content = sys.io.File.getContent(file); 72 | json = haxe.Json.parse(content); 73 | } catch (e:Dynamic) { 74 | Sys.println('ERROR :: this path in incorrect: ' + file); 75 | return ; 76 | } 77 | 78 | var str = hxjsondef.convert('${capString(fileName)}Obj', content); 79 | 80 | Sys.println('${Hxjsondef.NAME} (${Hxjsondef.VERSION}) :: write data to "AST${fileName}.hx" ...'); 81 | 82 | write(fileName, str); 83 | } 84 | 85 | 86 | // ____________________________________ info ____________________________________ 87 | 88 | private function showHelp () : Void { 89 | Sys.println(' 90 | ${Hxjsondef.NAME} (version ${Hxjsondef.VERSION}) 91 | 92 | how to use: 93 | neko ${Hxjsondef.NAME.toLowerCase()} \'path/to/folder/foobar.json\' 94 | 95 | -help : show this help 96 | '); 97 | } 98 | 99 | // ____________________________________ misc ____________________________________ 100 | 101 | private function isValidJson(filePath:String):Bool 102 | { 103 | return (filePath.indexOf(".json") != -1); 104 | } 105 | 106 | private function validFileName(name:String):String 107 | { 108 | return name.replace("-", ""); 109 | } 110 | 111 | private function capString(str:String):String 112 | { 113 | var tempstr = ''; 114 | tempstr = str.substring(0,1).toUpperCase() + str.substring(1,str.length); 115 | return tempstr; 116 | } 117 | 118 | // ____________________________________ write file ____________________________________ 119 | 120 | private function write(name:String, data:String):Void 121 | { 122 | // var temp = Sys.executablePath().split('/'); 123 | // temp.pop(); 124 | 125 | // var _path = temp.join("/") + '/AST${name}.hx'; 126 | var _path = path + '/AST${name}.hx'; 127 | var f:FileOutput = File.write(_path,false); 128 | f.writeString(data); 129 | f.close(); 130 | } 131 | 132 | static public function main(){ 133 | var app = new Main(Sys.args()); 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # HxJsonDef 2 | 3 | ![](icon.png) 4 | 5 | HxJsonDef is command-line app/macro/class written in [Haxe](http://www.haxe.org) that helps you quickly define a typedef from some arbitrary `.json` 6 | 7 | I found a gist written in ruby that does the same (written by [Justin Donaldson](https://gist.github.com/jdonaldson/1454243)) and it inspired to write it in Haxe/Neko. 8 | 9 | ## JSON Values 10 | 11 | There are some rules you have to keep in mind. 12 | For the conversion it best **NOT** to use `null` as a value. 13 | It will be automatically converted to `Dynamic`, but if you know what the value will be; remove `null` and replace with one of the values described below. 14 | 15 | JSON values can be: 16 | 17 | - A number (integer or floating point `1` / `1.1`) 18 | - A string (in double quotes `"...."`) 19 | - A Boolean (`true` or `false`) 20 | - An array (in square brackets `[...]`) 21 | - An object (in curly braces `{...}`) 22 | - null 23 | 24 | [https://www.w3schools.com/js/js_json_datatypes.asp](https://www.w3schools.com/js/js_json_datatypes.asp) 25 | 26 | 27 | 28 | 29 | ## Haxelib 30 | 31 | How to get this working? 32 | 33 | 34 | You might want to update and/or correct the externs: install this repo locally 35 | 36 | ```bash 37 | haxelib dev hxjsondef path/to/folder/src 38 | ``` 39 | 40 | Or use the developers version / cutting edge: this git repo 41 | 42 | ```bash 43 | haxelib git hxjsondef https://github.com/MatthijsKamstra/hxjsondef 44 | ``` 45 | 46 | And don't forget to add it to your build file 47 | 48 | ```bash 49 | -lib hxjsondef 50 | ``` 51 | 52 | 53 | 54 | ## Usage 55 | 56 | You choose what works best for you: 57 | 58 | - Initialization [macro](#macro) in your build file 59 | - [haxelib run](#haxerun) 60 | - [neko](#neko) 61 | - via [class](#class) 62 | - [online](http://matthijskamstra.github.io/hxjsondef/) 63 | 64 | 65 | ### Macro 66 | 67 | Install the lib and add this to your `build.hmxl` 68 | 69 | ```haxe 70 | --macro hxjsondef.macro.AutomaticJsonDef.build('bin/example','src/ast') 71 | ``` 72 | 73 | First param is the source folder of the jsons, the second param is the "export" folder 74 | 75 | Remember this is done **every** time you build. And the `.hx` are automaticly overwritten so any changes to that file are gone. 76 | 77 | **NOTE: this macro needs more love, so let me know what would work better.** 78 | 79 | 80 | 81 | ### Haxelib run 82 | 83 | Install the lib and use your terminal to generate a `.hx` file based upon a `.json` file. 84 | 85 | ```bash 86 | cd path/to/folder 87 | haxelib run hxjsondef filename.json 88 | ``` 89 | 90 | And next to the `filename.json ` there will be the converted `ASTfilename.hx` file. 91 | 92 | You need to send the file you want to change. I might consider creating it for folders as well. Just let me know. Create an issue or a pull request. 93 | 94 | 95 | ### neko 96 | 97 | - Download this repo 98 | - Open your terminal 99 | - `cd ` to the correct folder (where hxjsondef is located: `/hxjsondef/bin/`) 100 | 101 | ``` 102 | neko hxjsondef /Volumes/path/to/foobar.json 103 | ``` 104 | 105 | And next to the `foobar.json` there will be the converted `ASTfoobar.hx` file. 106 | 107 | See two json file converted in the [example folder](bin/example) 108 | 109 | 110 | ### class 111 | 112 | Add lib to `build.hxml` 113 | 114 | ```bash 115 | -lib hxjsondef 116 | ``` 117 | 118 | Example code 119 | 120 | ```haxe 121 | var str = '{ 122 | "id": 1, 123 | "name": "A green door", 124 | "price": 12.50, 125 | "tags": ["home", "green"] 126 | }'; 127 | 128 | var hxjsondef = new Hxjsondef(); 129 | hxjsondef.fileName = 'foo'; 130 | trace(hxjsondef.convert('foobar', str)); 131 | 132 | ``` 133 | 134 | 135 | 136 | ## source 137 | 138 | - 139 | - 140 | - 141 | - 142 | -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | Haxe Json def 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 46 | 47 | 48 | 49 | 50 | 51 | 52 |
53 |
54 |
55 |

HxJsonDef

56 | Hxjsondef helps you quickly define a (Haxe) typedef from some arbitrary `.json`. This is the online methode, there are more options. 57 |
58 |
59 | 60 |
61 |
62 |

Json (in)

63 |

Just copy/paste your json file here and press "Convert »"

64 |

Or use example1 / example2 to checkout how it works

65 |
66 |
67 |

AST (out)

68 |

Copy/paste Haxe class

69 |
70 |
71 | 72 |
73 |
74 |
75 | 76 |
77 |

Convert »

78 |
79 |
80 |
81 | 82 |
83 |

Select »

84 |
85 |
86 |
87 | 88 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | -------------------------------------------------------------------------------- /docs/hxjsondef.js.map: -------------------------------------------------------------------------------- 1 | { 2 | "version":3, 3 | "file":"hxjsondef.js", 4 | "sourceRoot":"file:///", 5 | "sources":["/usr/local/lib/haxe/std/js/_std/HxOverrides.hx","/Users/matthijs/Documents/workingdir/haxe/hxjsondef/src/Hxjsondef.hx","/Users/matthijs/Documents/workingdir/haxe/hxjsondef/src/MainJS.hx","/usr/local/lib/haxe/std/js/_std/Reflect.hx","/usr/local/lib/haxe/std/js/_std/Std.hx","/usr/local/lib/haxe/std/StringTools.hx","/usr/local/lib/haxe/std/js/_std/Type.hx","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AAc,OAA7B,OAAoC;AAAA,UAAO;;EAChD,EAAI,OAAM,OAAQ,eAAe,OAA7B,OAAoC;AAAA,UAAO;;EAC5E,OAAO,cAAc;;;iBAIkB,cACxC;AAAA,GAAI,sBAAa,EAAG,IAAI;AAAA,SAAO;QAC1B;AAAA,QAAM,yCAAgB,WAAW,KAAK,SAAQ,WAAW;;;4BAKxD,YAA6C;AAAA,CACnD,WAAmB,qBAAa,SAAS,EAAG;CAG5C,EAAI,SAAQ,YAAY,QAAQ,cAAc,QAAQ,UAAU,QAAQ,QACvE;AAAA,SAAO;;CACR,OAAO;;wBAID,YACN;AAAA,QAAO,0BAAkB,MAAM;;+BAIzB,eACN;AAAA,QAAe,QAAc;;;;AJ3LE,6BAA6B,AAA8D;AAC5F,kBAAkB,AAA2C;AAE7D,iBAAiB,AAA0C;AAEzD,2BAAqC,AAAoE;AAC1G,gBAA0B,CAAC;AAGzD,UAAU,AAA6E,aAAa,CAAC;AAGrG,cAAc,AAAqF,aAAa,CAAC;AAGjH,YAAY,AAAyE;AACrF,iBAAiB,CAAC;AAGlB,WAAW,AAAuE;AAClF,iBAAiB,CAAC;AAGlB,YAAY,AAAiF,aAAa,CAAC;AAG3G,WAAW;AGuDJ;iBN1IyB;oBACG;kBOiOR;;;;" 8 | } -------------------------------------------------------------------------------- /src/Hxjsondef.hx: -------------------------------------------------------------------------------- 1 | package; 2 | 3 | using StringTools; 4 | 5 | class Hxjsondef { 6 | 7 | public static var NAME : String = "HxJsonDef"; 8 | public static var VERSION : String = "0.0.8"; 9 | 10 | /** 11 | * 0.0.8 - macro 12 | * 0.0.7 - haxelib run command 13 | * 0.0.6 - @:optional fixed @optional 14 | * 0.0.5 - fixed bug with `\n` in String 15 | * 0.0.4 - loop through all arrays, chances that it will add optionals // doesn't work 16 | * 0.0.3 - external class so it works with js 17 | * 0.0.2 - fixed Array with objects 18 | * 0.0.1 - initial release 19 | */ 20 | 21 | private var str = ''; 22 | private var isComment : Bool = false; 23 | 24 | public var fileName(get_fileName, set_fileName):String; 25 | private var _fileName:String = 'foobar'; 26 | 27 | 28 | 29 | // private var isFileSet : Bool = false; 30 | 31 | // private var path:String; 32 | // private var fileName:String; 33 | 34 | private var typeDefMap : Map> = new Map>(); 35 | 36 | 37 | public function new() {} 38 | 39 | /** 40 | * convert this for js/neko 41 | * 42 | * @param name json filename 43 | * @param content json content 44 | * @return String (haxe class with typedef) 45 | */ 46 | public function convert(name:String, content:String):String 47 | { 48 | // [mck] reset defaults 49 | str = ''; 50 | typeDefMap = new Map>(); 51 | 52 | content = content.replace('\n',''); 53 | 54 | // [mck] start everything from here 55 | convert2Typedef('${capString(name)}Obj', content); 56 | 57 | // [mck] create the content for the .hx file 58 | for (key in typeDefMap.keys()) 59 | { 60 | var arr = typeDefMap.get(key); 61 | str += '\ntypedef ${key} =\n{\n'; 62 | for (i in 0 ... arr.length) { 63 | str += '${arr[i]}\n'; 64 | } 65 | 66 | str += '};\n'; 67 | } 68 | 69 | str = headerInfo() + str; 70 | 71 | return str; 72 | } 73 | 74 | function convert2Typedef(typeName:String, pjson:String) 75 | { 76 | typeDefMap.set(typeName , []); 77 | 78 | readJson(typeName, haxe.Json.parse(pjson)); 79 | } 80 | 81 | 82 | function readJson(typeName:String, pjson:Dynamic, tab:String = '\t') 83 | { 84 | // [mck] it's an array? 85 | if(pjson.length != null) 86 | { 87 | for (i in 0 ... pjson.length) { 88 | readJson(typeName,pjson[i],tab); 89 | } 90 | // readJson(typeName,pjson[0],tab); 91 | return; 92 | } 93 | 94 | for (varName in Reflect.fields(pjson)) 95 | { 96 | var store = ''; 97 | var c = ''; 98 | if(isComment) c = ' // ${varName}:${Reflect.field(pjson,varName)}'; 99 | 100 | switch (Type.typeof(Reflect.field(pjson,varName))) 101 | { 102 | 103 | case TObject: 104 | // deeper into the rabit hole 105 | store = '${tab}var ${varName} : ${capString(varName)};${c}'; 106 | convert2Typedef(capString(varName), haxe.Json.stringify(Reflect.field(pjson,varName))); 107 | 108 | case TClass(String): 109 | store = '${tab}var ${varName} : String;${c}'; 110 | 111 | case TClass(Array): 112 | // [mck] is it an Array or is it an Array? 113 | store = whatSortArray(varName,Reflect.field(pjson,varName),tab); 114 | 115 | case TInt: 116 | store = '${tab}var ${varName} : Int;${c}'; 117 | 118 | case TFloat: 119 | store = '${tab}var ${varName} : Float;${c}'; 120 | 121 | case TBool: 122 | store = '${tab}var ${varName} : Bool;${c}'; 123 | 124 | case TNull: 125 | store = '${tab}var ${varName} : Dynamic; // ${varName}:${Reflect.field(pjson,varName)} // [mck] provide json without `null` values'; 126 | 127 | // trace(Type.getClassName(Type.getClass(Reflect.field(pjson,i)))); 128 | default : 129 | // trace(">>>>>> " + Type.typeof(pjson)); 130 | // trace(">>>>>> " + (Reflect.field(pjson,i))); 131 | trace("[FIXME] type: " + Type.typeof(Reflect.field(pjson,varName)) + ' / ${varName}: ' + Reflect.field(pjson,varName)); 132 | } 133 | 134 | var arr = typeDefMap.get('${typeName}'); 135 | arr.push(store); 136 | typeDefMap.set('${typeName}' , arr); 137 | 138 | // trace(i + ":" + Reflect.field(pjson,i)); 139 | } 140 | 141 | 142 | } 143 | 144 | 145 | function whatSortArray(varName:String, value:Array, tab:String = '\t'):String 146 | { 147 | var xc = ''; 148 | var type : String = 'Dynamic'; 149 | 150 | // for (i in 0 ... value.length) { 151 | 152 | 153 | switch (Type.typeof(value[0])) 154 | { 155 | case TClass(String): 156 | type = 'String'; 157 | 158 | case TClass(Array): 159 | // I guess I find this just stupid, so won't fix for now 160 | type = 'Dynamic'; 161 | if(isComment){ 162 | xc = ' // [FIXME] (array) not sure why you would nest this deep'; 163 | } else { 164 | xc = ' // ${varName}:${value[0]} // [FIXME] (array) not sure why you would nest this deep'; 165 | } 166 | 167 | case TInt: 168 | type = 'Int'; 169 | 170 | case TFloat: 171 | type = 'Float'; 172 | 173 | case TBool: 174 | type = 'Bool'; 175 | 176 | case TNull: 177 | type = 'Dynamic'; 178 | if(isComment){ 179 | xc = ' // [mck] provide json without `null` values'; 180 | } else { 181 | xc = ' // ${varName}:${value[0]} // [mck] provide json without `null` values'; 182 | } 183 | 184 | case TObject: 185 | type = '${capString(varName)}'; 186 | convert2Typedef(capString(varName), haxe.Json.stringify(value[0])); 187 | 188 | default : 189 | trace('[FIXME] : ' + Type.typeof(value[0])); 190 | 191 | } 192 | 193 | var c = ''; 194 | if(isComment) c = ' // ${varName}:${value[0]}'; 195 | 196 | var _str = '${tab}var ${varName} : Array<$type>;${c}${xc}'; 197 | return _str; 198 | } 199 | 200 | // ____________________________________ info ____________________________________ 201 | 202 | private function headerInfo():String 203 | { 204 | var temp = ''; 205 | for (key in typeDefMap.keys()) 206 | { 207 | temp += '\n * \t\t${key}'; 208 | } 209 | 210 | var str = ''; 211 | str += 'package;'; 212 | if(!isComment){ 213 | str += 214 | '\n\n'+ 215 | '/**'+ 216 | '\n * Generated with ${NAME} (version ${VERSION}) on ' + Date.now() + 217 | '\n * from : ${fileName}' + 218 | '\n * '+ 219 | '\n * AST = Abstract Syntax Tree'+ 220 | '\n * '+ 221 | '\n * Note:'+ 222 | '\n * If you provide a .json there should be no null values'+ 223 | '\n * comments in this document show you the values that need to be changed!'+ 224 | '\n * '+ 225 | '\n * Some (backend)-developers choose to hide empty/null values, you can add them:'+ 226 | '\n * \t\t@:optional var _id : Int;'+ 227 | '\n * '+ 228 | '\n * Name(s) that you possibly need to change:'+ 229 | '$temp'+ 230 | '\n */'+ 231 | '\n'; 232 | } 233 | 234 | return str; 235 | } 236 | 237 | // ____________________________________ misc ____________________________________ 238 | 239 | private function capString(str:String):String 240 | { 241 | var tempstr = ''; 242 | tempstr = str.substring(0,1).toUpperCase() + str.substring(1,str.length); 243 | return tempstr; 244 | } 245 | 246 | // ____________________________________ getter/setter ____________________________________ 247 | 248 | function get_fileName():String { 249 | return _fileName; 250 | } 251 | function set_fileName(value:String):String { 252 | return _fileName = value; 253 | } 254 | 255 | } 256 | -------------------------------------------------------------------------------- /docs/hxjsondef.js: -------------------------------------------------------------------------------- 1 | // Generated by Haxe 3.4.2 2 | (function ($global) { "use strict"; 3 | var $estr = function() { return js_Boot.__string_rec(this,''); }; 4 | function $extend(from, fields) { 5 | function Inherit() {} Inherit.prototype = from; var proto = new Inherit(); 6 | for (var name in fields) proto[name] = fields[name]; 7 | if( fields.toString !== Object.prototype.toString ) proto.toString = fields.toString; 8 | return proto; 9 | } 10 | var HxOverrides = function() { }; 11 | HxOverrides.__name__ = true; 12 | HxOverrides.dateStr = function(date) { 13 | var m = date.getMonth() + 1; 14 | var d = date.getDate(); 15 | var h = date.getHours(); 16 | var mi = date.getMinutes(); 17 | var s = date.getSeconds(); 18 | return date.getFullYear() + "-" + (m < 10 ? "0" + m : "" + m) + "-" + (d < 10 ? "0" + d : "" + d) + " " + (h < 10 ? "0" + h : "" + h) + ":" + (mi < 10 ? "0" + mi : "" + mi) + ":" + (s < 10 ? "0" + s : "" + s); 19 | }; 20 | HxOverrides.iter = function(a) { 21 | return { cur : 0, arr : a, hasNext : function() { 22 | return this.cur < this.arr.length; 23 | }, next : function() { 24 | return this.arr[this.cur++]; 25 | }}; 26 | }; 27 | var Hxjsondef = function() { 28 | this.typeDefMap = new haxe_ds_StringMap(); 29 | this._fileName = "foobar"; 30 | this.isComment = false; 31 | this.str = ""; 32 | }; 33 | Hxjsondef.__name__ = true; 34 | Hxjsondef.prototype = { 35 | convert: function(name,content) { 36 | this.str = ""; 37 | this.typeDefMap = new haxe_ds_StringMap(); 38 | content = StringTools.replace(content,"\n",""); 39 | this.convert2Typedef("" + this.capString(name) + "Obj",content); 40 | var key = this.typeDefMap.keys(); 41 | while(key.hasNext()) { 42 | var key1 = key.next(); 43 | var _this = this.typeDefMap; 44 | var arr = __map_reserved[key1] != null ? _this.getReserved(key1) : _this.h[key1]; 45 | this.str += "\ntypedef " + key1 + " =\n{\n"; 46 | var _g1 = 0; 47 | var _g = arr.length; 48 | while(_g1 < _g) { 49 | var i = _g1++; 50 | this.str += "" + arr[i] + "\n"; 51 | } 52 | this.str += "};\n"; 53 | } 54 | this.str = this.headerInfo() + this.str; 55 | return this.str; 56 | } 57 | ,convert2Typedef: function(typeName,pjson) { 58 | var _this = this.typeDefMap; 59 | var value = []; 60 | if(__map_reserved[typeName] != null) { 61 | _this.setReserved(typeName,value); 62 | } else { 63 | _this.h[typeName] = value; 64 | } 65 | this.readJson(typeName,JSON.parse(pjson)); 66 | } 67 | ,readJson: function(typeName,pjson,tab) { 68 | if(tab == null) { 69 | tab = "\t"; 70 | } 71 | if(pjson.length != null) { 72 | var _g1 = 0; 73 | var _g = pjson.length; 74 | while(_g1 < _g) { 75 | var i = _g1++; 76 | this.readJson(typeName,pjson[i],tab); 77 | } 78 | return; 79 | } 80 | var _g2 = 0; 81 | var _g11 = Reflect.fields(pjson); 82 | while(_g2 < _g11.length) { 83 | var varName = _g11[_g2]; 84 | ++_g2; 85 | var store = ""; 86 | var c = ""; 87 | if(this.isComment) { 88 | c = " // " + varName + ":" + Std.string(Reflect.field(pjson,varName)); 89 | } 90 | var _g21 = Type["typeof"](Reflect.field(pjson,varName)); 91 | switch(_g21[1]) { 92 | case 0: 93 | store = "" + tab + "var " + varName + " : Dynamic; // " + varName + ":" + Std.string(Reflect.field(pjson,varName)) + " // [mck] provide json without `null` values"; 94 | break; 95 | case 1: 96 | store = "" + tab + "var " + varName + " : Int;" + c; 97 | break; 98 | case 2: 99 | store = "" + tab + "var " + varName + " : Float;" + c; 100 | break; 101 | case 3: 102 | store = "" + tab + "var " + varName + " : Bool;" + c; 103 | break; 104 | case 4: 105 | store = "" + tab + "var " + varName + " : " + this.capString(varName) + ";" + c; 106 | this.convert2Typedef(this.capString(varName),JSON.stringify(Reflect.field(pjson,varName))); 107 | break; 108 | case 6: 109 | switch(_g21[2]) { 110 | case Array: 111 | store = this.whatSortArray(varName,Reflect.field(pjson,varName),tab); 112 | break; 113 | case String: 114 | store = "" + tab + "var " + varName + " : String;" + c; 115 | break; 116 | default: 117 | console.log("[FIXME] type: " + Std.string(Type["typeof"](Reflect.field(pjson,varName))) + (" / " + varName + ": ") + Std.string(Reflect.field(pjson,varName))); 118 | } 119 | break; 120 | default: 121 | console.log("[FIXME] type: " + Std.string(Type["typeof"](Reflect.field(pjson,varName))) + (" / " + varName + ": ") + Std.string(Reflect.field(pjson,varName))); 122 | } 123 | var _this = this.typeDefMap; 124 | var key = "" + typeName; 125 | var arr = __map_reserved[key] != null ? _this.getReserved(key) : _this.h[key]; 126 | arr.push(store); 127 | var _this1 = this.typeDefMap; 128 | var key1 = "" + typeName; 129 | if(__map_reserved[key1] != null) { 130 | _this1.setReserved(key1,arr); 131 | } else { 132 | _this1.h[key1] = arr; 133 | } 134 | } 135 | } 136 | ,whatSortArray: function(varName,value,tab) { 137 | if(tab == null) { 138 | tab = "\t"; 139 | } 140 | var xc = ""; 141 | var type = "Dynamic"; 142 | var _g = Type["typeof"](value[0]); 143 | switch(_g[1]) { 144 | case 0: 145 | type = "Dynamic"; 146 | if(this.isComment) { 147 | xc = " // [mck] provide json without `null` values"; 148 | } else { 149 | xc = " // " + varName + ":" + Std.string(value[0]) + " // [mck] provide json without `null` values"; 150 | } 151 | break; 152 | case 1: 153 | type = "Int"; 154 | break; 155 | case 2: 156 | type = "Float"; 157 | break; 158 | case 3: 159 | type = "Bool"; 160 | break; 161 | case 4: 162 | type = "" + this.capString(varName); 163 | this.convert2Typedef(this.capString(varName),JSON.stringify(value[0])); 164 | break; 165 | case 6: 166 | switch(_g[2]) { 167 | case Array: 168 | type = "Dynamic"; 169 | if(this.isComment) { 170 | xc = " // [FIXME] (array) not sure why you would nest this deep"; 171 | } else { 172 | xc = " // " + varName + ":" + Std.string(value[0]) + " // [FIXME] (array) not sure why you would nest this deep"; 173 | } 174 | break; 175 | case String: 176 | type = "String"; 177 | break; 178 | default: 179 | console.log("[FIXME] : " + Std.string(Type["typeof"](value[0]))); 180 | } 181 | break; 182 | default: 183 | console.log("[FIXME] : " + Std.string(Type["typeof"](value[0]))); 184 | } 185 | var c = ""; 186 | if(this.isComment) { 187 | c = " // " + varName + ":" + Std.string(value[0]); 188 | } 189 | var _str = "" + tab + "var " + varName + " : Array<" + type + ">;" + c + xc; 190 | return _str; 191 | } 192 | ,headerInfo: function() { 193 | var temp = ""; 194 | var key = this.typeDefMap.keys(); 195 | while(key.hasNext()) { 196 | var key1 = key.next(); 197 | temp += "\n * \t\t" + key1; 198 | } 199 | var str = ""; 200 | str += "package;"; 201 | if(!this.isComment) { 202 | str += "\n\n" + "/**" + ("\n * Generated with " + Hxjsondef.NAME + " (version " + Hxjsondef.VERSION + ") on ") + Std.string(new Date()) + ("\n * from : " + this.get_fileName()) + "\n * " + "\n * AST = Abstract Syntax Tree" + "\n * " + "\n * Note:" + "\n * If you provide a .json there should be no null values" + "\n * comments in this document show you the values that need to be changed!" + "\n * " + "\n * Some (backend)-developers choose to hide empty/null values, you can add them:" + "\n * \t\t@:optional var _id : Int;" + "\n * " + "\n * Name(s) that you possibly need to change:" + ("" + temp) + "\n */" + "\n"; 203 | } 204 | return str; 205 | } 206 | ,capString: function(str) { 207 | var tempstr = ""; 208 | tempstr = str.substring(0,1).toUpperCase() + str.substring(1,str.length); 209 | return tempstr; 210 | } 211 | ,get_fileName: function() { 212 | return this._fileName; 213 | } 214 | ,set_fileName: function(value) { 215 | return this._fileName = value; 216 | } 217 | ,__class__: Hxjsondef 218 | }; 219 | var MainJS = function() { 220 | this.jsonExample2 = "{\n\t\"title\": \"Product\",\n\t\"description\": \"A product from Acme's catalog\",\n\t\"type\": \"object\",\n\t\"properties\": {\n\t\t\"id\": {\n\t\t\t\"description\": \"The unique identifier for a product\",\n\t\t\t\"type\": \"integer\"\n\t\t},\n\t\t\"name\": {\n\t\t\t\"description\": \"Name of the product\",\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"price\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"minimum\": 0,\n\t\t\t\"exclusiveMinimum\": true\n\t\t},\n\t\t\"tags\": {\n\t\t\t\"type\": \"array\",\n\t\t\t\"items\": {\n\t\t\t\t\"type\": \"string\"\n\t\t\t},\n\t\t\t\"minItems\": 1,\n\t\t\t\"uniqueItems\": true\n\t\t}\n\t},\n\t\"required\": [\"id\", \"name\", \"price\"]\n}"; 221 | this.jsonExample1 = "{\n\t\"id\": 1,\n\t\"name\": \"A green door\",\n\t\"price\": 12.50,\n\t\"tags\": [\"home\", \"green\"]\n}"; 222 | var _gthis = this; 223 | $(function() { 224 | $("#btn_convert").click($bind(_gthis,_gthis.onClick)); 225 | $("#btn_select").click($bind(_gthis,_gthis.onClick)); 226 | $("#example1").click($bind(_gthis,_gthis.onClick)); 227 | $("#example2").click($bind(_gthis,_gthis.onClick)); 228 | _gthis.inArea = $("#in_json"); 229 | _gthis.outArea = $("#out_hxjson"); 230 | _gthis.inTextArea = js_Boot.__cast(window.document.getElementById("in_json") , HTMLTextAreaElement); 231 | _gthis.outTextArea = js_Boot.__cast(window.document.getElementById("out_hxjson") , HTMLTextAreaElement); 232 | _gthis.hxjsondef = new Hxjsondef(); 233 | _gthis.hxjsondef.set_fileName(window.location.href); 234 | _gthis.convert(_gthis.jsonExample1); 235 | }); 236 | }; 237 | MainJS.__name__ = true; 238 | MainJS.main = function() { 239 | var app = new MainJS(); 240 | }; 241 | MainJS.prototype = { 242 | convert: function(str) { 243 | this.inArea.val(str); 244 | this.outArea.val(this.hxjsondef.convert("foobar",str)); 245 | this.outTextArea.scrollTop = this.outTextArea.scrollHeight; 246 | this.outTextArea.select(); 247 | } 248 | ,selectAll: function() { 249 | this.outTextArea.select(); 250 | } 251 | ,onClick: function(e) { 252 | var id = e.currentTarget.id; 253 | switch(id) { 254 | case "btn_convert": 255 | this.convert(this.inArea.val()); 256 | break; 257 | case "btn_select": 258 | this.selectAll(); 259 | break; 260 | case "example1": 261 | this.convert(this.jsonExample1); 262 | break; 263 | case "example2": 264 | this.convert(this.jsonExample2); 265 | break; 266 | } 267 | e.preventDefault(); 268 | } 269 | ,__class__: MainJS 270 | }; 271 | Math.__name__ = true; 272 | var Reflect = function() { }; 273 | Reflect.__name__ = true; 274 | Reflect.field = function(o,field) { 275 | try { 276 | return o[field]; 277 | } catch( e ) { 278 | return null; 279 | } 280 | }; 281 | Reflect.fields = function(o) { 282 | var a = []; 283 | if(o != null) { 284 | var hasOwnProperty = Object.prototype.hasOwnProperty; 285 | for( var f in o ) { 286 | if(f != "__id__" && f != "hx__closures__" && hasOwnProperty.call(o,f)) { 287 | a.push(f); 288 | } 289 | } 290 | } 291 | return a; 292 | }; 293 | var Std = function() { }; 294 | Std.__name__ = true; 295 | Std.string = function(s) { 296 | return js_Boot.__string_rec(s,""); 297 | }; 298 | var StringTools = function() { }; 299 | StringTools.__name__ = true; 300 | StringTools.replace = function(s,sub,by) { 301 | return s.split(sub).join(by); 302 | }; 303 | var ValueType = { __ename__ : true, __constructs__ : ["TNull","TInt","TFloat","TBool","TObject","TFunction","TClass","TEnum","TUnknown"] }; 304 | ValueType.TNull = ["TNull",0]; 305 | ValueType.TNull.toString = $estr; 306 | ValueType.TNull.__enum__ = ValueType; 307 | ValueType.TInt = ["TInt",1]; 308 | ValueType.TInt.toString = $estr; 309 | ValueType.TInt.__enum__ = ValueType; 310 | ValueType.TFloat = ["TFloat",2]; 311 | ValueType.TFloat.toString = $estr; 312 | ValueType.TFloat.__enum__ = ValueType; 313 | ValueType.TBool = ["TBool",3]; 314 | ValueType.TBool.toString = $estr; 315 | ValueType.TBool.__enum__ = ValueType; 316 | ValueType.TObject = ["TObject",4]; 317 | ValueType.TObject.toString = $estr; 318 | ValueType.TObject.__enum__ = ValueType; 319 | ValueType.TFunction = ["TFunction",5]; 320 | ValueType.TFunction.toString = $estr; 321 | ValueType.TFunction.__enum__ = ValueType; 322 | ValueType.TClass = function(c) { var $x = ["TClass",6,c]; $x.__enum__ = ValueType; $x.toString = $estr; return $x; }; 323 | ValueType.TEnum = function(e) { var $x = ["TEnum",7,e]; $x.__enum__ = ValueType; $x.toString = $estr; return $x; }; 324 | ValueType.TUnknown = ["TUnknown",8]; 325 | ValueType.TUnknown.toString = $estr; 326 | ValueType.TUnknown.__enum__ = ValueType; 327 | var Type = function() { }; 328 | Type.__name__ = true; 329 | Type["typeof"] = function(v) { 330 | var _g = typeof(v); 331 | switch(_g) { 332 | case "boolean": 333 | return ValueType.TBool; 334 | case "function": 335 | if(v.__name__ || v.__ename__) { 336 | return ValueType.TObject; 337 | } 338 | return ValueType.TFunction; 339 | case "number": 340 | if(Math.ceil(v) == v % 2147483648.0) { 341 | return ValueType.TInt; 342 | } 343 | return ValueType.TFloat; 344 | case "object": 345 | if(v == null) { 346 | return ValueType.TNull; 347 | } 348 | var e = v.__enum__; 349 | if(e != null) { 350 | return ValueType.TEnum(e); 351 | } 352 | var c = js_Boot.getClass(v); 353 | if(c != null) { 354 | return ValueType.TClass(c); 355 | } 356 | return ValueType.TObject; 357 | case "string": 358 | return ValueType.TClass(String); 359 | case "undefined": 360 | return ValueType.TNull; 361 | default: 362 | return ValueType.TUnknown; 363 | } 364 | }; 365 | var haxe_IMap = function() { }; 366 | haxe_IMap.__name__ = true; 367 | var haxe_ds_StringMap = function() { 368 | this.h = { }; 369 | }; 370 | haxe_ds_StringMap.__name__ = true; 371 | haxe_ds_StringMap.__interfaces__ = [haxe_IMap]; 372 | haxe_ds_StringMap.prototype = { 373 | setReserved: function(key,value) { 374 | if(this.rh == null) { 375 | this.rh = { }; 376 | } 377 | this.rh["$" + key] = value; 378 | } 379 | ,getReserved: function(key) { 380 | if(this.rh == null) { 381 | return null; 382 | } else { 383 | return this.rh["$" + key]; 384 | } 385 | } 386 | ,keys: function() { 387 | return HxOverrides.iter(this.arrayKeys()); 388 | } 389 | ,arrayKeys: function() { 390 | var out = []; 391 | for( var key in this.h ) { 392 | if(this.h.hasOwnProperty(key)) { 393 | out.push(key); 394 | } 395 | } 396 | if(this.rh != null) { 397 | for( var key in this.rh ) { 398 | if(key.charCodeAt(0) == 36) { 399 | out.push(key.substr(1)); 400 | } 401 | } 402 | } 403 | return out; 404 | } 405 | ,__class__: haxe_ds_StringMap 406 | }; 407 | var js__$Boot_HaxeError = function(val) { 408 | Error.call(this); 409 | this.val = val; 410 | this.message = String(val); 411 | if(Error.captureStackTrace) { 412 | Error.captureStackTrace(this,js__$Boot_HaxeError); 413 | } 414 | }; 415 | js__$Boot_HaxeError.__name__ = true; 416 | js__$Boot_HaxeError.wrap = function(val) { 417 | if((val instanceof Error)) { 418 | return val; 419 | } else { 420 | return new js__$Boot_HaxeError(val); 421 | } 422 | }; 423 | js__$Boot_HaxeError.__super__ = Error; 424 | js__$Boot_HaxeError.prototype = $extend(Error.prototype,{ 425 | __class__: js__$Boot_HaxeError 426 | }); 427 | var js_Boot = function() { }; 428 | js_Boot.__name__ = true; 429 | js_Boot.getClass = function(o) { 430 | if((o instanceof Array) && o.__enum__ == null) { 431 | return Array; 432 | } else { 433 | var cl = o.__class__; 434 | if(cl != null) { 435 | return cl; 436 | } 437 | var name = js_Boot.__nativeClassName(o); 438 | if(name != null) { 439 | return js_Boot.__resolveNativeClass(name); 440 | } 441 | return null; 442 | } 443 | }; 444 | js_Boot.__string_rec = function(o,s) { 445 | if(o == null) { 446 | return "null"; 447 | } 448 | if(s.length >= 5) { 449 | return "<...>"; 450 | } 451 | var t = typeof(o); 452 | if(t == "function" && (o.__name__ || o.__ename__)) { 453 | t = "object"; 454 | } 455 | switch(t) { 456 | case "function": 457 | return ""; 458 | case "object": 459 | if(o instanceof Array) { 460 | if(o.__enum__) { 461 | if(o.length == 2) { 462 | return o[0]; 463 | } 464 | var str = o[0] + "("; 465 | s += "\t"; 466 | var _g1 = 2; 467 | var _g = o.length; 468 | while(_g1 < _g) { 469 | var i = _g1++; 470 | if(i != 2) { 471 | str += "," + js_Boot.__string_rec(o[i],s); 472 | } else { 473 | str += js_Boot.__string_rec(o[i],s); 474 | } 475 | } 476 | return str + ")"; 477 | } 478 | var l = o.length; 479 | var i1; 480 | var str1 = "["; 481 | s += "\t"; 482 | var _g11 = 0; 483 | var _g2 = l; 484 | while(_g11 < _g2) { 485 | var i2 = _g11++; 486 | str1 += (i2 > 0 ? "," : "") + js_Boot.__string_rec(o[i2],s); 487 | } 488 | str1 += "]"; 489 | return str1; 490 | } 491 | var tostr; 492 | try { 493 | tostr = o.toString; 494 | } catch( e ) { 495 | return "???"; 496 | } 497 | if(tostr != null && tostr != Object.toString && typeof(tostr) == "function") { 498 | var s2 = o.toString(); 499 | if(s2 != "[object Object]") { 500 | return s2; 501 | } 502 | } 503 | var k = null; 504 | var str2 = "{\n"; 505 | s += "\t"; 506 | var hasp = o.hasOwnProperty != null; 507 | for( var k in o ) { 508 | if(hasp && !o.hasOwnProperty(k)) { 509 | continue; 510 | } 511 | if(k == "prototype" || k == "__class__" || k == "__super__" || k == "__interfaces__" || k == "__properties__") { 512 | continue; 513 | } 514 | if(str2.length != 2) { 515 | str2 += ", \n"; 516 | } 517 | str2 += s + k + " : " + js_Boot.__string_rec(o[k],s); 518 | } 519 | s = s.substring(1); 520 | str2 += "\n" + s + "}"; 521 | return str2; 522 | case "string": 523 | return o; 524 | default: 525 | return String(o); 526 | } 527 | }; 528 | js_Boot.__interfLoop = function(cc,cl) { 529 | if(cc == null) { 530 | return false; 531 | } 532 | if(cc == cl) { 533 | return true; 534 | } 535 | var intf = cc.__interfaces__; 536 | if(intf != null) { 537 | var _g1 = 0; 538 | var _g = intf.length; 539 | while(_g1 < _g) { 540 | var i = _g1++; 541 | var i1 = intf[i]; 542 | if(i1 == cl || js_Boot.__interfLoop(i1,cl)) { 543 | return true; 544 | } 545 | } 546 | } 547 | return js_Boot.__interfLoop(cc.__super__,cl); 548 | }; 549 | js_Boot.__instanceof = function(o,cl) { 550 | if(cl == null) { 551 | return false; 552 | } 553 | switch(cl) { 554 | case Array: 555 | if((o instanceof Array)) { 556 | return o.__enum__ == null; 557 | } else { 558 | return false; 559 | } 560 | break; 561 | case Bool: 562 | return typeof(o) == "boolean"; 563 | case Dynamic: 564 | return true; 565 | case Float: 566 | return typeof(o) == "number"; 567 | case Int: 568 | if(typeof(o) == "number") { 569 | return (o|0) === o; 570 | } else { 571 | return false; 572 | } 573 | break; 574 | case String: 575 | return typeof(o) == "string"; 576 | default: 577 | if(o != null) { 578 | if(typeof(cl) == "function") { 579 | if(o instanceof cl) { 580 | return true; 581 | } 582 | if(js_Boot.__interfLoop(js_Boot.getClass(o),cl)) { 583 | return true; 584 | } 585 | } else if(typeof(cl) == "object" && js_Boot.__isNativeObj(cl)) { 586 | if(o instanceof cl) { 587 | return true; 588 | } 589 | } 590 | } else { 591 | return false; 592 | } 593 | if(cl == Class ? o.__name__ != null : false) { 594 | return true; 595 | } 596 | if(cl == Enum ? o.__ename__ != null : false) { 597 | return true; 598 | } 599 | return o.__enum__ == cl; 600 | } 601 | }; 602 | js_Boot.__cast = function(o,t) { 603 | if(js_Boot.__instanceof(o,t)) { 604 | return o; 605 | } else { 606 | throw new js__$Boot_HaxeError("Cannot cast " + Std.string(o) + " to " + Std.string(t)); 607 | } 608 | }; 609 | js_Boot.__nativeClassName = function(o) { 610 | var name = js_Boot.__toStr.call(o).slice(8,-1); 611 | if(name == "Object" || name == "Function" || name == "Math" || name == "JSON") { 612 | return null; 613 | } 614 | return name; 615 | }; 616 | js_Boot.__isNativeObj = function(o) { 617 | return js_Boot.__nativeClassName(o) != null; 618 | }; 619 | js_Boot.__resolveNativeClass = function(name) { 620 | return $global[name]; 621 | }; 622 | var $_, $fid = 0; 623 | function $bind(o,m) { if( m == null ) return null; if( m.__id__ == null ) m.__id__ = $fid++; var f; if( o.hx__closures__ == null ) o.hx__closures__ = {}; else f = o.hx__closures__[m.__id__]; if( f == null ) { f = function(){ return f.method.apply(f.scope, arguments); }; f.scope = o; f.method = m; o.hx__closures__[m.__id__] = f; } return f; } 624 | String.prototype.__class__ = String; 625 | String.__name__ = true; 626 | Array.__name__ = true; 627 | Date.prototype.__class__ = Date; 628 | Date.__name__ = ["Date"]; 629 | var Int = { __name__ : ["Int"]}; 630 | var Dynamic = { __name__ : ["Dynamic"]}; 631 | var Float = Number; 632 | Float.__name__ = ["Float"]; 633 | var Bool = Boolean; 634 | Bool.__ename__ = ["Bool"]; 635 | var Class = { __name__ : ["Class"]}; 636 | var Enum = { }; 637 | var __map_reserved = {} 638 | Hxjsondef.NAME = "HxJsonDef"; 639 | Hxjsondef.VERSION = "0.0.8"; 640 | js_Boot.__toStr = ({ }).toString; 641 | MainJS.main(); 642 | })(typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : this); 643 | 644 | //# sourceMappingURL=hxjsondef.js.map --------------------------------------------------------------------------------