MCPcopy
hub / github.com/mcnamee/react-native-starter-kit / stripHtml

Function stripHtml

src/lib/string.js:43–72  ·  view source on GitHub ↗
(string)

Source from the content-addressed store, hash-verified

41 * @param {str} string
42 */
43export const stripHtml = (string) => {
44 let returnString = string;
45
46 // Remove DOM tags
47 returnString = returnString.replace(/<[^>]*>?/gm, '');
48
49 // Remove entities
50 const entities = [
51 ['amp', '&'],
52 ['apos', "'"],
53 ['#x27', "'"],
54 ['#x2F', '/'],
55 ['#39', "'"],
56 ['#47', '/'],
57 ['lt', '<'],
58 ['gt', '>'],
59 ['nbsp', ' '],
60 ['quot', '"'],
61 ['hellip', '...'],
62 ['#8217', "'"],
63 ['#8230', '...'],
64 ['#8211', '-'],
65 ];
66
67 entities.map((item) => { // eslint-disable-line
68 returnString = returnString.replace(new RegExp(`&${item[0]};`, 'g'), item[1]);
69 });
70
71 return returnString;
72};

Callers 1

transformFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected