Skip to content

Read and write files parsing and formatting according to file extension in the file path.

License

Notifications You must be signed in to change notification settings

fcostarodrigo/files

Repository files navigation

Files

Read and write files parsing and formatting according to file extension in the file path.

Install

npm i @fcostarodrigo/files

Features

  • Parse file based on extension.
  • Format files using prettier.
  • Create missing folders when writing files.

Usage

import { writeFile, readFile, fileExist } from "@fcostarodrigo/files";

await writeFile("user.json", { id: 123 });
const user = await readFile("user.json");
user.id; // 123

await fileExist("user.json"); // true

Options

Pass an object with the following properties as the last argument.

  • extension: Pretend the file has some extension.
  • parse: When reading a file, boolean to indicate if file should be parsed.
  • defaultValue: When reading a file, return default value if file doesn't exist
  • format: When writing a file, boolean to indicate if file should be formatted.

Available formats

  • json
  • js: Parsed with recast.
  • ts: Parsed with recast.
  • toml
  • yaml

Changelog

Changelog

License

MIT License

About

Read and write files parsing and formatting according to file extension in the file path.

Resources

License

Stars

Watchers

Forks

Packages

No packages published