Skip to content

Commit f179847

Browse files
committed
refactor(core): improve and simplify logic
1 parent a1626bb commit f179847

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

index.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
import path from 'node:path';
2+
import fs from 'node:fs';
23
import {loadJsonFileSync} from 'load-json-file';
34

45
export default function lastName(options) {
56
options = options || {};
6-
const locale = options.locale === undefined ? 'en_US' : options.locale;
7+
const locale = options.locale || 'en_US';
78
const filePath = `./locales/${locale}/lastnames.json`;
89
let lastnames = [];
9-
10-
try {
11-
lastnames = loadJsonFileSync(filePath);
12-
} catch {
13-
lastnames = loadJsonFileSync(path.resolve('node_modules/@fakerjs/lastname/', filePath));
14-
}
15-
10+
lastnames = fs.existsSync(path.resolve(filePath)) ? loadJsonFileSync(filePath) : loadJsonFileSync(path.resolve('node_modules/@fakerjs/lastname/', filePath));
1611
return lastnames[Math.floor(Math.random() * lastnames.length)];
1712
}

0 commit comments

Comments
 (0)