const SearchString = require("search-string")
// All pizzas to me NOT from jane topped with cheese and NOT mushrooms. :)
const str = 'to:me -from:jane@mixmax.com pizza topping:cheese -topping:mushrooms'
// Parse string into SearchString object.
const searchString = SearchString.parse(str);
// Add another topping choise. In this case: NOT onions.
searchString.addEntry('topping', 'onion', true /* negated */);
// Get results into an array format:
/* [{"keyword":"to","value":"me","negated":false},{"keyword":"from","value":"jane@mixmax.com","negated":true},{"keyword":"topping","value":"cheese","negated":false},{"keyword":"topping","value":"-mushrooms","negated":false},{"keyword":"topping","value":"onion","negated":true}] */
searchString.getConditionArray();
// Get results back into a human readable string. Useful for passing to APIs.
// to:me -from:jane@mixmax.com topping:cheese -topping:mushrooms,onion pizza
searchString.toString();