A lightweight, zero-dependency TypeScript library for generating cross-browser CSS gradient strings.
- 🚀 Zero Dependencies: Pure TypeScript logic.
- 🎨 Cross-Browser Support: Generates standard,
-webkit-,-moz-, and legacy IE filter strings. - 🛡️ Type Safe: Fully typed with TypeScript.
- 📦 Modern Exports: Supports ESM and CommonJS.
npm install @nyanxx/gradient-maker
# or
pnpm add @nyanxx/gradient-maker
# or
yarn add @nyanxx/gradient-makerimport { gradientMaker } from '@nyanxx/gradient-maker';
const result = gradientMaker({
type: 'linear',
rotation: 135,
colors: [
{ color: '#FB6947', position: 0 },
{ color: '#F89B29', position: 100 }
]
});
console.log(result.standard);
// "background: linear-gradient(135deg, hsla(11, 96%, 63%, 1) 0%, hsla(33, 94%, 56%, 1) 100%);"
console.log(result.full);
// Returns all versions (fallback, standard, moz, webkit, filter) joined by newlines.The main function to generate gradient strings.
| Property | Type | Description |
|---|---|---|
colors |
ColorPoint[] |
Array of { color: string, position: number } |
type |
'linear' | 'radial' |
Gradient shape |
rotation |
number |
Angle in degrees (linear only) |
| Property | Description |
|---|---|
standard |
W3C Standard CSS |
webkit |
Chrome/Safari prefix |
moz |
Firefox prefix |
filter |
Legacy IE Filter |
fallback |
Solid color fallback |
full |
All of the above joined |
Contributions are welcome! Please feel free to submit a Pull Request.
MIT © Nayan