Skip to content

Commit

Permalink
Improving the non-standard naming warning.
Browse files Browse the repository at this point in the history
  • Loading branch information
jobyrao committed Aug 14, 2019
1 parent e9f3b47 commit 07b0cc7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
.nyc_output/
node_modules/
test/assets/debug.js
test/assets/debug.json
package-lock.json
27 changes: 15 additions & 12 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class XLSX2JSON {
// 自定义解析后的缓存
this.parse2jsonDataCache = [];
// 解析过程,记录一些覆盖赋值的情况。
this.parse2jsonCover = [];
this.parse2jsonCover = new Set();
}
/**
* Rotate each'sheet'structure. Fill in the blank'cell'
Expand Down Expand Up @@ -118,7 +118,7 @@ class XLSX2JSON {
}
return keyPartDescription;
}
createJsonEnumCol(columnObject, key, value, colIndex) {
createJsonEnumCol(columnObject, key, value, colIndex, rowIndex, sheetIndex) {
if (key === '') return ;
if (typeof key !== 'object') {
key = key.split('.');
Expand All @@ -136,7 +136,7 @@ class XLSX2JSON {
let requireSheetResult = this.parsedXlsxData[requireSheetIndex].data;

requireSheetResult = this.convertProcess(requireSheetResult, requireSheetIndex)[colIndex];
return this.createJsonEnumCol(columnObject, keyPart, requireSheetResult, colIndex);
return this.createJsonEnumCol(columnObject, keyPart, requireSheetResult, colIndex, rowIndex, requireSheetIndex);
}
const keyFirstPartDesc = this.analysisAttrDesc(keyPart);
const keyPartIsArr = keyFirstPartDesc[0];
Expand All @@ -148,32 +148,32 @@ class XLSX2JSON {
if (columnObject[keyPartKeyName] === undefined) {
columnObject[keyPartKeyName] = [];
} else if (!Array.isArray(columnObject[keyPartKeyName])) {
this.parse2jsonCover.push(`${XLSX2JSON.getJsonCoverKey(keyPart, key)}`);
this.collectCoverKey(sheetIndex, rowIndex);
columnObject[keyPartKeyName] = [];
}
if (keyPartKeyIndex === null) {
columnObject[keyPartKeyName].push(isKeyPartEnd ? value : {});
} else {
if (columnObject[keyPartKeyName][keyPartKeyIndex] !== undefined) {
this.parse2jsonCover.push(`${XLSX2JSON.getJsonCoverKey(keyPart, key)}`);
this.collectCoverKey(sheetIndex, rowIndex);
}
columnObject[keyPartKeyName][keyPartKeyIndex] = isKeyPartEnd ? value : {};
}
const quoteIndex = keyPartKeyIndex || columnObject[keyPartKeyName].length - 1;
return this.createJsonEnumCol(columnObject[keyPartKeyName][quoteIndex], key, value, colIndex);
return this.createJsonEnumCol(columnObject[keyPartKeyName][quoteIndex], key, value, colIndex, rowIndex, sheetIndex);
} else {
if (columnObject[keyPartKeyName] === undefined) {
columnObject[keyPartKeyName] = isKeyPartEnd ? value : {};
} else if (Object.prototype.toString.call(columnObject[keyPartKeyName]) !== '[object Object]') {
this.parse2jsonCover.push(`${XLSX2JSON.getJsonCoverKey(keyPart, key)}`);
this.collectCoverKey(sheetIndex, rowIndex);
columnObject[keyPartKeyName] = isKeyPartEnd ? value : {};
}else {
if (isKeyPartEnd) {
this.parse2jsonCover.push(`${XLSX2JSON.getJsonCoverKey(keyPart, key)}`);
this.collectCoverKey(sheetIndex, rowIndex);
columnObject[keyPartKeyName] = value;
}
}
return this.createJsonEnumCol(columnObject[keyPartKeyName], key, value, colIndex);
return this.createJsonEnumCol(columnObject[keyPartKeyName], key, value, colIndex, rowIndex, sheetIndex);
}
}
convertProcess(sheetData, sheetIndex = 0) {
Expand All @@ -191,7 +191,7 @@ class XLSX2JSON {
for (let j = 0, lenJ = colValueArr.length; j < lenJ; j += 1) {

// 返回此次tab[].c 数显转换后的深度结构的属性引用。
this.createJsonEnumCol(colValueJson, attrDescArr[j], colValueArr[j], i - 1);
this.createJsonEnumCol(colValueJson, attrDescArr[j], colValueArr[j], i - 1, j, sheetIndex);
}
parsedJson.push(colValueJson);
}
Expand Down Expand Up @@ -219,8 +219,11 @@ class XLSX2JSON {
}
return index;
}
static getJsonCoverKey(keyPart, key) {
return `${keyPart}${key.length ? '.' + key.join('.') : ''}`;
collectCoverKey(sheetIndex, rowIndex) {
const sheetName = this.parsedXlsxData[sheetIndex].sheetName;
const keyDescName = this.parsedXlsxData[sheetIndex].data[0][rowIndex];
const msg = `sheet name "${sheetName}", row ${rowIndex}, value "${keyDescName}"`;
this.parse2jsonCover.add(msg);
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "xlsx-json-js",
"version": "0.0.2",
"version": "0.0.3",
"description": "Parse the'xlsx'file as JSON according to a set of attribute description syntax.",
"main": "lib/index.js",
"scripts": {
Expand Down

0 comments on commit 07b0cc7

Please sign in to comment.