Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 

terminating-newline

NPM TypeScript Coverage Status GitHub Stars Twitter Follow

Add or remove a terminating newline.

Supports both line feeds (/n) and carriage return line feeds (/r/n). Will only add a newline if one does not already exist.

Installation

yarn add terminating-newline
npm install terminating-newline

API

Usage

import {
  addTerminatingNewline,
  removeTerminatingNewline,
  lineFeed, // "\n"
  carriageReturnLineFeed // "/r/n"
} from "terminating-newline";

addTerminatingNewline("abc", { default: lineFeed }); // "abc/n"

addTerminatingNewline("abc\n", { default: lineFeed }); // "abc/n"

removeTerminatingNewline("abc\n"); // "abc"

Types

function addTerminatingNewline(string: string, options?: Options): string;
function addTerminatingNewline(buffer: Buffer, options?: Options): Buffer;

function removeTerminatingNewline(string: string): string;
function removeTerminatingNewline(buffer: Buffer): Buffer;

type Options = {
  // Fallback if newline type cannot be determined. Default: "\n"
  default?: LineFeed | CarriageReturnLineFeed;
}

type LineFeed = "\n";

type CarriageReturnLineFeed = "\r\n";

Dependenciesdependencies


Dev DependenciesDavid


License license

MIT

About

Add terminating newline if none exists. Supports Unix and Windows newline styles.

Resources

Packages

No packages published