Skip to content

Commit

Permalink
refactor(core): improve and simplify logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Awilum committed Jan 25, 2022
1 parent 0975771 commit 3232c3f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
13 changes: 13 additions & 0 deletions browsers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
"Chrome",
"Edge",
"Firefox",
"Internet Explorer",
"Safari",
"Opera",
"Yandex",
"Chromium",
"Vivaldi",
"Baidu",
"Brave",
]
20 changes: 7 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import path from 'node:path';
import fs from 'node:fs';
import {loadJsonFileSync} from 'load-json-file';

export default function browser() {
const browsers = [
'Chrome',
'Edge',
'Firefox',
'Internet Explorer',
'Safari',
'Opera',
'Yandex',
'Chromium',
'Vivaldi',
'Baidu',
'Brave',
];
const filePath = `./browsers.json`;
let browsers = [];
browsers = fs.existsSync(path.resolve(filePath)) ? loadJsonFileSync(filePath) : loadJsonFileSync(path.resolve('node_modules/@fakerjs/browser/', filePath));
return browsers[Math.floor(Math.random() * browsers.length)];
}
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fakerjs/browser",
"version": "1.0.0",
"version": "1.1.0",
"description": "Browser package provides functionality to generate a fake browser value.",
"license": "MIT",
"repository": "faker-javascript/browser",
Expand All @@ -17,6 +17,9 @@
"scripts": {
"test": "c8 ava; xo --space 4; tsd;"
},
"dependencies": {
"load-json-file": "^7.0.1"
},
"devDependencies": {
"ava": "^4.0.0",
"c8": "^7.11.0",
Expand All @@ -25,7 +28,8 @@
},
"files": [
"index.js",
"index.d.ts"
"index.d.ts",
"browsers.json"
],
"keywords": [
"fakerjs",
Expand Down

0 comments on commit 3232c3f

Please sign in to comment.