faisalman / ua-parser-js

"Unmask Your Traffic" - UAParser.js: The Essential Web Development Tool for User-Agent Detection
https://uaparser.dev/
GNU Affero General Public License v3.0
9.28k stars 1.19k forks source link

Export the enums #715

Closed MarianoFacundoArch closed 5 months ago

MarianoFacundoArch commented 8 months ago

It would be nice if we could export the ENUMS to make comparisons later on without relying on strings, for example if (currentOsName === LINUX)

faisalman commented 5 months ago

You can use it already, just import the enums from 'ua-parser-js/enums' submodule:

import { UAParser } from 'ua-parser-js';
import { OS } from 'ua-parser-js/enums';

const ua = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.32';
const currentOSName = UAParser(ua).os.name;

if (currentOSName === OS.LINUX) {
    console.log('Hello! you are using Linux');
}