Skip to content

Instantly share code, notes, and snippets.

View ramziddin's full-sized avatar

Ramziddin Makhmudov ramziddin

  • Uzbekistan, Tashkent
  • 12:21 (UTC +05:00)
View GitHub Profile
@ramziddin
ramziddin / phone-input.ts
Last active January 12, 2025 19:17
Uzbekistan phone number input component
import { ComponentProps, useState } from "react"
function PhoneInput(props: ComponentProps<"input">) {
const [value, setValue] = useState<string>("+998")
const formattedValue = value
.replaceAll(" ", "") // remove whitespace
.slice(4) // strip the country code
.match(/(\d{1,2})?(\d{1,3})?(\d{1,2})?(\d{1,2})?/)! // split into multiple components
.toSpliced(0, 1, "+998") // replace global match with country code
@ramziddin
ramziddin / index.js
Created July 7, 2017 09:15
Check if hex color dark or light
const isColorDark = color => {
const c = color.substring(1); // strip #
const rgb = parseInt(c, 16); // convert rrggbb to decimal
const r = (rgb >> 16) & 0xff; // extract red
const g = (rgb >> 8) & 0xff; // extract green
const b = (rgb >> 0) & 0xff; // extract blue
const luma = 0.2126 * r + 0.7152 * g + 0.0722 * b; // per ITU-R BT.709
const isDark = luma < 40;