trim-newlines

  • Version 5.0.0
  • Published
  • 4.61 kB
  • No dependencies
  • MIT license

Install

npm i trim-newlines
yarn add trim-newlines
pnpm add trim-newlines

Overview

Trim newlines from the start and/or end of a string

Index

Functions

function trimNewlines

trimNewlines: <S extends string>(string: S) => Trim<S>;
  • Trim from the start and end of a string.

    Example 1

    import {trimNewlines} from 'trim-newlines';
    trimNewlines('\nšŸ¦„\nšŸ¦„\r\n');
    //=> 'šŸ¦„\nšŸ¦„'

function trimNewlinesEnd

trimNewlinesEnd: <S extends string>(string: S) => TrimEnd<S>;
  • Trim from the end of a string.

    Example 1

    import {trimNewlinesEnd} from 'trim-newlines';
    trimNewlinesEnd('\nšŸ¦„\r\n');
    //=> '\nšŸ¦„'

function trimNewlinesStart

trimNewlinesStart: <S extends string>(string: S) => TrimStart<S>;
  • Trim from the start of a string.

    Example 1

    import {trimNewlinesStart} from 'trim-newlines';
    trimNewlinesStart('\nšŸ¦„\r\n');
    //=> 'šŸ¦„\r\n'

Type Aliases

type Newline

type Newline =
| '\u{A}' // '\n'
| '\u{D}'; // '\r'

    type Trim

    type Trim<S extends string> = TrimStart<TrimEnd<S>>;

      type TrimEnd

      type TrimEnd<S extends string> = S extends `${infer R}${Newline}` ? TrimEnd<R> : S;

        type TrimStart

        type TrimStart<S extends string> = S extends `${Newline}${infer R}`
        ? TrimStart<R>
        : S;

          Package Files (1)

          Dependencies (0)

          No dependencies.

          Dev Dependencies (3)

          Peer Dependencies (0)

          No peer dependencies.

          Badge

          To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

          You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/trim-newlines.

          • Markdown
            [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/trim-newlines)
          • HTML
            <a href="https://www.jsdocs.io/package/trim-newlines"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>