Skip to content

Commit fa33c63

Browse files
authored
Merge pull request #30 from koalaylj/dev
bugfix:d.ts format error.
2 parents 509bf04 + f48d300 commit fa33c63

File tree

6 files changed

+15
-18
lines changed

6 files changed

+15
-18
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# nodejs
1+
# nodejs
22
package-lock.json
33
json/
4-
node_modules/
4+
node_modules/

.jshintignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
node_modules/**
1+
node_modules/**

.travis.yml

Lines changed: 0 additions & 3 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
* feature: sheet名字以`!`开头则不导出此表。
88
* feature: 列名字以`!`开头则不导出此列。
99
* feature: 对象列支持对象嵌套,写法和JS中对象写法一致。
10-
* modify: 去掉对象数组列类型,统一为数组。
1110
* feature: 数组可嵌套数组和对象,和JS中数组写法一致(除了最外层不需要写中括号[])。
1211
* fix: 去掉自定义数组分隔符。
1312
* fix: excel单元格空的时候json中无此列的key。
13+
* modify: 去掉对象数组列类型,统一为数组。
1414
* modify: 去掉无用依赖,更新依赖库,精简代码。
1515

1616
### 分支

lib/xlsx-to-json.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ const DataType = {
6161
BOOL: 'bool',
6262
DATE: 'date',
6363
ID: 'id',
64-
ARRAY: '[]',
65-
OBJECT: '{}',
64+
ARRAY: 'array',
65+
OBJECT: 'object',
6666
UNKOWN: 'unkown'
6767
};
6868

@@ -119,6 +119,9 @@ function formatDTS(name, head) {
119119
let className = name.substring(0, 1).toUpperCase() + name.substring(1);
120120
let strHead = "interface " + className + "Template {\r\n";
121121
for (let i = 0; i < head.names.length; ++i) {
122+
if (head.names[i].startsWith('!')) {
123+
continue;
124+
}
122125
let typesDes = "any";
123126
switch (head.types[i]) {
124127
case DataType.NUMBER:
@@ -328,10 +331,15 @@ function parseRow(row, rowIndex, head) {
328331
result[name] = toBoolean(cell);
329332
break;
330333
case DataType.OBJECT:
334+
case '{}':
331335
result[name] = parseJsonObject(cell);
332336
break;
333337
case DataType.ARRAY:
334-
result[name] = parseJsonObject(`[${cell}]`);
338+
case '[]':
339+
if (!cell.startsWith('[')) {
340+
cell = `[${cell}]`;
341+
}
342+
result[name] = parseJsonObject(cell);
335343
break;
336344
default:
337345
console.log('无法识别的类型:', '[' + rowIndex + ',' + index + ']', cell, typeof (cell));

test/test.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)