From dfa62b6e7a23be9ad57ee96fa6c5e5b9df05cb5a Mon Sep 17 00:00:00 2001 From: Faisal Salman Date: Tue, 10 Sep 2024 20:15:02 +0700 Subject: [PATCH] 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) --- package.json | 1 + script/cli.js | 4 ++++ 2 files changed, 5 insertions(+) create mode 100755 script/cli.js diff --git a/package.json b/package.json index abe6f97..5d80f85 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/script/cli.js b/script/cli.js new file mode 100755 index 0000000..785a104 --- /dev/null +++ b/script/cli.js @@ -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)); \ No newline at end of file