Skip to content

Commit 3232c3f

Browse files
committed
refactor(core): improve and simplify logic
1 parent 0975771 commit 3232c3f

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

browsers.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[
2+
"Chrome",
3+
"Edge",
4+
"Firefox",
5+
"Internet Explorer",
6+
"Safari",
7+
"Opera",
8+
"Yandex",
9+
"Chromium",
10+
"Vivaldi",
11+
"Baidu",
12+
"Brave",
13+
]

index.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
1+
import path from 'node:path';
2+
import fs from 'node:fs';
3+
import {loadJsonFileSync} from 'load-json-file';
4+
15
export default function browser() {
2-
const browsers = [
3-
'Chrome',
4-
'Edge',
5-
'Firefox',
6-
'Internet Explorer',
7-
'Safari',
8-
'Opera',
9-
'Yandex',
10-
'Chromium',
11-
'Vivaldi',
12-
'Baidu',
13-
'Brave',
14-
];
6+
const filePath = `./browsers.json`;
7+
let browsers = [];
8+
browsers = fs.existsSync(path.resolve(filePath)) ? loadJsonFileSync(filePath) : loadJsonFileSync(path.resolve('node_modules/@fakerjs/browser/', filePath));
159
return browsers[Math.floor(Math.random() * browsers.length)];
1610
}

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@fakerjs/browser",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"description": "Browser package provides functionality to generate a fake browser value.",
55
"license": "MIT",
66
"repository": "faker-javascript/browser",
@@ -17,6 +17,9 @@
1717
"scripts": {
1818
"test": "c8 ava; xo --space 4; tsd;"
1919
},
20+
"dependencies": {
21+
"load-json-file": "^7.0.1"
22+
},
2023
"devDependencies": {
2124
"ava": "^4.0.0",
2225
"c8": "^7.11.0",
@@ -25,7 +28,8 @@
2528
},
2629
"files": [
2730
"index.js",
28-
"index.d.ts"
31+
"index.d.ts",
32+
"browsers.json"
2933
],
3034
"keywords": [
3135
"fakerjs",

0 commit comments

Comments
 (0)