Socket
Socket
Sign inDemoInstall

trim-trailing-lines

Package Overview
Dependencies
0
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    trim-trailing-lines

Remove final line feeds from a string


Version published
Weekly downloads
2.7M
increased by3.73%
Maintainers
1
Install size
6.52 kB
Created
Weekly downloads
 

Package description

What is trim-trailing-lines?

The npm package 'trim-trailing-lines' is designed to remove trailing newline characters from a string. This is particularly useful in text processing where consistent formatting is required, or when preparing output for further processing that does not handle trailing newlines well.

What are trim-trailing-lines's main functionalities?

Trim trailing newlines

This feature allows you to remove all trailing newline characters from the end of a string. It is useful for cleaning up text data before saving or processing it further.

const trimTrailingLines = require('trim-trailing-lines');
const result = trimTrailingLines('Hello World\n\n');
console.log(result); // 'Hello World'

Other packages similar to trim-trailing-lines

Readme

Source

trim-trailing-lines

Build Coverage Downloads Size

Remove final line endings from a string.

Contents

What is this?

This is a tiny package that removes final line endings (CR, LF, CR+LF) from a string.

When should I use this?

This package is rather niche, I found myself repeating this code when working with a lot of markdown.

Install

This package is ESM only. In Node.js (version 14.14+, 16.0+), install with npm:

npm install trim-trailing-lines

In Deno with esm.sh:

import {trimTrailingLines} from 'https://esm.sh/trim-trailing-lines@2'

In browsers with esm.sh:

<script type="module">
  import {trimTrailingLines} from 'https://esm.sh/trim-trailing-lines@2?bundle'
</script>

Use

import {trimTrailingLines} from 'trim-trailing-lines'

trimTrailingLines('foo\nbar') // => 'foo\nbar'
trimTrailingLines('foo\nbar\n') // => 'foo\nbar'
trimTrailingLines('foo\nbar\n\n') // => 'foo\nbar'

API

This package exports the identifier trimTrailingLines. There is no default export.

trimTrailingLines(value)

Remove final line endings from value.

Parameters
valeu

Value with trailing line endings, coerced to string (unknown).

Returns

Value without trailing line endings (string).

Types

This package is fully typed with TypeScript. It exports no additional types.

Compatibility

This package is at least compatible with all maintained versions of Node.js. As of now, that is Node.js 14.14+ and 16.0+. It also works in Deno and modern browsers.

Contribute

Yes please! See How to Contribute to Open Source.

Security

This package is safe.

License

MIT © Titus Wormer

Keywords

FAQs

Last updated on 14 Nov 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc