{"_id":"@theguyswithaball/color-utils","_rev":"2-4156755378efc3d082e7917014807db5","name":"@theguyswithaball/color-utils","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"@theguyswithaball/color-utils","version":"1.0.0","keywords":["color","hex","rgb","hsl","convert","lighten","darken","contrast","accessibility","wcag"],"author":{"name":"theguyswithaballinthepocket"},"license":"MIT","_id":"@theguyswithaball/color-utils@1.0.0","maintainers":[{"name":"theguyswithaballinthepocket","email":"theguyswithaballinthepocket@tuta.io"}],"homepage":"https://github.com/theguyswithaballinthepocket/color-utils#readme","bugs":{"url":"https://github.com/theguyswithaballinthepocket/color-utils/issues"},"dist":{"shasum":"cbbb544190e4c98139d701b0114089262f0b5a5e","tarball":"https://registry.npmjs.org/@theguyswithaball/color-utils/-/color-utils-1.0.0.tgz","fileCount":4,"integrity":"sha512-RnoDoRa+kDuzFpZIjwyG/uw9QLn3fE2MoucsldqccY33ebrmXzmPf5F/r0LLFqXaybZivw9w7J0XMdPcSh2PDA==","signatures":[{"sig":"MEUCIGFmBmNYWSH9g1Uo1OXjUGF/WvyCKuZUyz8BXR1FCn0GAiEA6OFi4mHgG76+rs8EhMuM40hC+O8zVi2z25gHXfUzI7s=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":30314},"main":"index.js","scripts":{"test":"node test.js"},"_npmUser":{"name":"theguyswithaballinthepocket","email":"theguyswithaballinthepocket@tuta.io"},"repository":{"url":"git+https://github.com/theguyswithaballinthepocket/color-utils.git","type":"git"},"_npmVersion":"10.9.2","description":"Color conversion, manipulation, and accessibility utilities for hex, RGB, and HSL colors","directories":{},"_nodeVersion":"22.14.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/color-utils_1.0.0_1779878906718_0.9860737295890107","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"@theguyswithaball/color-utils","version":"1.0.1","description":"Color conversion, manipulation, and accessibility utilities for hex, RGB, and HSL colors","main":"index.js","scripts":{"test":"node test.js"},"keywords":["color","hex","rgb","hsl","convert","lighten","darken","contrast","accessibility","wcag"],"author":{"name":"theguyswithaballinthepocket"},"license":"MIT","publishConfig":{"access":"public"},"repository":{"type":"git","url":"git+https://github.com/theguyswithaballinthepocket/color-utils.git"},"_id":"@theguyswithaball/color-utils@1.0.1","bugs":{"url":"https://github.com/theguyswithaballinthepocket/color-utils/issues"},"homepage":"https://github.com/theguyswithaballinthepocket/color-utils#readme","_nodeVersion":"22.14.0","_npmVersion":"10.9.2","dist":{"integrity":"sha512-7HK4Kbn7b6vmJKbG///Px4f1goYZFNMkEChaU+hVgkCSHFotv9wp2qyTfab/+p+0WYBHik5xdQwt+sSyQjTjYQ==","shasum":"626abbf45fb670e215cb072b52f53a2ef1f55001","tarball":"https://registry.npmjs.org/@theguyswithaball/color-utils/-/color-utils-1.0.1.tgz","fileCount":5,"unpackedSize":32110,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCICwfI+UOuq9zvcU7Oj6/4dqY+jUEeKHpMtvN6iZofxadAiA21P9GXWubOF6qLcdg5FhY3e3X/Q2C0JYjnZPAup/ECQ=="}]},"_npmUser":{"name":"theguyswithaballinthepocket","email":"theguyswithaballinthepocket@tuta.io"},"directories":{},"maintainers":[{"name":"theguyswithaballinthepocket","email":"theguyswithaballinthepocket@tuta.io"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/color-utils_1.0.1_1779884695200_0.9882206288211448"},"_hasShrinkwrap":false}},"time":{"created":"2026-05-27T10:48:26.584Z","modified":"2026-05-27T12:24:55.477Z","1.0.0":"2026-05-27T10:48:26.833Z","1.0.1":"2026-05-27T12:24:55.333Z"},"bugs":{"url":"https://github.com/theguyswithaballinthepocket/color-utils/issues"},"author":{"name":"theguyswithaballinthepocket"},"license":"MIT","homepage":"https://github.com/theguyswithaballinthepocket/color-utils#readme","keywords":["color","hex","rgb","hsl","convert","lighten","darken","contrast","accessibility","wcag"],"repository":{"type":"git","url":"git+https://github.com/theguyswithaballinthepocket/color-utils.git"},"description":"Color conversion, manipulation, and accessibility utilities for hex, RGB, and HSL colors","maintainers":[{"name":"theguyswithaballinthepocket","email":"theguyswithaballinthepocket@tuta.io"}],"readme":"# color-utils\n\nColor conversion, manipulation, and accessibility utilities for hex, RGB, and HSL colors.\n\n## Install\n\n```bash\nnpm install @theguyswithaball/color-utils\n```\n\n## Usage\n\n```js\nconst color = require('@theguyswithaball/color-utils');\n\ncolor.hexToRgb('#3498db');        // { r: 52, g: 152, b: 219 }\ncolor.lighten('#3498db', 15);     // '#66b2e8'\ncolor.getContrastRatio('#000', '#fff'); // 21\ncolor.isAccessible('#000', '#fff');     // true\ncolor.getReadableColor('#3498db');      // '#000000' or '#ffffff'\n```\n\n## API\n\n### Validation\n\n#### `isValidHex(hex)` → `boolean`\nReturns `true` if `hex` is a valid `#rgb` or `#rrggbb` color string.\n\n#### `isValidRgb(r, g, b)` → `boolean`\nReturns `true` if all three values are integers in `[0, 255]`.\n\n#### `isValidHsl(h, s, l)` → `boolean`\nReturns `true` if `h` is in `[0, 360)` and `s`, `l` are in `[0, 100]`.\n\n---\n\n### Conversions\n\n#### `hexToRgb(hex)` → `{r, g, b}`\n#### `rgbToHex(r, g, b)` → `string`\n#### `rgbToHsl(r, g, b)` → `{h, s, l}`\n#### `hslToRgb(h, s, l)` → `{r, g, b}`\n#### `hexToHsl(hex)` → `{h, s, l}`\n#### `hslToHex(h, s, l)` → `string`\n\n---\n\n### Manipulation\n\nAll manipulation functions accept and return hex color strings.\n\n#### `lighten(hex, amount)` → `string`\nIncreases lightness by `amount` (0–100).\n\n#### `darken(hex, amount)` → `string`\nDecreases lightness by `amount` (0–100).\n\n#### `saturate(hex, amount)` → `string`\nIncreases saturation by `amount` (0–100).\n\n#### `desaturate(hex, amount)` → `string`\nDecreases saturation by `amount` (0–100).\n\n#### `mix(hex1, hex2, weight = 50)` → `string`\nMixes two colors. `weight` (0–100) controls how much of `hex1` is used.\n\n#### `invert(hex)` → `string`\nReturns the negative/inverted color.\n\n#### `grayscale(hex)` → `string`\nConverts to grayscale using luminance weights.\n\n#### `rotate(hex, degrees)` → `string`\nRotates the hue by the given number of degrees.\n\n#### `complement(hex)` → `string`\nReturns the complementary color (hue rotated 180°).\n\n#### `triadic(hex)` → `[string, string, string]`\nReturns the base color and two triadic colors (120° apart).\n\n#### `tetradic(hex)` → `[string, string, string, string]`\nReturns four tetradic colors (90° apart).\n\n#### `analogous(hex, angle = 30)` → `[string, string, string]`\nReturns the base color and its two analogous neighbors at ±`angle` degrees.\n\n---\n\n### Accessibility (WCAG 2.1)\n\n#### `getLuminance(hex)` → `number`\nReturns the relative luminance, from `0` (black) to `1` (white).\n\n#### `getContrastRatio(hex1, hex2)` → `number`\nReturns the contrast ratio between two colors (1–21).\n\n#### `isAccessible(foreground, background, level = 'AA', size = 'normal')` → `boolean`\nChecks if the color pair meets the WCAG contrast threshold.\n\n| Level | Size   | Min ratio |\n|-------|--------|-----------|\n| AA    | normal | 4.5       |\n| AA    | large  | 3.0       |\n| AAA   | normal | 7.0       |\n| AAA   | large  | 4.5       |\n\n#### `getReadableColor(background)` → `'#000000' | '#ffffff'`\nReturns black or white, whichever is more readable on the given background.\n\n---\n\n### String output\n\n#### `toRgbString(r, g, b)` → `string`\nReturns `'rgb(r, g, b)'`.\n\n#### `toHslString(h, s, l)` → `string`\nReturns `'hsl(h, s%, l%)'`.\n\n#### `alpha(hex, opacity)` → `string`\nReturns `'rgba(r, g, b, opacity)'`. Opacity must be between 0 and 1.\n\n---\n\n### Misc\n\n#### `randomColor()` → `string`\nReturns a random hex color string.\n\n#### `parseColor(color)` → `{format, hex, rgb, hsl}`\nParses a hex, `rgb(...)`, or `hsl(...)` string and returns a normalized object with all three representations.\n\n```js\ncolor.parseColor('rgb(255, 0, 0)');\n// {\n//   format: 'rgb',\n//   hex: '#ff0000',\n//   rgb: { r: 255, g: 0, b: 0 },\n//   hsl: { h: 0, s: 100, l: 50 }\n// }\n```\n\n## License\n\nMIT\n","readmeFilename":"README.md"}