|
@@ -11,7 +11,8 @@
|
|
|
|
|
|
|
|
(function() {
|
|
(function() {
|
|
|
'use strict';
|
|
'use strict';
|
|
|
- const convertType = (type) => {
|
|
|
|
|
|
|
+ const makeClassName = s => s?.replace(/(?:_|^)([a-z])/g, g => g.substring(g.length - 1).toUpperCase()) || ''
|
|
|
|
|
+ const convertType = (type, name) => {
|
|
|
const isList = type.endsWith('[]')
|
|
const isList = type.endsWith('[]')
|
|
|
if (isList) type = type.substring(0, type.length - 2)
|
|
if (isList) type = type.substring(0, type.length - 2)
|
|
|
switch (type.toLowerCase()) {
|
|
switch (type.toLowerCase()) {
|
|
@@ -24,7 +25,7 @@
|
|
|
case 'boolean': type = 'Boolean'; break
|
|
case 'boolean': type = 'Boolean'; break
|
|
|
case 'string': type = 'String'; break
|
|
case 'string': type = 'String'; break
|
|
|
case 'json':
|
|
case 'json':
|
|
|
- case 'object': type = 'Object'; break
|
|
|
|
|
|
|
+ case 'object': type = makeClassName(name) || 'Object'; break
|
|
|
}
|
|
}
|
|
|
if (isList) type = `List<${type}>`
|
|
if (isList) type = `List<${type}>`
|
|
|
return type
|
|
return type
|
|
@@ -34,7 +35,7 @@
|
|
|
for (const node of childNodes) {
|
|
for (const node of childNodes) {
|
|
|
if (node.nodeType === Node.TEXT_NODE) {
|
|
if (node.nodeType === Node.TEXT_NODE) {
|
|
|
const text = node.textContent.trim()
|
|
const text = node.textContent.trim()
|
|
|
- if (text) return text
|
|
|
|
|
|
|
+ if (text) return text.replace(/\n/g, '')
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -44,7 +45,7 @@
|
|
|
const optional = tds[0].querySelector('span.tag')?.innerText?.trim() !== '必填'
|
|
const optional = tds[0].querySelector('span.tag')?.innerText?.trim() !== '必填'
|
|
|
const type = tds[1].innerText.trim()
|
|
const type = tds[1].innerText.trim()
|
|
|
const comment = tds[2].innerText.trim()
|
|
const comment = tds[2].innerText.trim()
|
|
|
- return ` val ${name.replace(/\n/g, '')}: ${convertType(type)}${optional ? '? = null' : ''}, // ${comment.replace(/\n/g, ' ')}\n`
|
|
|
|
|
|
|
+ return ` val ${name}: ${convertType(type, name)}${optional ? '? = null' : ''}, // ${comment.replace(/\n/g, ' ')}\n`
|
|
|
}
|
|
}
|
|
|
const parseEnumRow = (tds) => {
|
|
const parseEnumRow = (tds) => {
|
|
|
const name = parseName(tds[0].querySelector('div')?.childNodes)
|
|
const name = parseName(tds[0].querySelector('div')?.childNodes)
|