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

sv

Package Overview
Dependencies
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sv - npm Package Compare versions

Comparing version 0.3.10 to 0.4.0

bin/sv.d.ts

19

common.d.ts

@@ -29,10 +29,11 @@ /**

*/
export declare function merge(target: any, ...sources: any[]): any;
export declare function zip(keys: any, values: any, missing: any): {};
export declare function inferColumns(rows: string[][]): string[];
/**
returns a single char code (a byte) denoting the inferred delimiter.
*/
export declare function inferDelimiter(buffer: Buffer): number;
export declare function commonPrefix(filepaths: any): any;
export declare function countLinebreaks(stream: any, callback: (error: Error, lines: number) => void): void;
export declare function merge(target: {
[index: string]: any;
}, ...sources: {
[index: string]: any;
}[]): {
[index: string]: any;
};
export declare function zip<T>(keys: string[], values: T[], missing: T): {
[index: string]: T;
};

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

"use strict";
/**

@@ -20,39 +21,8 @@ Like reverse Object.assign, but with special treatment for undefined.

function zip(keys, values, missing) {
var obj = {};
var object = {};
for (var i = 0, l = keys.length; i < l; i++) {
obj[keys[i]] = values[i] || missing;
object[keys[i]] = values[i] || missing;
}
return obj;
return object;
}
exports.zip = zip;
function commonPrefix(filepaths) {
var prefix = filepaths[0];
for (var filepath, i = 1; (filepath = filepaths[i]) && prefix.length; i++) {
for (var c = 0; prefix[c] == filepath[c]; c++)
;
prefix = prefix.slice(0, c);
}
return prefix;
}
exports.commonPrefix = commonPrefix;
function countLinebreaks(stream, callback) {
var count = 0;
stream
.on('data', function (buffer) {
for (var i = 0; i < buffer.length; i++) {
// universal newlines: handle \r (13), \r\n (13, 10), or \n (10) as one line break
if (buffer[i] == 13) {
count++;
if (buffer[i + 1] == 10) {
i++;
}
}
else if (buffer[i] == 10) {
count++;
}
}
})
.on('end', function () { return callback(null, count); })
.on('error', function (err) { return callback(err, count); });
}
exports.countLinebreaks = countLinebreaks;

@@ -1,5 +0,12 @@

import { Parser } from './parser';
import { Stringifier } from './stringifier';
import { Parser, ParserConfiguration } from './parser';
import { Stringifier, StringifierConfiguration } from './stringifier';
export interface TransformParserConfiguration extends ParserConfiguration {
json?: boolean;
}
export interface TransformStringifierConfiguration extends StringifierConfiguration {
filter?: string;
omit?: string;
json?: boolean;
}
export { Parser, Stringifier };
export declare function transform(input: NodeJS.ReadableStream, parserConfig: any, stringifierConfig: any, callback: any): void;
export declare function main(): void;
export declare function transform(input: NodeJS.ReadableStream, parserConfig: TransformParserConfiguration, stringifierConfig: TransformStringifierConfiguration, callback: (error?: Error) => void): void;

@@ -0,7 +1,4 @@

"use strict";
var json_1 = require('streaming/json');
var property_1 = require('streaming/property');
var fs_1 = require('fs');
var async_1 = require('async');
// import * as optimist from 'optimist';
var optimist = require('optimist');
var parser_1 = require('./parser');

@@ -11,17 +8,3 @@ exports.Parser = parser_1.Parser;

exports.Stringifier = stringifier_1.Stringifier;
function pluck(xs, prop) {
return xs.map(function (x) { return x[prop]; });
}
var whitespace_literals = {
'\r': '\\r',
'\n': '\\n',
'\t': '\\t',
};
function escapeWhitespace(s) {
return whitespace_literals[s];
}
function transform(input, parserConfig, stringifierConfig, callback) {
// if (filename) {
// console.error('Transforming ' + filename);
// }
var transforms = [

@@ -48,93 +31,1 @@ parserConfig.json ? new json_1.Parser() : new parser_1.Parser(parserConfig),

exports.transform = transform;
function main() {
var argvparser = optimist
.usage([
'Consolidate any tabular format.',
'',
'Usage: <sprints.txt sv [options] > sprints.csv',
' or: sv [options] ~/Desktop/**/*.csv > ~/all.csv',
'',
'Parser options:',
' --in-delimiter field separator (inferred if unspecified)',
' --in-quotechar " ',
' --in-json parse input as JSON (one object per row)',
'',
'Stringifier options:',
' --peek 10 infer columns from first ten objects of input',
' --out-delimiter , field separator',
' --out-quotechar " marks beginning and end of fields containing delimiter',
' --filter a,b keep only fields a and b in the results',
' --omit c,d leave out fields x and y from the results (processed before filter)',
' -j, --json write one JSON object per row',
'',
'Other options:',
' --version print version and quit',
' -v --verbose turn up the verbosity (still all on STDERR)',
'',
'STDIN, if supplied, will be coerced to utf8',
].join('\n'))
.string(['delimiter', 'quotechar', 'escapechar'])
.boolean(['json', 'verbose', 'version', 'in-json'])
.alias({
j: 'json',
v: 'verbose',
})
.default({
width: process.stdout['columns'] || 80,
});
var argv = argvparser.argv;
var parser_opts = {
delimiter: argv['in-delimiter'],
quotechar: argv['in-quotechar'],
json: argv['in-json'],
};
var stringifier_opts = {
delimiter: argv['out-delimiter'],
quotechar: argv['out-quotechar'],
peek: argv.peek,
filter: argv.filter,
omit: argv.omit,
json: argv.json,
width: argv.width,
};
function exit(err) {
if (err && err.code != 'EPIPE') {
throw err;
}
// if err.code == 'EPIPE' that just means that someone down
// the line cut us short with a | head or something
if (argv.verbose) {
console.error('Done.');
}
// process.exit(); // wait for stdout to finish, actually.
}
if (argv.help) {
argvparser.showHelp();
console.log('ARGV: ' + process.argv.join(' '));
if (argv.verbose) {
console.log(' argv: ' + JSON.stringify(argv, null, ' ').replace(/\n/g, '\n '));
}
console.log(' parser options: ' + JSON.stringify(parser_opts, null, ' ').replace(/\n/g, '\n '));
console.log(' stringifier options: ' + JSON.stringify(stringifier_opts, null, ' ').replace(/\n/g, '\n '));
}
else if (argv.version) {
console.log(require('../package').version);
}
else if (!process.stdin['isTTY']) {
// process.stdin.setEncoding('utf8');
transform(process.stdin, parser_opts, stringifier_opts, exit);
}
else if (argv._.length) {
var filepaths = argv._;
async_1.eachSeries(filepaths, function (filepath, callback) {
var stream = fs_1.createReadStream(filepath);
transform(stream, parser_opts, stringifier_opts, callback);
console.error(''); // newline
}, exit);
}
else {
argvparser.showHelp();
console.error('You must supply data via STDIN or as unflagged command line arguments.');
}
}
exports.main = main;
{
"name": "sv",
"version": "0.3.10",
"version": "0.4.0",
"description": "Any separated values.",

@@ -27,5 +27,7 @@ "keywords": [

"devDependencies": {
"babel-core": "^5.0.0",
"coveralls": "*",
"declarations": "*",
"istanbul": "*",
"mocha": "*",
"mocha-lcov-reporter": "*",
"typescript": "*"

@@ -37,4 +39,4 @@ },

"bin": {
"sv": "bin/sv"
"sv": "bin/sv.js"
}
}

@@ -7,2 +7,6 @@ import { Transform } from 'stream';

/**
returns a single char code (a byte) denoting the inferred delimiter.
*/
export declare function inferDelimiter(buffer: Buffer): number;
/**
- `byteBuffer` is a buffer (of bytes) that have yet to be processed (and sent to output).

@@ -22,6 +26,6 @@ - `cellBuffer` is a list of strings that have yet to be processed (and sent to output).

constructor(config?: ParserConfiguration);
protected writeRow(cells: any): void;
flush(callback: any, nonfinal: any): void;
_flush(callback: any): void;
_transform(chunk: any, encoding: any, callback: any): void;
protected writeRow(cells: string[]): void;
flush(callback: (error?: Error) => void, nonfinal: boolean): void;
_flush(callback: (error?: Error) => void): void;
_transform(chunk: Buffer, encoding: string, callback: (error?: Error) => void): void;
}

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

"use strict";
var __extends = (this && this.__extends) || function (d, b) {

@@ -25,4 +26,4 @@ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];

for (var i = 0; i < upto && buffer[i] != 10 && buffer[i] != 13; i++) {
var char_code = buffer[i];
counts[char_code] = (counts[char_code] || 0) + 1;
var charCode = buffer[i];
counts[charCode] = (counts[charCode] || 0) + 1;
}

@@ -38,3 +39,3 @@ // we'll go through, prioritizing characters that aren't likely to show

// TODO: make this more robust (that's why I even counted them)
for (var candidate, j = 0; (candidate = candidates[j]); j++) {
for (var candidate = void 0, j = 0; (candidate = candidates[j]); j++) {
if (counts[candidate] > 0) {

@@ -57,13 +58,7 @@ return candidate;

decodeStrings: true,
objectMode: true,
readableObjectMode: true,
writableObjectMode: false,
});
this.byteBuffer = new Buffer(0);
this.cellBuffer = [];
// this._readableState.objectMode = true; // default, good
// decodeStrings: true, dammit! ()
// stream.Transform({decodeStrings: true}) is not honored if objectMode: true,
// because objectMode: true (intended for the Readable) overrides the decodeStrings: true
// if this gets fixed, you can remove the private field setting below.
// Issue at https://github.com/joyent/node/issues/5580
this['_writableState'].objectMode = false;
// merge defaults

@@ -106,3 +101,3 @@ this.config = common_1.merge(config, exports.defaultParserConfiguration);

var eos = !nonfinal && i + 1 == end;
// var snippet = buffer.toString('utf8', 0, i) +
// const snippet = buffer.toString('utf8', 0, i) +
// '\x1b[7m' + buffer.toString('utf8', i, i + 1) + '\x1b[0m' +

@@ -202,3 +197,3 @@ // buffer.toString('utf8', i + 1, end);

return Parser;
})(stream_1.Transform);
}(stream_1.Transform));
exports.Parser = Parser;
# sv
[![npm version](https://badge.fury.io/js/sv.svg)](https://www.npmjs.com/package/sv)
[![Travis CI Build Status](https://travis-ci.org/chbrown/sv.svg)](https://travis-ci.org/chbrown/sv)
[![Coverage Status](https://coveralls.io/repos/chbrown/sv/badge.svg)](https://coveralls.io/github/chbrown/sv)
For all your separated value needs.

@@ -138,2 +142,2 @@

Copyright 2013-2015 Christopher Brown. [MIT Licensed](http://chbrown.github.io/licenses/MIT/#2013-2015).
Copyright 2013-2016 Christopher Brown. [MIT Licensed](http://chbrown.github.io/licenses/MIT/#2013-2016).

@@ -15,2 +15,3 @@ import { Transform } from 'stream';

};
export declare function inferColumns(rows: string[][]): string[];
/** Stringifier class

@@ -39,5 +40,5 @@ new Stringifier();

protected writeObjects(objects: any[]): void;
flush(callback: any, nonfinal: any): void;
_flush(callback: any): void;
_transform(chunk: any, encoding: any, callback: any): void;
flush(callback: (error?: Error) => void, nonfinal: boolean): void;
_flush(callback: (error?: Error) => void): void;
_transform(chunk: any, encoding: string, callback: (error?: Error) => void): void;
}

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

"use strict";
var __extends = (this && this.__extends) || function (d, b) {

@@ -56,8 +57,4 @@ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];

if (config === void 0) { config = {}; }
_super.call(this, { objectMode: true });
_super.call(this, { readableObjectMode: false, writableObjectMode: true });
this.rowBuffer = [];
// we want:
// Readable({objectMode: false})
// Writable({objectMode: true})
this['_readableState'].objectMode = false;
this.config = common_1.merge(config, exports.defaultStringifierConfiguration);

@@ -82,9 +79,9 @@ this.quotecharRegExp = new RegExp(this.config.quotechar, 'ig');

// if object is an array, we ignore this.columns
var length = object.length;
var length_1 = object.length;
if (!Array.isArray(object)) {
// object
length = this.config.columns.length;
length_1 = this.config.columns.length;
// pull properties off the given object in proper column order
var list = new Array(length);
for (var i = 0; i < length; i++) {
var list = new Array(length_1);
for (var i = 0; i < length_1; i++) {
var column_value = object[this.config.columns[i]];

@@ -96,3 +93,3 @@ list[i] = (column_value === undefined) ? this.config.missing : column_value;

// obj is definitely an array now, but the fields aren't quoted.
for (var j = 0; j < length; j++) {
for (var j = 0; j < length_1; j++) {
// assume minimal quoting (don't quote unless the cell contains the delimiter)

@@ -164,3 +161,3 @@ var value = object[j].toString();

return Stringifier;
})(stream_1.Transform);
}(stream_1.Transform));
exports.Stringifier = Stringifier;

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