Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jsonverse

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsonverse - npm Package Compare versions

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

8

package.json
{
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc