mirror of
https://github.com/faisalman/ua-parser-js.git
synced 2025-09-27 16:08:47 +03:00
New feature: CLI support
This commit is contained in:
parent
7ae3098778
commit
6f621f1ae2
2
dist/ua-parser.min.js
vendored
2
dist/ua-parser.min.js
vendored
File diff suppressed because one or more lines are too long
2
dist/ua-parser.pack.js
vendored
2
dist/ua-parser.pack.js
vendored
File diff suppressed because one or more lines are too long
12
readme.md
12
readme.md
@ -224,6 +224,18 @@ $ bower install ua-parser-js
|
|||||||
$ meteor add faisalman:ua-parser-js
|
$ meteor add faisalman:ua-parser-js
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Using CLI
|
||||||
|
|
||||||
|
```sh
|
||||||
|
$ node ua-parser.min.js "Mozilla/4.0 (compatible; MSIE 4.01; Windows 98)"
|
||||||
|
# multiple args
|
||||||
|
$ node ua-parser.min.js "Opera/1.2" "Opera/3.4"
|
||||||
|
# piped args
|
||||||
|
$ echo "Opera/1.2" | node ua-parser.min.js
|
||||||
|
# log file
|
||||||
|
$ cat ua.log | node ua-parser.min.js
|
||||||
|
```
|
||||||
|
|
||||||
## Using jQuery/Zepto ($.ua)
|
## Using jQuery/Zepto ($.ua)
|
||||||
|
|
||||||
Although written in vanilla js (which means it doesn't depends on jQuery), this library will automatically detect if jQuery/Zepto is present and create `$.ua` object based on browser's user-agent (although in case you need, `window.UAParser` constructor is still present). To get/set user-agent you can use: `$.ua.get()` / `$.ua.set(uastring)`.
|
Although written in vanilla js (which means it doesn't depends on jQuery), this library will automatically detect if jQuery/Zepto is present and create `$.ua` object based on browser's user-agent (although in case you need, `window.UAParser` constructor is still present). To get/set user-agent you can use: `$.ua.get()` / `$.ua.set(uastring)`.
|
||||||
|
27
src/ua-parser.js
Normal file → Executable file
27
src/ua-parser.js
Normal file → Executable file
@ -996,6 +996,33 @@
|
|||||||
if (typeof module !== UNDEF_TYPE && module.exports) {
|
if (typeof module !== UNDEF_TYPE && module.exports) {
|
||||||
exports = module.exports = UAParser;
|
exports = module.exports = UAParser;
|
||||||
}
|
}
|
||||||
|
// TODO: test!!!
|
||||||
|
if (require && require.main === module && process) {
|
||||||
|
// cli
|
||||||
|
var jsonize = function (arr) {
|
||||||
|
var res = [];
|
||||||
|
for (var i in arr) {
|
||||||
|
res.push(new UAParser(arr[i]).getResult());
|
||||||
|
}
|
||||||
|
process.stdout.write(JSON.stringify(res, null, 2) + '\n');
|
||||||
|
};
|
||||||
|
if (process.stdin.isTTY) {
|
||||||
|
// via args
|
||||||
|
jsonize(process.argv.slice(2));
|
||||||
|
} else {
|
||||||
|
// via pipe
|
||||||
|
var str = '';
|
||||||
|
process.stdin.on('readable', function() {
|
||||||
|
var read = process.stdin.read();
|
||||||
|
if (read !== null) {
|
||||||
|
str += read;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
process.stdin.on('end', function () {
|
||||||
|
jsonize(str.replace(/\n$/, '').split('\n'));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
exports.UAParser = UAParser;
|
exports.UAParser = UAParser;
|
||||||
} else {
|
} else {
|
||||||
// requirejs env (optional)
|
// requirejs env (optional)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user