export function toCells()

in website/src/components/explorer/utils.ts [68:100]


export function toCells(str: string): (string | undefined)[] | undefined {
  str = str.trim();
  if (isValidCell(str)) {
    return [str];
  }
  if (isBigIntString(str)) {
    const bigint = BigInt(str);
    const index = bigint.toString(16);
    if (isValidCell(index)) {
      return [index];
    }
  }
  // Check if json
  try {
    const parsed = JSON.parse(str);
    if (Array.isArray(parsed)) {
      return parsed.flatMap(toCells);
    }
  } catch {
    // Do nothing
  }
  if (str.includes(",")) {
    return str.split(",").flatMap(toCells);
  }
  if (str.startsWith("[")) {
    return toCells(str.slice(1));
  }
  if (str.endsWith("]")) {
    return toCells(str.slice(0, -1));
  }

  return undefined;
}