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

46 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

normalized-string

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


๐Ÿ’– Support further development

Donate to igorskyflyer



๐Ÿ•ต๐Ÿผโ€โ™‚๏ธ Usage

Install it by executing:

npm i "@igor.dvlpr/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.


import { NormalizedString, LineEnding } from '@igor.dvlpr/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'


๐Ÿค” Examples

import { NormalizedString, LineEnding } from '@igor.dvlpr/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.'