Skip to content

Commit

Permalink
Gender 2.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Awilum committed Jan 19, 2022
1 parent 31857f3 commit ceec2fb
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Global
node_modules/
coverage
package-lock.json

# OS Generated
.DS_Store*
Expand Down
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.2.0"></a>
# [2.2.0](https://github.com/faker-javascript/gender) (2022-01-19)
* Add locales folder for genders.

<a name="2.1.1"></a>
# [2.1.1](https://github.com/faker-javascript/gender) (2022-01-15)
* Typo updates.
Expand Down
25 changes: 13 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
/* eslint camelcase: ["error", {properties: "never"}] */
import path from 'node:path';
import {loadJsonFileSync} from 'load-json-file';

export default function gender(options) {
options = options || {};
const genders = {
en_US: [
'Male',
'Female',
],
ru_RU: [
'Мужской',
'Женский',
],
};
const locale = options.locale || 'en_US';
const gendersWithExtra = [...genders[locale], ...options.extra || []];
const filePath = `./locales/${locale}/gender.json`;
let genders = [];

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

const gendersWithExtra = [...genders, ...options.extra || []];
const randomGender = gendersWithExtra[Math.floor(Math.random() * gendersWithExtra.length)];
return randomGender;
}
4 changes: 4 additions & 0 deletions locales/en_US/gender.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[
"Male",
"Female"
]
4 changes: 4 additions & 0 deletions locales/ru_RU/gender.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[
"Мужской",
"Женский"
]
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fakerjs/gender",
"version": "2.1.1",
"version": "2.2.0",
"description": "Gender package provides functionality to generate a fake gender value.",
"license": "MIT",
"repository": "faker-javascript/gender",
Expand All @@ -17,6 +17,9 @@
"scripts": {
"test": "c8 ava; xo --space 4; tsd;"
},
"dependencies": {
"load-json-file": "^7.0.1"
},
"devDependencies": {
"ava": "^4.0.0",
"c8": "^7.11.0",
Expand Down

0 comments on commit ceec2fb

Please sign in to comment.