// Generated by CoffeeScript 2.3.2 // # Stream Transformer Sync // Provides a synchronous alternative to the CSV transformer. // ## Usage // `const records = transform(data, [options])` // ## Source Code var transform; transform = require('.'); module.exports = function() { var argument, callback, chunks, data, expected_handler_length, handler, i, j, k, l, len, len1, options, record, transformer, type, v; // Import arguments normalization options = {}; for (i = j = 0, len = arguments.length; j < len; i = ++j) { argument = arguments[i]; type = typeof argument; if (argument === null) { type = 'null'; } else if (type === 'object' && Array.isArray(argument)) { type = 'array'; } if (i === 0) { if (type === 'function') { handler = argument; } else if (type !== null) { data = argument; } continue; } if (type === 'object') { for (k in argument) { v = argument[k]; options[k] = v; } } else if (type === 'function') { if (handler && i === arguments.length - 1) { callback = argument; } else { handler = argument; } } else if (type !== 'null') { throw new Error('Invalid arguments'); } } // Validate arguments expected_handler_length = 1; if (options.params) { expected_handler_length++; } if (handler.length > expected_handler_length) { throw Error('Invalid Handler: only synchonous handlers are supported'); } // Start transformation chunks = []; transformer = new transform.Transformer(options, handler); transformer.push = function(chunk) { return chunks.push(chunk); }; for (l = 0, len1 = data.length; l < len1; l++) { record = data[l]; transformer._transform(record, null, (function() {})); } return chunks; };