Line Ending Corrector - An utility that makes sure your files have consistent line endings.
Last updated 5 years ago by ishafayet .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install line-ending-corrector 
SYNC missed versions from official npm registry.


Line Ending Corrector - A utility that makes sure your files have consistent line endings.

It converts all those pesky \r\n (a.k.a CRLF) line endings in Microsoft Windows operating systems into the more commonly used and recognized \n (a.k.a LF). Though it lets you do the opposite as well ( converting LF to CRLF ). It supports \r (a.k.a CR) as well for the sake of completion.

You should definitely have this in your build process especially if someone in your team works from a non UNIX system.


  • Supports recusive mode for all files in a directory
  • Can be used from the command line using lec. See Here
  • Has a gulp module
  • Exposes a programmatic API.


For using programmatically

[sudo] npm install line-ending-corrector

Programmatic Usage

To require


{ LineEndingCorrector } = require 'line-ending-corrector'


LineEndingCorrector = require('line-ending-corrector').LineEndingCorrector


LineEndingCorrector.correctSync(contents, options)

returns [ wasAltered Boolean, modifiedContents String ]


contentsOfSomeFile = arbitaryFunctionToLoadFile()
[ wasAltered, modifiedContents ] = LineEndingCorrector.correctSync contentsOfSomeFile
if wasAltered
  arbitaryFunctionToSaveFile modifiedContents


contentsOfSomeFile = arbitaryFunctionToLoadFile();
res = LineEndingCorrector.correctSync(contentsOfSomeFile);
if(res.wasAltered) {


contentsOfSomeFile = arbitaryFunctionToLoadFile();
{ wasAltered, modifiedContents } = LineEndingCorrector.correctSync(contentsOfSomeFile);
if(wasAltered) {

LineEndingCorrector.correctStream(contentStream, options)

returns modifiedContentStream stream.Readable


contentStream = arbitaryFunctionToLoadFileAsStream()
modifiedContentStream = LineEndingCorrector.correctStream contentStream, { encoding: 'utf8', eolc: 'LF'}
arbitaryFunctionToSaveFileFromStream modifiedContents

LineEndingCorrector.correct(content, options, callbackFunction)

callbackFunction is called with (err Error, wasAltered boolean, modifiedContent String)


content = arbitaryFunctionToLoadFile()
LineEndingCorrector.correct content, { eolc: 'LF' }, (err, wasAltered, modifiedContent)=>
  throw err if err
  if wasAltered
    arbitaryFunctionToSaveFileFromStream modifiedContent


eolc Desired End of Line character. can be CR (\r), LF(\n) (Default), CRLF(\r\n)

encoding Any meaningful encoding that nodejs supports. Default utf8. It is advisable to use utf8 since others are not tested by the devs.


See gulp-line-ending-corrector


You need mocha

npm test


We actively check for issues even for the least used repositories (unless explicitly abandoned). All of our opensource repositories are being used in commercial projects by teamO4 or bbsenterprise. So, it is very likely that we will sort out important issues not long after they are posted.

Please create a github issue if you find a bug or have a feature request.

Pull requests are always welcome for any of our public repos.

Current Tags

  • 1.0.1                                ...           latest (3 years ago)

6 Versions

  • 1.0.1                                ...           3 years ago
  • 1.0.0                                ...           5 years ago
  • 0.0.4                                ...           5 years ago
  • 0.0.3                                ...           5 years ago
  • 0.0.2                                ...           5 years ago
  • 0.0.1                                ...           5 years ago
Maintainers (1)
Today 0
This Week 26
This Month 50
Last Day 9
Last Week 35
Last Month 118
Dependencies (1)
Dev Dependencies (2)

Copyright 2014 - 2017 © |