{"id":22631715,"url":"https://github.com/vinaypillai/ac-colors","last_synced_at":"2025-04-05T07:07:01.040Z","repository":{"id":48687399,"uuid":"264543860","full_name":"vinaypillai/ac-colors","owner":"vinaypillai","description":"ac-colors is a reactive JavaScript color library that can freely convert between RGB, HSL, HEX, XYZ, LAB, LCHab, LUV, and LCHuv, as well as handle random color generation and contrast ratio calculation.","archived":false,"fork":false,"pushed_at":"2021-07-14T15:35:52.000Z","size":1460,"stargazers_count":281,"open_issues_count":4,"forks_count":11,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-03-29T06:07:50.735Z","etag":null,"topics":["ac-colors","acute-components","color-conversion","color-converter","color-hex","colors","contrast-ratio","hsl-color","javascript","javascript-color-picker","javascript-library","lab-color","lch","lchab","lchuv","luv","random-colors","rgb-color","xyz-color"],"latest_commit_sha":null,"homepage":"https://colors.acutecomponents.com/","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/vinaypillai.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-05-16T23:04:14.000Z","updated_at":"2025-01-14T10:47:24.000Z","dependencies_parsed_at":"2022-07-25T01:32:16.528Z","dependency_job_id":null,"html_url":"https://github.com/vinaypillai/ac-colors","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vinaypillai%2Fac-colors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vinaypillai%2Fac-colors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vinaypillai%2Fac-colors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vinaypillai%2Fac-colors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vinaypillai","download_url":"https://codeload.github.com/vinaypillai/ac-colors/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247299832,"owners_count":20916190,"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":["ac-colors","acute-components","color-conversion","color-converter","color-hex","colors","contrast-ratio","hsl-color","javascript","javascript-color-picker","javascript-library","lab-color","lch","lchab","lchuv","luv","random-colors","rgb-color","xyz-color"],"created_at":"2024-12-09T02:11:11.826Z","updated_at":"2025-04-05T07:07:01.011Z","avatar_url":"https://github.com/vinaypillai.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# ac-colors\n\n[![NPM](https://nodei.co/npm/ac-colors.png?downloads=true\u0026downloadRank=true\u0026stars=true)](https://www.npmjs.com/package/ac-colors)\n\n![package release version badge](https://img.shields.io/github/v/release/vinaypillai/ac-colors) ![minified size badge](https://img.shields.io/bundlephobia/min/ac-colors) ![travis ci status badge](https://img.shields.io/travis/com/vinaypillai/ac-colors) ![Coveralls coverage badge](https://coveralls.io/repos/github/vinaypillai/ac-colors/badge.svg?branch=master) ![dependency status badge](https://img.shields.io/librariesio/release/npm/ac-colors) ![mit license badge](https://img.shields.io/npm/l/ac-colors)\n\nac-colors is a reactive JavaScript color library that can freely convert between sRGB, HSL, HEX, XYZ, LAB, LCHab, LUV, and LCHuv, as well as handle random color generation and contrast ratio calculation. A live color picker running on ac-colors can be found at [http://colors.acutecomponents.com/](http://colors.acutecomponents.com/).\n\n* [Installation](#Installation)\n    * [Node.js](#nodejs)\n    * [Browser](#browser)\n* [Making a Color object](#making-a-color-object)\n    * [color](#color)\n    * [type](#type)\n    * [precision](#precision)\n    * [capitalize](#capitalize)\n    * [Color object reactivity](#color-object-reactivity)\n* [Color class API](#color-class-api)\n    * [Object properties](#properties)\n        * [rgb](#rgb)\n        * [rgbString](#rgbString)\n        * [hex](#hex)\n        * [hexString](#hexString)\n        * [hsl](#hsl)\n        * [hslString](#hslString)\n        * [xyz](#xyz)\n        * [xyzString](#xyzString)\n        * [lab](#lab)\n        * [labString](#labString)\n        * [lchab](#lchab)\n        * [lchabString](#lchabString)\n        * [luv](#luv)\n        * [luvString](#luvString)\n        * [lchuv](#lchuv)\n        * [lchuvString](#lchuvString)\n        * [precision](#precision-1)\n        * [capitalize](#capitalize-1)\n    * [Static methods](#static-methods)\n        * [Color.rgbToHsl](#colorrgbtohsl)\n        * [Color.hslToRgb](#colorhsltorgb)\n        * [Color.rgbToHex](#colorrgbtohex)\n        * [Color.hexToRgb](#colorhextorgb)\n        * [Color.rgbToXyz](#colorrgbtoxyz)\n        * [Color.xyzToRgb](#colorxyztorgb)\n        * [Color.xyzToLab](#colorxyztolab)\n        * [Color.labToXyz](#colorlabtoxyz)\n        * [Color.labToLCHab](#colorlabtolchab)\n        * [Color.lchABToLab](#colorlchabtolab)\n        * [Color.xyzToLuv](#colorxyztoluv)\n        * [Color.luvToXyz](#colorluvtoxyz)\n        * [Color.luvToLCHuv](#colorluvtolchuv)\n        * [Color.lchUVToLuv](#colorlchuvtoluv)\n        * [Color.luminance](#colorluminance)\n        * [Color.random](#colorrandom)\n        * [Color.randomFromString](#colorrandomfromstring)\n        * [Color.randomOfType](#colorrandomoftype)\n        * [Color.randomOfTypeFormatted](#colorrandomoftypeformatted)\n        * [Color.contrastTextColor](#colorcontrasttextcolor)\n        * [Color.contrastRatio](#colorcontrastratio)\n        * [Color.blend](#colorblend)\n* [Acknowledgements](#acknowledgements)\n* [License](#license)\n\n## Installation\n### Node.js\n``` bash\nnpm install --save ac-colors\n```\n### Browser\n#### Download\nDownload the minified transpiled [ac-colors.min.js](https://raw.githubusercontent.com/vinaypillai/ac-colors/master/dist/ac-colors.min.js) and include it in a `\u003cscript\u003e` tag\n``` html\n\u003cscript src=\"ac-colors.min.js\"\u003e\u003c/script\u003e\n```\n#### CDN\nAlternatively add this `\u003cscript\u003e` tag to your body to load the minified version from a CDN.\n```html\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/ac-colors@1/dist/ac-colors.min.js\"\u003e\u003c/script\u003e\n```\n## Making a Color object\nThe easiest way to get started with color conversion in ac-colors is by creating a Color object. The constructor takes  an object with up to four deconstructed properties which help determine how to convert and format color output:\n* `color`: An array (or string if `type` is hex) containing the three numbers for the color (ex. [r,g,b]). Defaults to `[0,0,0]`.\n* `type`: The format for the color being inputted. A full list of types can be found [below](#type). Defaults to `\"rgb\"`.\n* `precision`: The number of decimals to be outputted from the string output methods. Defaults to `3`.\n* `capitalize`: A boolean flag for whether or not to capitalize the string output. Defaults to `true`.\n\n```javascript\n// Node.js users will need to import the module\nconst Color = require(\"ac-colors\");\nlet black = new Color();\nconsole.log(black.hex); // #000000\n```\n### `color`\nThe `color` property is usually a three element array containing the three RGB, HSL, LAB, XYZ, LUV, LCHuv, or LCHab digits, but can also be a string containing a 3 or 6 digit hexcode. The default color, `[0,0,0,]` evaluates to black when used with the default type of `\"rgb\"`.\n```javascript\nlet red = new Color({\"color\":[255,0,0]});\nconsole.log(red.rgbString); // RGB(255, 0, 0)\n```\nHex colors can be specified with 3 or six digits and with or without the leading '#'.\n```javascript\nlet grey = new Color({\"color\":\"#333\",\"type\":\"hex\"});\nconsole.log(grey.hsl); // [0, 0, 20]\n```\n### `type`\nThe `type` property is a string with the following possible values:\n* `\"rgb\"` (Default)\n* `\"hex\"`\n* `\"hsl\"`\n* `\"xyz\"`\n* `\"lab\"`\n* `\"lchab\"`\n* `\"luv\"`\n* `\"lchuv\"`\n\nThe type merely specifies the format of the incoming color. Once the type is specified, all of the below [properties](#color-object-properties) will be set.\n```javascript\nlet blue = new Color({\"color\":\"#0000FF\",\"type\":\"hex\"});\nconsole.log(blue.rgb); // [0,0,255]\n```\n### `precision`\nThe `precision` property specifies how many decimal places to return in the string format of the color in representations where decimals are allowed, and defaults to 3 places.\n```javascript\nlet green = new Color({\"color\":\"#00FF00\",\"type\":\"hex\", \"precision\":1});\n// The hslString property allows for decimal values\nconsole.log(green.hslString); // HSL(120.0, 100.0, 50.0)\n// The rgbString property does not\nconsole.log(green.rgbString); // RGB(0, 255, 0)\n```\n### `capitalize`\nThe `capitalize` property specifies whether or not to capitalize the string of the returned by the output functions.\n```javascript\n// capitalize: true\nlet yellowCaps = new Color({\"color\":[53.418,96.735,48.039],\"type\":\"hsl\", \"precision\":1, \"capitalize\":true});\n// capitalize: false\nlet yellowNoCaps = new Color({\"color\":[53.418,96.735,48.039],\"type\":\"hsl\", \"precision\":1, \"capitalize\":false});\n\nconsole.log(yellowCaps.hexString); // #F1D704\nconsole.log(yellowNoCaps.hexString); // #f1d704\n```\n### Color object reactivity\nEach Color object has six [reactive color members](#object-properties) and two reactive formatting members, `precision` and `capitalize`. This means that setting the value of any of the properties will automatically trigger updates of all the other values, so conversion between all the possible types is done simultaneously.\n```javascript\nconst green = new Color({\"color\":\"#00FF00\",\"type\":\"hex\"});\nconsole.log(green.rgbString); // RGB(0, 255, 0)\ngreen.rgb = [255,0,0]\nconsole.log(green.hslString); // HSL(0.000, 100.000, 50.000)\ngreen.capitalize = false;\nconsole.log(green.hexString); // #ff0000\ngreen.lab = [32.297, 79.194, -107.859];\ngreen.precision = 5;\nconsole.log(green.lchabString); // lchAB(32.29701, 133.81132, 306.28752)\n```\n\n## Color class API\nThe color object contains two main sets of data members which can be used for color conversion. There are the reactive properties which can be accessed from each Color instance, but there are also static methods which can be used for general color conversion without creating a Color object.\n### Object properties \nThere are 14 primary instance properties, as well as two formatting properties (`precision` and `capitalize`) in each Color object that can be used for color conversion. The 14 main conversion properties can be divided into two categories: Reactive members and their complementary formatted string outputs.\n| Reactive members | Formatted string outputs |\n|:--:|:--:|\n| rgb | rgbString |\n| hex | hexString |\n| hsl | hslString |\n| xyz | xyzString |\n| lab | labString |\n| lchab | lchabString |\n| luv | luvString |\n| lchuv | lchuvString |\n\n#### `rgb` \nThe `rgb` property is a reactive getter and setter for the three element array representing the colors [r,g,b] values.\n```javascript\nlet black = new Color();\nconsole.log(black.rgb); // [0,0,0]\nblack.rgb = [255,255,255];\nconsole.log(black.hex); // #ffffff\n```\n#### `rgbString` \nThe `rgbString` property is a formatted string output for the rgb color. It is not impacted by the Color object's `precision`, but is affected by its `capitalize` value.\n```javascript\nlet black = new Color();\nconsole.log(black.rgbString); // RGB(0, 0, 0)\nblack.capitalize = false;\nconsole.log(black.rgbString); // rgb(0, 0, 0)\n```\n\n#### `hex` \nThe `hex` property is a reactive getter and setter for the string representing the colors three or six digit hex code.\n```javascript\nlet black = new Color();\nconsole.log(black.hex); // #000000\nblack.hex = \"#FFF\";\nconsole.log(black.rgbString); // RGB(255, 255, 255)\n```\n#### `hexString` \nThe `hexString` property is a formatted string output for the hex color. It is not impacted by the Color object's `precision`, but is affected by its `capitalize` value.\n```javascript\nlet white = new Color({\"color\":[255,255,255]});\nconsole.log(white.hexString) // #FFFFFF\nwhite.capitalize = false;\nconsole.log(white.hexString) // #ffffff\n```\n#### `hsl` \nThe `hsl` property is a reactive getter and setter for the three element array representing the colors [h,s,l] values.\n```javascript\nlet black = new Color();\nconsole.log(black.hsl); // [0,0,0]\nblack.hsl = [240,20.863,27.255];\nconsole.log(black.rgbString); // RGB(55, 55, 84)\n```\n#### `hslString` \nThe `hslString` property is a formatted string output for the hsl color. It is  impacted by the Color object's `precision` and `capitalize` values.\n```javascript\nlet white = new Color({\"color\":[255,255,255]});\nconsole.log(white.hslString) // HSL(0.000, 0.000, 100.000)\nwhite.capitalize = false;\nconsole.log(white.hslString) // hsl(0.000, 0.000, 100.000)\n```\n#### `xyz` \nThe `xyz` property is a reactive getter and setter for the three element array representing the colors [x,y,z] values.\n```javascript\nlet black = new Color();\nconsole.log(black.xyz); // [0,0,0]\nblack.xyz = [4.542,4.185,8.954];\nconsole.log(black.rgbString); // RGB(55, 55, 84)\n```\n#### `xyzString` \nThe `xyzString` property is a formatted string output for the xyz color. It is  impacted by the Color object's `precision` and `capitalize` values.\n```javascript\nlet white = new Color({\"color\":[255,255,255]});\nconsole.log(white.xyzString) // XYZ(95.047, 100.000, 100.000)\nwhite.capitalize = false;\nconsole.log(white.xyzString) // xyz(95.047, 100.000, 100.000)\n```\n#### `lab` \nThe `lab` property is a reactive getter and setter for the three element array representing the colors [l,a,b] values.\n```javascript\nlet black = new Color();\nconsole.log(black.lab); // [0,0,0]\nblack.lab = [24.272,7.853,-17.538];\nconsole.log(black.rgbString); // RGB(55, 55, 84)\n```\n#### `labString` \nThe `labString` property is a formatted string output for the lab color. It is  impacted by the Color object's `precision` and `capitalize` values.\n```javascript\nlet white = new Color({\"color\":[255,255,255]});\nconsole.log(white.labString) // LAB(100.000, 0.000, 0.000)\nwhite.capitalize = false;\nconsole.log(white.labString) // lab(100.000, 0.000, 0.000)\n```\n#### `lchab` \nThe `lchab` property is a reactive getter and setter for the three element array representing the colors [l,c,h] values.\n```javascript\nlet black = new Color();\nconsole.log(black.lchab); // [0,0,0]\nblack.lchab = [24.272,7.853,294.121];\nconsole.log(black.rgbString); // RGB(55, 55, 84)\n```\n#### `lchabString` \nThe `lchabString` property is a formatted string output for the lab color. It is  impacted by the Color object's `precision` and `capitalize` values. However, the capitalization is inverted for the subscripted 'ab'.\n```javascript\nlet white = new Color({\"color\":[255,255,255]});\nconsole.log(white.lchabString) // LCHab(100.000, 0.000,0.000)\nwhite.capitalize = false;\nconsole.log(white.lchabString) // lchAB(100.000, 0.000,0.000)\n```\n#### `luv` \nThe `luv` property is a reactive getter and setter for the three element array representing the colors [l,u,v] values.\n```javascript\nlet black = new Color();\nconsole.log(black.luv); // [0,0,0]\nblack.luv = [24.272,7.853,-17.538];\nconsole.log(black.rgbString); // RGB(70, 51, 78)\n```\n#### `luvString` \nThe `luvString` property is a formatted string output for the lab color. It is  impacted by the Color object's `precision` and `capitalize` values.\n```javascript\nlet white = new Color({\"color\":[255,255,255]});\nconsole.log(white.luvString) // LUV(100.000, 0.000, 0.000)\nwhite.capitalize = false;\nconsole.log(white.luvString) // luv(100.000, 0.000, 0.000)\n```\n#### `lchuv` \nThe `lchuv` property is a reactive getter and setter for the three element array representing the colors [l,c,h] values.\n```javascript\nlet black = new Color();\nconsole.log(black.lchuv); // [0,0,0]\nblack.lchuv = [24.272,7.853,294.121];\nconsole.log(black.rgbString); // RGB(63, 55, 66)\n```\n#### `lchuvString` \nThe `lchuvString` property is a formatted string output for the lab color. It is  impacted by the Color object's `precision` and `capitalize` values. However, the capitalization is inverted for the subscripted 'uv'.\n```javascript\nlet white = new Color({\"color\":[255,255,255]});\nconsole.log(white.lchuvString) // LCHuv(100.000, 0.000,0.000)\nwhite.capitalize = false;\nconsole.log(white.lchuvString) // lchUV(100.000, 0.000,0.000)\n```\n#### `precision` \nThe `precision` property is a reactive formatting property that controls the number of decimal places outputted from a formatted string property. It is set during object initialization, but can be updated at any time.\n```javascript\nlet white = new Color({\"color\":[255,255,255],\"precision\":3});\nconsole.log(white.lchabString) // LCHab(100.000, 0.000,0.000)\nwhite.precision = 1;\nconsole.log(white.lchabString) // LCHab(100.0, 0.0,0.0))\n```\n\n#### `capitalize` \nThe `capitalize` property is a reactive formatting property that controls the capitalization of a formatted string property. It is set during object initialization, but can be updated at any time.\n```javascript\nlet white = new Color({\"color\":[255,255,255], \"capitalize\":false});\nconsole.log(white.lchabString) // lchAB(100.000, 0.000,0.000)\nwhite.capitalize = true;\nconsole.log(white.lchabString) // LCHab(100.000, 0.000,0.000)\n```\n### Static Methods\nAlthough it is easier to handle color conversion by creating Color objects and making use of the automatic type conversion, ac-colors supports manual color conversion using the underlying static methods. In addition, static methods are provided for handling random color generation and color contrast ratio checking.\n\n#### `Color.rgbToHsl`\nThis method takes in a three element array `[r,g,b]` representing a color's rgb values, and returns a three element array `[h,s,l]` representing the color's hsl values\n```javascript\n// Color.rgbToHex(hex)\nconsole.log(Color.rgbToHsl([85,46,58])); // [341.53846153846155,29.770992366412212,25.68627450980392]\n```\n#### `Color.hslToRgb`\nThis method takes in a three element array `[h,s,l]` representing a color's hsl values, and returns a three element array `[r,g,b]` representing the color's rgb values\n```javascript\n// Color.hslToRgb(hsl)\nconsole.log(Color.hslToRgb([341.538,29.771,25.686])); // [85,46,58]\n```\n#### `Color.rgbToHex`\nThis method takes in a three element array `[r,g,b]` representing a color's rgb values, and returns a string representing the color's hex code.\n```javascript\n// Color.rgbToHex(rgb)\nconsole.log(Color.rgbToHex([85,46,58])); // #552e3a\n```\n#### `Color.hexToRgb`\nThis method takes in a three or six digit hexcode and returns a three element array `[r,g,b]` representing a color's rgb values.\n```javascript\n// Color.hexToRgb(hex)\nconsole.log(Color.hexToRgb(\"#552e3a\")); // [85,46,58]\n```\n#### `Color.rgbToXyz`\nThis method takes in a three element array `[r,g,b]` representing a color's rgb values, and returns a three element array `[x,y,z]` representing the color's xyz values\n```javascript\n// Color.rgbToXyz(rgb)\nconsole.log(Color.rgbToXyz([85,46,58])); // [5.487028215922665, 4.19077333446813, 4.522689110429709]\n```\n#### `Color.xyzToRgb`\nThis method takes in a three element array `[x,y,z]` representing the color's xyz values and returns a three element array `[r,g,b]` representing a color's rgb values.\n```javascript\n// Color.xyzToRgb(xyz)\nconsole.log(Color.xyzToRgb([5.487,4.191,4.522])); // [85,46,58]\n```\n#### `Color.xyzToLab`\nThis method takes in a three element array `[x,y,z]` representing the color's xyz values and returns a three element array `[l,a,b]` representing a color's lab values.\n```javascript\n// Color.xyzToLab(xyz)\nconsole.log(Color.xyzToLab([5.487,4.191,4.522])); // [24.293087120125165, 19.563162207233198, 0.21375272337743612]\n```\n#### `Color.labToXyz`\nThis method takes in a three element array `[l,a,b]` representing a color's lab values. and returns a three element array `[x,y,z]` representing the color's xyz values.\n```javascript\n// Color.labToXyz(lab)\nconsole.log(Color.labToXyz([24.294,19.570,0.211])); // [5.487917707204406, 4.191284860245909, 4.522847553083241]\n```\n#### `Color.labToLCHab`\nThis method takes in a three element array `[l,a,b]` representing a color's lab values. and returns a three element array `[l,c,h]` representing the color's LCHab values.\n```javascript\n// Color.labToLCHab(lab)\nconsole.log(Color.labToLCHab([24.294,19.570,0.211])); // [24.294, 19.57113744778264, 0.617728209288702]\n```\n#### `Color.lchABToLab`\nThis method takes in a three element array `[l,c,h]` representing a color's LCHab values. and returns a three element array `[l,a,b]` representing the color's lab values.\n```javascript\n// Color.lchABToLab(lchAB)\nconsole.log(Color.lchABToLab([24.294,19.571,0.617])); // [24.294, 19.56986524034229, 0.21074979203493507]\n```\n#### `Color.xyzToLuv`\nThis method takes in a three element array `[x,y,z]` representing the color's xyz values and returns a three element array `[l,u,v]` representing a color's luv values.\n```javascript\n// Color.xyzToLuv(xyz)\nconsole.log(Color.xyzToLuv([5.487,4.191,4.522])); // [24.293087120125165, 22.133854138128648, -2.4869700034790783]\n```\n#### `Color.luvToXyz`\nThis method takes in a three element array `[l,u,v]` representing a color's luv values. and returns a three element array `[x,y,z]` representing the color's xyz values.\n```javascript\n// Color.luvToXyz(luv)\nconsole.log(Color.luvToXyz([24.294,22.134,-2.487])); //  [5.487326075294226, 4.191284860245909, 4.522311066039963]\n```\n#### `Color.luvToLCHuv`\nThis method takes in a three element array `[l,u,v]` representing a color's lab values. and returns a three element array `[l,c,h]` representing the color's LCHuv values.\n```javascript\n// Color.luvToLCHuv(luv)\nconsole.log(Color.luvToLCHuv([24.294,22.134,-2.487])); // [24.294, 22.27328276208965, 353.5890738118895]\n```\n#### `Color.lchUVToLuv`\nThis method takes in a three element array `[l,c,h]` representing a color's LCHuv values. and returns a three element array `[l,u,v]` representing the color's luv values.\n```javascript\n// Color.lchUVToLuv(lchUV)\nconsole.log(Color.lchUVToLuv([24.294,22.273,353.589])); // [24.294, 22.133715802240754, -2.48699694122008]\n```\n#### `Color.luminance`\nThis method takes in a three element array and a string representing its type and returns its [relative luminance](https://www.w3.org/TR/WCAG20/#relativeluminancedef). Default type is `\"rgb\"`.\n```javascript\n// Color.luminance(color,type)\nconsole.log(Color.luminance([0,255,0])); // 0.7152\nconsole.log(Color.luminance(\"#ff0000\",\"hex\")); // 0.2126\n```\n#### `Color.random`\nThis method returns a new Color instance with a random color selected.\n```javascript\n// Color.random()\nconsole.log(Color.random()); // Color {_rgb: Array(3), _hsl: Array(3), _hex: \"#b3eeb6\", _xyz: Array(3), _lab: Array(3), …}\nconsole.log(Color.random()); // Color {_rgb: Array(3), _hsl: Array(3), _hex: \"#85dd60\", _xyz: Array(3), _lab: Array(3), …}\n```\n#### `Color.randomFromString`\nThis method returns a new Color instance with a deterministic random color derived from the given string. The string is hashed under the PJW-32 hash to achieve pseudorandom distribution of colors.\n```javascript\n// Color.randomFromString(str)\nconsole.log(Color.randomFromString(\"Hello World!\")); // Color {_xyz: Array(3), _rgb: Array(3), _hsl: Array(3), _hex: \"#712199\", _lab: Array(3), …}\nconsole.log(Color.randomFromString(\"Hello World!\")); // Color {_xyz: Array(3), _rgb: Array(3), _hsl: Array(3), _hex: \"#712199\", _lab: Array(3), …}\nconsole.log(Color.randomFromString(\"Foo Bar\")); // Color {_xyz: Array(3), _rgb: Array(3), _hsl: Array(3), _hex: \"#b20092\", _lab: Array(3), …}\n```\n#### `Color.randomOfType`\nThis method takes in a type and returns a new three element array of the type selected, or six digit hex code if type is `\"hex\"`. Default type is `\"rgb\"`.\n```javascript\n// Color.randomOfType(type)\nconsole.log(Color.randomOfType()); // [24, 60, 77]\nconsole.log(Color.randomOfType(\"hex\")); // #4c4f92\n```\n#### `Color.randomOfTypeFormatted`\nThis method takes in a type, a `capitalize` flag, and a `precision` and returns a formatted string for the type specified. The `capitalize` flag determines whether or not the returned string will capitalized, and defaults to true. The `precision` flag determines how many decimal places to round the values returned, if applicable, and defaults to 3. Default type is `\"rgb\"`.\n```javascript\n// Color.randomOfTypeFormatted(type,capitalize,precision)\nconsole.log(Color.randomOfTypeFormatted()); // RGB(237, 216, 88)\nconsole.log(Color.randomOfTypeFormatted(\"hex\")); // #FD3741\nconsole.log(Color.randomOfTypeFormatted(\"rgb\",false)); // rgb(120, 156, 72)\nconsole.log(Color.randomOfTypeFormatted(\"hsl\",true,1)); // HSL(296.9, 90.6, 79.2)\n```\n#### `Color.contrastTextColor`\nThis method takes in a three element array or string representing a color, and the type of the color, and return `#FFFFFF` or `#000000` depending on which one has a higher [contrast ratio](https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html#contrast-ratiodef) with the color provided.\n```javascript\n// Color.contrastTextColor(color,type)\nconsole.log(Color.contrastTextColor([10,20,30])); // #FFFFFF\nconsole.log(Color.contrastTextColor(\"#e8e9ea\",\"hex\")); // #000000\n```\n#### `Color.contrastRatio`\nThis method takes in two Color instances and returns the [contrast ratio](https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html#contrast-ratiodef) between the two. \n```javascript\n// Color.contrastRatio(color1,color2)\nconst red = new Color({\"color\":\"#ff0000\",\"type\":\"hex\"});\nconst white = new Color({\"color\":[255,255,255]})\nconsole.log(Color.contrastRatio(red,white)); // 3.9984767707539985\n```\n#### `Color.blend`\nThis method takes in two Color instances and return their weighted average within a given colorspace. Default type is `\"rgb\"`. Default weight is `0.5`.\n```javascript\n// Color.blend(color1, color2, type, weight)\nconst red = new Color({\"color\":\"#ff0000\",\"type\":\"hex\"});\nconst white = new Color({\"color\":[255,255,255]})\nconsole.log(Color.blend(red,white)); // Color {_xyz: Array(3), _rgb: Array(3), _hsl: Array(3), _hex: \"#ff8080\", _lab: Array(3), …}\nconsole.log(Color.blend(red,white,'hsl')); // Color {_xyz: Array(3), _rgb: Array(3), _hsl: Array(3), _hex: \"#df9f9f\", _lab: Array(3), …}\nconsole.log(Color.blend(red,white,'hex',0.75)); // Color {_xyz: Array(3), _rgb: Array(3), _hsl: Array(3), _hex: \"#ff4040\", _lab: Array(3), …}\n```\n## Acknowledgements\nThanks to [Jonas Jacek](https://jonasjacek.github.io/colors/), [ColorMine.org](http://colormine.org/colors-by-name), and [EasyRGB](https://www.easyrgb.com/en/convert.php#inputFORM) for providing some of the  sample data used for testing the color conversion. Additional resources for implementing color space transformations, including the ones used in this library, are listed below:\n* [http://www.color.org/iccmax/profiles/sRGB_D65_colorimetric.icc](http://www.color.org/iccmax/profiles/sRGB_D65_colorimetric.icc)\n* [https://graphics.stanford.edu/courses/cs148-10-summer/docs/2010--kerr--cie_xyz.pdf](https://graphics.stanford.edu/courses/cs148-10-summer/docs/2010--kerr--cie_xyz.pdf)\n* [http://www.color.org/sRGB.pdf](http://www.color.org/sRGB.pdf)\n* [https://www.sis.se/api/document/preview/562720/](https://www.sis.se/api/document/preview/562720/)\n* [http://coecsl.ece.illinois.edu/ge423/spring05/group8/finalproject/hsv_writeup.pdf](http://coecsl.ece.illinois.edu/ge423/spring05/group8/finalproject/hsv_writeup.pdf)\n* [https://www.cs.rit.edu/~ncs/color/t_convert.html#XYZ%20to%20CIELUV%20\u0026%20CIELUV%20to%20XYZ](https://www.cs.rit.edu/~ncs/color/t_convert.html#XYZ%20to%20CIELUV%20\u0026%20CIELUV%20to%20XYZ)\n* [http://docs-hoffmann.de/cielab03022003.pdf](http://docs-hoffmann.de/cielab03022003.pdf)\n* [http://faculty.washington.edu/jokelly/gammaFaq1.htm](http://faculty.washington.edu/jokelly/gammaFaq1.htm)\n* [http://www.brucelindbloom.com/index.html](http://www.brucelindbloom.com/index.html)\n* [http://cs.haifa.ac.il/hagit/courses/ist/Lectures/Demos/ColorApplet/me/infoluv.html](http://cs.haifa.ac.il/hagit/courses/ist/Lectures/Demos/ColorApplet/me/infoluv.html)\n* [https://engineering.purdue.edu/~bouman/ece637/notes/pdf/ColorSpaces.pdf](https://engineering.purdue.edu/~bouman/ece637/notes/pdf/ColorSpaces.pdf)\n## License\nCopyright 2020 Vinay Pillai\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvinaypillai%2Fac-colors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvinaypillai%2Fac-colors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvinaypillai%2Fac-colors/lists"}