New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@aternus/csv-to-xlsx

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aternus/csv-to-xlsx - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

6

CHANGELOG.md

@@ -16,3 +16,7 @@ # Changelog

## [1.0.1] - 2018-09-17
### Changed
- Updated the publish script.
## [1.0.0] - 2018-09-17
- First release.
- First release.

55

dist/convertCsvToXlsx.js

@@ -1,54 +0,1 @@

"use strict";
const fs = require('fs-extra');
const csv = require('csv-parse/lib/sync');
const xlsx = require('xlsx');
/**
* CSV to XLSX
*
* @param {string} source
* @param {string} destination
*
* @throws Error
*/
function convertCsvToXlsx(source, destination) {
// sanity checks
if (typeof source !== 'string' || typeof destination !== 'string') {
throw new Error(`"source" and "destination" arguments must be of type string.`);
} // source exists
if (!fs.existsSync(source)) {
throw new Error(`source "${source}" doesn't exist.`);
} // destination doesn't exist
if (fs.existsSync(destination)) {
throw new Error(`destination "${destination}" already exists.`);
} // read source
const csvFile = fs.readFileSync(source, 'UTF-8'); // csv parser options
const csvOptions = {
columns: true,
delimiter: ',',
ltrim: true,
rtrim: true
}; // get records
const records = csv(csvFile, csvOptions); // prepare the xlsx workbook
const wb = xlsx.utils.book_new(); // insert the records as a sheet
const ws = xlsx.utils.json_to_sheet(records);
xlsx.utils.book_append_sheet(wb, ws); // write the xlsx workbook to destination
xlsx.writeFile(wb, String(destination));
}
module.exports = convertCsvToXlsx;
"use strict";const fs=require("fs-extra");const csv=require("csv-parse/lib/sync");const xlsx=require("xlsx");function convertCsvToXlsx(source,destination){if(typeof source!=="string"||typeof destination!=="string"){throw new Error(`"source" and "destination" arguments must be of type string.`)}if(!fs.existsSync(source)){throw new Error(`source "${source}" doesn't exist.`)}if(fs.existsSync(destination)){throw new Error(`destination "${destination}" already exists.`)}const csvFile=fs.readFileSync(source,"UTF-8");const csvOptions={columns:true,delimiter:",",ltrim:true,rtrim:true};const records=csv(csvFile,csvOptions);const wb=xlsx.utils.book_new();const ws=xlsx.utils.json_to_sheet(records);xlsx.utils.book_append_sheet(wb,ws);xlsx.writeFile(wb,String(destination))}module.exports=convertCsvToXlsx;

@@ -1,71 +0,1 @@

"use strict";
/*
Requires
*********************************************************/
const path = require('path');
const fs = require('fs-extra');
const program = require('commander');
const convertCsvToXlsx = require('./convertCsvToXlsx');
if (module.parent) {
module.exports = convertCsvToXlsx;
} else {
/*
Variables
*********************************************************/
const pkg = require('../package');
/*
Program
*********************************************************/
program.version(pkg.version, '-v, --version').option('-i, --input-dir [dir]', 'Input directory that has the CSV files', 'csv').option('-o, --output-dir [dir]', 'Output directory for the XLSX files', 'xlsx');
program.on('--help', function () {
console.log(``);
console.log(`Created by: ${pkg.author}`);
console.log(`Please report bugs at: ${pkg.bugs.url}`);
});
program.parse(process.argv);
const csvPath = path.join(process.cwd(), program.inputDir);
const xlsxPath = path.join(process.cwd(), program.outputDir); // check the csvPath
if (!fs.existsSync(csvPath)) {
// csv folder doesn't exist, doing it wrong
console.error(`Invalid input directory: ${csvPath}\n`);
process.exitCode = 1;
program.help(); // exit immediately
} // check the xlsxPath
if (!fs.existsSync(xlsxPath)) {
// create xlsx folder
console.info(`Creating output directory: ${xlsxPath}`);
fs.mkdirpSync(xlsxPath);
} // read csvPath
const csvFiles = fs.readdirSync(csvPath);
for (let file of csvFiles) {
// parse file
const fileObject = path.parse(file); // check file extension
if (fileObject.ext !== '.csv') {
continue;
}
console.info(`Converting: ${fileObject.name}`); // convert
try {
convertCsvToXlsx(path.join(csvPath, file), path.join(xlsxPath, `${fileObject.name}.xlsx`));
} catch (e) {
console.info(`${e.toString()}`);
}
}
console.log(`Complete.`);
}
"use strict";const path=require("path");const fs=require("fs-extra");const program=require("commander");const convertCsvToXlsx=require("./convertCsvToXlsx");if(module.parent){module.exports=convertCsvToXlsx}else{const pkg=require("../package");program.version(pkg.version,"-v, --version").option("-i, --input-dir [dir]","Input directory that has the CSV files","csv").option("-o, --output-dir [dir]","Output directory for the XLSX files","xlsx");program.on("--help",function(){console.log(``);console.log(`Created by: ${pkg.author}`);console.log(`Please report bugs at: ${pkg.bugs.url}`)});program.parse(process.argv);const csvPath=path.join(process.cwd(),program.inputDir);const xlsxPath=path.join(process.cwd(),program.outputDir);if(!fs.existsSync(csvPath)){console.error(`Invalid input directory: ${csvPath}\n`);process.exitCode=1;program.help()}if(!fs.existsSync(xlsxPath)){console.info(`Creating output directory: ${xlsxPath}`);fs.mkdirpSync(xlsxPath)}const csvFiles=fs.readdirSync(csvPath);for(let file of csvFiles){const fileObject=path.parse(file);if(fileObject.ext!==".csv"){continue}console.info(`Converting: ${fileObject.name}`);try{convertCsvToXlsx(path.join(csvPath,file),path.join(xlsxPath,`${fileObject.name}.xlsx`))}catch(e){console.info(`${e.toString()}`)}}console.log(`Complete.`)}
{
"name": "@aternus/csv-to-xlsx",
"version": "1.0.0",
"version": "1.0.1",
"description": "Node.js command-line tool and a library to convert CSV files to XLSX (Excel 2007+ XML Format) files.",

@@ -26,4 +26,3 @@ "keywords": [

"build:bin": "npx pkg --out-path ./bin .",
"test:raw": "npx mocha",
"test": "npm-run-all build:src test:raw",
"test": "npx mocha",
"start:raw": "node ./dist/csv-to-xlsx.js",

@@ -30,0 +29,0 @@ "start": "npm-run-all build:src start:raw",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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