Skip to content

Commit

Permalink
feat: Setting default language
Browse files Browse the repository at this point in the history
  • Loading branch information
MilosPaunovic committed Jun 5, 2022
1 parent 86e57e1 commit 0ca2f51
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ npm i @paunovic/random-words
```js
import { initialize } from '@paunovic/random-words'

// Default language pack
// Initialization with default language pack
const RANDOM = initialize();

// Initialization with different language pack
const RANDOM = initialize({ countryCode: 'rs' })

// With variation
// Initialization with different language pack, including variation
const RANDOM = initialize({ countryCode: 'rs', variation: 'cyrillic' })
```

Expand All @@ -31,9 +34,11 @@ Currently available country codes and variations:
| Country | Country code | Variation |
| :------------ | :----------: | :--------: |
| Serbia | `rs` | `cyrillic` |
| United States | `us` | |
| United States `*` | `us` | |
| Spain | `es` | |

`*` Default language; if no `countryCode` parameter is passed to `initialize` method, english will be loaded as a default language.

## Methods

```js
Expand Down
4 changes: 1 addition & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ import { randomNumber } from './helpers/general.js';
*
*/

export const initialize = ({ countryCode, variation = 'default' }) => {
if (!countryCode) throw new Error('Missing parameter countryCode.');

export const initialize = ({ countryCode = 'us', variation = 'default' }) => {
const WORDS = LANGUAGES[countryCode][variation];

/**
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@paunovic/random-words",
"version": "1.2.0",
"version": "1.2.1",
"type": "module",
"description": "Serving random words in any language has never been this easy.",
"author": {
Expand Down

0 comments on commit 0ca2f51

Please sign in to comment.