Add pass through to stripHtml for undefined and null inputs
This commit is contained in:
parent
6aad7b4941
commit
b12d6546af
|
@ -74,7 +74,11 @@ export function capitalizeFirstCharacter(text) {
|
||||||
* @param {*} replace
|
* @param {*} replace
|
||||||
* @returns {String}
|
* @returns {String}
|
||||||
*/
|
*/
|
||||||
export const stripHtml = (string, replace = '') => string.replace(/<[^>]*>/g, replace);
|
export const stripHtml = (string, replace = '') => {
|
||||||
|
if (!string) return string;
|
||||||
|
|
||||||
|
return string.replace(/<[^>]*>/g, replace);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts snake_case string to camelCase
|
* Converts snake_case string to camelCase
|
||||||
|
|
|
@ -75,6 +75,14 @@ describe('text_utility', () => {
|
||||||
'This is a text with html .',
|
'This is a text with html .',
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('passes through with null string input', () => {
|
||||||
|
expect(textUtils.stripHtml(null, ' ')).toEqual(null);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('passes through with undefined string input', () => {
|
||||||
|
expect(textUtils.stripHtml(undefined, ' ')).toEqual(undefined);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('convertToCamelCase', () => {
|
describe('convertToCamelCase', () => {
|
||||||
|
|
Loading…
Reference in New Issue