How to use the web-ext-native-msg.Input function in web-ext-native-msg

To help you get started, we’ve selected a few web-ext-native-msg examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github asamuzaK / withExEditorHost / modules / main.js View on Github external
func.push(initPrivateTmpDir(value));
          break;
        default:
          func.push(
            writeStdout(hostMsg(`No handler found for ${key}.`, "warn")),
          );
      }
    }
  } else {
    func.push(writeStdout(hostMsg(`No handler found for ${msg}.`, "warn")));
  }
  return Promise.all(func);
};

/* input */
const input = new Input();

/**
 * read stdin
 * @param {string|Buffer} chunk - chunk
 * @returns {?AsyncFunction} - Promise chain
 */
const readStdin = chunk => {
  const func = [];
  const arr = input.decode(chunk);
  if (Array.isArray(arr) && arr.length) {
    for (const msg of arr) {
      msg && func.push(handleMsg(msg));
    }
  }
  return func.length && Promise.all(func).catch(handleReject) || null;
};