-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
19 lines (16 loc) · 987 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import path from 'node:path';
import fs from 'node:fs';
import {loadJsonFileSync} from 'load-json-file';
export default function profession(options) {
options = options || {};
const locale = options.locale || 'en_US';
const ranksFilePath = `./locales/${locale}/ranks.json`;
const ranks = fs.existsSync(path.resolve(ranksFilePath)) ? loadJsonFileSync(ranksFilePath) : loadJsonFileSync(path.resolve('node_modules/@fakerjs/profession/', ranksFilePath));
const professionsFilePath = `./locales/${locale}/professions.json`;
const professions = fs.existsSync(path.resolve(professionsFilePath)) ? loadJsonFileSync(professionsFilePath) : loadJsonFileSync(path.resolve('node_modules/@fakerjs/profession/', professionsFilePath));
const randomProfession = professions[Math.floor(Math.random() * professions.length)];
if (options.rank) {
return `${ranks[Math.floor(Math.random() * ranks.length)]} ${randomProfession}`;
}
return randomProfession;
}