search-string demo

node v8.17.0
version: 2.0.0
const SearchString = require("search-string") // All pizzas to me NOT from jane topped with cheese and NOT mushrooms. :) const str = 'to:me 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":"","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 topping:cheese -topping:mushrooms,onion pizza searchString.toString();

no comments

    sign in to comment