UNPKG

bootstrap-vue

Version:

With more than 85 components, over 45 available plugins, several directives, and 1000+ icons, BootstrapVue provides one of the most comprehensive implementations of the Bootstrap v4 component and grid system available for Vue.js v2.6, complete with extens

40 lines (34 loc) 1.54 kB
import { arrayIncludes } from '../../../utils/array' import { isArray, isFunction } from '../../../utils/inspect' import { clone, keys, pick } from '../../../utils/object' import { IGNORED_FIELD_KEYS } from './constants' // Return a copy of a row after all reserved fields have been filtered out export const sanitizeRow = (row, ignoreFields, includeFields, fieldsObj = {}) => { // We first need to format the row based on the field configurations // This ensures that we add formatted values for keys that may not // exist in the row itself const formattedRow = keys(fieldsObj).reduce((result, key) => { const field = fieldsObj[key] const { filterByFormatted } = field const formatter = isFunction(filterByFormatted) ? /* istanbul ignore next */ filterByFormatted : filterByFormatted ? /* istanbul ignore next */ field.formatter : null if (isFunction(formatter)) { result[key] = formatter(row[key], key, row) } return result }, clone(row)) // Determine the allowed keys: // - Ignore special fields that start with `_` // - Ignore fields in the `ignoreFields` array // - Include only fields in the `includeFields` array const allowedKeys = keys(formattedRow).filter( key => !IGNORED_FIELD_KEYS[key] && !(isArray(ignoreFields) && ignoreFields.length > 0 && arrayIncludes(ignoreFields, key)) && !(isArray(includeFields) && includeFields.length > 0 && !arrayIncludes(includeFields, key)) ) return pick(formattedRow, allowedKeys) }