tabs-to-spaces-stream

1.0.1 • Public • Published

tabs-to-spaces-stream

Travis Codecov npm npm semantic-release

A little library that converts tabs in streaming data to spaces.

Installation

npm install --save tabs-to-spaces-stream

Usage

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

API

convertStream(numberOfSpaces)

 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)

convert(str, numberOfSpaces)

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'

Contributing

This is a pretty small library but if you find any issues, I'll happily take pull requests.

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i tabs-to-spaces-stream

Weekly Downloads

2

Version

1.0.1

License

MIT

Last publish

Collaborators

  • emilkloeden