Skip to content

Commit 4afdd80

Browse files
committed
fix(core): fix issue with file path
1 parent 561fa91 commit 4afdd80

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
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="1.0.1"></a>
2+
# [1.0.1](https://github.com/faker-javascript/firstname) (2022-01-18)
3+
* Fix issue with file path.
4+
15
<a name="1.0.0"></a>
26
# [1.0.0](https://github.com/faker-javascript/firstname) (2022-01-18)
37
* Initial release

index.js

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

34
export default function firstName(options) {
45
options = options || {};
56
const gender = options.gender === undefined ? 'female' : options.gender;
67
const locale = options.locale === undefined ? 'en_US' : options.locale;
7-
const firtnames = loadJsonFileSync(`./locales/${locale}/${gender}.json`);
8-
return firtnames[Math.floor(Math.random() * firtnames.length)];
8+
const filePath = `./locales/${locale}/${gender}.json`;
9+
let firstnames = [];
10+
11+
try {
12+
firstnames = loadJsonFileSync(filePath);
13+
} catch {
14+
firstnames = loadJsonFileSync(path.resolve('node_modules/@fakerjs/firstname/', filePath));
15+
}
16+
17+
return firstnames[Math.floor(Math.random() * firstnames.length)];
918
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@fakerjs/firstname",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "Firstname package provides functionality to generate a fake first name value.",
55
"license": "MIT",
66
"repository": "faker-javascript/firstname",

0 commit comments

Comments
 (0)