Skip to content

Commit e112e2a

Browse files
committed
Gender 2.3.0
1 parent 4a92dd1 commit e112e2a

File tree

3 files changed

+10
-13
lines changed

3 files changed

+10
-13
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
<a name="2.3.0"></a>
2+
# [2.3.0](https://github.com/faker-javascript/gender) (2022-01-25)
3+
* Improve and simplify logic.
4+
15
<a name="2.2.0"></a>
26
# [2.2.0](https://github.com/faker-javascript/gender) (2022-01-19)
37
* Add locales folder for genders.

index.js

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

45
export default function gender(options) {
56
options = options || {};
6-
const locale = options.locale || 'en_US';
7-
const filePath = `./locales/${locale}/gender.json`;
8-
let genders = [];
9-
10-
try {
11-
genders = loadJsonFileSync(filePath);
12-
} catch {
13-
genders = loadJsonFileSync(path.resolve('node_modules/@fakerjs/gender/', filePath));
14-
}
15-
7+
const filePath = `./locales/${options.locale || 'en_US'}/gender.json`;
8+
const genders = fs.existsSync(path.resolve(filePath)) ? loadJsonFileSync(filePath) : loadJsonFileSync(path.resolve('node_modules/@fakerjs/gender/', filePath));
169
const gendersWithExtra = [...genders, ...options.extra || []];
1710
const randomGender = gendersWithExtra[Math.floor(Math.random() * gendersWithExtra.length)];
1811
return randomGender;

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@fakerjs/gender",
3-
"version": "2.2.0",
3+
"version": "2.3.0",
44
"description": "Gender package provides functionality to generate a fake gender value.",
55
"license": "MIT",
66
"repository": "faker-javascript/gender",
@@ -23,8 +23,8 @@
2323
"devDependencies": {
2424
"ava": "^4.0.0",
2525
"c8": "^7.11.0",
26-
"tsd": "^0.19.1",
27-
"xo": "^0.47.0"
26+
"tsd": "^0.19.1",
27+
"xo": "^0.47.0"
2828
},
2929
"files": [
3030
"index.js",

0 commit comments

Comments
 (0)