summaryrefslogtreecommitdiff
path: root/src/escape.mjs
blob: 78e08f879c39c98af511dd0a7d940ad59d362e9d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
const FROM = /[&<>'"]/g;

const ESCAPES = {
	'&': '&amp;',
	'<': '&lt;',
	'>': '&gt;',
	"'": '&#39;',
	'"': '&quot;'
};

const mappingFn = c => ESCAPES[c];

export const escape = s =>
	String.prototype.replace.call(s, FROM, mappingFn);