Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@igorskyflyer/normalized-string

igorskyflyer0MIT1.1.0TypeScript support: included

💊 NormalizedString provides you with a String type with consistent line-endings, guaranteed. 📮

string, string-utils, string-normalization, line-endings, newline, lf, crlf, cross-platform, text-processing, string-formatting, typescript, typescript-library, extendable, string-wrapper, text-normalization, igor dimitrijević, igorskyflyer

readme

Icon of Normalized String

Normalized String


💊 NormalizedString provides you with a String type with consistent line-endings, guaranteed. 📮



📃 Table of Contents



🤖 Features

  • 🔄 Guarantees consistent line endings across platforms
  • ⚙️ Automatically normalizes text to LF or CRLF format
  • 🛡️ Prevents mixed or invalid newline styles
  • 🧩 Extends base transformation logic for easy reuse
  • 📦 Encapsulates normalization in a single class
  • 🚀 Delivers ready-to-use normalized string output


🕵🏼 Usage

Install it by executing any of the following, depending on your preferred package manager:

pnpm add @igorskyflyer/normalized-string
yarn add @igorskyflyer/normalized-string
npm i @igorskyflyer/normalized-string


🤹🏼 API

constructor(value: string, endings: LineEndings = LineEnding.lf)

value - A string to work with.

endings - The line endings to use:

  • LineEnding.lf - UNIX-like line endings (line feed),

  • LineEnding.crlf - Windows line endings (carriage return + line feed).



You can also set the property value directly and the line endings will be correct.



🗒️ Examples

import { NormalizedString, LineEnding } from '@igorskyflyer/normalized-string'

const loremIpsum: string =
  'Lorem ipsum dolor sit amet, consectetur adipiscing elit.\r\n\r\nPellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.\n\nDuis in nulla ut leo lobortis venenatis.'

const lfEndings: NormalizedString = new NormalizedString(loremIpsum)

lfEndings.value = 'Hello\r\nworld!'

console.log(JSON.stringify(lfEndings.value)) // returns 'Hello\nworld'


import { NormalizedString, LineEnding } from '@igorskyflyer/normalized-string'

const loremIpsum: string =
  'Lorem ipsum dolor sit amet, consectetur adipiscing elit.\r\n\r\nPellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.\n\nDuis in nulla ut leo lobortis venenatis.'

const lfEndings: NormalizedString = new NormalizedString(loremIpsum) // LF are the default endings
const crlfEndings: NormalizedString = new NormalizedString(loremIpsum, LineEnding.crlf)

console.log(JSON.stringify(lfEndings.value)) // returns 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n\nPellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.\n\nDuis in nulla ut leo lobortis venenatis.'
console.log(JSON.stringify(crlfEndings.value)) // returns 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.\r\n\r\nPellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.\r\n\r\nDuis in nulla ut leo lobortis venenatis.'


📝 Changelog

📑 The changelog is available here, CHANGELOG.md.



🪪 License

Licensed under the MIT license which is available here, MIT license.



💖 Support

I work hard for every project, including this one and your support means a lot to me!
Consider buying me a coffee. ☕

Donate to igorskyflyer

Thank you for supporting my efforts! 🙏😊


@igorskyflyer/zing

🐌 Zing is a C# style String formatter for JavaScript that empowers Strings with positional arguments - composite formatting. 🚀


@igorskyflyer/strip-html

🥞 Removes HTML code from the given string. Can even extract text-only from the given an HTML string. ✨


@igorskyflyer/common-color

🎨 Provides common Color-related TypeScript types. 🌈


@igorskyflyer/astro-escaped-component

🏃🏻‍♂️‍➡️ An Astro component that holds only HTML-encoded content. 📜


@igorskyflyer/duoscribi

✒ DúöScríbî allows you to convert letters with diacritics to regular letters. 🤓




👨🏻‍💻 Author

Created by Igor Dimitrijević (@igorskyflyer).

changelog

📒 Changelog

of @igorskyflyer/normalized-string


v1.1.0 (04-Sep-2025)

  • 💻 dev: upgrade Node to >= v22
  • 💻 dev: upgrade dependencies


1.0.2 (02-Jul-2023)

  • dev: add this CHANGELOG file


1.0.1 (02-Jul-2023)

  • dev: add more code examples, document the value property


1.0.0 (30-Jun-2023)

  • initial release 🎉