Skip to content
xpyjsPublic

About

A tiny, fast, and plugin-extensible color manipulation library for JavaScript/TypeScript.

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

xcolor logo

@xpyjs/color

version bundle size license CI coverage

A small (~5.7 kB gzipped core), fast, and plugin-extensible color manipulation library for JavaScript/TypeScript.

简体中文 | English

📖 Documentation


✨ Features

  • 🪶 Small core — ~17 kB minified / ~5.7 kB gzip, zero runtime dependencies; optional plugins are additional
  • 🔌 Plugin System — Extend functionality like dayjs, load what you need
  • 🎯 TypeScript First — Full type definitions and IntelliSense
  • ⛓️ Chainable API — Fluent interface for all operations
  • 🎨 Multi-format — Hex, RGB, HSL, Numbers (named colors via the name plugin)
  • 🏷️ Method Aliases — Shorthand aliases like r(), g(), b(), h(), s(), l()
  • ♿ Accessibility — WCAG contrast ratio, readability checks (via plugin)
  • 🎭 Blend Modes — Photoshop-like blending (via plugin)
  • 🧪 Well Tested — Coverage thresholds enforced in CI

📦 Installation

npm install @xpyjs/color
yarn add @xpyjs/color
pnpm add @xpyjs/color

Requirements: Node.js >= 14.0.0 | Browsers: ES2015+ (ES6)

Build the repository with Node 20 or 22. For browser, CDN and TypeScript entry points, see the installation guide.

🚀 Quick Start

import xcolor from '@xpyjs/color'
import name from '@xpyjs/color/plugins/name'

xcolor.use(name)

// Create from various formats
const red = xcolor('#ff0000')
const blue = xcolor('rgb(0, 0, 255)')
const green = xcolor('hsl(120, 100%, 50%)')
// Named colors require plugin registration
import namePlugin from '@xpyjs/color/plugins/name'
xcolor.use(namePlugin)
const named = xcolor('coral')
named.toHex() // '#ff7f50'
const obj = xcolor({ r: 255, g: 128, b: 0 })
const num = xcolor(0xFF8040)

// Chain operations
const result = xcolor('#ff0000')
  .lighten(20)
  .saturate(10)
  .alpha(0.8)
  .toHex()

// Check properties
xcolor('#fff').isLight() // true
xcolor('#000').isDark()  // true

// Compare colors
xcolor('#000').contrast('#fff') // 21 (max contrast)

Documentation

📄 License

MIT © xpyjs

Compatibility changes

Malformed color tokens now fail validation. Decimal RGB input retains fractional precision before instance rounding. Functional color strings preserve alpha, and WCAG levels use the unrounded ratio. Node ESM and CommonJS share plugin and configuration state.

Accessibility checks now reject invalid colors. Use blend(color, "normal") for ordinary alpha compositing. Node TypeScript users mixing ESM and CommonJS share the same XColor type.

About

A tiny, fast, and plugin-extensible color manipulation library for JavaScript/TypeScript.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages