Skip to content

Commit

Permalink
Gender 2.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Awilum committed Jan 25, 2022
1 parent 4a92dd1 commit e112e2a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<a name="2.3.0"></a>
# [2.3.0](https://github.com/faker-javascript/gender) (2022-01-25)
* Improve and simplify logic.

<a name="2.2.0"></a>
# [2.2.0](https://github.com/faker-javascript/gender) (2022-01-19)
* Add locales folder for genders.
Expand Down
13 changes: 3 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
import path from 'node:path';
import fs from 'node:fs';
import {loadJsonFileSync} from 'load-json-file';

export default function gender(options) {
options = options || {};
const locale = options.locale || 'en_US';
const filePath = `./locales/${locale}/gender.json`;
let genders = [];

try {
genders = loadJsonFileSync(filePath);
} catch {
genders = loadJsonFileSync(path.resolve('node_modules/@fakerjs/gender/', filePath));
}

const filePath = `./locales/${options.locale || 'en_US'}/gender.json`;
const genders = fs.existsSync(path.resolve(filePath)) ? loadJsonFileSync(filePath) : loadJsonFileSync(path.resolve('node_modules/@fakerjs/gender/', filePath));
const gendersWithExtra = [...genders, ...options.extra || []];
const randomGender = gendersWithExtra[Math.floor(Math.random() * gendersWithExtra.length)];
return randomGender;
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fakerjs/gender",
"version": "2.2.0",
"version": "2.3.0",
"description": "Gender package provides functionality to generate a fake gender value.",
"license": "MIT",
"repository": "faker-javascript/gender",
Expand All @@ -23,8 +23,8 @@
"devDependencies": {
"ava": "^4.0.0",
"c8": "^7.11.0",
"tsd": "^0.19.1",
"xo": "^0.47.0"
"tsd": "^0.19.1",
"xo": "^0.47.0"
},
"files": [
"index.js",
Expand Down

0 comments on commit e112e2a

Please sign in to comment.