JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1351
  • Score
    100M100P100Q134799F

angular2+ pipe to transform new line character to <br />

Package Exports

  • nl2br-pipe

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (nl2br-pipe) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

nl2br-pipe

  1. Description
  2. Installation
  3. Usage
  4. Methods
  5. Git repository
  6. Version

1. Description

nl2br-pipe or Nl2BrPipe is a pipe for angular2 projects which replaces the new line characters \n in a string with the <br /> tag.

2. Installation

Install the module into your application and save it as a dev dependency in your package.json file

npm install nl2br-pipe --save-dev

3. Usage

In order to use the Nl2BrPipe you have to include/import it into your application:

import {Nl2BrPipe} from "nl2br-pipe";

Include it in your components declarations list in your @NgModule(...):

@NgModule({
  //...
  declarations: [Nl2BrPipe],
  //...
})

Use it in your template to replace new line characters \n with the <br /> tag:

<div [innerHTML]="'<strong>test html content</strong>\nnew line\nthird line' | nl2br"></div>

Output:

<div>
  <strong>test html content</strong><br />new line<br />third line
</div>

4. Methods

transform(value: string): string

Replace the new line characters \n in a string with the <br /> tag Bypass security and trust the given value to be safe HTML. The sanitizer will leave safe HTML intact and will replace new line character \n with the <br /> tag.
WARNING: calling this method with untrusted user data exposes your application to XSS security risks!

Parameters:
value - string where to replace \n with <br /> and not to escape the HTML tags.

Return:
Method returns the new string containing <br /> tag instead of \n.

5. Git repository

https://github.com/tvicpe/nl2br-pipe

6. Version

0.0.4