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

belousov-utils

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

belousov-utils - npm Package Compare versions

Comparing version 1.0.2 to 1.1.0

5

build/index.d.ts

@@ -1,3 +0,2 @@

export declare const a: (str: string) => string;
declare const _default: () => void;
export default _default;
import 'exit-on-epipe';
export default function run(): void;

57

build/index.js
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.a = void 0;
const a = (str) => str;
exports.a = a;
exports.default = () => console.log('Hello');
require("exit-on-epipe");
const fs_1 = __importDefault(require("fs"));
const commander_1 = require("commander");
const readline_1 = __importDefault(require("readline"));
const path_1 = __importDefault(require("path"));
const UTILS_NAME = 'belousov-utils';
function run() {
commander_1.program
.requiredOption('-f, --file <file>', 'Путь до файла')
.requiredOption('-o, --output <path>', 'Папка, куда складывать файлы')
.option('-h, --header <count-rows>', 'Количество строк в хедере. Default 1')
.option('-c, --colname <num-column>', 'Из какой колонки брать имя. Default 1')
.option('-e, --encoding <str>', 'Кодировка. Default utf-8')
.option('-s, --separator <str>', 'Разделитель в csv. Default ;');
commander_1.program.parse(process.argv);
const options = commander_1.program.opts();
const separator = options.separator || ';';
const file = options.file;
const encoding = options.encoding || 'utf-8';
const headerRows = options.header || 1;
const colname = options.colname || 1;
const output = options.output;
if (!fs_1.default.existsSync(file)) {
commander_1.program.error(UTILS_NAME + ': ' + file + ': No such file', { exitCode: 2 });
}
if (!fs_1.default.existsSync(output)) {
commander_1.program.error(UTILS_NAME + ': ' + output + ': No such directory', { exitCode: 2 });
}
const readStream = fs_1.default.createReadStream(file, encoding);
const rl = readline_1.default.createInterface({ input: readStream });
const header = [];
rl.on('line', (line) => {
if (header.length < headerRows) {
header.push(line);
}
else {
const columns = line.split(separator);
if (columns.some(Boolean)) {
const filename = columns[colname - 1] || `rand_${Math.random()}`;
const data = header.join('\r\n') + '\r\n' + line + '\r\n';
fs_1.default.appendFileSync(path_1.default.join(output, filename + '.csv'), data, encoding);
}
}
});
rl.on('error', (error) => commander_1.program.error(error.message));
rl.on('close', () => {
console.log('FINISH');
});
}
exports.default = run;
{
"name": "belousov-utils",
"version": "1.0.2",
"version": "1.1.0",
"description": "",

@@ -38,2 +38,3 @@ "author": "jhoncool",

"devDependencies": {
"@types/node": "^18.11.9",
"@yandex-cloud/eslint-config": "github:yandex-cloud/eslint-config",

@@ -48,3 +49,7 @@ "@yandex-cloud/prettier-config": "^1.0.0",

"typescript": "^4.9.3"
},
"dependencies": {
"commander": "^9.4.1",
"exit-on-epipe": "^1.0.1"
}
}

@@ -5,2 +5,2 @@ # Belousov utils

TODO
npx belousov-utils --header 3 --file Андрей.csv --output output_folder

@@ -1,3 +0,57 @@

export const a = (str: string) => str;
import 'exit-on-epipe';
import fs from 'fs';
import {program} from 'commander';
import readline from 'readline';
import path from 'path';
export default () => console.log('Hello');
const UTILS_NAME = 'belousov-utils';
export default function run() {
program
.requiredOption('-f, --file <file>', 'Путь до файла')
.requiredOption('-o, --output <path>', 'Папка, куда складывать файлы')
.option('-h, --header <count-rows>', 'Количество строк в хедере. Default 1')
.option('-c, --colname <num-column>', 'Из какой колонки брать имя. Default 1')
.option('-e, --encoding <str>', 'Кодировка. Default utf-8')
.option('-s, --separator <str>', 'Разделитель в csv. Default ;');
program.parse(process.argv);
const options = program.opts();
const separator = options.separator || ';';
const file = options.file;
const encoding = options.encoding || 'utf-8';
const headerRows = options.header || 1;
const colname = options.colname || 1;
const output = options.output;
if (!fs.existsSync(file)) {
program.error(UTILS_NAME + ': ' + file + ': No such file', {exitCode: 2});
}
if (!fs.existsSync(output)) {
program.error(UTILS_NAME + ': ' + output + ': No such directory', {exitCode: 2});
}
const readStream = fs.createReadStream(file, encoding);
const rl = readline.createInterface({input: readStream});
const header: string[] = [];
rl.on('line', (line) => {
if (header.length < headerRows) {
header.push(line);
} else {
const columns = line.split(separator);
if (columns.some(Boolean)) {
const filename = columns[colname - 1] || `rand_${Math.random()}`;
const data = header.join('\r\n') + '\r\n' + line + '\r\n';
fs.appendFileSync(path.join(output, filename + '.csv'), data, encoding);
}
}
});
rl.on('error', (error) => program.error(error.message));
rl.on('close', () => {
console.log('FINISH');
});
}

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