json2dart-generator 0.3.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/core/json2dart.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ json2dart options
|
|
|
18
18
|
Options:
|
|
19
19
|
-d, --dir <dir> json文件夹路径,默认 .json_models/
|
|
20
20
|
-o, --output <dir> dart模型输出路径,默认 lib/models
|
|
21
|
-
-s, --suffix <value> 自定义dart
|
|
21
|
+
-s, --suffix <value> 自定义dart模型类名后缀,如 Entity、Model
|
|
22
22
|
-e, --excludes <value...> 需要排除的文件或文件夹,可指定多个文件
|
|
23
23
|
--numparse 使用num数据类型而不是double/int
|
|
24
24
|
--nullsafety 是否启用空安全
|
|
@@ -38,7 +38,7 @@ json2dart --help
|
|
|
38
38
|
- 执行命令
|
|
39
39
|
|
|
40
40
|
```bash
|
|
41
|
-
json2dart --dir .json_models -o lib/models --nullsafety
|
|
41
|
+
json2dart --dir .json_models -o lib/models --nullsafety --numparse
|
|
42
42
|
```
|
|
43
43
|
|
|
44
44
|
### 示例
|
package/dist/core/json2dart.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';
|
|
1
|
+
'use strict';function a0_0x4273(_0x4fd6cb,_0x1a5bd6){_0x4fd6cb=_0x4fd6cb-0x71;const _0x589c04=a0_0x589c();let _0x42732a=_0x589c04[_0x4fd6cb];return _0x42732a;}const a0_0x1b54f5=a0_0x4273;(function(_0x23cfac,_0x367126){const _0x5e411c=a0_0x4273,_0x5905f5=_0x23cfac();while(!![]){try{const _0x20dca4=-parseInt(_0x5e411c(0xba))/0x1+-parseInt(_0x5e411c(0xc1))/0x2*(parseInt(_0x5e411c(0x91))/0x3)+-parseInt(_0x5e411c(0x9b))/0x4*(parseInt(_0x5e411c(0x71))/0x5)+-parseInt(_0x5e411c(0xa1))/0x6+parseInt(_0x5e411c(0xc3))/0x7+parseInt(_0x5e411c(0x84))/0x8+-parseInt(_0x5e411c(0x78))/0x9*(-parseInt(_0x5e411c(0x72))/0xa);if(_0x20dca4===_0x367126)break;else _0x5905f5['push'](_0x5905f5['shift']());}catch(_0x2cdeb4){_0x5905f5['push'](_0x5905f5['shift']());}}}(a0_0x589c,0x4f867));Object[a0_0x1b54f5(0xc0)](exports,a0_0x1b54f5(0xb9),{'value':!![]}),exports['jsonToDart']=jsonToDart;const js_utils_plus_1=require('js-utils-plus');function modelTypeGenerator(_0x2d49da,_0x40a366,_0x437695,_0x2913f6,_0x3bb484){const _0xf591e0=a0_0x1b54f5;if((0x0,js_utils_plus_1['isBoolean'])(_0x2d49da))return{'type':_0xf591e0(0x85),'typeTo':_0x13b2c3=>_0x13b2c3,'typeFrom':_0x224cfd=>_0x224cfd+_0xf591e0(0x94)};if((0x0,js_utils_plus_1[_0xf591e0(0x97)])(_0x2d49da))return{'type':'String','typeTo':_0x3142d5=>_0x3142d5,'typeFrom':_0x367e1d=>_0x367e1d+_0xf591e0(0x7e)};if((0x0,js_utils_plus_1[_0xf591e0(0xc4)])(_0x2d49da)){if(_0x3bb484)return{'type':'num','typeTo':_0x853f90=>_0x853f90,'typeFrom':_0x869324=>_0xf591e0(0xb3)+_0x869324+_0xf591e0(0xbf)};return(0x0,js_utils_plus_1[_0xf591e0(0xaa)])(_0x2d49da)?{'type':_0xf591e0(0xac),'typeTo':_0x1419e2=>_0x1419e2,'typeFrom':_0x312801=>_0xf591e0(0x79)+_0x312801+_0xf591e0(0xbf)}:{'type':_0xf591e0(0x99),'typeTo':_0x13e814=>_0x13e814,'typeFrom':_0x3ccfc4=>_0xf591e0(0xb7)+_0x3ccfc4+'?.toString()\x20??\x20\x27\x27)'};}if((0x0,js_utils_plus_1['isObject'])(_0x2d49da))return{'type':''+_0x40a366+_0x437695,'typeTo':_0x25840d=>_0x25840d+'?.toJson()','typeFrom':_0x5e7ced=>''+_0x40a366+_0x437695+_0xf591e0(0x9a)+_0x5e7ced+'\x20as\x20Map<String,\x20dynamic>?)','subLines':jsonToDart(_0x2d49da,_0x40a366,_0x437695,_0x2913f6,_0x3bb484)};if((0x0,js_utils_plus_1['isArray'])(_0x2d49da)){const _0x1be063=_0x2d49da[0x0];if(!_0x1be063)console[_0xf591e0(0xa2)]('-\x20警告!:'+_0x40a366+_0x437695+_0xf591e0(0x9f));const {type:_0xec6a6,typeTo:_0x18d164,typeFrom:_0x490bde,subLines:_0x2f5be8}=modelTypeGenerator(_0x1be063||'',_0x40a366,_0x437695,_0x2913f6,_0x3bb484);return{'type':'List<'+_0xec6a6+(_0x2913f6?'?':'')+'>','typeTo':_0x5dee11=>_0x5dee11+_0xf591e0(0x83)+_0x18d164('e')+_0xf591e0(0xbe),'typeFrom':_0x49cae6=>'('+_0x49cae6+_0xf591e0(0xad)+_0x490bde('e')+_0xf591e0(0xbe),'subLines':_0x2f5be8};}return console[_0xf591e0(0xa2)](_0xf591e0(0x90)+_0x40a366+_0x437695+_0xf591e0(0x9f)),{'type':_0xf591e0(0xb2),'typeTo':_0x47da7f=>_0x47da7f,'typeFrom':_0x507567=>_0x507567+_0xf591e0(0x7e)};}function modelKeywordDefence(_0x30f615){const _0x4447fb=a0_0x1b54f5;let _0x408d43=['num',_0x4447fb(0x99),'int','String','bool',_0x4447fb(0x87),_0x4447fb(0x9d),_0x4447fb(0x76),'implements',_0x4447fb(0x8d),'as','else','import',_0x4447fb(0x9e),'assert',_0x4447fb(0x98),'in',_0x4447fb(0x73),'async',_0x4447fb(0xb8),_0x4447fb(0x95),_0x4447fb(0xb1),_0x4447fb(0x86),_0x4447fb(0xc5),'is',_0x4447fb(0xa9),_0x4447fb(0x92),'external',_0x4447fb(0xa8),_0x4447fb(0x7f),_0x4447fb(0xa5),_0x4447fb(0xbb),'mixin',_0x4447fb(0xae),_0x4447fb(0xa4),'false',_0x4447fb(0x8a),_0x4447fb(0xbc),'class',_0x4447fb(0x7b),'null','try',_0x4447fb(0x89),'finally','on',_0x4447fb(0xab),'continue',_0x4447fb(0xc6),_0x4447fb(0x93),_0x4447fb(0x9c),_0x4447fb(0x8e),'Function',_0x4447fb(0xa7),_0x4447fb(0x96),_0x4447fb(0x8f),_0x4447fb(0xb5),_0x4447fb(0x81),'while','deferred',_0x4447fb(0x88),_0x4447fb(0x7d),_0x4447fb(0x7a),'do','if','set',_0x4447fb(0x74)];if(_0x408d43[_0x4447fb(0xb4)](_0x30f615)||/^\d/[_0x4447fb(0xaf)](_0x30f615))return'the'+(0x0,js_utils_plus_1[_0x4447fb(0xc2)])(_0x30f615);return(0x0,js_utils_plus_1['snakeToCamel'])(_0x30f615);}function jsonToDart(_0x41109e,_0x1ca3c9,_0xf6d690,_0x1bd2b8,_0x3b1137){const _0x142ff6=a0_0x1b54f5;_0x1ca3c9=(0x0,js_utils_plus_1[_0x142ff6(0xc2)])((0x0,js_utils_plus_1[_0x142ff6(0x8b)])(_0x1ca3c9));let _0x500a04=[],_0x331ce7=[],_0x229af0=[],_0x1dd6ab=[],_0x4b9508=[],_0x1a9a5e=[];_0x500a04[_0x142ff6(0x8c)]('class\x20'+_0x1ca3c9+_0xf6d690+'\x20{'),_0x229af0[_0x142ff6(0x8c)]('\x20\x20'+_0x1ca3c9+_0xf6d690+_0x142ff6(0xa0)),_0x1dd6ab['push']('\x20\x20'+_0x1ca3c9+_0xf6d690+'.fromJson(Map<String,\x20dynamic>?\x20json)\x20{\x0a'),_0x4b9508[_0x142ff6(0x8c)](_0x142ff6(0xb6));for(const [_0x1f83b8,_0x29fb89]of Object[_0x142ff6(0x80)](_0x41109e)){let _0x14c528='\x27'+_0x1f83b8+'\x27',_0x57b0c3=modelKeywordDefence(_0x1f83b8);const _0xb1efaf=(0x0,js_utils_plus_1['uppercaseFirst'])((0x0,js_utils_plus_1[_0x142ff6(0x8b)])(_0x1f83b8)),{type:_0x1e836c,typeTo:_0x1acfb9,typeFrom:_0x47db02,subLines:_0x5a11b7}=modelTypeGenerator(_0x29fb89,_0xb1efaf,_0xf6d690,_0x1bd2b8,_0x3b1137);if(_0x5a11b7)_0x1a9a5e['push'](_0x5a11b7);_0x229af0['push'](_0x142ff6(0xb0)+_0x57b0c3+',\x0a'),_0x331ce7[_0x142ff6(0x8c)]('\x20\x20'+_0x1e836c+(_0x1bd2b8?'?':'')+'\x20'+_0x57b0c3+';\x0a'),_0x1dd6ab[_0x142ff6(0x8c)]('\x20\x20\x20\x20'+_0x57b0c3+_0x142ff6(0x7c)+_0x47db02(_0x142ff6(0xa3)+_0x14c528+']')+';\x0a'),_0x4b9508[_0x142ff6(0x8c)](_0x142ff6(0x82)+_0x14c528+':\x20'+_0x1acfb9(_0x57b0c3)+',\x0a');}return _0x229af0[_0x142ff6(0x8c)](_0x142ff6(0x77)),_0x1dd6ab['push'](_0x142ff6(0xbd)),_0x4b9508[_0x142ff6(0x8c)](_0x142ff6(0x75)),_0x500a04[_0x142ff6(0x8c)](_0x331ce7[_0x142ff6(0xa6)]('')),_0x500a04[_0x142ff6(0x8c)](_0x229af0[_0x142ff6(0xa6)]('')),_0x500a04[_0x142ff6(0x8c)](_0x1dd6ab[_0x142ff6(0xa6)]('')),_0x500a04[_0x142ff6(0x8c)](_0x4b9508[_0x142ff6(0xa6)]('')),_0x500a04[_0x142ff6(0x8c)]('}\x0a'),_0x500a04[_0x142ff6(0x8c)](_0x1a9a5e[_0x142ff6(0xa6)]('')),_0x500a04[_0x142ff6(0xa6)]('\x0d\x0a');}function a0_0x589c(){const _0x2ac214=[').toList()','?.toString()\x20??\x20\x27\x27)','defineProperty','4226JYOwen','uppercaseFirst','2471917FqsUli','isNumber','extends','for','72495Xjpnno','1130GGWOuS','super','yield','\x20\x20\x20\x20\x20\x20};','dynamic','\x20\x20});','91521zfdgqI','int.tryParse(','with','final','\x20=\x20','return','?.toString()','this','entries','rethrow','\x20\x20\x20\x20\x20\x20\x20\x20','?.map((e)\x20=>\x20','1823464ZGnFWP','bool','await','List','hide','const','new','snakeToCamel','push','show','covariant','default','-\x20警告!:','762czFIcW','break','operator','\x20as\x20bool?','interface','void','isString','enum','double','.fromJson(','148eoJpdI','var','abstract','static','\x20类包含值为\x22空\x22的属性,将被默认视为”String“类型','({\x0a','1791282qidHmI','log','json?[','catch','case','join','part','library','sync','isInt','typedef','int','\x20as\x20List<dynamic>?)?.map((e)\x20=>\x20','throw','test','\x20\x20\x20\x20this.','switch','String','num.tryParse(','includes','get','\x20\x20Map<String,\x20dynamic>\x20toJson()\x20=>\x20{\x0a','double.tryParse(','export','__esModule','32714RXbcEJ','factory','true','\x20\x20}'];a0_0x589c=function(){return _0x2ac214;};return a0_0x589c();}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#! /usr/bin/env node
|
|
2
|
-
'use strict';const
|
|
2
|
+
'use strict';const a1_0x49cde8=a1_0x40e5;(function(_0x427424,_0x11e1b7){const _0x311bec=a1_0x40e5,_0x2504ab=_0x427424();while(!![]){try{const _0x3803aa=-parseInt(_0x311bec(0x15a))/0x1+-parseInt(_0x311bec(0x182))/0x2+-parseInt(_0x311bec(0x15f))/0x3*(parseInt(_0x311bec(0x15d))/0x4)+parseInt(_0x311bec(0x184))/0x5*(-parseInt(_0x311bec(0x169))/0x6)+parseInt(_0x311bec(0x16d))/0x7+-parseInt(_0x311bec(0x164))/0x8*(-parseInt(_0x311bec(0x166))/0x9)+parseInt(_0x311bec(0x177))/0xa*(parseInt(_0x311bec(0x16e))/0xb);if(_0x3803aa===_0x11e1b7)break;else _0x2504ab['push'](_0x2504ab['shift']());}catch(_0x22006f){_0x2504ab['push'](_0x2504ab['shift']());}}}(a1_0x3cc7,0x57d4f));function a1_0x40e5(_0x5210a5,_0x2b027f){_0x5210a5=_0x5210a5-0x159;const _0x3cc772=a1_0x3cc7();let _0x40e501=_0x3cc772[_0x5210a5];return _0x40e501;}var __importDefault=this&&this[a1_0x49cde8(0x179)]||function(_0x1f241e){const _0x1d25a6=a1_0x49cde8;return _0x1f241e&&_0x1f241e[_0x1d25a6(0x176)]?_0x1f241e:{'default':_0x1f241e};};Object[a1_0x49cde8(0x181)](exports,a1_0x49cde8(0x176),{'value':!![]});const json2dart_1=require(a1_0x49cde8(0x160)),js_utils_plus_1=require(a1_0x49cde8(0x15b)),commander_1=require('commander'),path_1=__importDefault(require(a1_0x49cde8(0x17c))),program=new commander_1[(a1_0x49cde8(0x167))](),_path=process['cwd']();function a1_0x3cc7(){const _0x22797f=['--nullsafety','9qSKedX','Command','dart模型输出路径,默认\x20lib/models','612642GxxGLo','-o,\x20--output\x20<dir>','numparse','-d,\x20--dir\x20<dir>','5016956NDbJwi','5196312nmpLPr','-e,\x20--excludes\x20<value...>','lib/models','--numparse','dir','jsonToDart','-\x20执行文件:','log','__esModule','10RPumFO','使用num数据类型而不是double/int','__importDefault','.json_models/','assign','path','json','error','option','listFilesRecursively','defineProperty','683326GUZjpL','-s,\x20--suffix\x20<value>','5iaBUXQ','name','excludes','658577ERURNT','js-utils-plus','__className','808ooOKrU','join','3477llSpmp','./core/json2dart','自定义dart模型类名后缀,\x20如\x20Entity、Model','json文件夹路径,默认\x20.json_models/','default','4056992HzvGxH'];a1_0x3cc7=function(){return _0x22797f;};return a1_0x3cc7();}program[a1_0x49cde8(0x17f)](a1_0x49cde8(0x16c),a1_0x49cde8(0x162))[a1_0x49cde8(0x17f)](a1_0x49cde8(0x16a),a1_0x49cde8(0x168))[a1_0x49cde8(0x17f)](a1_0x49cde8(0x183),a1_0x49cde8(0x161))[a1_0x49cde8(0x17f)](a1_0x49cde8(0x16f),'需要排除的文件或文件夹,可指定多个文件')[a1_0x49cde8(0x17f)](a1_0x49cde8(0x171),a1_0x49cde8(0x178))[a1_0x49cde8(0x17f)](a1_0x49cde8(0x165),'是否启用空安全'),program['parse']();const options=Object[a1_0x49cde8(0x17b)]({'dir':a1_0x49cde8(0x17a),'output':a1_0x49cde8(0x170),'suffix':''},program['opts']());function run(){const _0x296899=a1_0x49cde8,_0x4eb52a=path_1[_0x296899(0x163)][_0x296899(0x15e)](_path,options[_0x296899(0x172)]),_0x4f26ea=(0x0,js_utils_plus_1[_0x296899(0x180)])(_0x4eb52a,_0x296899(0x17d),options[_0x296899(0x159)]||[]);console[_0x296899(0x175)](new Array(0x50)[_0x296899(0x15e)]('-')),_0x4f26ea['forEach'](function(_0x5d5bb7){const _0xe5fcae=_0x296899,_0x57e0c2=(0x0,js_utils_plus_1['readFileSync'])(_0x5d5bb7,!![]);if(!_0x57e0c2){console[_0xe5fcae(0x17e)](_0xe5fcae(0x174)+_0x5d5bb7);return;}console[_0xe5fcae(0x175)]('-\x20执行文件:'+_0x5d5bb7);const _0x17369e=path_1[_0xe5fcae(0x163)]['parse'](_0x5d5bb7);let _0x530d97=_0x57e0c2[_0xe5fcae(0x15c)]||_0x17369e[_0xe5fcae(0x185)];if(_0x57e0c2[_0xe5fcae(0x15c)])delete _0x57e0c2['__className'];const _0x440dfa=(0x0,json2dart_1[_0xe5fcae(0x173)])(_0x57e0c2,_0x530d97,options['suffix'],options['nullsafety'],options[_0xe5fcae(0x16b)]),_0x4cce66=path_1['default'][_0xe5fcae(0x15e)](_path,options['output'],_0x17369e[_0xe5fcae(0x185)]+'.dart');(0x0,js_utils_plus_1['writeFileSync'])(_0x4cce66,_0x440dfa);});}run();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "json2dart-generator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "JSON 转 Dart Model 类构建工具",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
10
|
"dev": "tsc -w",
|
|
11
|
-
"test": "tsc && node dist/index.js -d ./.json_models -o ./models --nullsafety
|
|
11
|
+
"test": "tsc && node dist/index.js -d ./.json_models -o ./models --nullsafety",
|
|
12
12
|
"build": "rimraf dist && tsc && javascript-obfuscator dist --output dist"
|
|
13
13
|
},
|
|
14
14
|
"author": "evan.lin",
|