UNPKG

vinmonopolet-ts

Version:

Extracts information on products, categories and stores from Vinmonopolet

31 lines (30 loc) 1.01 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const identity = (val) => val; const baseQuery = ":relevance:visibleInSearch:true:"; const reduceQuery = (query = "") => { return query.indexOf(baseQuery) === 0 ? query.substr(baseQuery.length) : query; }; class FacetValue { constructor(value, filter = identity) { this.name = filter(value.name); this.count = value.count; this.query = reduceQuery(value.query && value.query.query.value); } static cooerce(facetVal) { if (facetVal instanceof FacetValue) { return facetVal; } const val = String(facetVal); if (!/^\w+:.+/i.test(val)) { throw new Error("Facet value string must be in <facet>:<value> format"); } return new FacetValue({ query: { query: { value: val } } }); } } FacetValue.prototype.toString = function () { return this.query; }; exports.default = FacetValue;