2.0.0 • Published 1 year ago

terminating-newline v2.0.0

Weekly downloads
17
License
MIT
Repository
github
Last release
1 year ago

If I should maintain this repo, please ⭐️

DM me on Twitter if you have questions or suggestions.


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
pnpm add 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";
  • autorepo: Autorepo abstracts away your dev dependencies, providing a single command to run all of your scripts.

MIT