-
Notifications
You must be signed in to change notification settings - Fork 4
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 #7 from yusufshakeel/dev
v0.6.1
- Loading branch information
Showing
7 changed files
with
122 additions
and
62 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
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,57 @@ | ||
const { | ||
ALPHABET_UPPERCASE, | ||
ALPHABET_LOWERCASE, | ||
DIGIT, | ||
BINARY, | ||
OCTAL, | ||
HEX, | ||
HEX_LOWER, | ||
CHARSET_ALPHA, | ||
CHARSET_ALPHA_LOWER, | ||
CHARSET_DIGIT, | ||
CHARSET_ALNUM, | ||
CHARSET_BINARY, | ||
CHARSET_OCTAL, | ||
CHARSET_HEX, | ||
CHARSET_HEX_LOWER | ||
} = require('./constants.js'); | ||
|
||
/** | ||
* This will return the characters based on the character set name. | ||
* @param {string} charSetName This is the name of the character set. | ||
* @returns {string} String of characters. | ||
*/ | ||
function characterSet(charSetName) { | ||
const validCharSets = [ | ||
CHARSET_ALPHA, | ||
CHARSET_ALPHA_LOWER, | ||
CHARSET_DIGIT, | ||
CHARSET_ALNUM, | ||
CHARSET_BINARY, | ||
CHARSET_OCTAL, | ||
CHARSET_HEX, | ||
CHARSET_HEX_LOWER | ||
]; | ||
switch (charSetName) { | ||
case CHARSET_ALPHA: | ||
return ALPHABET_UPPERCASE; | ||
case CHARSET_ALPHA_LOWER: | ||
return ALPHABET_LOWERCASE; | ||
case CHARSET_DIGIT: | ||
return DIGIT; | ||
case CHARSET_ALNUM: | ||
return `${ALPHABET_UPPERCASE}${ALPHABET_LOWERCASE}${DIGIT}`; | ||
case CHARSET_BINARY: | ||
return `${BINARY}`; | ||
case CHARSET_OCTAL: | ||
return `${OCTAL}`; | ||
case CHARSET_HEX: | ||
return `${HEX}`; | ||
case CHARSET_HEX_LOWER: | ||
return `${HEX_LOWER}`; | ||
default: | ||
throw new Error(`Invalid builtIn characterSet specified. Allowed values: ${validCharSets.join(', ')}`); | ||
} | ||
} | ||
|
||
module.exports = characterSet; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,57 @@ | ||
const characterSet = require('../../app/character-set.js'); | ||
const { | ||
ALPHABET_UPPERCASE, | ||
ALPHABET_LOWERCASE, | ||
DIGIT, | ||
BINARY, | ||
OCTAL, | ||
HEX, | ||
HEX_LOWER, | ||
CHARSET_ALPHA, | ||
CHARSET_ALPHA_LOWER, | ||
CHARSET_DIGIT, | ||
CHARSET_ALNUM, | ||
CHARSET_BINARY, | ||
CHARSET_OCTAL, | ||
CHARSET_HEX, | ||
CHARSET_HEX_LOWER | ||
} = require('../../app/constants.js'); | ||
|
||
test('Should throw error if invalid charSetName provided', () => { | ||
expect(() => { | ||
const chars = characterSet('UNKNOWN'); | ||
throw new Error('Should have failed.'); | ||
}).toThrow('Invalid builtIn characterSet specified. Allowed values: CHARSET_ALPHA, CHARSET_ALPHA_LOWER, CHARSET_DIGIT, CHARSET_ALNUM, CHARSET_BINARY, CHARSET_OCTAL, CHARSET_HEX, CHARSET_HEX_LOWER'); | ||
}); | ||
|
||
test('Should return uppercase alphabet A-Z when using charSetName "CHARSET_ALPHA"', () => { | ||
expect(characterSet(CHARSET_ALPHA)).toBe(ALPHABET_UPPERCASE); | ||
}); | ||
|
||
test('Should return lowercase alphabet a-z when using charSetName "CHARSET_ALPHA_LOWER"', () => { | ||
expect(characterSet(CHARSET_ALPHA_LOWER)).toBe(ALPHABET_LOWERCASE); | ||
}); | ||
|
||
test('Should return digits 0-9 when using charSetName "CHARSET_DIGIT"', () => { | ||
expect(characterSet(CHARSET_DIGIT)).toBe(DIGIT); | ||
}); | ||
|
||
test('Should return uppercase, lowercase alphabet and digit when using charSetName "CHARSET_ALNUM"', () => { | ||
expect(characterSet(CHARSET_ALNUM)).toBe(`${ALPHABET_UPPERCASE}${ALPHABET_LOWERCASE}${DIGIT}`); | ||
}); | ||
|
||
test('Should return binary characters when using charSetName "CHARSET_BINARY"', () => { | ||
expect(characterSet(CHARSET_BINARY)).toBe(BINARY); | ||
}); | ||
|
||
test('Should return octal characters when using charSetName "CHARSET_OCTAL"', () => { | ||
expect(characterSet(CHARSET_OCTAL)).toBe(OCTAL); | ||
}); | ||
|
||
test('Should characterSet hex characters when using charSetName "CHARSET_HEX"', () => { | ||
expect(characterSet(CHARSET_HEX)).toBe(HEX); | ||
}); | ||
|
||
test('Should return hex lowercase characters when using charSetName "CHARSET_HEX_LOWER"', () => { | ||
expect(characterSet(CHARSET_HEX_LOWER)).toBe(HEX_LOWER); | ||
}); |