export const INPUT_MAX_LENGTH = { maxlength: 100 };

export const REMARK_MAX_LENGTH = {
  maxlength: 1000,
  showWordLimit: true
};

// 判断一个URI是否被encode过
export function isEncoded(URI: string = '') {
  if(!URI || URI.indexOf('%') === -1) return false
  return URI !== decodeURIComponent(URI);
}

// 从一个对象中提取部分属性 如果属性名带有|则认为是需要转换的属性
export function pick(obj: object, parameters: string[], translator?: Record<string, Function>): any{
  const newObject: object = {}
  if(!parameters || parameters.length === 0) return newObject

  for(let parameter of parameters){
    let originalParameter = ''
    // 需要转换
    if(parameter.indexOf('|') !== -1){
      const [source, target] = parameter.split('|')
      originalParameter = source
      parameter = target
    }

    let originalData = obj[originalParameter || parameter]
    if(translator[parameter]){ originalData = translator[parameter](originalData) }
    newObject[parameter] = originalData
  }

  return newObject
}
