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

@nocojs/client

v0.0.1

Published

A lightweight client library for generating optimized image previews at build time. The `@nocojs/client` package provides a simple API that integrates with build tools to replace image URLs with small, optimized placeholder images.

Readme

@nocojs/client

A lightweight client library for generating optimized image previews at build time. The @nocojs/client package provides a simple API that integrates with build tools to replace image URLs with small, optimized placeholder images.

Installation

npm install @nocojs/client

Usage

The package exports a single function preview that by itself is a pass-through function returning the first argument unchanged. However, when used with the appropriate build-time integration (webpack, rollup, or parcel), the preview function calls are replaced with small optimized versions of the images.

Basic Usage

import { preview } from '@nocojs/client';

// Basic usage - just pass the image URL
const imagePreview = preview('https://example.com/image.jpg');

// Use in your components
function ImageComponent() {
  return (
    <img 
      src={preview('/path/to/image.jpg')} 
      alt="Optimized preview"
    />
  );
}

With Options

The second argument allows you to customize the preview generation:

import { preview } from '@nocojs/client';

// Custom width (default: 12px)
const smallPreview = preview('/image.jpg', { width: 8 });

// Custom height
const tallPreview = preview('/image.jpg', { height: 20 });

// Different placeholder types
const blurredPreview = preview('/image.jpg', { placeholderType: 'blurred' });
const grayscalePreview = preview('/image.jpg', { placeholderType: 'grayscale' });
const dominantColorPreview = preview('/image.jpg', { placeholderType: 'dominant-color' });

// Disable caching for specific images
const uncachedPreview = preview('/image.jpg', { cache: false });

API Reference

preview(url, options?)

Generates an optimized preview of an image at build time.

Parameters

  • url (string): The path or URL to the image
  • options (PreviewOptions, optional): Configuration options for the preview generation

Returns

  • string: The original URL (at runtime), or optimized preview data URL (after build transformation)

PreviewOptions

interface PreviewOptions {
  placeholderType?: PlaceholderType;
  replaceFunctionCall?: boolean;
  cache?: boolean;
  width?: number;
  height?: number;
  wrapWithSvg?: boolean;
}

Options

  • placeholderType: The type of placeholder to generate

    • 'normal' (default): Standard downscaled image
    • 'blurred': Blurred version of the normal one
    • 'grayscale': Grayscale version of the image
    • 'dominant-color': Single color based on dominant color
    • 'average-color': Single color based on average color
    • 'transparent': Transparent placeholder
  • width: Width of the generated preview in pixels (default: 12)

  • height: Height of the generated preview in pixels (calculated from aspect ratio if not specified)

  • cache: Whether to cache the generated preview (default: true)

  • replaceFunctionCall: Whether to replace the function call entirely (default: true)

  • wrapWithSvg: Whether to wrap the generated image with SVG - helps to keep exact aspect ratio (default: true)

Build Tool Integration

To actually generate the optimized previews, you need to use one of the build tool integrations:

Webpack

npm install @nocojs/webpack-loader
// webpack.config.js
module.exports = {
  module: {
    rules: [
      {
        test: /\.(ts|js)$/,
        use: [
          'ts-loader', // or your preferred loader
          {
            loader: '@nocojs/webpack-loader',
            options: {
              publicDir: 'public',
              placeholderType: 'blurred',
              width: 12
            }
          }
        ]
      }
    ]
  }
};

Rollup/Vite

npm install @nocojs/plugin-rollup
// rollup.config.js or vite.config.js
import { nocojs } from '@nocojs/plugin-rollup';

export default {
  plugins: [
    nocojs({
      publicDir: 'public',
      placeholderType: 'blurred'
    })
  ]
};

Parcel

npm install @nocojs/parcel-transformer
{
  "extends": "@parcel/config-default",
  "transformers": {
    "*.{js,jsx,ts,tsx}": [
      "@nocojs/parcel-transformer",
      "..."
    ]
  }
}

Examples

Image Gallery with Previews

import { preview } from '@nocojs/client';

function createImageGallery() {
  const images = [
    {
      preview: preview('https://images.unsplash.com/photo-1506905925346-21bda4d32df4'),
      src: 'https://images.unsplash.com/photo-1506905925346-21bda4d32df4'
    },
    {
      preview: preview('https://images.unsplash.com/photo-1518837695005-2083093ee35b', { 
        placeholderType: 'blurred',
        width: 16 
      }),
      src: 'https://images.unsplash.com/photo-1518837695005-2083093ee35b'
    }
  ];

  return images.map(image => `
    <img src="${image.preview}" 
         data-src="${image.src}" 
         style="width: 300px; height: 200px;" />
  `).join('');
}

How It Works

At build time, the build tool integration:

  • Analyzes your code for preview() function calls
  • Downloads or accesses the images from the specified paths
  • Generates small, optimized placeholder images (12px width by default)
  • Replaces the function calls with base64-encoded data URLs of the placeholders

This enables instant loading of image previews while maintaining the flexibility to lazy-load full-resolution images when needed.

License

MIT