UNPKG

bootstrap-vue

Version:

BootstrapVue, with over 40 plugins and more than 80 custom components, custom directives, and over 300 icons, provides one of the most comprehensive implementations of Bootstrap v4 components and grid system for Vue.js. With extensive and automated WAI-AR

33 lines (30 loc) 1.31 kB
import { keys } from '../../../utils/object' import { arrayIncludes } from '../../../utils/array' import { isFunction } from '../../../utils/inspect' import { IGNORED_FIELD_KEYS } from './constants' // Return a copy of a row after all reserved fields have been filtered out const sanitizeRow = (row, ignoreFields, includeFields, fieldsObj = {}) => keys(row).reduce((obj, key) => { // Ignore special fields that start with `_` // Ignore fields in the `ignoreFields` array // Include only fields in the `includeFields` array if ( !IGNORED_FIELD_KEYS[key] && !(ignoreFields && ignoreFields.length > 0 && arrayIncludes(ignoreFields, key)) && !(includeFields && includeFields.length > 0 && !arrayIncludes(includeFields, key)) ) { const f = fieldsObj[key] || {} const val = row[key] // `f.filterByFormatted` will either be a function or boolean // `f.formater` will have already been noramlized into a function ref const filterByFormatted = f.filterByFormatted const formatter = isFunction(filterByFormatted) ? filterByFormatted : filterByFormatted ? f.formatter : null obj[key] = isFunction(formatter) ? formatter(val, key, row) : val } return obj }, {}) export default sanitizeRow