search-string transformer example

node v8.17.0
version: 2.0.0
endpointsharetweet
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();
Loading…

no comments

    sign in to comment