![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
mad-colorlib
Advanced tools
Initialization: const colorlib = ColorLib()
colorlib.get_dominant(image, palette_size=1, use_limits=false)
This gets the dominant color or colors of an image.
Palette size is the number of colors to return.
If use_limits is true it will ignore colors when r, g, and b are below 10 or above 245.
colorlib.get_lighter_or_darker(rgb, amount=0.2)
This returns a darker color if the color is considered light,
or a lighter color if the color is considered dark.
rgb is an array like [0, 20, 5].
amount specifies how much darker or lighter it gets.
colorlib.is_light(rgb)
Checks if a color is considered light.
Receives an rgb array.
colorlib.is_dark(rgb)
Checks if a color is considered dark.
Receives an rgb array.
colorlib.get_proper_font(rgb)
Used to give a proper font color to a background color.
If color is light it returns #000000.
If color is dark it returns #ffffff.
Although it's advised to use get_lighter_or_darker to achieve more natural contrasts.
colorlib.array_to_rgb(array)
Transforms an rgb array like [x, y, z] into rgb(x, y, z).
An array with multiple array arguments can be passed.
colorlib.rgb_to_array(rgb)
Transforms rgb(x, y, z) to [x, y, z].
An array with multiple rgb arguments can be passed.
colorlib.rgb_to_rgba(rgb, alpha)
Replaces rgb(x, y, z) to rgba(x, y, z, alpha).
colorlib.rgba_to_rgb(rgb, alpha)
Replaces rgba(x, y, z, alpha) to rgb(x, y, z).
colorlib.rgb_to_hex(rgb, hash=true)
This turns an array to a hex string.
If an rgb string is given it will convert it to an array automatically.
For instance [1,2,3] or "rgb(1, 2, 3)" will turn to "#010203",
If hash is false it won't add the # to the string.
colorlib.hex_to_rgb(hex)
This turns a hex string to an rgb array.
For instance "#010203" or "010203" will return [1,2,3],
colorlib.check_array(array)
Checks if an rgb array is composed of valid values.
A valid value is between 0 and 255.
If a value is not in that range it is fixed.
This returns a valid array, not true or false.
colorlib.check_rgb(rgb)
This checks if rgb is an array.
If not, an array is created and returned.
rgb(0, 1, 2) would return [0, 1, 2].
FAQs
Some utilities to deal with colors.
The npm package mad-colorlib receives a total of 2 weekly downloads. As such, mad-colorlib popularity was classified as not popular.
We found that mad-colorlib demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.