{"library":"rgb2hex","title":"RGB/RGBA to Hex Color Parser","description":"rgb2hex is a lightweight JavaScript library designed to parse RGB and RGBA color strings into their hexadecimal representation, including an alpha value for transparency. It operates without any external dependencies, making it suitable for environments where bundle size is critical. The current stable version is 0.2.5, released in November 2020. While updates have been infrequent since then, the library provides a focused solution for color conversion. A key differentiator is its minimal footprint and direct functionality, contrasting with larger color manipulation libraries that offer broader feature sets. It includes TypeScript type definitions for enhanced developer experience in modern projects. The library gained significant stability and security improvements between its early `v0.1.x` and `v0.2.x` releases, particularly addressing RegExp Denial of Service vulnerabilities.","language":"javascript","status":"maintenance","last_verified":"Sun Apr 19","install":{"commands":["npm install rgb2hex"],"cli":null},"imports":["import rgb2hex from 'rgb2hex';","const rgb2hex = require('rgb2hex');","import type { RgbResult } from 'rgb2hex';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import rgb2hex from 'rgb2hex';\n\n// Example 1: Basic RGB string\nconst result1 = rgb2hex('rgb(210,43,255)');\nconsole.log('RGB(210,43,255):', result1); // Expected: { hex: '#d22bff', alpha: 1 }\n\n// Example 2: RGBA string with transparency\nconst result2 = rgb2hex('rgba(12, 173, 22, .67)');\nconsole.log('RGBA(12,173,22,.67):', result2); // Expected: { hex: '#0cadaa', alpha: 0.67 }\n\n// Example 3: Handle transparent keyword\nconst result3 = rgb2hex('transparent');\nconsole.log('transparent:', result3); // Expected: { hex: '#000000', alpha: 0 }\n\n// Example 4: Invalid input (returns default/error structure)\ntry {\n  const result4 = rgb2hex('not a color string');\n  console.log('Invalid input:', result4);\n} catch (e) {\n  console.error('Invalid input error:', e.message);\n}","lang":"typescript","description":"Demonstrates parsing of various RGB/RGBA strings, including alpha values and the 'transparent' keyword, showing typical outputs and error handling for invalid input.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}