JSPM

  • Created
  • Published
  • Downloads 121
  • Score
    100M100P100Q72096F
  • License MIT

A human-friendly file system with glob patterns

Package Exports

  • @techor/fs

Readme


Read a file content by glob patterns

NPM Version NPM Version NPM package ( download / month ) Follow @mastercorg Github release actions


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
}

NPM Version