Package Exports
- @techor/fs
Readme
Getting Started
npm install @techor/fs
Usage
readFile(source?: fg.Pattern | fg.Pattern[], options?: Options): Buffer
readFileAsStr(source?: fg.Pattern | fg.Pattern[], options?: Options): string
readFileAsJSON(source?: fg.Pattern | fg.Pattern[], options?: Options): any
readFiles(source?: fg.Pattern | fg.Pattern[], options?: Options): Buffer[]
writeToFile(filePath: fs.PathOrFileDescriptor, data: any, options?: WriteToFileOptions): void
a.json
{ "name": "a" }
b.json
{ "name": "b" }
import { readFile, readFiles } from '@techor/fs'
readFile('a.*')
// Buffer
readFile('./fewjiogw/wiefoiwe')
// undefined
readFileAsStr('a.*')
// '{ "name": "a" }'
readFileAsJSON('./package.json')
// { "name": "root", ... }
readFileAsJSON('./package.json', { cwd: path.resolve('./packages/a') })
// { "name": "a", ... }
readFiles('*.json').toString()
// [Buffer, Buffer]
Options
File reading methods inherit fast-glob options
{
cwd: process.cwd()
}
With additional options:
{
encoding?: null
flag?: string
}