
Research
Security News
Malicious PyPI Package Exploits Deezer API for Coordinated Music Piracy
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
contrastrast
Advanced tools
A lightweight tool that parses color strings and recommends text contrast based on WCAG Standards
A lightweight tool that parses color strings and recommends text contrast based on WCAG Standards
Install constrastrast
by running one of the following commands:
npm install --save constrastrast@latest
yarn add constrastrast@latest
pnpm install --save constrastrast@latest
constrastrast
takes a given background color as a string in either HEX, HSL, or RGB format, and (by default) returns "dark"
or "light"
as a recommended text variant for that given background color
For example, you may use it like this:
import { textContrastForBGColor } from "contrastrast";
const MyColorChangingComponent = (backgroundColor: string) => {
return <div style={{ backgroundColor }} className={textContrastForBGColor(backgroundColor) === "dark" : "text-black" : "text-white"}>
This text is readable no matter what the background color is!
</div>
}
constrastrast
supports the following color string formats:
HEX Notation in either 3 or 6 length format
examples
#ad1232
ad1232
#ada
ada
Standard RGB notation
examples
rgb(100,200, 230)
rgb(5, 30, 40)
HSL Notation with or without the symbol markers
examples
hsl(217°, 90%, 61%)
hsl(72°, 90%, 61%)
hsl(121deg, 90%, 61%)
hsl(298, 90, 61)
Currently contrastrast
doesn't support alpha formats and will log an error and return the default value
If an unhandled string is passed, by default contrastrast
will log an error and return the default value ("dark"
)
textContrastForBGColor
takes an ContrastrastOptions
object as an optional second parameter, it currently has the following configuration options:
type ContrastrastOptions = {
fallbackOption?: "dark" | "light"; // Defaults to "dark" if not specified
throwErrorOnUnhandled?: boolean; // Throws an error instead of returning the `fallbackOption`. Defaults to `false` if not specific
};
Happy for any and all contributions. Please note the project uses pnpm
and I prefer to have git commits formatted with gitmoji-cli
FAQs
A lightweight tool that parses color strings and recommends text contrast based on WCAG Standards
The npm package contrastrast receives a total of 19 weekly downloads. As such, contrastrast popularity was classified as not popular.
We found that contrastrast demonstrated a healthy version release cadence and project activity because the last version was released less than 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.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.
Security News
Newly introduced telemetry in devenv 1.4 sparked a backlash over privacy concerns, leading to the removal of its AI-powered feature after strong community pushback.