mirror of
https://github.com/UnickSoft/graphonline.git
synced 2026-02-16 02:30:51 +00:00
Change script location.
Split js code. Added cache and changed loading mechanism for js sources.
This commit is contained in:
50
script/shared/utils.js
Normal file
50
script/shared/utils.js
Normal file
@@ -0,0 +1,50 @@
|
||||
|
||||
function gEncodeToHTML(str)
|
||||
{
|
||||
if (typeof str !== 'string')
|
||||
return str;
|
||||
|
||||
return str.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''');
|
||||
}
|
||||
|
||||
function gDecodeFromHTML(str)
|
||||
{
|
||||
if (typeof str !== 'string')
|
||||
return str;
|
||||
|
||||
return str.replace(/'/g, "'")
|
||||
.replace(/"/g, '"')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/</g, '<')
|
||||
.replace(/&/g, '&');
|
||||
}
|
||||
|
||||
function FullObjectCopy(obj)
|
||||
{
|
||||
var newObj = Object.create(Object.getPrototypeOf(obj));
|
||||
|
||||
return Object.assign(newObj, obj);
|
||||
}
|
||||
|
||||
function FullArrayCopy(arr)
|
||||
{
|
||||
var res = [];
|
||||
|
||||
arr.forEach(function(element) {
|
||||
|
||||
var copyElement = FullObjectCopy(element);
|
||||
res.push(copyElement);
|
||||
});
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
function formatString(string, params) {
|
||||
return string.replace(/{(\d+)}/g, (match, index) => {
|
||||
return typeof params[index] !== 'undefined' ? params[index] : match;
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user