Licence
MIT
Version
0.0.3
Deps
6
Vulns
0
Weekly
0
file-chain
fluent api for File operations, with concurrency safe read/writes & plugins
install
yarn add file-chain
npm i file-chain --save
use
const File = require('file-chain')
// can also import destructured
// const {File} = require('file-chain')
examples
const datas = File
.init()
.dir(__dirname)
.src('./index.js')
.load()
.json()
.setIfNotEmpty({eh: true})
.update({moose: true})
.parse() // optional, is done for you
.clean()
.write()
const stats = datas
.getStats() // read stats
.del() // delete file
.info() // stats are already loaded
dir
const file = File
.src('./index.js')
.dir(__dirname)
.load(true)
.setContent('...')
.prependContent('alpha')
.appendContent('omega')
.write() // alpha...omega
plugins
const plugin = {
setContentToMagic() {
this.contents = 'magic'
return this
}
}
const file = new File()
file
.use(plugin)
.src('./index.js')
.dir(__dirname)
.setContentToMagic()
.write()
more
- for json, json-chain is used
- for resolving paths (unless .dir is used), flipfind is used
- for all fs operations, flipfile is used
- for all chaining, flipchain is used