-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
30 lines (30 loc) · 866 Bytes
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// optimize svg code
const cleanSvg = (svgContent) =>{
svgContent = svgContent
.replace(/<\?xml.*\?>/g, '')
.replace(/<!DOCTYPE.*>/g, '')
.replace(/<!--[\s\S]*?-->/g, '')
.replace(/width="([^"]+)"/, '')
.replace(/height="([^"]+)"/, '')
.trim();
return svgContent;
}
// encoding query string
const removeUndefinedData = (query) =>{
Object.keys(query).forEach(
(key) =>
!query[key] && typeof query[key] != 'boolean' && delete query[key]
);
return query;
}
const encodeQueryData = (query) =>{
query = this.removeUndefinedData(query);
const ret = [];
for (let d in query)
ret.push(encodeURIComponent(d) + '=' + encodeURIComponent(query[d]));
return ret.join('&');
}
// remove duplicate objects
let unique = data.filter(
(item, index, self) => index === self.findIndex((t) => t.id === item.id)
);