import queryString from "query-string";

export function object2QueryString(obj) {
  return queryString.stringify(obj);
}

/**
 * 判断富文本是否是一个空，用来判断富文本是否为空
 *
 * @param {cont} 富文本对象
 */
export function isAnEmptyRichText(cont) {
  if (!cont) return true;

  if (!cont.sections || !cont.sections.length) return true;

  let blocks = [];
  cont.sections.forEach((section) => {
    blocks = [...blocks, ...section.blocks];
  });

  if (!blocks.length) return true;

  if (blocks.some((item) => item.type !== "text")) {
    return false;
  } else {
    return !blocks
      .map((item) => item.value)
      .join("")
      .trim();
  }
}
