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

@fluxmedia/core

v2.0.0

Published

Core types and abstractions for FluxMedia - unified media upload library

Downloads

296

Readme

@fluxmedia/core

Core library for FluxMedia - a unified media upload library for JavaScript and TypeScript.

Installation

pnpm add @fluxmedia/core

Note: You also need a provider package (e.g., @fluxmedia/cloudinary, @fluxmedia/s3, @fluxmedia/r2)

Quick Start

import { MediaUploader } from '@fluxmedia/core';
import { CloudinaryProvider } from '@fluxmedia/cloudinary';

const uploader = new MediaUploader(
  new CloudinaryProvider({
    cloudName: 'your-cloud',
    apiKey: 'your-key',
    apiSecret: 'your-secret'
  })
);

// Upload a file
const result = await uploader.upload(file, {
  folder: 'avatars',
  transformation: {
    width: 400,
    height: 400,
    fit: 'cover',
    format: 'webp'
  },
  metadata: {
    userId: '12345',
    uploadedAt: new Date().toISOString()
  }
});

console.log(result.url);

MediaUploader API

Constructor

new MediaUploader(provider: MediaProvider)

Methods

| Method | Description | | --------------------------------- | ------------------------------------------ | | upload(file, options?) | Upload a single file | | uploadMultiple(files, options?) | Upload multiple files with concurrency | | delete(id) | Delete a file by ID | | deleteMultiple(ids) | Delete multiple files | | get(id) | Get file metadata | | getUrl(id, transform?) | Generate URL with optional transformations | | supports(feature) | Check if provider supports a feature |

Upload Options

interface UploadOptions {
  filename?: string;           // Custom filename
  folder?: string;             // Destination folder
  tags?: string[];             // Tags for organizing
  metadata?: Record<string, unknown>;
  onProgress?: (percent: number) => void;
  transformation?: TransformationOptions;
  uniqueFilename?: boolean;    // Generate unique name (default: true)
}

Transformations

interface TransformationOptions {
  width?: number;
  height?: number;
  quality?: number;            // 0-100
  format?: 'auto' | 'webp' | 'avif' | 'jpg' | 'png';
  fit?: 'cover' | 'contain' | 'fill' | 'inside' | 'outside';
}

Upload Result

interface UploadResult {
  id: string;          // Unique file identifier
  url: string;         // Direct URL
  publicUrl: string;   // Public access URL
  size: number;        // Size in bytes
  format: string;      // File format
  width?: number;      // Image/video width
  height?: number;     // Image/video height
  provider: string;    // Provider name
  metadata: Record<string, unknown>;
  createdAt: Date;
}

Using Plugins

Extend functionality with plugins:

import { createFileValidationPlugin } from '@fluxmedia/plugins';

const uploader = new MediaUploader(provider);

// Add validation
await uploader.use(createFileValidationPlugin({
  maxSize: 10 * 1024 * 1024, // 10MB
  allowedTypes: ['image/*', 'video/mp4']
}));

// Now uploads are validated
await uploader.upload(file);

File Type Detection

Detect file types using magic bytes (more reliable than extensions):

import { getFileType, isImage, isVideo } from '@fluxmedia/core';

const type = await getFileType(buffer);
console.log(type); // { mime: 'image/jpeg', ext: 'jpg' }

if (await isImage(buffer)) {
  // Handle image
}

if (await isVideo(buffer)) {
  // Handle video
}

Error Handling

All errors use standardized MediaErrorCode:

import { MediaError, MediaErrorCode } from '@fluxmedia/core';

try {
  await uploader.upload(file);
} catch (err) {
  if (err instanceof MediaError) {
    console.log(err.code);      // e.g., 'FILE_TOO_LARGE'
    console.log(err.provider);  // e.g., 'cloudinary'
    console.log(err.message);   // Human-readable message
  }
}

Error Codes

| Code | Description | | --------------------- | ------------------------ | | UPLOAD_FAILED | General upload failure | | FILE_TOO_LARGE | File exceeds size limit | | INVALID_FILE_TYPE | Unsupported file type | | NETWORK_ERROR | Network or timeout issue | | INVALID_CREDENTIALS | Bad credentials | | UNAUTHORIZED | Access denied | | FILE_NOT_FOUND | File doesn't exist | | QUOTA_EXCEEDED | Storage quota reached |

Feature Detection

Check what your provider supports:

// Transformation features
uploader.supports('transformations.resize');
uploader.supports('transformations.blur');

// Capabilities
uploader.supports('capabilities.aiTagging');
uploader.supports('capabilities.videoProcessing');

License

MIT