File tree Expand file tree Collapse file tree 1 file changed +3
-8
lines changed Expand file tree Collapse file tree 1 file changed +3
-8
lines changed Original file line number Diff line number Diff line change 1
1
import path from 'node:path' ;
2
+ import fs from 'node:fs' ;
2
3
import { loadJsonFileSync } from 'load-json-file' ;
3
4
4
5
export default function lastName ( options ) {
5
6
options = options || { } ;
6
- const locale = options . locale === undefined ? 'en_US' : options . locale ;
7
+ const locale = options . locale || 'en_US' ;
7
8
const filePath = `./locales/${ locale } /lastnames.json` ;
8
9
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 ) ) ;
16
11
return lastnames [ Math . floor ( Math . random ( ) * lastnames . length ) ] ;
17
12
}
You can’t perform that action at this time.
0 commit comments