Comparing version 1.3.1 to 1.3.2
90
index.js
@@ -16,2 +16,4 @@ /*! | ||
const colors = require("./lib/colors"); | ||
const ExcelJS = require("exceljs"); | ||
const json2xls = require("json2xls"); | ||
@@ -117,4 +119,2 @@ function formatDateTime(date) { | ||
// Encrypt sensitive data | ||
@@ -341,2 +341,6 @@ encrypt(data, secretKey) { | ||
this.logSuccess(`Data exported to CSV: ${filePath}`); | ||
} else if (format === "xlsx") { | ||
// Export as XLSX using exceljs | ||
const filePath = this.getFilePath(dataName + ".xlsx"); | ||
await this.writeDataToXLSX(filePath, data); | ||
} | ||
@@ -358,2 +362,10 @@ } | ||
this.logSuccess(`Data imported from CSV: ${filePath}`); | ||
} else if (format === "xlsx") { | ||
// Import XLSX data using exceljs | ||
const xlsxData = await this.readXLSX(filePath); | ||
await this.writeDataByFileName(dataName, xlsxData); | ||
this.logSuccess(`Data imported from XLSX: ${filePath}`); | ||
} else { | ||
// Handle unsupported file format | ||
this.logError(`Unsupported file format: ${format}`); | ||
} | ||
@@ -389,2 +401,76 @@ } | ||
// Function to read data from an XLSX file using exceljs | ||
async readXLSX(filePath) { | ||
try { | ||
const workbook = new ExcelJS.Workbook(); | ||
await workbook.xlsx.readFile(filePath); | ||
const worksheet = workbook.getWorksheet(1); // Assuming there's only one sheet | ||
const data = []; | ||
worksheet.eachRow((row, rowNumber) => { | ||
if (rowNumber !== 1) { | ||
const rowData = row.values.map((cell) => cell); | ||
data.push(rowData); | ||
} | ||
}); | ||
return data; | ||
} catch (error) { | ||
this.logError(`Reading XLSX file: ${error}`); | ||
return null; | ||
} | ||
} | ||
// Helper method to write data to an XLSX file using exceljs | ||
async writeDataToXLSX(filePath, data) { | ||
const workbook = new ExcelJS.Workbook(); | ||
const worksheet = workbook.addWorksheet("Sheet1"); | ||
// Add headers to the worksheet | ||
if (data.length > 0) { | ||
const headers = Object.keys(data[0]); | ||
worksheet.addRow(headers); | ||
} | ||
// Add data rows to the worksheet | ||
data.forEach((row) => { | ||
worksheet.addRow(Object.values(row)); | ||
}); | ||
await workbook.xlsx.writeFile(filePath); | ||
this.logSuccess(`Data exported to XLSX: ${filePath}`); | ||
} | ||
// Export Data to XLSX | ||
async exportDataToXLSX(dataName) { | ||
const data = await this.readData(dataName); | ||
// Check if the data is empty | ||
if (data.length === 0) { | ||
this.logError(`No data to export in ${dataName}.`); | ||
return; | ||
} | ||
// Create an XLSX object from the JSON data | ||
const xls = json2xls(data); | ||
// Specify the file path where the XLSX file will be saved | ||
const filePath = this.getFilePath(dataName + ".xlsx"); | ||
try { | ||
// Save the XLSX data to the file | ||
fs.writeFileSync(filePath, xls, "binary"); | ||
this.logSuccess(`Data exported to XLSX: ${filePath}`); | ||
} catch (error) { | ||
this.logError(`Failed to export data to XLSX: ${error}`); | ||
} | ||
} | ||
// Function to convert XLS data to JSON | ||
async xlsToJSON(xlsData) { | ||
const wb = XLSX.read(xlsData, { type: "buffer" }); | ||
const ws = wb.Sheets[wb.SheetNames[0]]; // Assuming there's only one sheet | ||
return XLSX.utils.sheet_to_json(ws); | ||
} | ||
isCacheExpired(dataName) { | ||
@@ -391,0 +477,0 @@ const CACHE_EXPIRATION_TIME = 10 * 60 * 1000; // 10 minutes in milliseconds |
{ | ||
"name": "jsonverse", | ||
"version": "1.3.1", | ||
"version": "1.3.2", | ||
"description": "jsonVerse is a lightweight JSON-based database package for Node.js. It provides a simple interface to store, retrieve, and manage data using JSON files.", | ||
@@ -25,3 +25,3 @@ "main": "index.js", | ||
], | ||
"homepage": "https://github.com/Marco5dev/jsonverse#readme", | ||
"homepage": "https://jsonversedb.web.app", | ||
"keywords": [ | ||
@@ -70,4 +70,6 @@ "JSON", | ||
"dateformat": "^5.0.3", | ||
"exceljs": "^4.3.0", | ||
"fuse.js": "^6.6.2", | ||
"json2csv": "^6.0.0-alpha.2" | ||
"json2csv": "^6.0.0-alpha.2", | ||
"json2xls": "^0.1.2" | ||
}, | ||
@@ -74,0 +76,0 @@ "devDependencies": { |
@@ -5,3 +5,9 @@ # jsonVerse | ||
[![Node.js Package NPM](https://github.com/Marco5dev/jsonverse/actions/workflows/npm-publish.yml/badge.svg)](https://github.com/Marco5dev/jsonverse/actions/workflows/npm-publish.yml) | ||
[![Build](https://github.com/Marco5dev/jsonverse/actions/workflows/npm-publish.yml/badge.svg)](https://github.com/Marco5dev/jsonverse/actions/workflows/npm-publish.yml) | ||
[![NPM Version](https://img.shields.io/npm/v/jsonverse.svg)](https://www.npmjs.com/package/jsonverse) | ||
[![NPM Downloads](https://img.shields.io/npm/dt/jsonverse.svg)](https://www.npmjs.com/package/jsonverse) | ||
[![Github Repo Size](https://img.shields.io/github/repo-size/Marco5dev/jsonverse.svg)](https://github.com/Marco5dev/jsonverse) | ||
[![LICENSE](https://img.shields.io/npm/l/jsonverse.svg)](https://github.com/Marco5dev/jsonverse/blob/master/LICENSE) | ||
[![Contributors](https://img.shields.io/github/contributors/Marco5dev/jsonverse.svg)](https://github.com/Marco5dev/jsonverse/graphs/contributors) | ||
[![Commit](https://img.shields.io/github/last-commit/Marco5dev/jsonverse.svg)](https://github.com/Marco5dev/jsonverse/commits/master) | ||
@@ -8,0 +14,0 @@ ## Introduction |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
32391
650
235
7
+ Addedexceljs@^4.3.0
+ Addedjson2xls@^0.1.2
+ Added@fast-csv/format@4.3.5(transitive)
+ Added@fast-csv/parse@4.3.6(transitive)
+ Added@types/node@14.18.63(transitive)
+ Addedarchiver@5.3.2(transitive)
+ Addedarchiver-utils@2.1.03.0.4(transitive)
+ Addedasync@3.2.6(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbase64-js@1.5.1(transitive)
+ Addedbig-integer@1.6.52(transitive)
+ Addedbinary@0.3.0(transitive)
+ Addedbl@4.1.0(transitive)
+ Addedbluebird@3.4.7(transitive)
+ Addedbrace-expansion@1.1.112.0.1(transitive)
+ Addedbuffer@5.7.1(transitive)
+ Addedbuffer-crc32@0.2.13(transitive)
+ Addedbuffer-indexof-polyfill@1.0.2(transitive)
+ Addedbuffers@0.1.1(transitive)
+ Addedchainsaw@0.1.0(transitive)
+ Addedcompress-commons@4.1.2(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addedcrc-32@1.2.2(transitive)
+ Addedcrc32-stream@4.0.3(transitive)
+ Addeddayjs@1.11.13(transitive)
+ Addedduplexer2@0.1.4(transitive)
+ Addedend-of-stream@1.4.4(transitive)
+ Addedexcel-export@0.3.11(transitive)
+ Addedexceljs@4.4.0(transitive)
+ Addedfast-csv@4.3.6(transitive)
+ Addedfs-constants@1.0.0(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedfstream@1.0.12(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedgraceful-fs@4.2.11(transitive)
+ Addedieee754@1.2.1(transitive)
+ Addedimmediate@3.0.6(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedjson2xls@0.1.2(transitive)
+ Addedjszip@2.5.03.10.1(transitive)
+ Addedlazystream@1.0.1(transitive)
+ Addedlie@3.3.0(transitive)
+ Addedlistenercount@1.0.1(transitive)
+ Addedlodash.defaults@4.2.0(transitive)
+ Addedlodash.difference@4.5.0(transitive)
+ Addedlodash.escaperegexp@4.1.2(transitive)
+ Addedlodash.flatten@4.4.0(transitive)
+ Addedlodash.groupby@4.6.0(transitive)
+ Addedlodash.isboolean@3.0.3(transitive)
+ Addedlodash.isequal@4.5.0(transitive)
+ Addedlodash.isfunction@3.0.9(transitive)
+ Addedlodash.isnil@4.0.0(transitive)
+ Addedlodash.isplainobject@4.0.6(transitive)
+ Addedlodash.isundefined@3.0.1(transitive)
+ Addedlodash.union@4.6.0(transitive)
+ Addedlodash.uniq@4.5.0(transitive)
+ Addedminimatch@3.1.25.1.6(transitive)
+ Addedmkdirp@0.5.6(transitive)
+ Addednode-zip@1.1.1(transitive)
+ Addednormalize-path@3.0.0(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpako@0.2.91.0.11(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedreadable-stream@2.3.83.6.2(transitive)
+ Addedreaddir-glob@1.1.3(transitive)
+ Addedrimraf@2.7.1(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
+ Addedsaxes@5.0.1(transitive)
+ Addedsetimmediate@1.0.5(transitive)
+ Addedstring_decoder@1.1.1(transitive)
+ Addedtar-stream@2.2.0(transitive)
+ Addedtmp@0.2.3(transitive)
+ Addedtraverse@0.3.9(transitive)
+ Addedunzipper@0.10.14(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addeduuid@8.3.2(transitive)
+ Addedwrappy@1.0.2(transitive)
+ Addedxmlchars@2.2.0(transitive)
+ Addedzip-stream@4.1.1(transitive)