Skip to content

Instantly share code, notes, and snippets.

View carlos3g's full-sized avatar
💻
Coding with community

Carlos Mesquita carlos3g

💻
Coding with community
View GitHub Profile
/**
* v0 by Vercel.
* @see https://v0.dev/t/uNOsfYuMiZR
* Documentation: https://v0.dev/docs#integrating-generated-code-into-your-nextjs-app
*/
import { Button } from "@/components/ui/button"
export default function Component() {
return (
<div className="max-w-2xl mx-auto px-4 py-8 sm:px-6 lg:px-8">
@carlos3g
carlos3g / textToColor.ts
Created June 13, 2024 15:23
text to color | base 36 to 16
// see: https://www.charlie-coleman.com/experiments/1
export const textToColor = (unsafeColor: string): string => {
// Remove all non-alphanumeric characters and spaces
let color = unsafeColor.replace(/\s+/g, '').replace(/[^a-zA-Z0-9]+/g, '');
// Calculate required length and padding
const lengthC = color.length;
const amount = Math.ceil(lengthC / 3);
const add = amount * 3 - lengthC;
const DIGIT = '9';
const ALPHA = 'A';
const ALPHANUM = 'S';
const toPattern = (value: string, pattern: string): string => {
const resultArray = pattern.split('');
const values = value.split('');
let index = 0;
let i = 0;