Menu

gitpiper

extendHex javascript Code Snippet in 2024

stringintermediate

Last Updated: 10 April 2024

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.
const extendHex = shortHex => '#' + shortHex .slice(shortHex.startsWith('#') ? 1 : 0) .split('') .map(x => x + x) .join('');
extendHex('#03f'); // '#0033ff' extendHex('05a'); // '#0055aa'

javascript snippet similar to extendHex For You in April 2024

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2024 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️