react-nl2br
Advanced tools
Comparing version 0.4.1 to 0.5.0
@@ -7,6 +7,4 @@ 'use strict'; | ||
module.exports = function(str) { | ||
if (typeof str === 'number') { | ||
if (typeof str !== 'string') { | ||
return str; | ||
} else if (typeof str !== 'string') { | ||
return ''; | ||
} | ||
@@ -13,0 +11,0 @@ |
{ | ||
"name": "react-nl2br", | ||
"version": "0.4.1", | ||
"version": "0.5.0", | ||
"description": "newlines like '\\n', '\\n\\r' to <br /> for React", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
28
test.js
@@ -26,26 +26,38 @@ const nl2br = require('.'); | ||
it('should return an empty string if the param is undefined', function () { | ||
it('should return undefined if the param is undefined', function () { | ||
const result = nl2br(undefined); | ||
const expected = ''; | ||
const expected = undefined; | ||
assert.deepEqual(expected, result); | ||
}); | ||
it('should return an empty string if the param is null', function () { | ||
it('should return null if the param is null', function () { | ||
const result = nl2br(null); | ||
const expected = ''; | ||
const expected = null; | ||
assert.deepEqual(expected, result); | ||
}); | ||
it('should return an empty string if the param is an array', function () { | ||
it('should return an array if the param is an array', function () { | ||
const result = nl2br([]); | ||
const expected = ''; | ||
const expected = []; | ||
assert.deepEqual(expected, result); | ||
}); | ||
it('should return an empty string if the param is an object', function () { | ||
it('should return an object if the param is an object', function () { | ||
const result = nl2br({}); | ||
const expected = ''; | ||
const expected = {}; | ||
assert.deepEqual(expected, result); | ||
}); | ||
it('should return a boolean if the param is a boolean', function () { | ||
const result = nl2br(false); | ||
const expected = false; | ||
assert.deepEqual(expected, result); | ||
}); | ||
it('should return the given React component if the param is a React component', function () { | ||
const component = React.createElement('p', {}, 'Lorem ipsum'); | ||
const result = nl2br(component); | ||
assert.strictEqual(component, result); | ||
}); | ||
}); | ||
3343
72