Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
"use strict";

const _require = require('path'),
      resolve = _require.resolve;

const log = require('fliplog');

const parse = require('csv-parse/lib/sync');

const _require2 = require('flipfile'),
      read = _require2.read,
      write = _require2.write;

const _require3 = require("../../chain-able/exportsMiddleman"),
      keyValueToIterator = _require3.keyValueToIterator,
      keys = _require3.keys;

class Spreadsheet {
  static init() {
    return new Spreadsheet().setReadPath().setWritePath().read().parse().setup();
  }

  setReadPath(pathname = './csv.csv') {
    this.filePath = resolve(__dirname, pathname);
    return this;
  }

  setWritePath(pathname = './output.csv') {
    this.outputPath = resolve(__dirname, pathname);
    return this;
  }

  read() {
    const contents = read(this.filePath);
    this.contents = contents;
    return this;
  }

  parse() {
    const parseOptions = {
      columns: true
    };
    const rows = parse(this.contents, parseOptions);
    this.rows = rows;
    return this;
  }

  setup() {
    this.setupOutputString();
    return this;
  } // private


  setupOutputString() {
    // save this to spreadsheet
    this.outputString = '';
    this.outputString += this.headings;
  } // in csv, this is first line


  get headings() {
    return Object.keys(this.rows[0]).join(',') + '\n';
  }

  transformRow(row) {
    // is indexed
    // const { img_main, img_alt, photograph, skuid } = row
    return row;
  } // eslint-disable-next-line


  async onRow(row) {
    log.bold('row').data(row).echo();
    const transformedRow = this.transformRow(row);
    const asString = Object.values(transformedRow).map(cell => cell).join(',') + '\n';
    this.outputString += asString;
    log.blue(asString).echo();
    return Promise.resolve(asString);
  }

  save() {
    const rowrowrowYourBoat = this.rows.map(this.onRow);

    const gentlyDownTheStream = () => write(this.outputPath, this.outputString);

    Promise.all(rowrowrowYourBoat).then(gentlyDownTheStream);
  }

  [Symbol.iterator]() {
    const range = keys(this.rows);
    return keyValueToIterator(range, this.rows, this.rows.length);
  }
  /**
   * ls
   */


  set(columnName = 'columnName.rowName?') {//
  }

  get(columnName = 'columnName.rowName?') {}

  has(key) {//
  }

  delete(key) {//
  }

}

const csv = Spreadsheet.init();

for (const row of csv) {
  console.log({
    row
  });
}