Giter VIP home page Giter VIP logo

read-transform-write's Introduction

read-transform-write

An easy-to-use utility to transform files with a single function.
It uses fs.readFile and fs.writeFile under the hood and throws an error if something goes wrong.
The encoding is set to utf8. If you need something else, please file an issue.

TravisCI Test Coverage npm version npm downloads dependencies

Support Me

If you're using Robin Frischmann's work, please consider supporting his Open Source Projects on Patreon.

Installation

# yarn
yarn add read-transform-write

# npm
npm i --save read-transform-write

Usage

Parameter

Parameter Type  Description
inputPath (string) The absolute path to the input file.
transform (Function) The transformation method.
It receives the input data and returns method receving a write-method that must be called with the transformed data and a output path.
callback (Function?) An optional callback that receives an object with the callback shape.

Callback Shape

type Callback {
  inputPath: string,
  outputPath: string,
  input: string,
  output: string
}

Example

import { join } from 'path'
import transformFile from 'read-transform-write'

const input = join(__dirname, 'input.txt')
const output = join(__dirname, 'output.txt')

const transform = data => write => write(
  output,
  data
    .split('\n')
    .map(val => parseInt(val, 10))
    .map(Math.sqrt)
    .join('\n')
)

transformFile(
  input,
  transform,
  ({ output, outputPath }) => {
    console.log(`Written ${output} to ${outputPath}.`)
  }
)
input.txt
49
36
25
16
output.txt
7
6
5
4

License

read-transform-write is licensed under the MIT License.
Documentation is licensed under Creative Common License.
Created with ♥ by @rofrischmann.

read-transform-write's People

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.