Nest all content into snippets

This commit is contained in:
Angelos Chalaris
2023-05-07 16:07:29 +03:00
parent 2ecadbada9
commit 6a45d2ec07
1240 changed files with 0 additions and 0 deletions

View File

@ -0,0 +1,28 @@
---
title: Extend hex value
type: snippet
language: javascript
tags: [string]
cover: red-mountain
dateModified: 2020-09-15T16:28:04+03:00
---
Extends a 3-digit color code to a 6-digit color code.
- Use `Array.prototype.map()`, `String.prototype.split()` and `Array.prototype.join()` to join the mapped array for converting a 3-digit RGB notated hexadecimal color-code to the 6-digit form.
- `Array.prototype.slice()` is used to remove `#` from string start since it's added once.
```js
const extendHex = shortHex =>
'#' +
shortHex
.slice(shortHex.startsWith('#') ? 1 : 0)
.split('')
.map(x => x + x)
.join('');
```
```js
extendHex('#03f'); // '#0033ff'
extendHex('05a'); // '#0055aa'
```