Skip to content

๐Ÿ’Š NormalizedString provides you with a String type with consistent line-endings, guaranteed. ๐Ÿ“ฎ

License

Notifications You must be signed in to change notification settings

igorskyflyer/npm-normalized-string

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

68 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

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! ๐Ÿ™๐Ÿ˜Š


๐Ÿงฌ Related

@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).

Sponsor this project