File tree Expand file tree Collapse file tree 3 files changed +16
-3
lines changed
Expand file tree Collapse file tree 3 files changed +16
-3
lines changed Original file line number Diff line number Diff line change 1+ <a name =" 1.0.1 " ></a >
2+ # [ 1.0.1] ( https://github.com/faker-javascript/firstname ) (2022-01-18)
3+ * Fix issue with file path.
4+
15<a name =" 1.0.0 " ></a >
26# [ 1.0.0] ( https://github.com/faker-javascript/firstname ) (2022-01-18)
37* Initial release
Original file line number Diff line number Diff line change 1+ import path from 'node:path' ;
12import { loadJsonFileSync } from 'load-json-file' ;
23
34export default function firstName ( options ) {
45 options = options || { } ;
56 const gender = options . gender === undefined ? 'female' : options . gender ;
67 const locale = options . locale === undefined ? 'en_US' : options . locale ;
7- const firtnames = loadJsonFileSync ( `./locales/${ locale } /${ gender } .json` ) ;
8- return firtnames [ Math . floor ( Math . random ( ) * firtnames . length ) ] ;
8+ const filePath = `./locales/${ locale } /${ gender } .json` ;
9+ let firstnames = [ ] ;
10+
11+ try {
12+ firstnames = loadJsonFileSync ( filePath ) ;
13+ } catch {
14+ firstnames = loadJsonFileSync ( path . resolve ( 'node_modules/@fakerjs/firstname/' , filePath ) ) ;
15+ }
16+
17+ return firstnames [ Math . floor ( Math . random ( ) * firstnames . length ) ] ;
918}
Original file line number Diff line number Diff line change 11{
22 "name" : " @fakerjs/firstname" ,
3- "version" : " 1.0.0 " ,
3+ "version" : " 1.0.1 " ,
44 "description" : " Firstname package provides functionality to generate a fake first name value." ,
55 "license" : " MIT" ,
66 "repository" : " faker-javascript/firstname" ,
You can’t perform that action at this time.
0 commit comments