fs-chain
v8.2.4
Published
A file I/O tool chain
Downloads
132
Maintainers
Readme
fs-chain
A file I/O tool chain.
Installation
npm install fs-chain --save-dev
Usage
const { Text, Json } = require('fs-chain');
new Text() // create file
.onDone(() => 'text:sample')
.output('./filename');
new Json() // copy file
.source('./old-filename')
.output('./new-filename');
new Text() // edit file
.source('./filename')
.onDone((data) => data.trim())
.output();
new Json() // transfer file
.source('./old-filename')
.onDone((data) => data.value)
.output('./new-filename');
new Json().source('~qss'); // require.resolve
new Text()
.onFail(() => {
// skip following step
throw new Error('skip');
})
.onDone(() => {
// other step
});
new Text()
.logger('testing 1') // √ testing 1
.onDone(() => {
throw new Error('fail');
})
.logger('testing 2'); // × testing 2
new Text(process.cwd()).source('./');
new Text(__dirname).source('./');
new Text(__filename).source('../');
new Text(import.meta.url).source('../');