Skip to content

Commit a1626bb

Browse files
committed
fix(core): fix issue with file path
1 parent 0e3eca9 commit a1626bb

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
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/lastname) (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/lastname) (2022-01-18)
37
* Initial release

index.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1+
import path from 'node:path';
12
import {loadJsonFileSync} from 'load-json-file';
23

34
export default function lastName(options) {
45
options = options || {};
56
const locale = options.locale === undefined ? 'en_US' : options.locale;
6-
const lastnames = loadJsonFileSync(`./locales/${locale}/lastnames.json`);
7+
const filePath = `./locales/${locale}/lastnames.json`;
8+
let lastnames = [];
9+
10+
try {
11+
lastnames = loadJsonFileSync(filePath);
12+
} catch {
13+
lastnames = loadJsonFileSync(path.resolve('node_modules/@fakerjs/lastname/', filePath));
14+
}
15+
716
return lastnames[Math.floor(Math.random() * lastnames.length)];
817
}

package.json

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

0 commit comments

Comments
 (0)