fs-chain

8.2.3 • Public • Published

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

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

Package Sidebar

Install

npm i fs-chain

Weekly Downloads

37

Version

8.2.3

License

MIT

Unpacked Size

7.98 kB

Total Files

6

Last publish

Collaborators

  • airkro