wzp
2021-05-13 7d694a9113118daec5be7ac224dab46a3b20f106
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
"use strict";
 
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
 
// Generated by CoffeeScript 2.4.1
// # Stream Transformer Sync
// Provides a synchronous alternative to the CSV transformer.
// ## Usage  
// `const records = transform(records, [options], handler)`  
// ## Source Code
var clone, transform;
transform = require('.');
 
var _require = require('mixme');
 
clone = _require.clone;
 
module.exports = function () {
  var argument, callback, chunks, expected_handler_length, handler, i, j, k, len, len1, options, record, records, transformer, type; // 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 (type === 'array') {
      records = argument;
    } else if (type === 'object') {
      options = clone(argument);
    } else if (type === 'function') {
      if (handler && i === arguments.length - 1) {
        callback = argument;
      } else {
        handler = argument;
      }
    } else if (type !== 'null') {
      throw new Error("Invalid Arguments: got ".concat(JSON.stringify(argument), " at position ").concat(i));
    }
  } // 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 (k = 0, len1 = records.length; k < len1; k++) {
    record = records[k];
 
    transformer._transform(record, null, function () {});
  }
 
  return chunks;
};