import { exec } from 'child_process';
import sq from 'shell-quote';

/**
 * Customizable MeCab connector.
 */
export default class MeCab {
  /**
   * @param {string} command a command string to be executed via spawn.
   */
  constructor({ command = 'mecab' }) {
    this._command = command;
  }

  _getCommandStr(text) {
    const echoCommand = sq.quote(['echo', text]);
    return `${echoCommand} | ${this._command}`;
  }

  /**
   * Analyze a given text with MeCab.
   * @param {string} text a text string to be parsed.
   * @param {Function} [callback] a callback function.
   * @return {Promise<Array<Array<string>>}
   * @note The user can receive a result via a callback function
   *       and a promise object.
   */
  parse(text, callback) {
    return new Promise((resolve, reject) => {
      exec(this._getCommandStr(text), (err, result) => {
        if (err) {
          reject(err);
          if (callback) {
            callback(err);
          }
          return;
        }

        const parsed = result.split('\n')
          .map((line) => line.replace(/\t/g, ',').split(','))
          .filter((line) => line.length >= 6);

        resolve(parsed);

        if (callback) {
          callback(err, parsed);
        }
      });
    });
  }
}

@@ -525,198 +525,45 @@
  * @
-param %7BFunction%7D %5Bcallback%5D a callback function.%0A   * @return %7BPromise%3CArray%3CArray%3Cstring%3E%3E%7D%0A   * @note The user can receive a result via a callback function%0A   *       and a promise object.
+return %7BPromise%3CArray%3CArray%3Cstring%3E%3E%7D
 %0A   
@@ -581,18 +581,8 @@
 text
-, callback
 ) %7B%0A
@@ -696,106 +696,51 @@
     
-if (err) %7B%0A          reject(err);%0A          if (callback) %7B%0A            callback(err);%0A          %7D
+/* istanbul ignore if */%0A        if (err) %7B
 %0A   
@@ -752,16 +752,28 @@
   return
+ reject(err)
 ;%0A      
@@ -937,16 +937,23 @@
         
+return 
 resolve(
@@ -964,76 +964,8 @@
 ed);
-%0A%0A        if (callback) %7B%0A          callback(err, parsed);%0A        %7D
 %0A   

Remove callback support from Mecab#parse