adobe-ase
v1.0.0
Published
A TypeScript library for reading and writing Adobe Swatch Exchange (.ase) files
Downloads
7
Maintainers
Readme
Adobe-ASE
A TypeScript library for reading and writing Adobe Swatch Exchange (.ase) files.
Features
- Read ASE files and parse color swatches
- Write ASE files from color data
- Full TypeScript support with type definitions
- Support for multiple color models:
- RGB (with hex conversion)
- CMYK (with hex conversion)
- Grayscale
- LAB
- Support for color groups
- Support for color types (global, spot, normal)
- Zero dependencies
- Fully tested
Installation
npm install adobe-aseUsage
Reading ASE Files
import { readAse } from 'adobe-ase';
import { readFileSync } from 'fs';
// Read ASE file
const buffer = readFileSync('colors.ase');
const swatches = readAse(buffer);
// Iterate through colors and groups
swatches.forEach((item) => {
if (item.type === 'color') {
console.log(`Color: ${item.name}`);
console.log(`Model: ${item.color.model}`);
if (item.color.model === 'RGB') {
console.log(`RGB: ${item.color.r}, ${item.color.g}, ${item.color.b}`);
console.log(`Hex: ${item.color.hex}`);
}
} else if (item.type === 'group') {
console.log(`Group: ${item.name}`);
item.entries.forEach((color) => {
console.log(` - ${color.name}`);
});
}
});Writing ASE Files
import { writeAse } from 'adobe-ase';
import { writeFileSync } from 'fs';
import type { AseStructure } from 'adobe-ase';
// Create color structure
const swatches: AseStructure = [
{
type: 'color',
name: 'Red',
color: {
model: 'RGB',
r: 255,
g: 0,
b: 0,
type: 'normal',
},
},
{
type: 'color',
name: 'Green',
color: {
model: 'RGB',
r: 0,
g: 255,
b: 0,
type: 'normal',
},
},
{
type: 'group',
name: 'Blues',
entries: [
{
type: 'color',
name: 'Light Blue',
color: {
model: 'RGB',
r: 173,
g: 216,
b: 230,
type: 'normal',
},
},
{
type: 'color',
name: 'Dark Blue',
color: {
model: 'RGB',
r: 0,
g: 0,
b: 139,
type: 'normal',
},
},
],
},
];
// Write to buffer
const buffer = writeAse(swatches);
// Save to file
writeFileSync('my-colors.ase', buffer);Working with Different Color Models
RGB Colors
const rgbColor: AseStructure = [
{
type: 'color',
name: 'Purple',
color: {
model: 'RGB',
r: 128,
g: 0,
b: 128,
type: 'normal',
},
},
];
const buffer = writeAse(rgbColor);
const parsed = readAse(buffer);
// Hex value is automatically calculated when reading
console.log(parsed[0].color.hex); // "#800080"CMYK Colors
const cmykColor: AseStructure = [
{
type: 'color',
name: 'Process Cyan',
color: {
model: 'CMYK',
c: 100,
m: 0,
y: 0,
k: 0,
type: 'spot',
},
},
];Grayscale Colors
const grayColor: AseStructure = [
{
type: 'color',
name: 'Medium Gray',
color: {
model: 'Gray',
gray: 0.5, // 0-1 range
type: 'normal',
},
},
];LAB Colors
const labColor: AseStructure = [
{
type: 'color',
name: 'Lab Color',
color: {
model: 'LAB',
lightness: 50,
a: 25,
b: -25,
type: 'normal',
},
},
];Color Types
Colors can be classified as:
'normal'- Regular color swatch'global'- Global color (affects all instances when changed)'spot'- Spot color (for printing)
Utility Functions
The library also exports utility functions for color conversion:
import { rgbToHex, cmykToHex } from 'adobe-ase';
// Convert RGB to hex
const hex1 = rgbToHex({ r: 255, g: 0, b: 0 }); // "#ff0000"
// Convert CMYK to hex (basic conversion without color profile)
const hex2 = cmykToHex({ c: 100, m: 0, y: 0, k: 0 }); // "#00ffff"TypeScript Support
This library is written in TypeScript and includes full type definitions:
import type {
AseStructure,
ColorEntry,
ColorGroup,
Color,
RGBColor,
CMYKColor,
GrayColor,
LABColor,
ColorType,
} from 'adobe-ase';API Reference
readAse(buffer: Buffer): AseStructure
Reads and parses an ASE file from a Buffer.
Parameters:
buffer- Buffer containing ASE file data
Returns: Parsed structure containing colors and groups
Throws:
TypeError- If buffer is not a valid Buffer instanceError- If file signature or version is invalid
writeAse(structure: AseStructure): Buffer
Writes an ASE file to a Buffer.
Parameters:
structure- Structure containing colors and groups to write
Returns: Buffer containing the ASE file data
Development
See CONTRIBUTING.md for development guidelines.
License
MIT
Credits
Based on the ASE format specification and inspired by existing ASE parsing implementations.
