index.ts 695 Bytes
import { DataSource } from '../../palette/types';
import { PublicComponentOptions } from '../index.type';
import { isArray } from '/@/utils/is';

export const getAttributeName = (option: PublicComponentOptions & DataSource) => {
  const { attribute, attributeRename, attributeName } = option || {};
  return attributeRename || attributeName || attribute;
};

export const useExtractValueByKeys = <T = Recordable>(
  keys: string[] | string,
  sourceValue: T = {} as T,
  defaultValue: Recordable = {} as Recordable
): T => {
  keys = isArray(keys) ? keys : [keys];
  return keys.reduce((prev, next) => {
    return { ...prev, [next]: sourceValue[next] || defaultValue[next] };
  }, {} as T);
};