Socket
Socket
Sign inDemoInstall

csv-generate

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

csv-generate - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

CHANGELOG.md

147

lib/index.js

@@ -1,4 +0,16 @@

// Generated by CoffeeScript 1.10.0
var Generator, stream, util;
// Generated by CoffeeScript 2.0.1
// # CSV Generator
// A Readable Stream for random CSV and data generator. Features include:
// * Node.js Stream 2 implementation.
// * Idempotence with the "seed" option.
// * Framework to generate custom data.
// * Various option to personnalize the generation.
// Please look at the [documentation], the [README], the [samples] and the
// [tests] for additional information.
var Generator, stream, util,
indexOf = [].indexOf;
stream = require('stream');

@@ -8,2 +20,11 @@

// ## Usage
// Callback approach, for ease of use:
// `generate([options])`
// Stream API, for maximum of power:
// `generate([options], callback)`
module.exports = function() {

@@ -43,42 +64,48 @@ var callback, data, generator, options;

Generator = function(options1) {
var base, base1, base2, base3, base4, base5, base6, base7, base8, i, j, len, ref, v;
this.options = options1 != null ? options1 : {};
// ## `Generator([options])`
// Feel free to ask for new features and to participate by writting issues and
// preparing push requests.
// Options are documented [here](http://csv.adaltas.com/generate/).
Generator = function(options1 = {}) {
var accepted_header_types, base, base1, base2, base3, base4, base5, base6, i, j, len, ref, v;
this.options = options1;
// @options = {}
// for k, v of options
// @options[k] = v
stream.Readable.call(this, this.options);
this.options.count = 0;
if ((base = this.options).duration == null) {
base.duration = 4 * 60 * 1000;
if ((base = this.options).columns == null) {
base.columns = 8;
}
if ((base1 = this.options).columns == null) {
base1.columns = 8;
if ((base1 = this.options).max_word_length == null) {
base1.max_word_length = 16;
}
if ((base2 = this.options).max_word_length == null) {
base2.max_word_length = 16;
if ((base2 = this.options).fixed_size == null) {
base2.fixed_size = false;
}
if ((base3 = this.options).fixed_size == null) {
base3.fixed_size = false;
if ((base3 = this.options).end == null) {
base3.end = null;
}
if (this.fixed_size_buffer == null) {
this.fixed_size_buffer = '';
if ((base4 = this.options).seed == null) {
base4.seed = false;
}
if ((base4 = this.options).start == null) {
base4.start = Date.now();
if ((base5 = this.options).length == null) {
base5.length = -1;
}
if ((base5 = this.options).end == null) {
base5.end = null;
if ((base6 = this.options).delimiter == null) {
base6.delimiter = ',';
}
if ((base6 = this.options).seed == null) {
base6.seed = false;
}
if ((base7 = this.options).length == null) {
base7.length = -1;
}
if ((base8 = this.options).delimiter == null) {
base8.delimiter = ',';
}
this.count_written = 0;
this.count_created = 0;
// State
this._ = {
fixed_size_buffer: '',
count_written: 0,
count_created: 0
};
if (typeof this.options.columns === 'number') {
this.options.columns = new Array(this.options.columns);
}
accepted_header_types = Object.keys(Generator).filter(function(t) {
return t !== 'super_';
});
ref = this.options.columns;

@@ -91,2 +118,5 @@ for (i = j = 0, len = ref.length; j < len; i = ++j) {

if (typeof v === 'string') {
if (indexOf.call(accepted_header_types, v) < 0) {
throw Error(`Invalid column type: got "${v}", default values are ${JSON.stringify(accepted_header_types)}`);
}
this.options.columns[i] = Generator[v];

@@ -102,2 +132,6 @@ }

// ## `Generator.prototype.random()`
// Generate a random number between 0 and 1 with 2 decimals. The function is
// idempotent if it detect the "seed" option.
Generator.prototype.random = function() {

@@ -111,2 +145,5 @@ if (this.options.seed) {

// ## `Generator.prototype.end()`
// Stop the generation.
Generator.prototype.end = function() {

@@ -116,11 +153,17 @@ return this.push(null);

// ## `Generator.prototype._read(size)`
// Put new data into the read queue.
Generator.prototype._read = function(size) {
var column, data, header, j, k, l, len, len1, len2, len3, length, line, lineLength, m, ref;
// Already started
data = [];
length = this.fixed_size_buffer.length;
length = this._.fixed_size_buffer.length;
if (length) {
data.push(this.fixed_size_buffer);
data.push(this._.fixed_size_buffer);
}
while (true) {
if ((this.count_created === this.options.length) || (this.options.end && Date.now() > this.options.end)) {
// Time for some rest: flush first and stop later
if ((this._.count_created === this.options.length) || (this.options.end && Date.now() > this.options.end)) {
// Flush
if (data.length) {

@@ -130,12 +173,14 @@ if (this.options.objectMode) {

line = data[j];
this.count_written++;
this._.count_written++;
this.push(line);
}
} else {
this.count_written++;
this._.count_written++;
this.push(data.join(''));
}
}
// Stop
return this.push(null);
}
// Create the line
line = [];

@@ -145,4 +190,6 @@ ref = this.options.columns;

header = ref[k];
line.push("" + (header(this)));
// Create the field
line.push(`${header(this)}`);
}
// Obtain line length
if (this.options.objectMode) {

@@ -155,6 +202,7 @@ lineLength = 0;

} else {
line = "" + (this.count_created === 0 ? '' : '\n') + (line.join(this.options.delimiter));
// Stringify the line
line = `${(this._.count_created === 0 ? '' : '\n')}${line.join(this.options.delimiter)}`;
lineLength = line.length;
}
this.count_created++;
this._.count_created++;
if (length + lineLength > size) {

@@ -165,3 +213,3 @@ if (this.options.objectMode) {

line = data[m];
this.count_written++;
this._.count_written++;
this.push(line);

@@ -171,3 +219,3 @@ }

if (this.options.fixed_size) {
this.fixed_size_buffer = line.substr(size - length);
this._.fixed_size_buffer = line.substr(size - length);
data.push(line.substr(0, size - length));

@@ -177,3 +225,3 @@ } else {

}
this.count_written++;
this._.count_written++;
this.push(data.join(''));

@@ -188,4 +236,8 @@ }

// ## `Generator.ascii(gen)`
// Generate an ASCII value.
Generator.ascii = function(gen) {
var char, column, j, nb_chars, ref;
// Column
column = [];

@@ -199,2 +251,5 @@ for (nb_chars = j = 0, ref = Math.ceil(gen.random() * gen.options.max_word_length); 0 <= ref ? j < ref : j > ref; nb_chars = 0 <= ref ? ++j : --j) {

// ## `Generator.ascii(gen)`
// Generate an integer value.
Generator.int = function(gen) {

@@ -204,4 +259,12 @@ return Math.floor(gen.random() * Math.pow(2, 52));

// ## `Generator.bool(gen)`
// Generate an boolean value.
Generator.bool = function(gen) {
return Math.floor(gen.random() * 2);
};
// [documentation]: http://csv.adaltas.com/generate/
// [readme]: https://github.com/wdavidw/node-csv-generate
// [samples]: https://github.com/wdavidw/node-csv-generate/tree/master/samples
// [tests]: https://github.com/wdavidw/node-csv-generate/tree/master/test
{
"version": "1.0.0",
"version": "1.1.0",
"name": "csv-generate",

@@ -9,10 +9,12 @@ "description": "CSV and object generation implementing the Node.js `stream.Readable` API",

"type": "git",
"url": "http://www.github.com/wdavidw/node-csv-generate"
"url": "http://www.github.com/adaltas/node-csv-generate"
},
"homepage": "http://csv.adaltas.com/generate/",
"bugs": "https://github.com/adaltas/node-csv-generate/issues",
"author": "David Worms <david@adaltas.com> (http://www.adaltas.com)",
"dependencies": {},
"devDependencies": {
"coffee-script": "latest",
"mocha": "latest",
"should": "latest"
"coffeescript": "~2.0.1",
"mocha": "~4.0.1",
"should": "~13.1.2"
},

@@ -24,4 +26,4 @@ "optionalDependencies": {},

"pretest": "./node_modules/.bin/coffee -b -o lib src",
"test": "NODE_ENV=test ./node_modules/.bin/mocha --compilers coffee:coffee-script/register --reporter dot"
"test": "NODE_ENV=test ./node_modules/.bin/mocha test/**/*.coffee"
}
}

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

[![Build Status](https://secure.travis-ci.org/wdavidw/node-csv-generate.png)](http://travis-ci.org/wdavidw/node-csv-generate)
[![Build Status](https://secure.travis-ci.org/adaltas/node-csv-generate.svg)][travis]

@@ -21,3 +21,3 @@ CSV and object generation

Run `npm install csv` to install the full csv module or run
`npm install csv-generate` if you are only interested by the CSV parser.
`npm install csv-generate` if you are only interested by the CSV generator.

@@ -101,3 +101,3 @@ Use the callback style API for simplicity or the stream based API for

[home]: http://csv.adaltas.com/generate/
[csv]: https://github.com/wdavidw/node-csv
[travis]: https://travis-ci.org/#!/wdavidw/node-csv-generate
[csv]: https://github.com/adaltas/node-csv
[travis]: https://travis-ci.org/#!/adaltas/node-csv-generate
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