Backport - Add new feature: parse user-agent in CLI using npx ua-parser-js "[INSERT-UA-HERE]" and print the result in JSON format

(cherry picked from commit 150d3c6b4af498ca754099ab34e9426a02c82ab7)
This commit is contained in:
Faisal Salman 2024-09-10 20:15:02 +07:00
parent cede70136b
commit dfa62b6e7a
2 changed files with 5 additions and 0 deletions

View File

@ -153,6 +153,7 @@
"dist",
"src"
],
"bin": "./script/cli.js",
"scripts": {
"build": "uglifyjs src/ua-parser.js -o dist/ua-parser.min.js --comments '/^ UA/' && uglifyjs src/ua-parser.js -o dist/ua-parser.pack.js --comments '/^ UA/' --compress --mangle",
"test": "jshint src/ua-parser.js && mocha -R nyan test/test.js",

4
script/cli.js Executable file
View File

@ -0,0 +1,4 @@
#!/usr/bin/env node
const UAParser = require('ua-parser-js');
console.log(JSON.stringify(process.argv.slice(2).map(ua => UAParser(ua)), null, 4));