All notable changes to this project are documented here. The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
⚠️ Breaking: this release is ESM-only.require('invert-color')and the UMD browser bundle (lib/invert.min.js) are gone, and the minimum Node.js is now 20. Staying on CommonJS/UMD? Pinnpm i invert-color@2. Everything below the packaging is source-compatible — theinvert()API is unchanged.
Modernization release. The callable API — invert(), invert.asRGB(), invert.asRgbArray(), invert.asRgbObject() and invert.defaultThreshold — behaves exactly as in v2; the only runtime-behavior change is stricter, more predictable handling of out-of-range and malformed input (see below).
- CSS
rgb()/rgba()string input.invert('rgb(40, 43, 53)')andinvert('rgba(40, 43, 53, 0.5)')now work; anrgba()alpha below1is preserved oninvert()as the trailing hex byte (#rrggbbaa), whileasRGB/asRgbArrayreturn RGB only. Resolves #21 (#22, thanks @luatnd). - Plain
number[]array input.invert.asRGB(channels)wherechannels: number[]now type-checks — the accepted array type was widened from the strict[number, number, number]tuple (still the return type). Resolves #23. - A named export:
import { invert } from 'invert-color'now works alongside the defaultimport invert from 'invert-color'(both resolve to the same function). - Input validation. Array/object colors must have exactly 3 finite channels — a wrong-length array or a non-finite channel (
NaN/Infinity) now throws a clear error, matching the existing HEX validation.
- BREAKING — ESM-only. Dropped the CommonJS and UMD bundles; the package now ships a single ESM build with type declarations.
require('invert-color')and thelib/invert.min.jsbrowser file are gone. If you need CommonJS/UMD, pininvert-color@2. - BREAKING —
engines. Now requires Node.js >= 20. - Out-of-range channels are now clamped to
0–255and rounded, so they degrade predictably (invert([300, 300, 300]) → '#000000'). Previously such values produced an artifact of the last two hex digits (→ '#2d2d2d'). Valid0–255colors are unaffected. - Rewrote the internals against modern JavaScript:
String.prototype.padStart, object spread, the**operator, and small pure helpers replace the hand-rolled zero-pad,Object.assignandMath.pow. Output for valid colors is identical. - Enabled
strictTypeScript; tightened and re-exampled the public type declarations (TSDoc with@exampleblocks).
- The
browser,moduleandjsnext:mainbundle fields and the multi-format build (rollup + uglify). Replaced by a singletscbuild and anexportsmap.
- Migrated the toolchain: Biome (from TSLint), Vitest (from Jest), GitHub Actions (from Travis), and Stryker mutation testing.
- Test suite reaches 100% coverage (statements, branches, functions, lines) and a 100% mutation score.
- BREAKING: Switched to a default export only, for consistency. Added ESM, UMD and CommonJS bundles (via rollup). See the Usage section.
package.jsonnow also definesmodule,jsnext:mainandbrowseralongsidemain.
threshold: numberoption to theBlackWhiteinterface. Fixes #16.invert.defaultThresholdconstant.
- Re-written in TypeScript.
.asRGB()— alias of.asRgbObject().
- Better error messages. (PR #9 by @CAYdenberg) Fixes #8.
- An issue with UMD output. Fixes #7.
- Adapted webpack for UMD.
- UMD support. (PR #6 by @criography — revised for the latest Babel.)
- Migrated tests to Jest (dropped Jasmine).
- Ability to customize black/white color values. (PR #3 by @BrainCrumbz)
- Initial version.