fs-chain

A file I/O tool chain.

Usage no npm install needed!

<script type="module">
  import fsChain from 'https://cdn.skypack.dev/fs-chain';
</script>

README

fs-chain

A file I/O tool chain.

npm github node

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

// base url
new Text(process.cwd()).source('./');
new Text(__dirname).source('./');
new Text(__filename).source('../');
new Text(import.meta.url).source('../');