From e112e2a94f9c9a6b6bc8bc59802e76deceaa0a89 Mon Sep 17 00:00:00 2001 From: Sergey Romanenko Date: Tue, 25 Jan 2022 20:46:44 +0300 Subject: [PATCH] Gender 2.3.0 --- CHANGELOG.md | 4 ++++ index.js | 13 +++---------- package.json | 6 +++--- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f534d3..8cc4962 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ + +# [2.3.0](https://github.com/faker-javascript/gender) (2022-01-25) +* Improve and simplify logic. + # [2.2.0](https://github.com/faker-javascript/gender) (2022-01-19) * Add locales folder for genders. diff --git a/index.js b/index.js index e39a714..06ed599 100644 --- a/index.js +++ b/index.js @@ -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; diff --git a/package.json b/package.json index 8f2e2a1..8ec4c04 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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",