-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #233 from goodeggs/feat/add-state-generator
Add 2 letter state generator
- Loading branch information
Showing
5 changed files
with
36 additions
and
0 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
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,15 @@ | ||
import {Chance} from 'chance'; | ||
|
||
import createStateGenerator from '.'; | ||
|
||
describe('state', () => { | ||
it('generates a random state string', (): void => { | ||
const chance = new Chance(); | ||
const state = createStateGenerator(chance); | ||
|
||
const stateValue = state(); | ||
|
||
expect(stateValue).not.toBe(null); | ||
expect(stateValue).toMatch(/^[A-Z][A-Z]$/); | ||
}); | ||
}); |
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,10 @@ | ||
import {Chance} from 'chance'; | ||
|
||
/** | ||
* Returns a random 2 letter state (e.g., 'CA'). | ||
*/ | ||
const createStateGenerator = (chance: Chance.Chance) => (): string => { | ||
return chance.state(); | ||
}; | ||
|
||
export default createStateGenerator; |
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