-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
18 lines (15 loc) · 607 Bytes
/
index.js
File metadata and controls
18 lines (15 loc) · 607 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import path from 'node:path';
import {loadJsonFileSync} from 'load-json-file';
export default function letter(options) {
options = options || {};
const locale = options.locale || 'en_US';
const filePath = `./locales/${locale}/letters.json`;
let letters = [];
try {
letters = loadJsonFileSync(filePath);
} catch {
letters = loadJsonFileSync(path.resolve('node_modules/@fakerjs/letter/', filePath));
}
const letter = letters[0].charAt(Math.floor(Math.random() * letters[0].length));
return (options.casing === 'upper' ? letter.toUpperCase() : letter);
}