Merge pull request #143 from Pl4gue/patch-1
Create hexadecimal-to-RGB.md
This commit is contained in:
8
snippets/hexcode-to-RGB.md
Normal file
8
snippets/hexcode-to-RGB.md
Normal file
@ -0,0 +1,8 @@
|
||||
### Hexcode to RGB
|
||||
|
||||
Use `Array.slice()`, `Array.map()` and `match()` to convert a hexadecimal colorcode (prefixed with `#`) to a string with the RGB values.
|
||||
|
||||
```js
|
||||
const hexToRgb = hex => `rgb(${hex.slice(1).match(/.{2}/g).map(x => parseInt(x, 16)).join()})`
|
||||
// hexToRgb('#27ae60') -> 'rgb(39,174,96)'
|
||||
```
|
||||
Reference in New Issue
Block a user