UNPKG

@empathyco/x-components

Version:
38 lines (36 loc) 1.25 kB
/** * Sets the query of the module. * * @param state - State of the module. * @param query - The new query to set. * @public */ function setQuery(state, query) { state.query = query; } /** * Creates a getter that combines the current selected related tags and the query of the module. * * @param options - Options on how the getter should behave. * @returns A getter that combines the selected related tags with the query. * @public */ function createRelatedTagsQueryGetter({ getRelatedTags, }) { return function relatedTagsQuery(state, getters) { const query = state.query.trim(); return query ? getRelatedTags(state, getters).reduce(concatRelatedTag, query).trim() : ''; }; } /** * Joins a query and a related tag respecting the tag position. * * @param partialQuery - The query to concatenate the related tag with. * @param relatedTag - The related tag to concatenate. * @returns The query and the related tag joined. * @internal */ function concatRelatedTag(partialQuery, { tag, query: relatedTagQuery }) { return relatedTagQuery.startsWith(tag) ? `${tag} ${partialQuery}` : `${partialQuery} ${tag}`; } export { createRelatedTagsQueryGetter, setQuery }; //# sourceMappingURL=query.utils.js.map