utils.js 653 Bytes
Newer Older
1 2 3
(function(define, undefined) {
    'use strict';
    define([], function($, _) {
4 5 6 7 8 9 10 11 12 13 14 15
    /**
     * Replaces all newlines in a string by HTML line breaks.
     * @param {String} str The input string.
     * @return `String` with '<br>' instead all newlines (\r\n, \n\r, \n and \r).
     * @example
     *   nl2br("This\r\nis\n\ra\nstring\r")
     *   Output:
     *   This<br>
     *   is<br>
     *   a<br>
     *   string<br>
     */
16 17 18
        var nl2br = function(str) {
            return (str + '').replace(/(\r\n|\n\r|\r|\n)/g, '<br>');
        };
19

20 21 22 23
        return {
            nl2br: nl2br
        };
    });
24
}).call(this, define || RequireJS.define);