fixes #76
This commit is contained in:
parent
5f54e0197e
commit
2b9fd1f182
1 changed files with 24 additions and 2 deletions
|
@ -193,8 +193,30 @@ const ua = {
|
||||||
userAgent: s
|
userAgent: s
|
||||||
}, prefs.parser[s]);
|
}, prefs.parser[s]);
|
||||||
}
|
}
|
||||||
// build ua string from browser defaults;
|
// build ua string from the navigator object or from a custom UAParser;
|
||||||
s = s.replace(/\${([^}]+)}/g, (a, b) => navigator[b]);
|
// examples: ${platform}, ${browser.version|ua-parser}
|
||||||
|
s = s.replace(/\${([^}]+)}/g, (a, b) => {
|
||||||
|
const key = (parent, keys) => {
|
||||||
|
for (const key of keys) {
|
||||||
|
parent = parent[key] || {};
|
||||||
|
}
|
||||||
|
|
||||||
|
return parent;
|
||||||
|
};
|
||||||
|
|
||||||
|
let [childs, object] = b.split('|');
|
||||||
|
object = object || 'navigator';
|
||||||
|
|
||||||
|
let v;
|
||||||
|
if (object.startsWith('ua-parser')) {
|
||||||
|
const [a, b] = object.split('@');
|
||||||
|
object = a;
|
||||||
|
|
||||||
|
v = key((new UAParser(b || navigator.userAgent)).getResult(), childs.split('.'));
|
||||||
|
}
|
||||||
|
v = v || key(navigator, childs.split('.'));
|
||||||
|
return typeof v === 'string' ? v : 'cannot parse your ${...} replacements.';
|
||||||
|
});
|
||||||
const o = {};
|
const o = {};
|
||||||
o.userAgent = s;
|
o.userAgent = s;
|
||||||
o.appVersion = s
|
o.appVersion = s
|
||||||
|
|
Loading…
Reference in a new issue