npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@fileslim/compress

v2.1.0

Published

Client-side image and PDF compression. Zero servers, complete privacy.

Readme

@fileslim/compress

Client-side file compression. Zero servers, complete privacy.

npm version License: MIT

Features

  • 🖼️ Image compression — JPEG, PNG, WebP, AVIF with quality control
  • 📄 PDF compression — Full embedded image recompression pipeline
  • 📊 Quality scoring — Optional SSIM measurement with rating
  • 100% client-side — No uploads, complete privacy
  • 🎯 Simple API — 3 functions, 4 presets
  • 📦 Tiny bundle — ~15KB gzipped (core)

Install

npm install @fileslim/compress

Optional: Better compression quality

Install @jsquash encoders for significantly better compression:

npm install @jsquash/jpeg @jsquash/png @jsquash/avif

The SDK automatically uses @jsquash when available and falls back to browser-image-compression otherwise.

Quick Start

import { compress, compressPDF, compressBatch } from '@fileslim/compress';

// Compress an image (auto-selects best format: AVIF > WebP > JPEG)
const result = await compress(file, { format: 'auto' });
console.log(`Saved ${result.savings}%`); // "Saved 72%"

// Compress a PDF (full image recompression)
const pdf = await compressPDF(pdfFile, {
  mode: 'high',
  onProgress: (phase, pct) => console.log(`${phase}: ${pct}%`)
});

// Batch compress multiple files
const { results } = await compressBatch(files, { preset: 'web' });

Presets

const result = await compress(file, { preset: 'web' });

| Preset | Quality | Max Width | Format | Best For | |--------|---------|-----------|--------|----------| | web | 75% | 1920px | Auto (AVIF/WebP) | Websites | | social | 80% | 1080px | JPEG | Instagram, Twitter | | email | 65% | 800px | JPEG | Email attachments | | print | 95% | No limit | Auto | Printing |

Image Compression

const result = await compress(file, {
  quality: 0.8,           // 0.0 - 1.0
  maxWidth: 1920,         // pixels (null = no resize)
  format: 'avif',         // 'auto' | 'jpeg' | 'png' | 'webp' | 'avif'
  stripMetadata: true,    // remove EXIF data (default: true)
  measureQuality: true    // return SSIM score
});

// Quality score (only when measureQuality: true)
console.log(result.qualityScore);
// { ssim: 0.97, rating: 'good' }

Format auto-detection

When format: 'auto' (default for web and print presets), the SDK picks the best format:

  1. AVIF — if browser supports it (best compression)
  2. WebP — universal modern fallback
  3. JPEG — legacy fallback

Encoder pipeline

The SDK uses a hybrid approach:

  1. @jsquash encoders (AVIF, JPEG, PNG) — superior quality-per-byte, used when installed
  2. browser-image-compression — automatic fallback if @jsquash is not available

PDF Compression

PDF compression now includes a full image extraction and recompression pipeline:

const pdf = await compressPDF(file, {
  mode: 'balanced',       // 'low' | 'balanced' | 'high' | 'maximum'
  imageQuality: 0.7,      // override mode default
  maxImageDimension: 1600, // max pixels for embedded images
  stripMetadata: true,     // remove title, author, etc.
  onProgress: (phase, percent) => {
    console.log(`${phase}: ${percent}%`);
  }
});

PDF modes

| Mode | Image Quality | Max Dimension | Use Case | |------|--------------|---------------|----------| | low | 85% | 2000px | Print-safe, light compression | | balanced | 70% | 1600px | Good balance (default) | | high | 50% | 1200px | Aggressive, smaller files | | maximum | 30% | 1000px | Smallest possible output |

What the PDF pipeline does

  1. Extracts all embedded images from the PDF
  2. Decodes compressed image bytes to raw pixels
  3. Resizes oversized images based on mode settings
  4. Recompresses with @jsquash/jpeg (or canvas fallback)
  5. Replaces images in the PDF only if smaller
  6. Strips document metadata (title, author, keywords)
  7. Tries multiple save strategies and picks the smallest

Batch Processing

const { results, errors } = await compressBatch(files, {
  preset: 'social',
  continueOnError: true,
  onProgress: (current, total) => {
    console.log(`Processing ${current}/${total}`);
  }
});

Result Object

All functions return a CompressedFile object:

interface CompressedFile {
  blob: Blob;              // The compressed file
  filename: string;        // Suggested filename
  originalSize: number;    // Bytes
  compressedSize: number;  // Bytes
  savings: number;         // Percentage (0-100)
  format: string;          // MIME type
  qualityScore?: {         // Only if measureQuality: true
    ssim: number;          // 0-1 (higher = better)
    rating: 'excellent' | 'good' | 'acceptable' | 'poor';
  };
}

Download Result

const result = await compress(file);

const url = URL.createObjectURL(result.blob);
const a = document.createElement('a');
a.href = url;
a.download = result.filename;
a.click();
URL.revokeObjectURL(url);

Browser Support

| Browser | Images | PDF | AVIF | |---------|--------|-----|------| | Chrome 89+ | ✅ | ✅ | ✅ | | Firefox 93+ | ✅ | ✅ | ✅ (v93+) | | Safari 16+ | ✅ | ✅ | ✅ (v16.4+) | | Edge 89+ | ✅ | ✅ | ✅ |

License

MIT © Juraj Cukan


Made with ❤️ by FileSlim