{"id":21158237,"url":"https://github.com/simbo/color-name-to-code","last_synced_at":"2026-04-11T21:44:47.921Z","repository":{"id":158899825,"uuid":"633949039","full_name":"simbo/color-name-to-code","owner":"simbo","description":"A javascript library that returns a color code for a given color name.","archived":false,"fork":false,"pushed_at":"2023-05-01T21:12:01.000Z","size":160,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-22T05:18:02.369Z","etag":null,"topics":["color","color-name","color-names","css","hex","rgb"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/simbo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-28T16:47:01.000Z","updated_at":"2023-05-01T16:03:08.000Z","dependencies_parsed_at":null,"dependency_job_id":"9b75da0e-8feb-4ff0-b3bd-99179c817463","html_url":"https://github.com/simbo/color-name-to-code","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simbo%2Fcolor-name-to-code","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simbo%2Fcolor-name-to-code/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simbo%2Fcolor-name-to-code/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simbo%2Fcolor-name-to-code/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simbo","download_url":"https://codeload.github.com/simbo/color-name-to-code/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243599769,"owners_count":20317156,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["color","color-name","color-names","css","hex","rgb"],"created_at":"2024-11-20T12:18:59.504Z","updated_at":"2026-04-11T21:44:42.877Z","avatar_url":"https://github.com/simbo.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Color Name to Code\n\n[![npm Package Version](https://img.shields.io/npm/v/color-name-to-code?)](https://www.npmjs.com/package/color-name-to-code)\n[![License MIT](https://img.shields.io/badge/license-MIT-4cc552)](http://simbo.mit-license.org/)\n[![GitHub Repo](https://img.shields.io/badge/repo-public-87ceeb)](https://github.com/simbo/color-name-to-code)\n![Native Typescript Support](https://img.shields.io/npm/types/color-name-to-code)\n[![Coveralls Coverage](https://img.shields.io/coveralls/github/simbo/color-name-to-code)](https://coveralls.io/github/simbo/color-name-to-code)\n[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/simbo/color-name-to-code/ci.yml?branch=main)](https://github.com/simbo/color-name-to-code/actions/workflows/ci.yml)\n\nA javascript library that returns a color code for a given color name.\n\nIt supports all color names from the list of\n[named CSS colors from W3C](https://drafts.csswg.org/css-color/#named-colors).\n\nIt includes also the enum [`ColorName`](./src/color-name.enum.ts) with a full\nlist of all known color names.\n\nThe library can return hex color values, CSS `rgb(…)` values or an array of\nnumeric RGB color values.\n\n---\n\n## Installation\n\nThis library is published to npm registry as\n[`color-name-to-code`](https://www.npmjs.com/package/color-name-to-code).\n\nYou can install it:\n\n```sh\n# with npm\nnpm install --save color-name-to-code\n\n# with yarn\nyarn add color-name-to-code\n```\n\nℹ️ **HINT**: This library is a pure ESM package. (You may want to\n[read this](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).)\n\n## Usage\n\n```js\nimport { colorNameToCode } from 'color-name-to-code';\n\n// color name to hex value\ncolorNameToCode('red'); // -\u003e '#FF0000'\n\n// color name to lowercase hex value\ncolorNameToCode('red', { lowercase: true }); // -\u003e '#ff0000\n\n// color name to short hex value\ncolorNameToCode('red', { short: true }); // -\u003e '#f00'\n\n// color name to hex value without leading hash\ncolorNameToCode('red', { hash: false }); // -\u003e 'FF0000'\n\n// color name to CSS `rgb(…)` value\ncolorNameToCode('red', { format: 'rgb' }); // -\u003e 'rgb(255, 0, 0)'\n\n// color name to CSS `rgba(…)` value\ncolorNameToCode('red', { format: 'rgb', alpha: 0.5 }); // -\u003e 'rgba(255, 0, 0, 0.5)'\n\n// color name to numeric RGB array\ncolorNameToCode('red', { format: 'array' }); // -\u003e [255, 0, 0]\n\n// color names will be sanitized before matching\ncolorNameToCode('\"white!\"'); // -\u003e '#FFFFFF'\ncolorNameToCode('Black'); // -\u003e '#000000'\ncolorNameToCode('RED'); // -\u003e '#FF0000'\ncolorNameToCode('Dodger Blue'); // -\u003e '#1E90FF'\ncolorNameToCode('dark-slate-gray'); // -\u003e '#2F4F4F'\ncolorNameToCode('DARK_SLATE_GREY'); // -\u003e '#2F4F4F'\ncolorNameToCode('LeMoN cHiFfOn'); // -\u003e '#FFFACD'\n\n// an unknown color name will be transformed to a fallback color\ncolorNameToCode('Foo Bar'); // -\u003e '#FFBBAA'\ncolorNameToCode(undefined); // -\u003e '#DEFE0D'\ncolorNameToCode('UNKNOWN'); // -\u003e '#000000'\n\n// if fallback is disabled and color name is unknown, an error is thrown\ncolorNameToCode('Foo Bar', { fallback: false }); // -\u003e ERROR: no matching color found for 'Foo Bar'\n```\n\n## API\n\n```ts\ncolorNameToCode(name: string, options: Partial\u003cOptions\u003e): string | [number, number, number];\n```\n\n### Options\n\n```ts\ninterface Options {\n  format: 'hex' | 'rgb' | 'array'; // default: 'hex'\n  fallback: boolean; // default: true\n  short: boolean; // default: false\n  hash: boolean; // default: true\n  lowercase: boolean; // default: false\n  alpha: number; // default: 1\n}\n```\n\n- `format: 'hex' | 'rgb' | 'array'` (default: `'hex'`)  \n  …defines the output format.\n\n  Possible values:\n\n  - `'hex'` defines a hex value as output format\n  - `'rgb'` defines a CSS `rgb(…)` value as output format\n  - `'array'` defines a numeric array of RGB values as output format\n\n- `fallback: boolean` (default: `true`)  \n   …tries to generate a color value from the given name input if a matching color\n  name could not be found.\n\n  To achieve this, all non-hex characters are removed from the given string and\n  up to the first six left characters are interpreted as hex color value.\n\n  If `fallback` is `false` and no matching color name is found,\n  `colorNameToCode` will throw an error.\n\n- `short: boolean` (default: `false`)  \n   …returns a hex value as short version if possible and set to `true`.\n\n  (This option only takes effect in combination with `format: 'hex'`.)\n\n- `hash: boolean` (default: `true`)  \n  …returns a hex value with or without leading hash.\n\n  (This option only takes effect in combination with `format: 'hex'`.)\n\n- `lowercase: boolean` (default: `false`)  \n  …return a hex value with lowercase letters if set to `true`.\n\n  (This option only takes effect in combination with `format: 'hex'`.)\n\n- `alpha: number` (default: `1`)  \n  …returns a CSS `rgba(…)` value with alpha value, if `alpha` is lower than `1`.\n\n  (This option only takes effect in combination with `format: 'rgb'`.)\n\n## License\n\n[MIT \u0026copy; Simon Lepel](http://simbo.mit-license.org/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimbo%2Fcolor-name-to-code","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimbo%2Fcolor-name-to-code","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimbo%2Fcolor-name-to-code/lists"}