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 0e3eca9 commit a1626bb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 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/lastname) (2022-01-18)
* Fix issue with file path.

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

export default function lastName(options) {
options = options || {};
const locale = options.locale === undefined ? 'en_US' : options.locale;
const lastnames = loadJsonFileSync(`./locales/${locale}/lastnames.json`);
const filePath = `./locales/${locale}/lastnames.json`;
let lastnames = [];

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

return lastnames[Math.floor(Math.random() * lastnames.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/lastname",
"version": "1.0.0",
"version": "1.0.1",
"description": "Lastname package provides functionality to generate a fake last name value.",
"license": "MIT",
"repository": "faker-javascript/lastname",
Expand Down

0 comments on commit a1626bb

Please sign in to comment.