-
Notifications
You must be signed in to change notification settings - Fork 62
Allow numbers < 100 to be input #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ronkorving
wants to merge
3
commits into
freeall:master
Choose a base branch
from
ronkorving:improvements
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,14 +1,35 @@ | ||
| var cc = require('./index'); | ||
| var assert = require('assert'); | ||
|
|
||
| assert(cc.code('EUR').countries.length === 35); | ||
| assert(cc.code('IDR').digits === 2); | ||
| assert(cc.number('967').currency === 'Zambian Kwacha'); | ||
| assert(cc.number(967).currency === 'Zambian Kwacha'); | ||
| assert(cc.country('Colombia').length === 2); | ||
| assert(cc.country('colombia').length === 2); | ||
| assert(cc.codes().length === 178); | ||
| assert(cc.countries().length === 250); | ||
| assert(cc.numbers().length === 178); | ||
| assert(cc.numbers()[0] === '784'); | ||
| assert(cc.data.length == 178); | ||
| // test properties of specific currencies | ||
|
|
||
| assert.strictEqual(cc.code('EUR').countries.length, 35, 'The Euro is used by 35 countries'); | ||
| assert.strictEqual(cc.code('IDR').digits, 2, 'The Indonesian Rupiah uses a fraction of 2 digits'); | ||
| assert.strictEqual(cc.number('967').currency, 'Zambian Kwacha', 'Zambian Kwacha is number 967'); | ||
| assert.strictEqual(cc.number('036').code, 'AUD', 'Australian Dollar is AUD'); | ||
| assert.strictEqual(cc.country('Colombia').length, 2, 'Colombia has 2 currencies'); | ||
| assert.strictEqual(typeof cc.code('JPY').number, 'string', 'Currency numbers are strings'); | ||
|
|
||
| // test input flexibility | ||
|
|
||
| assert.deepStrictEqual(cc.country('colombia'), cc.country('Colombia'), 'Searching by country name is case-insensitive'); | ||
| assert.strictEqual(cc.number(967).currency, 'Zambian Kwacha', 'Currencies can be found with a number as integer'); | ||
| assert.deepStrictEqual(cc.number(36), cc.number('036'), 'Currencies can be found with a number < 100 as integer'); | ||
| assert.deepStrictEqual(cc.number('36'), cc.number('036'), 'Currencies can be found with a number < 100 as string'); | ||
|
|
||
| // test data across all currencies | ||
|
|
||
| cc.numbers().forEach((number) => { | ||
| assert(number.match(/^[0-9]{3}$/), `"${number}" is expected to be exactly 3 digits`); | ||
| }); | ||
|
|
||
| cc.codes().forEach((code) => { | ||
| assert(code.match(/^[A-Z]{3}$/), `"${code}" is expected to be exactly 3 uppercase characters`); | ||
| }); | ||
|
|
||
| // test totals | ||
|
|
||
| assert.strictEqual(cc.data.length, 179, 'There are a total of 179 currencies'); | ||
| assert.strictEqual(cc.codes().length, cc.data.length, 'There are as many currency codes as there are currencies'); | ||
| assert.strictEqual(cc.numbers().length, cc.data.length, 'There are as many currency numbers as there are currencies'); | ||
| assert.strictEqual(cc.countries().length, 260, 'There are a total of 260 countries'); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could've used
String(number).padStart(3, '0'), but that requires Node 8. I don't know which version of Node you're intending to support, not to mention browsers, but given that all the JavaScript I see here is fairly legacy, I went with the safe option.