@@ -3,36 +3,36 @@ import fs from 'node:fs';
33import { loadJsonFileSync } from 'load-json-file' ;
44
55class Game {
6- titles = { } ;
7- genres = { } ;
8- platforms = { } ;
9- defaultLocale = 'en_US' ;
10- options = { } ;
6+ _titles = { } ;
7+ _genres = { } ;
8+ _platforms = { } ;
9+ _defaultLocale = 'en_US' ;
10+ _options = { } ;
1111
1212 constructor ( options ) {
13- this . options = options || { } ;
14- const titleFilePath = `./locales/${ this . options . locale || this . defaultLocale } /title.json` ;
15- const platformFilePath = `./locales/${ this . options . locale || this . defaultLocale } /platform.json` ;
16- const genreFilePath = `./locales/${ this . options . locale || this . defaultLocale } /genre.json` ;
17- this . titles = fs . existsSync ( path . resolve ( titleFilePath ) ) ? loadJsonFileSync ( titleFilePath ) : loadJsonFileSync ( path . resolve ( 'node_modules/@fakerjs/game/' , titleFilePath ) ) ;
18- this . platforms = fs . existsSync ( path . resolve ( platformFilePath ) ) ? loadJsonFileSync ( platformFilePath ) : loadJsonFileSync ( path . resolve ( 'node_modules/@fakerjs/game/' , platformFilePath ) ) ;
19- this . genres = fs . existsSync ( path . resolve ( genreFilePath ) ) ? loadJsonFileSync ( genreFilePath ) : loadJsonFileSync ( path . resolve ( 'node_modules/@fakerjs/game/' , genreFilePath ) ) ;
13+ this . _options = options || { } ;
14+ const titleFilePath = `./locales/${ this . _options . locale || this . _defaultLocale } /title.json` ;
15+ const platformFilePath = `./locales/${ this . _options . locale || this . _defaultLocale } /platform.json` ;
16+ const genreFilePath = `./locales/${ this . _options . locale || this . _defaultLocale } /genre.json` ;
17+ this . _titles = fs . existsSync ( path . resolve ( titleFilePath ) ) ? loadJsonFileSync ( titleFilePath ) : loadJsonFileSync ( path . resolve ( 'node_modules/@fakerjs/game/' , titleFilePath ) ) ;
18+ this . _platforms = fs . existsSync ( path . resolve ( platformFilePath ) ) ? loadJsonFileSync ( platformFilePath ) : loadJsonFileSync ( path . resolve ( 'node_modules/@fakerjs/game/' , platformFilePath ) ) ;
19+ this . _genres = fs . existsSync ( path . resolve ( genreFilePath ) ) ? loadJsonFileSync ( genreFilePath ) : loadJsonFileSync ( path . resolve ( 'node_modules/@fakerjs/game/' , genreFilePath ) ) ;
2020 }
2121
2222 _selectRandom ( items ) {
2323 return items [ Math . floor ( Math . random ( ) * items . length ) ] ;
2424 }
2525
2626 title ( ) {
27- return this . _selectRandom ( this . titles ) ;
27+ return this . _selectRandom ( this . _titles ) ;
2828 }
2929
3030 genre ( ) {
31- return this . _selectRandom ( this . genres ) ;
31+ return this . _selectRandom ( this . _genres ) ;
3232 }
3333
3434 platform ( ) {
35- return this . _selectRandom ( this . platforms ) ;
35+ return this . _selectRandom ( this . _platforms ) ;
3636 }
3737}
3838
0 commit comments