Skip to content

Commit

Permalink
Letter 1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Awilum committed Jan 8, 2022
1 parent 4b64cda commit 9e7604c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 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.1.0"></a>
# [1.1.0](https://github.com/faker-javascript/letter) (2022-01-08)
* Add locales support: ru_RU, en_US (default)

<a name="1.0.1"></a>
# [1.0.1](https://github.com/faker-javascript/letter) (2022-01-08)
* Package fixes
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ $ npm install --save @fakerjs/letter
import fakeLetter from '@fakerjs/letter';

fakeLetter();
//=> a
//=> z

fakeLetter({'casing': 'upper'});
//=> A
//=> Z

fakeLetter({'casing': 'upper', 'locale': 'ru_RU'});
//=> Я
```

## Tests
Expand Down
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
export default function fakeLetter(options) {
let keyspace = "abcdefghijklmnopqrstuvwxyz";
let letter = keyspace.charAt(Math.floor(Math.random() * keyspace.length));
options = options || {};
let keyspace = {
"en_US": "abcdefghijklmnopqrstuvwxyz",
"ru_RU": "абвгдеёжзийклмнопрстуфхцчшщъыьэюя"
};
let locale = ((options.locale === undefined) ? 'en_US' : options.locale);
let letter = keyspace[locale].charAt(Math.floor(Math.random() * keyspace[locale].length));
return (options.casing === 'upper' ? letter.toUpperCase() : letter);
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fakerjs/letter",
"version": "1.0.1",
"version": "1.1.0",
"description": "Letter package provides functionality to generate a fake letter value.",
"license": "MIT",
"repository": "faker-javascript/letter",
Expand Down
8 changes: 7 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@ test('fakeLetter return type to be string', t => {
t.is(typeof fakeLetter(), 'string');
});

test('fakeLetter string length less eq 1', t => {
test('fakeLetter length casing eq 1', t => {
t.is(fakeLetter().length, 1);
t.is(fakeLetter({ casing: 'upper' }).length, 1);
t.is(fakeLetter({ casing: 'lower' }).length, 1);
});

test('fakeLetter with casing and locale ru_RU length eq 1', t => {
t.is(fakeLetter().length, 1);
t.is(fakeLetter({ casing: 'upper', locale: 'ru_RU' }).length, 1);
t.is(fakeLetter({ casing: 'lower', locale: 'ru_RU' }).length, 1);
});

0 comments on commit 9e7604c

Please sign in to comment.