{"id":13394234,"url":"https://github.com/Qix-/color","last_synced_at":"2025-03-13T20:31:21.595Z","repository":{"id":40593419,"uuid":"1939300","full_name":"Qix-/color","owner":"Qix-","description":":rainbow: Javascript color conversion and manipulation library","archived":false,"fork":false,"pushed_at":"2025-02-12T11:16:17.000Z","size":169,"stargazers_count":4825,"open_issues_count":15,"forks_count":270,"subscribers_count":29,"default_branch":"master","last_synced_at":"2025-03-11T00:29:18.924Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/Qix-.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","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":"2011-06-23T03:13:37.000Z","updated_at":"2025-03-10T15:01:58.000Z","dependencies_parsed_at":"2025-02-24T22:29:26.342Z","dependency_job_id":"c0a9c765-c5c1-43d2-9be0-f530e21e80fb","html_url":"https://github.com/Qix-/color","commit_stats":{"total_commits":167,"total_committers":55,"mean_commits":3.036363636363636,"dds":0.8143712574850299,"last_synced_commit":"daec0b26942cd37dfa13bc5592a58670e77d2143"},"previous_names":["harthur/color","moox/color"],"tags_count":35,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Qix-%2Fcolor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Qix-%2Fcolor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Qix-%2Fcolor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Qix-%2Fcolor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Qix-","download_url":"https://codeload.github.com/Qix-/color/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243136242,"owners_count":20241988,"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":[],"created_at":"2024-07-30T17:01:13.362Z","updated_at":"2025-03-13T20:31:21.583Z","avatar_url":"https://github.com/Qix-.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","颜色","Color","Color [🔝](#readme)","Uncategorized","目录","Table of Contents"],"sub_categories":["Runner","React Components","Uncategorized","Color Libraries"],"readme":"# color\n\n\u003e JavaScript library for immutable color conversion and manipulation with support for CSS color strings.\n\n```js\nconst color = Color('#7743CE').alpha(0.5).lighten(0.5);\nconsole.log(color.hsl().string());  // 'hsla(262, 59%, 81%, 0.5)'\n\nconsole.log(color.cmyk().round().array());  // [ 16, 25, 0, 8, 0.5 ]\n\nconsole.log(color.ansi256().object());  // { ansi256: 183, alpha: 0.5 }\n```\n\n## Install\n```shell\nnpm install color\n```\n\n## Usage\n```js\nimport Color from 'color';\n```\n\n### Constructors\n```js\n// string constructor\nconst color = Color('rgb(255, 255, 255)')                       // { model: 'rgb', color: [ 255, 255, 255 ], valpha: 1 }\nconst color = Color('hsl(194, 53%, 79%)')                       // { model: 'hsl', color: [ 195, 53, 79 ], valpha: 1 }\nconst color = Color('hsl(194, 53%, 79%, 0.5)')                  // { model: 'hsl', color: [ 195, 53, 79 ], valpha: 0.5 }\nconst color = Color('#FF0000')                                  // { model: 'rgb', color: [ 255, 0, 0 ], valpha: 1 }\nconst color = Color('#FF000033')                                // { model: 'rgb', color: [ 255, 0, 0 ], valpha: 0.2 }\nconst color = Color('lightblue')                                // { model: 'rgb', color: [ 173, 216, 230 ], valpha: 1 }\nconst color = Color('purple')                                   // { model: 'rgb', color: [ 128, 0, 128 ], valpha: 1 }\n\n// rgb\nconst color = Color({r: 255, g: 255, b: 255})                   // { model: 'rgb', color: [ 255, 255, 255 ], valpha: 1 }\nconst color = Color({r: 255, g: 255, b: 255, alpha: 0.5})       // { model: 'rgb', color: [ 255, 255, 255 ], valpha: 0.5 }\nconst color = Color.rgb(255, 255, 255)                          // { model: 'rgb', color: [ 255, 255, 255 ], valpha: 1 }\nconst color = Color.rgb(255, 255, 255, 0.5)                     // { model: 'rgb', color: [ 255, 255, 255 ], valpha: 0.5 }\nconst color = Color.rgb(0xFF, 0x00, 0x00, 0.5)                  // { model: 'rgb', color: [ 255, 0, 0 ], valpha: 0.5 }\nconst color = Color.rgb([255, 255, 255])                        // { model: 'rgb', color: [ 255, 255, 255 ], valpha: 1 }\nconst color = Color.rgb([0xFF, 0x00, 0x00, 0.5])                // { model: 'rgb', color: [ 255, 0, 0 ], valpha: 0.5 }\n\n// hsl\nconst color = Color({h: 194, s: 53, l: 79})                     // { model: 'hsl', color: [ 195, 53, 79 ], valpha: 1 }\nconst color = Color({h: 194, s: 53, l: 79, alpha: 0.5})         // { model: 'hsl', color: [ 195, 53, 79 ], valpha: 0.5 }\nconst color = Color.hsl(194, 53, 79)                            // { model: 'hsl', color: [ 195, 53, 79 ], valpha: 1 }\n\n// hsv\nconst color = Color({h: 195, s: 25, v: 99})                     // { model: 'hsv', color: [ 195, 25, 99 ], valpha: 1 }\nconst color = Color({h: 195, s: 25, v: 99, alpha: 0.5})         // { model: 'hsv', color: [ 195, 25, 99 ], valpha: 0.5 }\nconst color = Color.hsv(195, 25, 99)                            // { model: 'hsv', color: [ 195, 25, 99 ], valpha: 1 }\nconst color = Color.hsv([195, 25, 99])                          // { model: 'hsv', color: [ 195, 25, 99 ], valpha: 1 }\n\n// cmyk\nconst color = Color({c: 0, m: 100, y: 100, k: 0})               // { model: 'cmyk', color: [ 0, 100, 100, 0 ], valpha: 1 }\nconst color = Color({c: 0, m: 100, y: 100, k: 0, alpha: 0.5})   // { model: 'cmyk', color: [ 0, 100, 100, 0 ], valpha: 0.5 }\nconst color = Color.cmyk(0, 100, 100, 0)                        // { model: 'cmyk', color: [ 0, 100, 100, 0 ], valpha: 1 }\nconst color = Color.cmyk(0, 100, 100, 0, 0.5)                   // { model: 'cmyk', color: [ 0, 100, 100, 0 ], valpha: 0.5 }\n\n// hwb\nconst color = Color({h: 180, w: 0, b: 0})                       // { model: 'hwb', color: [ 180, 0, 0 ], valpha: 1 }\nconst color = Color.hwb(180, 0, 0)                              // { model: 'hwb', color: [ 180, 0, 0 ], valpha: 1 }\n\n// lch\nconst color = Color({l: 53, c: 105, h: 40})                     // { model: 'lch', color: [ 53, 105, 40 ], valpha: 1 }\nconst color = Color.lch(53, 105, 40)                            // { model: 'lch', color: [ 53, 105, 40 ], valpha: 1 }\n\n// lab\nconst color = Color({l: 53, a: 80, b: 67})                      // { model: 'lab', color: [ 53, 80, 67 ], valpha: 1 }\nconst color = Color.lab(53, 80, 67)                             // { model: 'lab', color: [ 53, 80, 67 ], valpha: 1 }\n\n// hcg\nconst color = Color({h: 0, c: 100, g: 0})                       // { model: 'hcg', color: [ 0, 100, 0 ], valpha: 1 }\nconst color = Color.hcg(0, 100, 0)                              // { model: 'hcg', color: [ 0, 100, 0 ], valpha: 1 }\n\n// ansi16\nconst color = Color.ansi16(91)                                  // { model: 'ansi16', color: [ 91 ], valpha: 1 }\nconst color = Color.ansi16(91, 0.5)                             // { model: 'ansi16', color: [ 91 ], valpha: 0.5 }\n\n// ansi256\nconst color = Color.ansi256(196)                                // { model: 'ansi256', color: [ 196 ], valpha: 1 }\nconst color = Color.ansi256(196, 0.5)                           // { model: 'ansi256', color: [ 196 ], valpha: 0.5 }\n\n// apple\nconst color = Color.apple(65535, 65535, 65535)                  // { model: 'apple', color: [ 65535, 65535, 65535 ], valpha: 1 }\nconst color = Color.apple([65535, 65535, 65535])                // { model: 'apple', color: [ 65535, 65535, 65535 ], valpha: 1 }\n\n\n```\n\nSet the values for individual channels with `alpha`, `red`, `green`, `blue`, `hue`, `saturationl` (hsl), `saturationv` (hsv), `lightness`, `whiteness`, `blackness`, `cyan`, `magenta`, `yellow`, `black`\n\nString constructors are handled by [color-string](https://www.npmjs.com/package/color-string)\n\n### Getters\n```js\ncolor.hsl()\n```\nConvert a color to a different space (`hsl()`, `cmyk()`, etc.).\n\n```js\ncolor.object() // {r: 255, g: 255, b: 255}\n```\nGet a hash of the color value. Reflects the color's current model (see above).\n\n```js\ncolor.rgb().array() // [255, 255, 255]\n```\nGet an array of the values with `array()`. Reflects the color's current model (see above).\n\n```js\ncolor.rgbNumber() // 16777215 (0xffffff)\n```\nGet the rgb number value.\n\n```js\ncolor.hex() // #ffffff\n```\nGet the hex value. (**NOTE:** `.hex()` does not return alpha values; use `.hexa()` for an RGBA representation)\n\n```js\ncolor.red() // 255\n```\nGet the value for an individual channel.\n\n### CSS Strings\n```js\ncolor.hsl().string() // 'hsl(320, 50%, 100%)'\n```\n\nCalling `.string()` with a number rounds the numbers to that decimal place. It defaults to 1.\n\n### Luminosity\n```js\ncolor.luminosity(); // 0.412\n```\nThe [WCAG luminosity](http://www.w3.org/TR/WCAG20/#relativeluminancedef) of the color. 0 is black, 1 is white.\n\n```js\ncolor.contrast(Color(\"blue\")) // 12\n```\nThe [WCAG contrast ratio](http://www.w3.org/TR/WCAG20/#contrast-ratiodef) to another color, from 1 (same color) to 21 (contrast b/w white and black).\n\n```js\ncolor.isLight()  // true\ncolor.isDark()   // false\n```\nGet whether the color is \"light\" or \"dark\", useful for deciding text color.\n\n### Manipulation\n```js\ncolor.negate()         // rgb(0, 100, 255) -\u003e rgb(255, 155, 0)\n\ncolor.lighten(0.5)     // hsl(100, 50%, 50%) -\u003e hsl(100, 50%, 75%)\ncolor.lighten(0.5)     // hsl(100, 50%, 0)   -\u003e hsl(100, 50%, 0)\ncolor.darken(0.5)      // hsl(100, 50%, 50%) -\u003e hsl(100, 50%, 25%)\ncolor.darken(0.5)      // hsl(100, 50%, 0)   -\u003e hsl(100, 50%, 0)\n\ncolor.lightness(50)    // hsl(100, 50%, 10%) -\u003e hsl(100, 50%, 50%)\n\ncolor.saturate(0.5)    // hsl(100, 50%, 50%) -\u003e hsl(100, 75%, 50%)\ncolor.desaturate(0.5)  // hsl(100, 50%, 50%) -\u003e hsl(100, 25%, 50%)\ncolor.grayscale()      // #5CBF54 -\u003e #969696\n\ncolor.whiten(0.5)      // hwb(100, 50%, 50%) -\u003e hwb(100, 75%, 50%)\ncolor.blacken(0.5)     // hwb(100, 50%, 50%) -\u003e hwb(100, 50%, 75%)\n\ncolor.fade(0.5)        // rgba(10, 10, 10, 0.8) -\u003e rgba(10, 10, 10, 0.4)\ncolor.opaquer(0.5)     // rgba(10, 10, 10, 0.8) -\u003e rgba(10, 10, 10, 1.0)\n\ncolor.rotate(180)      // hsl(60, 20%, 20%) -\u003e hsl(240, 20%, 20%)\ncolor.rotate(-90)      // hsl(60, 20%, 20%) -\u003e hsl(330, 20%, 20%)\n\ncolor.mix(Color(\"yellow\"))        // cyan -\u003e rgb(128, 255, 128)\ncolor.mix(Color(\"yellow\"), 0.3)   // cyan -\u003e rgb(77, 255, 179)\n\n// chaining\ncolor.green(100).grayscale().lighten(0.6)\n```\n\n## Propers\nThe API was inspired by [color-js](https://github.com/brehaut/color-js). Manipulation functions by CSS tools like Sass, LESS, and Stylus.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FQix-%2Fcolor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FQix-%2Fcolor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FQix-%2Fcolor/lists"}