-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
29 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# Global | ||
node_modules/ | ||
coverage | ||
package-lock.json | ||
|
||
# OS Generated | ||
.DS_Store* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,18 @@ | ||
/* eslint camelcase: ["error", {properties: "never"}] */ | ||
import path from 'node:path'; | ||
import {loadJsonFileSync} from 'load-json-file'; | ||
|
||
export default function letter(options) { | ||
options = options || {}; | ||
const keyspace = { | ||
en_US: 'abcdefghijklmnopqrstuvwxyz', | ||
ru_RU: 'абвгдеёжзийклмнопрстуфхцчшщъыьэюя', | ||
}; | ||
const locale = options.locale || 'en_US'; | ||
const letter = keyspace[locale].charAt(Math.floor(Math.random() * keyspace[locale].length)); | ||
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[ | ||
"abcdefghijklmnopqrstuvwxyz" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[ | ||
"абвгдеёжзийклмнопрстуфхцчшщъыьэюя" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters