This guide covers migrating from tinycolor2 to tincture. There are two approaches — choose the one that fits your needs.
The fastest migration path. Replace only your import/require statement — all existing code works unchanged.
- const tinycolor = require("tinycolor2");
+ const tinycolor = require("@agentine/tincture/compat/tinycolor2");- import tinycolor from "tinycolor2";
+ import tinycolor from "@agentine/tincture/compat/tinycolor2";The compatibility layer exports a tinycolor function with identical behavior to tinycolor2. Every method, property, and static function works the same way.
- You have a large codebase with many
tinycolorcalls - You need the migration done quickly
- You want to verify everything works before committing to a full rename
- You depend on libraries that expect tinycolor2's interface
Migrate to the native tincture API. The API surface is the same — only the import and constructor name change.
CommonJS:
- const tinycolor = require("tinycolor2");
+ const { tincture } = require("@agentine/tincture");ESM:
- import tinycolor from "tinycolor2";
+ import tincture from "@agentine/tincture";- const color = tinycolor("red");
+ const color = tincture("red");
- const ratio = tinycolor.fromRatio({ r: 0.5, g: 0.5, b: 0.5 });
+ const ratio = tincture.fromRatio({ r: 0.5, g: 0.5, b: 0.5 });
- tinycolor.equals("red", "#ff0000");
+ tincture.equals("red", "#ff0000");
- tinycolor.mix("red", "blue", 50);
+ tincture.mix("red", "blue", 50);
- tinycolor.readability("#fff", "#000");
+ tincture.readability("#fff", "#000");
- tinycolor.isReadable("#fff", "#000");
+ tincture.isReadable("#fff", "#000");
- tinycolor.mostReadable("#000", ["#fff", "#ccc"]);
+ tincture.mostReadable("#000", ["#fff", "#ccc"]);
- tinycolor.random();
+ tincture.random();All instance methods are identical:
// These all work exactly the same
color.toHexString();
color.lighten(20);
color.complement();
color.isLight();
color.toRgbString();
color.setAlpha(0.5);
color.analogous();
// ... every method from tinycolor2 is supportedtincture ships as a dual ESM/CJS package. Both module systems are fully supported via the exports field in package.json.
import tincture from "@agentine/tincture";
import { TinctureColor } from "@agentine/tincture";const { tincture } = require("@agentine/tincture");
const { TinctureColor } = require("@agentine/tincture");// ESM
import tinycolor from "@agentine/tincture/compat/tinycolor2";
// CJS
const tinycolor = require("@agentine/tincture/compat/tinycolor2");tinycolor2 relies on @types/tinycolor2 from DefinitelyTyped, which can drift from the actual implementation. tincture is TypeScript-first:
- Full type inference — no
@types/package needed - Accurate types — generated from the same source code
- Generic input types —
ColorInputaccepts strings, RGB/HSL/HSV objects - Return type precision — methods return typed objects, not
any
// Requires: npm install @types/tinycolor2
import tinycolor from "tinycolor2";
const color = tinycolor("red"); // type: tinycolor.Instance
const rgb = color.toRgb(); // type: tinycolor.ColorFormats.RGBA// No additional @types/ package needed
import tincture from "@agentine/tincture";
import type { TinctureColor, ColorInput } from "@agentine/tincture";
const color = tincture("red"); // type: TinctureColor
const rgb = color.toRgb(); // type: { r: number; g: number; b: number; a: number }
// Type-safe input
function setBackground(input: ColorInput) {
return tincture(input).toHexString();
}Once migration is verified:
npm uninstall tinycolor2 @types/tinycolor2Every tinycolor2 method is supported in tincture:
| tinycolor2 | tincture | Notes |
|---|---|---|
tinycolor(input) |
tincture(input) |
Same input formats |
tinycolor.fromRatio() |
tincture.fromRatio() |
Identical |
tinycolor.equals() |
tincture.equals() |
Identical |
tinycolor.mix() |
tincture.mix() |
Identical |
tinycolor.random() |
tincture.random() |
Identical |
tinycolor.readability() |
tincture.readability() |
Identical |
tinycolor.isReadable() |
tincture.isReadable() |
Identical |
tinycolor.mostReadable() |
tincture.mostReadable() |
Identical |
.toHex() |
.toHex() |
Identical |
.toHexString() |
.toHexString() |
Identical |
.toRgb() |
.toRgb() |
Identical |
.toRgbString() |
.toRgbString() |
Identical |
.toHsl() |
.toHsl() |
Identical |
.toHslString() |
.toHslString() |
Identical |
.toHsv() |
.toHsv() |
Identical |
.toHsvString() |
.toHsvString() |
Identical |
.toName() |
.toName() |
Identical |
.toFilter() |
.toFilter() |
Identical |
.toString(fmt) |
.toString(fmt) |
Identical |
.lighten() |
.lighten() |
Identical |
.darken() |
.darken() |
Identical |
.saturate() |
.saturate() |
Identical |
.desaturate() |
.desaturate() |
Identical |
.greyscale() |
.greyscale() |
Identical |
.spin() |
.spin() |
Identical |
.complement() |
.complement() |
Identical |
.analogous() |
.analogous() |
Identical |
.monochromatic() |
.monochromatic() |
Identical |
.triad() |
.triad() |
Identical |
.tetrad() |
.tetrad() |
Identical |
.splitcomplement() |
.splitcomplement() |
Identical |
.clone() |
.clone() |
Identical |
.isValid() |
.isValid() |
Identical |
.getFormat() |
.getFormat() |
Identical |
.getAlpha() |
.getAlpha() |
Identical |
.setAlpha() |
.setAlpha() |
Identical |
.getBrightness() |
.getBrightness() |
Identical |
.getLuminance() |
.getLuminance() |
Identical |
.isLight() |
.isLight() |
Identical |
.isDark() |
.isDark() |
Identical |