search-string transformer example
const SearchString = require("search-string")
// Declare a short list of known pizza toppings.
const pizzaToppings = ['cheese', 'mushrooms', 'onions', 'green pepper'];
// A simple transformer that detects toppings in the string and adds them to the 'topping' search operator.
const toppingTransformer = (text) => (pizzaToppings.indexOf(text) >= 0 && { key: 'topping', value: text });
// Perform the parsing including the transformer.
const searchString = SearchString.parse('to:me cheese mushrooms dominos', [toppingTransformer]);
// Get back the human readable parsed search string.
// 'to:me topping:cheese,mushrooms dominos'
searchString.toString();
no comments