An open API service indexing awesome lists of open source software.

https://github.com/igorskyflyer/npm-normalized-string

๐Ÿ’Š NormalizedString provides you with a String type with consistent line-endings, guaranteed. ๐Ÿ“ฎ
https://github.com/igorskyflyer/npm-normalized-string

back-end carriage-return crlf endings igorskyflyer javascript js lf line-endings line-feed node normalized normalized-string skyflyer string typescript utility

Last synced: 15 days ago
JSON representation

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

Awesome Lists containing this project

README

          


Icon of Normalized String

Normalized String




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




## ๐Ÿ“ƒ Table of Contents

- [Features](#-features)
- [Usage](#-usage)
- [API](#-api)
- [Examples](#๏ธ-examples)
- [Changelog](#-changelog)
- [Support](#-support)
- [License](#-license)
- [Related](#-related)
- [Author](#-author)




## ๐Ÿค– 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:

```bash
pnpm add @igorskyflyer/normalized-string
```

```bash
yarn add @igorskyflyer/normalized-string
```

```bash
npm i @igorskyflyer/normalized-string
```




## ๐Ÿคน๐Ÿผ API

```ts
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

```ts
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'
```




```ts
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](https://github.com/igorskyflyer/npm-normalized-string/blob/main/CHANGELOG.md).




## ๐Ÿชช License

Licensed under the MIT license which is available here, [MIT license](https://github.com/igorskyflyer/npm-normalized-string/blob/main/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](https://www.npmjs.com/package/@igorskyflyer/zing)

> _๐ŸŒ Zing is a C# style String formatter for JavaScript that empowers Strings with positional arguments - composite formatting. ๐Ÿš€_


[@igorskyflyer/strip-html](https://www.npmjs.com/package/@igorskyflyer/strip-html)

> _๐Ÿฅž Removes HTML code from the given string. Can even extract text-only from the given an HTML string. โœจ_


[@igorskyflyer/common-color](https://www.npmjs.com/package/@igorskyflyer/common-color)

> _๐ŸŽจ Provides common Color-related TypeScript types. ๐ŸŒˆ_


[@igorskyflyer/astro-escaped-component](https://www.npmjs.com/package/@igorskyflyer/astro-escaped-component)

> _๐Ÿƒ๐Ÿปโ€โ™‚๏ธโ€โžก๏ธ An Astro component that holds only HTML-encoded content. ๐Ÿ“œ_


[@igorskyflyer/duoscribi](https://www.npmjs.com/package/@igorskyflyer/duoscribi)

> _โœ’ DรบรถScrรญbรฎ allows you to convert letters with diacritics to regular letters. ๐Ÿค“_






## ๐Ÿ‘จ๐Ÿปโ€๐Ÿ’ป Author
Created by **Igor Dimitrijeviฤ‡** ([*@igorskyflyer*](https://github.com/igorskyflyer/)).