Socket
Socket
Sign inDemoInstall

detect-newline

Package Overview
Dependencies
0
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    detect-newline

Detect the dominant newline character of a string


Version published
Weekly downloads
23M
decreased by-0.48%
Maintainers
1
Install size
3.86 kB
Created
Weekly downloads
 

Package description

What is detect-newline?

The detect-newline npm package is designed to help developers identify the type of newline character used in a string. This can be particularly useful when working with text data that originates from different operating systems, as Unix, Windows, and old Mac systems use different characters for line breaks (`\n` for Unix/Linux, `\r\n` for Windows, and `\r` for old Mac). The package provides a simple interface to detect the newline character and can also gracefully handle mixed or absent newlines.

What are detect-newline's main functionalities?

Detect the most common newline character in a string

This feature allows you to detect the most common newline character in a given string. If the string contains mixed newline characters, the most common one is returned. If there's a tie, `\n` is returned by default.

"const detectNewline = require('detect-newline');\nconst mixedNewlines = 'Hello\r\nWorld\nHello World';\nconsole.log(detectNewline(mixedNewlines)); // '\r\n'"

Detect the newline character used at the end of a string

This functionality is useful for determining the newline character at the end of a string, which can be critical for appending lines to files or data streams while maintaining consistency with the existing newline format.

"const detectNewline = require('detect-newline');\nconst stringWithNewlineAtEnd = 'Hello World\n';\nconsole.log(detectNewline(stringWithNewlineAtEnd)); // '\n'"

Other packages similar to detect-newline

Readme

Source

detect-newline

Detect the dominant newline character of a string

Install

npm install detect-newline

Usage

import {detectNewline} from 'detect-newline';

detectNewline('foo\nbar\nbaz\r\n');
//=> '\n'

API

detectNewline(string)

Returns the detected newline or undefined when no newline character is found or \n when no dominant newline is present.

detectNewlineGraceful(unknown)

Returns the detected newline or \n when no newline character is found, no dominant newline is present, or the input is not a string.

  • detect-newline-cli - CLI for this module
  • detect-indent - Detect the indentation of code

Keywords

FAQs

Last updated on 22 Sep 2023

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