human/src/sysinfo.ts

22 lines
751 B
TypeScript
Raw Normal View History

2021-05-25 14:58:20 +02:00
/**
* Helper function that returns basic system info
*/
2021-03-18 01:16:40 +01:00
export function info(): { platform: string, agent: string } {
2021-03-06 16:38:04 +01:00
let platform;
let agent;
if (typeof navigator !== 'undefined') {
const raw = navigator.userAgent.match(/\(([^()]+)\)/g);
if (raw && raw[0]) {
2021-04-09 16:02:40 +02:00
const platformMatch = raw[0].match(/\(([^()]+)\)/g);
platform = platformMatch ? platformMatch[0].replace(/\(|\)/g, '') : '';
2021-03-06 16:38:04 +01:00
agent = navigator.userAgent.replace(raw[0], '');
if (platform[1]) agent = agent.replace(raw[1], '');
agent = agent.replace(/ /g, ' ');
}
} else if (typeof process !== 'undefined') {
platform = `${process.platform} ${process.arch}`;
agent = `NodeJS ${process.version}`;
}
return { platform, agent };
}