3 | {{ line }} 4 | 5 | 6 | {{ name }}: 7 | {{ value }} 8 | {{ needComma ? ',' : '' }} 9 | 10 |
11 | 12 | 36 | -------------------------------------------------------------------------------- /src/tree.vue: -------------------------------------------------------------------------------- 1 | 2 |8 | {{ line }} 9 | 10 | 11 | {{ name }}: 12 | {{ isArray(type) ? '[' : '{' }} 13 | 14 | {{ isArray(type) ? '...]' : '...}' }}{{ needComma ? ',' : '' }} 17 |
18 |40 | {{ lastLine }} 41 | 42 | {{ isArray(type) ? ']' : '}' }}{{ needComma ? ',' : '' }} 45 |
46 |3 |18 | 19 | 20 | 52 | 53 | 218 | -------------------------------------------------------------------------------- /src/utils.js: -------------------------------------------------------------------------------- 1 | const isArray = (item) => { 2 | if (item === 'array') { 3 | return true; 4 | } 5 | return Object.prototype.toString.call(item) === '[object Array]'; 6 | }; 7 | 8 | const isObject = (item) => { 9 | return Object.prototype.toString.call(item) === '[object Object]'; 10 | }; 11 | 12 | const needFormat = (type) => { 13 | return type === 'array' || type === 'object'; 14 | }; 15 | 16 | const getIndent = (level) => { 17 | if (level === 1) { 18 | return { textIndent: '20px' }; 19 | } 20 | return { textIndent: `${level * 20}px` }; 21 | }; 22 | 23 | const getType = (item) => { 24 | let t = Object.prototype.toString.call(item); 25 | let match = /(?!\[).+(?=\])/g; 26 | t = t.match(match)[0].split(' ')[1]; 27 | return t.toLowerCase(); 28 | }; 29 | 30 | const isComplexType = (param) => { 31 | return isObject(param) || isArray(param); 32 | }; 33 | 34 | const isTheSametype = (a, b) => { 35 | return ( 36 | Object.prototype.toString.call(a) === Object.prototype.toString.call(b) 37 | ); 38 | }; 39 | 40 | const mergeData = (_old, _new) => { 41 | // finally result 42 | let result = []; 43 | // each line No. 44 | let start = 1; 45 | 46 | // convert array or object to Array{{isArray(newData) ? '[' : '{'}}
4 |16 | {{isArray(newData) ? ']' : '}'}}
17 |