json-as-xlsx 2.3.0 → 2.3.1
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/README.md +6 -2
- package/index.js +1 -1
- package/package.json +5 -7
package/README.md
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
# json-as-xlsx
|
|
2
2
|
|
|
3
|
-
This is a tool that helps to build an excel from a json and it depends only on `xlsx`
|
|
3
|
+
This is a tool that helps to build an excel from a json and it depends only on `xlsx` library
|
|
4
4
|
|
|
5
|
-
You can see a live example of it working on this
|
|
5
|
+
You can see a live example of it working on any of this sites (there are many just in case):
|
|
6
|
+
|
|
7
|
+
* [xlsx.pages.dev](https://xlsx.pages.dev)
|
|
8
|
+
* [xlsx.marroquin.dev](https://xlsx.marroquin.dev)
|
|
9
|
+
* [xlsx.luismarroquin.com](https://xlsx.luismarroquin.com)
|
|
6
10
|
|
|
7
11
|
## Usage
|
|
8
12
|
|
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");function getContentProperty(content,property){function accessContentProperties(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;function getJsonSheetRow(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;function getWorksheetColumnWidths(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;function getWorksheet(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}function writeWorkbook(workbook,settings){var _a,_b;if(settings===void 0){settings={}}var filename=((_a=settings.fileName)!==null&&_a!==void 0?_a:"Spreadsheet"
|
|
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");function getContentProperty(content,property){function accessContentProperties(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;function getJsonSheetRow(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;function getWorksheetColumnWidths(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;function getWorksheet(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}function writeWorkbook(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)}function xlsx(jsonSheets,settings){if(settings===void 0){settings={}}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)});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,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "json-as-xlsx",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.1",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
7
|
-
"description": "Create excel from json",
|
|
7
|
+
"description": "Create excel xlsx file from json",
|
|
8
8
|
"author": "LuisEnMarroquin <luis@marroquin.dev>",
|
|
9
|
-
"homepage": "https://
|
|
9
|
+
"homepage": "https://xlsx.marroquin.dev",
|
|
10
10
|
"scripts": {
|
|
11
11
|
"start": "tsc --watch index.ts",
|
|
12
12
|
"build": "tsc index.ts && uglifyjs index.js --output index.js",
|
|
@@ -23,18 +23,16 @@
|
|
|
23
23
|
"@types/express": "^4.17.13",
|
|
24
24
|
"@types/jest": "^27.0.2",
|
|
25
25
|
"@types/node": "^16.10.2",
|
|
26
|
-
"@vue/cli-service": "^
|
|
26
|
+
"@vue/cli-service": "^4.5.15",
|
|
27
27
|
"express": "^4.17.1",
|
|
28
28
|
"jest": "^27.3.1",
|
|
29
29
|
"ts-jest": "^27.0.7",
|
|
30
|
+
"ts-standard": "^11.0.0",
|
|
30
31
|
"typescript": "^4.4.3",
|
|
31
32
|
"uglify-js": "^3.14.2",
|
|
32
33
|
"vue": "^2.6.14",
|
|
33
34
|
"vue-template-compiler": "^2.6.14"
|
|
34
35
|
},
|
|
35
|
-
"optionalDependencies": {
|
|
36
|
-
"ts-standard": "^10.0.0"
|
|
37
|
-
},
|
|
38
36
|
"files": [
|
|
39
37
|
"index.js",
|
|
40
38
|
"types/index.d.ts"
|