Skip to content

Commit

Permalink
Merge 743e52b into 243061d
Browse files Browse the repository at this point in the history
  • Loading branch information
shfshanyue committed Mar 10, 2021
2 parents 243061d + 743e52b commit 3b6c5bb
Show file tree
Hide file tree
Showing 5 changed files with 619 additions and 8,831 deletions.
25 changes: 24 additions & 1 deletion index.js
Expand Up @@ -18,7 +18,30 @@ const cloneData = function (data) {
};

const getData = function (filter) {
return typeof filter === 'function' ? useragents.filter(filter) : useragents;
const agents = typeof filter === 'function' ? useragents.filter(filter) : useragents;
return agents.map(x => ({
folder: '',
description: '',
userAgent: '',
appCodename: '',
appName: '',
appVersion: '',
platform: '',
vendor: '',
vendorSub: '',
browserName: '',
browserMajor: '',
browserVersion: '',
deviceModel: '',
deviceType: '',
deviceVendor: '',
engineName: '',
engineVersion: '',
osName: '',
osVersion: '',
cpuArchitecture: '',
...x,
}))
};

exports.getRandom = function (filter) {
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Expand Up @@ -33,6 +33,7 @@
"chai": "^4.2.0",
"coveralls": "^3.1.0",
"eslint": "^7.6.0",
"lodash": "^4.17.21",
"mocha": "^8.1.1",
"npm-run-all": "^4.1.5",
"nyc": "^15.1.0",
Expand Down
6 changes: 4 additions & 2 deletions scripts/create-data.js
Expand Up @@ -18,6 +18,7 @@ const fs = require('fs');
const request = require('request');
const xml2js = require('xml2js');
const UAParser = require('ua-parser-js');
const _ = require('lodash')

// instance
const useragents = [];
Expand All @@ -32,7 +33,7 @@ const parseUseragents = function (folderName, folderItem) {
uaParser.setUA(useragent.useragent);
const parsed = uaParser.getResult();
if (typeof useragent.useragent === 'string' && useragent.useragent.length > 0) {
useragents.push({
const ua = {
folder: folderName,
description: useragent.description,
userAgent: useragent.useragent,
Expand All @@ -53,7 +54,8 @@ const parseUseragents = function (folderName, folderItem) {
osName: parsed.os.name || '',
osVersion: parsed.os.version || '',
cpuArchitecture: parsed.cpu.architecture || ''
});
};
useragents.push(_.pickBy(ua, x => x !== ''));
}
});
}
Expand Down

0 comments on commit 3b6c5bb

Please sign in to comment.