Skip to content

Commit

Permalink
fix(core): fix issue with file path
Browse files Browse the repository at this point in the history
  • Loading branch information
Awilum committed Jan 18, 2022
1 parent 561fa91 commit 4afdd80
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 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="1.0.1"></a>
# [1.0.1](https://github.com/faker-javascript/firstname) (2022-01-18)
* Fix issue with file path.

<a name="1.0.0"></a>
# [1.0.0](https://github.com/faker-javascript/firstname) (2022-01-18)
* Initial release
13 changes: 11 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
import path from 'node:path';
import {loadJsonFileSync} from 'load-json-file';

export default function firstName(options) {
options = options || {};
const gender = options.gender === undefined ? 'female' : options.gender;
const locale = options.locale === undefined ? 'en_US' : options.locale;
const firtnames = loadJsonFileSync(`./locales/${locale}/${gender}.json`);
return firtnames[Math.floor(Math.random() * firtnames.length)];
const filePath = `./locales/${locale}/${gender}.json`;
let firstnames = [];

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

return firstnames[Math.floor(Math.random() * firstnames.length)];
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fakerjs/firstname",
"version": "1.0.0",
"version": "1.0.1",
"description": "Firstname package provides functionality to generate a fake first name value.",
"license": "MIT",
"repository": "faker-javascript/firstname",
Expand Down

0 comments on commit 4afdd80

Please sign in to comment.