Source

admin-bro/src/utils/flat/filter-out-params.ts

import { propertyKeyRegex } from './property-key-regex'
import { FlattenParams } from './flat.types'

/**
 * @load ./filter-out-params.doc.md
 * @memberof module:flat
 * @param {FlattenParams} params
 * @param {string | Array<string>} properties
 * @returns {FlattenParams}
 */
const filterOutParams = (
  params: FlattenParams,
  properties: string | Array<string>,
): FlattenParams => {
  const propertyArray = Array.isArray(properties) ? properties : [properties]

  return propertyArray
    .filter(propertyPath => !!propertyPath)
    .reduce((globalFiltered, propertyPath) => {
      const regex = propertyKeyRegex(propertyPath)

      return Object.keys(globalFiltered)
        .filter(key => !key.match(regex))
        .reduce((memo, key) => {
          memo[key] = (params[key] as string)
          return memo
        }, {} as FlattenParams)
    }, params)
}

export { filterOutParams }
SoftwareBrothers

Proudly built and maintained by SoftwareBrothers

Software House with a passion for both JavaScript and TypeScript.

See what we do See what we believe in

Proudly built and maintained by

SoftwareBrothers