import api from "@/services/core/api";
/** 返回组合后的静态资源路径 */
export function composeImgUrl(imgStr?: string) {
  if (!imgStr) {
    return "";
  }
  return `${api.assetsUrl}${imgStr}`;
}
/**
 * @description 反序列化正则表达式
 * @param inputStr 反序列化前的字符串
 */
export function inversionSerializationRule(inputStr: string) {
  let value = JSON.parse(inputStr);

  if (Array.isArray(value) && value.length > 0) {
    const regexString = value[0].pattern.slice(1, -1);
    value[0].pattern = new RegExp(regexString);
  }

  return value;
}

export function objectToQuery(obj: Record<string, any>) {
  return Object.keys(obj)
    .map((k) => k + "=" + obj[k])
    .join("&");
}
