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. ๐ฎ
- Host: GitHub
- URL: https://github.com/igorskyflyer/npm-normalized-string
- Owner: igorskyflyer
- License: mit
- Created: 2023-05-30T22:54:56.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-07-02T15:36:48.000Z (almost 3 years ago)
- Last Synced: 2025-04-12T15:06:26.838Z (about 1 year ago)
- Topics: back-end, carriage-return, crlf, endings, igorskyflyer, javascript, js, lf, line-endings, line-feed, node, normalized, normalized-string, skyflyer, string, typescript, utility
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@igor.dvlpr/normalized-string
- Size: 52.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
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. โ
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/)).