color-fns is a modern, modular, and tree-shakable JavaScript utility library designed for comprehensive color manipulation and conversion. Inspired by the API design of `date-fns`, it emphasizes lightweight, individual function imports for optimal bundle sizes. The current stable version is 0.1.1, following a significant rewrite in version 0.1.0 that introduced a new, TypeScript-first API with reduced overloads and clearer handling of color values. The library supports multiple color models (RGB, HSL, HSV, CMYK, Hex) and offers functions for parsing, conversion, operations (like mixing), formatting to CSS-compatible output, validation, and querying (e.g., contrast, darkness). While still in pre-1.0 status, its development appears active, with a focus on type safety and modern JavaScript practices. Key differentiators include its modularity, explicit TypeScript types, and a clear, functional API.
npm install color-fnsVerified import paths — ran on the pinned version, not inferred.
Demonstrates parsing hex colors, converting between models (RGB to HSL), mixing colors, formatting output back to hex, and validating color strings using the `color-fns` library.
Consult the documentation for `color-fns` version 0.1.x for the updated API. Specifically review how color inputs are provided to functions, as previous 'acceptable color values' may no longer be supported or handled differently.
Pin your `color-fns` dependency to exact versions (e.g., '0.1.1') to ensure consistent behavior, and review release notes carefully when upgrading to newer pre-1.0 versions.
Ensure you are using ES module imports (e.g., `import { toRgb } from 'color-fns';`) and that your build tools are configured to handle ESM correctly. For CommonJS-only environments, use `const { toRgb } = require('color-fns');`.For browser usage with a script tag, ensure `<script src="https://unpkg.com/color-fns"></script>` is loaded *before* your script attempts to use `ColorFns`. For module environments (Node.js, bundlers), use `import { functionName } from 'color-fns';` or `const { functionName } = require('color-fns');`.No dependency data recorded yet.