json-as-xlsx 2.3.1 → 2.3.4
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/index.js +1 -1
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";exports.__esModule=true;exports.getWorksheetColumnWidths=exports.getJsonSheetRow=exports.getContentProperty=void 0;var xlsx_mini_min_1=require("xlsx/dist/xlsx.mini.min");
|
|
1
|
+
"use strict";exports.__esModule=true;exports.getWorksheetColumnWidths=exports.getJsonSheetRow=exports.getContentProperty=void 0;var xlsx_mini_min_1=require("xlsx/dist/xlsx.mini.min");var getContentProperty=function(content,property){var accessContentProperties=function(content,properties){var value=content[properties[0]];if(properties.length===1){return value!==null&&value!==void 0?value:""}if(value===undefined||typeof value==="string"||typeof value==="boolean"||typeof value==="number"||value instanceof Date){return""}return accessContentProperties(value,properties.slice(1))};var properties=property.split(".");return accessContentProperties(content,properties)};exports.getContentProperty=getContentProperty;var getJsonSheetRow=function(content,columns){var jsonSheetRow={};columns.forEach(function(column){if(typeof column.value==="function"){jsonSheetRow[column.label]=column.value(content)}else{jsonSheetRow[column.label]=getContentProperty(content,column.value)}});return jsonSheetRow};exports.getJsonSheetRow=getJsonSheetRow;var getWorksheetColumnWidths=function(worksheet,extraLength){var _a;if(extraLength===void 0){extraLength=1}var columnRange=xlsx_mini_min_1.utils.decode_range((_a=worksheet["!ref"])!==null&&_a!==void 0?_a:"");var columnLetters=[];for(var C=columnRange.s.c;C<=columnRange.e.c;C++){var address=xlsx_mini_min_1.utils.encode_col(C);columnLetters.push(address)}return columnLetters.map(function(column){var columnCells=Object.keys(worksheet).filter(function(cell){return cell.charAt(0)===column||cell.slice(0,2)===column});var maxWidthCell=columnCells.reduce(function(previousCell,currentCell){return worksheet[previousCell].v.length>worksheet[currentCell].v.length?previousCell:currentCell});return{width:worksheet[maxWidthCell].v.length+extraLength}})};exports.getWorksheetColumnWidths=getWorksheetColumnWidths;var getWorksheet=function(jsonSheet,settings){var jsonSheetRows;if(jsonSheet.content.length>0){jsonSheetRows=jsonSheet.content.map(function(contentItem){return getJsonSheetRow(contentItem,jsonSheet.columns)})}else{jsonSheetRows=jsonSheet.columns.map(function(column){var _a;return _a={},_a[column.label]="",_a})}var worksheet=xlsx_mini_min_1.utils.json_to_sheet(jsonSheetRows);worksheet["!cols"]=getWorksheetColumnWidths(worksheet,settings.extraLength);return worksheet};var writeWorkbook=function(workbook,settings){var _a,_b;if(settings===void 0){settings={}}var filename="".concat((_a=settings.fileName)!==null&&_a!==void 0?_a:"Spreadsheet",".xlsx");var writeOptions=(_b=settings.writeOptions)!==null&&_b!==void 0?_b:{};return writeOptions.type==="buffer"?(0,xlsx_mini_min_1.write)(workbook,writeOptions):(0,xlsx_mini_min_1.writeFile)(workbook,filename,writeOptions)};var xlsx=function(jsonSheets,settings,workbookCallback){if(settings===void 0){settings={}}if(workbookCallback===void 0){workbookCallback=function(){}}if(jsonSheets.length===0)return;var workbook=xlsx_mini_min_1.utils.book_new();jsonSheets.forEach(function(actualSheet,actualIndex){var _a;var worksheet=getWorksheet(actualSheet,settings);var worksheetName=(_a=actualSheet.sheet)!==null&&_a!==void 0?_a:"Sheet ".concat(actualIndex+1);xlsx_mini_min_1.utils.book_append_sheet(workbook,worksheet,worksheetName)});workbookCallback(workbook);return writeWorkbook(workbook,settings)};exports["default"]=xlsx;module.exports=xlsx;module.exports.getContentProperty=getContentProperty;module.exports.getJsonSheetRow=getJsonSheetRow;module.exports.getWorksheetColumnWidths=getWorksheetColumnWidths;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "json-as-xlsx",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.4",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@types/express": "^4.17.13",
|
|
24
24
|
"@types/jest": "^27.0.2",
|
|
25
|
-
"@types/node": "^
|
|
26
|
-
"@vue/cli-service": "^
|
|
25
|
+
"@types/node": "^17.0.0",
|
|
26
|
+
"@vue/cli-service": "^3.12.1",
|
|
27
27
|
"express": "^4.17.1",
|
|
28
28
|
"jest": "^27.3.1",
|
|
29
29
|
"ts-jest": "^27.0.7",
|