@fcostarodrigo/files
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i @fcostarodrigo/files

Weekly Downloads

3

Version

1.0.0

License

MIT

Unpacked Size

8.36 kB

Total Files

13

Last publish

Collaborators

  • fcostarodrigo