faisalman / ua-parser-js

UAParser.js - The Essential Tool for User-Agent Detection in JavaScript & Web Development.
https://uaparser.dev/
GNU Affero General Public License v3.0
8.85k stars 1.18k forks source link

Export the enums #715

Closed MarianoFacundoArch closed 1 month ago

MarianoFacundoArch commented 3 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 1 month 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');
}