https://github.com/airkro/fs-chain
https://github.com/airkro/fs-chain
Last synced: 5 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/airkro/fs-chain
- Owner: Airkro
- License: mit
- Created: 2019-03-25T04:00:36.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-04-10T05:43:11.000Z (about 1 year ago)
- Last Synced: 2024-04-10T10:27:50.750Z (about 1 year ago)
- Language: JavaScript
- Size: 991 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fs-chain
A file I/O tool chain.
[![npm][npm-badge]][npm-url]
[![github][github-badge]][github-url]
![node][node-badge][npm-url]: https://www.npmjs.com/package/fs-chain
[npm-badge]: https://img.shields.io/npm/v/fs-chain.svg?style=flat-square&logo=npm
[github-url]: https://github.com/airkro/fs-chain
[github-badge]: https://img.shields.io/npm/l/fs-chain.svg?style=flat-square&colorB=blue&logo=github
[node-badge]: https://img.shields.io/node/v/fs-chain.svg?style=flat-square&colorB=green&logo=node.js## Installation
```bash
npm install fs-chain --save-dev
```## Usage
```cjs
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 2new Text(process.cwd()).source('./');
new Text(__dirname).source('./');
new Text(__filename).source('../');
``````mjs
new Text(import.meta.url).source('../');
```