UNPKG

@lucasolivamorim/nl2br-pipe

Version:

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

28 lines 1.01 kB
import { Pipe, SecurityContext } from '@angular/core'; import { DomSanitizer } from '@angular/platform-browser'; var Nl2BrPipe = /** @class */ (function () { function Nl2BrPipe(sanitizer) { this.sanitizer = sanitizer; } Nl2BrPipe.prototype.transform = function (value, sanitizeBeforehand) { if (typeof value !== 'string') return value; // Protect against runtime errors var textParsed = value.replace(/(?:\r\n|\r|\n)/g, '<br />'); if (sanitizeBeforehand) { textParsed = this.sanitizer.sanitize(SecurityContext.HTML, textParsed) || value; } return textParsed; }; Nl2BrPipe.decorators = [ { type: Pipe, args: [{ name: 'nl2br' },] }, ]; /** @nocollapse */ Nl2BrPipe.ctorParameters = function () { return [ { type: DomSanitizer, }, ]; }; return Nl2BrPipe; }()); export { Nl2BrPipe }; //# sourceMappingURL=nl2br.pipe.js.map