Brent Keller

Check if a file contains an exact string

Very basic check to see if a file contains an exact string.

// Typescript
import * as fse from 'fs-extra';

export const fileContainsString = async (
  str: string | null | undefined,
  filepath: string,
) => {
  if (!str) return false;
  const data = await fse.readFile(filepath);
  if (data.includes(str)) return true;
  return false;
};