MooColor is a modern TypeScript library designed for comprehensive color parsing, conversion, and manipulation. Currently stable at version 2.0.0, the package maintains an active release cadence with minor updates and patches, and announces significant breaking changes with major versions. Key differentiators include its strictly immutable API, where all manipulation methods return new instances rather than mutating the original, and robust WCAG 2.1 compliance for accurate luminance and contrast ratio calculations. It provides dual ESM, CJS, and IIFE bundles, making it versatile across Node.js environments (requiring Node.js >=18 since v2) and browsers. The library is fully typed, including Template Literal Types for advanced color string representation, and supports a wide array of color models like hex, RGB, HSL, HWB, HSV, and CMYK, alongside named colors.
npm install moo-colorVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates parsing various color formats, performing immutable manipulations, chaining methods, checking WCAG contrast ratios, and generating constrained random colors.
Chain methods or assign the return value to a new variable. Do not assume the original instance is modified; always use the return value of these methods.
Use the `MooColor` constructor directly to create a new instance with the desired color, e.g., `const newColor = new MooColor(newColorString);`.
Ensure your project's Node.js environment is updated to version 18 or newer. Check your `package.json` engines field or global Node.js version.
Call `MooColor.random()` directly on the `MooColor` class rather than on an instance.
To get a specific hex format, use `color.toHex('short')` for `#f00` or `color.toHex('name')` for named colors like 'red' where applicable.Ensure you are using the return value of manipulation methods, as they now return new instances. For example, `const newColor = originalColor.lighten(10);`.
Instead of `color.setColor('blue')`, create a new instance with the desired color: `const blueColor = new MooColor('blue');`.Call `MooColor.random()` as a static method directly on the class.
Upgrade your Node.js runtime to version 18 or higher to meet the package's engine requirements.
No dependency data recorded yet.