FieldControl/carchost-node

View on GitHub
src/core/filter.js

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
const filterWith = (filter = {}, allowedProps = []) => {
  const filters = []
  for (const objectKey of Object.keys(filter)) {
    if (allowedProps.includes(objectKey)) {
      filters.push(`${objectKey}:"${filter[objectKey]}"`)
    }
  }
  return {
    q: filters.length ? filters.join(' ') : undefined
  }
}

module.exports = {
  filterWith
}