csv-generate
Advanced tools
Comparing version 1.1.1 to 1.1.2
@@ -1,15 +0,4 @@ | ||
// 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. | ||
// Generated by CoffeeScript 1.12.7 | ||
var Generator, stream, util, | ||
indexOf = [].indexOf; | ||
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; | ||
@@ -20,11 +9,2 @@ stream = require('stream'); | ||
// ## Usage | ||
// Callback approach, for ease of use: | ||
// `generate([options])` | ||
// Stream API, for maximum of power: | ||
// `generate([options], callback)` | ||
module.exports = function() { | ||
@@ -64,14 +44,5 @@ var callback, data, generator, options; | ||
// ## `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 = {}) { | ||
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 | ||
this.options = options1 != null ? options1 : {}; | ||
stream.Readable.call(this, this.options); | ||
@@ -99,3 +70,2 @@ if ((base = this.options).columns == null) { | ||
} | ||
// State | ||
this._ = { | ||
@@ -120,3 +90,3 @@ fixed_size_buffer: '', | ||
if (indexOf.call(accepted_header_types, v) < 0) { | ||
throw Error(`Invalid column type: got "${v}", default values are ${JSON.stringify(accepted_header_types)}`); | ||
throw Error("Invalid column type: got \"" + v + "\", default values are " + (JSON.stringify(accepted_header_types))); | ||
} | ||
@@ -133,6 +103,2 @@ this.options.columns[i] = Generator[v]; | ||
// ## `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() { | ||
@@ -146,5 +112,2 @@ if (this.options.seed) { | ||
// ## `Generator.prototype.end()` | ||
// Stop the generation. | ||
Generator.prototype.end = function() { | ||
@@ -154,8 +117,4 @@ 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 = []; | ||
@@ -167,5 +126,3 @@ length = this._.fixed_size_buffer.length; | ||
while (true) { | ||
// 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) { | ||
@@ -183,6 +140,4 @@ if (this.options.objectMode) { | ||
} | ||
// Stop | ||
return this.push(null); | ||
} | ||
// Create the line | ||
line = []; | ||
@@ -192,6 +147,4 @@ ref = this.options.columns; | ||
header = ref[k]; | ||
// Create the field | ||
line.push(`${header(this)}`); | ||
line.push("" + (header(this))); | ||
} | ||
// Obtain line length | ||
if (this.options.objectMode) { | ||
@@ -204,4 +157,3 @@ lineLength = 0; | ||
} else { | ||
// Stringify the line | ||
line = `${(this._.count_created === 0 ? '' : '\n')}${line.join(this.options.delimiter)}`; | ||
line = "" + (this._.count_created === 0 ? '' : '\n') + (line.join(this.options.delimiter)); | ||
lineLength = line.length; | ||
@@ -235,8 +187,4 @@ } | ||
// ## `Generator.ascii(gen)` | ||
// Generate an ASCII value. | ||
Generator.ascii = function(gen) { | ||
var char, column, j, nb_chars, ref; | ||
// Column | ||
column = []; | ||
@@ -250,5 +198,2 @@ 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) { | ||
@@ -258,12 +203,4 @@ 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.1.1", | ||
"version": "1.1.2", | ||
"name": "csv-generate", | ||
@@ -4,0 +4,0 @@ "description": "CSV and object generation implementing the Node.js `stream.Readable` API", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11890
204