graphonline/script/utils.js
2021-04-13 14:50:01 +02:00

37 lines
774 B
JavaScript

function gEncodeToHTML(str)
{
if (typeof str !== 'string')
return str;
return str.replace(/&/g, '&')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&apos;');
}
function gDecodeFromHTML(str)
{
if (typeof str !== 'string')
return str;
return str.replace(/&apos;/g, "'")
.replace(/&quot;/g, '"')
.replace(/&gt;/g, '>')
.replace(/&lt;/g, '<')
.replace(/&amp;/g, '&');
}
function FullArrayCopy(arr)
{
var res = [];
arr.forEach(function(element) {
var copyElement = Object.assign(Object.create(element), element);
res.push(copyElement);
});
return res;
}