Add or remove a terminating newline
npm install terminating-newlineAdd or remove a terminating newline.
_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.
``sh`
yarn add terminating-newline
`sh`
npm install terminating-newline
`sh`
pnpm add terminating-newline
ts
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"
`
$3
`ts
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";
``- detect-newline: Detect the dominant newline character of a string
- ends-with-string: Check if a string or buffer ends with a given string
- autorepo: Autorepo abstracts away your dev dependencies, providing a single command to run all of your scripts.