isText

tcmts.cli.files.isText · #bn5udtsp · term · runs anywhere

Whether content is text: valid UTF-8.

export function isText(content: Buffer): boolean {
  try {
    new TextDecoder("utf-8", { fatal: true }).decode(content);
    return true;
  } catch {
    return false;
  }
}

used by