map-file

0.2.0 • Public • Published

map-file

Map a file into another file in Node.js

npm install map-file

API

mapFile({from, to, map=identity}, callback=done)

  • from is the reading filename
    • supports relative or absolute
  • to is the writing filename
    • supports relative or absolute
    • makes nonexistent directories via fs.mkdir
  • map is the function you use to map the content
    • default returns the original text
  • callback is a function to call after mapping
    • default throws errors and logs success

Usage

const mapFile = require("map-file")

Copy file

mapFile({
  from: "original.css",
  to: "copy.css",
})

Trim file

mapFile({
  from: "example.css",
  to: "example.css",
  map: text => text.trim(),
})

Slice file

mapFile({
  from: "full.md",
  to: "summary.md",
  map: text => text.slice(0, 200),
})

Callback

mapFile({
  from: "source.txt",
  to: "target.txt",
  map: text => text,
}, err => {
  if (err) throw err
  // ...
})

Package Sidebar

Install

npm i map-file

Weekly Downloads

1

Version

0.2.0

License

CC0-1.0

Last publish

Collaborators

  • ryanve