A little library that converts tabs in streaming data to spaces.
npm install --save tabs-to-spaces-stream
const fs = require('fs')
const {convertStream} = require('tabs-to-spaces-stream')
const myStream = fs.createReadStream('hello.txt') //contents: hello world
myStream
.pipe(convertStream(4))
.pipe(process.stdout)
// hello world
const {convertStream} = require('tabs-to-spaces-stream')
/**
* Returns a transform stream converting tabs to spaces.
* Buffer streams will be converted to strings by default.
*
* @param {number} [numberOfSpaces=2] The number of spaces
* to replace each tab with.
* @throws {RangeError}
* @returns {stream}
*/
src
.pipe(convertStream())
.pipe(dest)
Alternatively you can use the base function that converts tabs to spaces in a string.
const {convert} = require('tabs-to-spaces-stream')
/**
* Returns a string converting tabs to spaces
*
* @param {string} str
* @param {number} [numberOfSpaces=2] The number of spaces
* to replace each tab with. Default is 2.
* @returns {string}
*/
convert('Hello world', 6) // 'Hello world'
This is a pretty small library but if you find any issues, I'll happily take pull requests.
MIT