Skip to content

Commit

Permalink
Merge pull request #169 from abmaonline/feature/137-digits-only-color…
Browse files Browse the repository at this point in the history
…-code

Add support for color codes containing only digits
  • Loading branch information
soldair committed Feb 5, 2019
2 parents 004e26c + d59c2bf commit 196a379
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lib/renderer/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
function hex2rgba (hex) {
if (typeof hex === 'number') {
hex = hex.toString()
}

if (typeof hex !== 'string') {
throw new Error('Color should be defined as hex string')
}
Expand Down
11 changes: 9 additions & 2 deletions test/unit/renderer/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,16 @@ test('Utils getOptions', function (t) {
dark: { r: 255, g: 255, b: 255, a: 255, hex: '#ffffff' },
light: { r: 0, g: 0, b: 0, a: 255, hex: '#000000' }
},
'Should return correct colors value')
'Should return correct colors value from strings')

t.throw(function () { Utils.getOptions({ color: { dark: 1234 } }) },
t.deepEqual(Utils.getOptions({ color: { dark: 111, light: 999 } }).color,
{
dark: { r: 17, g: 17, b: 17, a: 255, hex: '#111111' },
light: { r: 153, g: 153, b: 153, a: 255, hex: '#999999' }
},
'Should return correct colors value from numbers')

t.throw(function () { Utils.getOptions({ color: { dark: true } }) },
'Should throw if color is not a string')

t.throw(function () { Utils.getOptions({ color: { dark: '#aa' } }) },
Expand Down

0 comments on commit 196a379

Please sign in to comment.