2019-05-05 20:00:32 +02:00
|
|
|
import removeDiacritics from "./js/StackOverflow/removeDiacritics";
|
|
|
|
|
2019-05-03 20:29:53 +02:00
|
|
|
export function cloneObject(object) {
|
|
|
|
return JSON.parse(JSON.stringify(object));
|
|
|
|
}
|
|
|
|
|
2019-05-08 23:34:03 +02:00
|
|
|
export function getIndicesOf(searchStr, findIn, caseSensitive) {
|
|
|
|
// https://stackoverflow.com/a/3410557
|
|
|
|
const searchStrLen = searchStr.length;
|
|
|
|
if (searchStrLen == 0) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
let startIndex = 0, index, indices = [];
|
|
|
|
if (!caseSensitive) {
|
|
|
|
findIn = findIn.toLowerCase();
|
|
|
|
searchStr = searchStr.toLowerCase();
|
|
|
|
}
|
|
|
|
while ((index = findIn.indexOf(searchStr, startIndex)) > -1) {
|
|
|
|
indices.push(index);
|
|
|
|
startIndex = index + searchStrLen;
|
|
|
|
}
|
|
|
|
return indices;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getTimestampInSeconds() {
|
|
|
|
return Math.round(Date.now() / 1000);
|
|
|
|
}
|
|
|
|
|
2019-05-03 00:51:41 +02:00
|
|
|
export function removeTags(html) {
|
2019-05-04 00:10:41 +02:00
|
|
|
if (html) {
|
|
|
|
var tagBody = '(?:[^"\'>]|"[^"]*"|\'[^\']*\')*';
|
|
|
|
var tagOrComment = new RegExp(
|
|
|
|
'<(?:'
|
|
|
|
// Comment body.
|
|
|
|
+ '!--(?:(?:-*[^->])*--+|-?)'
|
|
|
|
// Special "raw text" elements whose content should be elided.
|
|
|
|
+ '|script\\b' + tagBody + '>[\\s\\S]*?</script\\s*'
|
|
|
|
+ '|style\\b' + tagBody + '>[\\s\\S]*?</style\\s*'
|
|
|
|
// Regular name
|
|
|
|
+ '|/?[a-z]'
|
|
|
|
+ tagBody
|
|
|
|
+ ')>',
|
|
|
|
'gi');
|
|
|
|
var oldHtml;
|
|
|
|
do {
|
|
|
|
oldHtml = html;
|
|
|
|
html = html.replace(tagOrComment, '');
|
|
|
|
} while (html !== oldHtml);
|
|
|
|
return html.replace(/</g, '<');
|
|
|
|
}
|
|
|
|
return html;
|
2019-05-03 20:29:53 +02:00
|
|
|
}
|
2019-05-05 20:00:32 +02:00
|
|
|
|
|
|
|
export function slugify(string) {
|
|
|
|
return removeDiacritics(string).replace(/[!a-zA-Z0-9-_]/g, '-');
|
|
|
|
}
|