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 🙏

© 2025 – Pkg Stats / Ryan Hefner

sass-clamp

v1.1.0

Published

Responsive CSS clamp() utility for Sass

Readme

sass-clamp

CI npm

A responsive CSS clamp() utility for Sass that generates fluid typography and spacing with linear interpolation.

Installation

npm install sass-clamp

Usage

Requirements: This library requires Dart Sass. Node Sass is not supported.

Modern Dart Sass (≥1.71.0)

@use 'pkg:sass-clamp' as clamp;

.heading {
  font-size: clamp.fluid(16px, 24px, 320px, 1200px);
  // Output: clamp(16px, 13.09px + 0.91vw, 24px)
}

CLI compilation:

sass --pkg-importer=node style.scss output.css

Vite configuration:

// vite.config.js
import { defineConfig } from 'vite';
import { NodePackageImporter } from 'sass';

export default defineConfig({
  css: {
    preprocessorOptions: {
      scss: {
        pkgImporter: new NodePackageImporter(),
      },
    },
  },
});

Legacy Dart Sass (<1.71.0)

// Option 1: Use --load-path flag (recommended)
@use 'sass-clamp' as clamp;

// Option 2: Relative path from node_modules
@use './node_modules/sass-clamp' as clamp;

CLI compilation:

# Option 1: Using load-path
sass --load-path=./node_modules style.scss output.css

# Option 2: Direct compilation (relative paths)
sass style.scss output.css

Vite configuration:

// vite.config.js
import { defineConfig } from 'vite';

export default defineConfig({
  css: {
    preprocessorOptions: {
      scss: {
        // Add node_modules to include paths
        includePaths: ['node_modules'],
      },
    },
  },
});

Note: The pkg: syntax requires Dart Sass 1.71.0 or later and the --pkg-importer=node flag when using CLI. For older versions, use --load-path=./node_modules flag or relative paths.

API

fluid($min, $max, $min-vw, $max-vw, $base-font-size)

Generates a responsive clamp() function with linear interpolation.

Parameters:

  • $min - Minimum value (px or rem)
  • $max - Maximum value (px or rem)
  • $min-vw - Minimum viewport width (px or rem)
  • $max-vw - Maximum viewport width (px or rem)
  • $base-font-size - Base font size for unit conversion (default: 16)

Returns:

  • CSS clamp() function as a string

Example:

font-size: clamp.fluid(1rem, 1.5rem, 320px, 1200px);
// Returns: clamp(1rem, 0.82rem + 0.91vw, 1.5rem)

minmax($min, $max, $min-vw, $max-vw, $base-font-size)

Generates a responsive max(min()) function with linear interpolation for legacy browser compatibility.

Parameters:

  • $min - Minimum value (px or rem)
  • $max - Maximum value (px or rem)
  • $min-vw - Minimum viewport width (px or rem)
  • $max-vw - Maximum viewport width (px or rem)
  • $base-font-size - Base font size for unit conversion (default: 16)

Returns:

  • CSS max(min()) function as a string

Example:

font-size: clamp.minmax(1rem, 1.5rem, 320px, 1200px);
// Returns: max(1rem, min(0.82rem + 0.91vw, 1.5rem))

Use cases:

  • Legacy browser support where clamp() is not available
  • CSS-in-JS libraries with clamp() parsing issues
  • Progressive enhancement scenarios
.heading {
  // Fallback for older browsers
  font-size: clamp.minmax(16px, 24px, 320px, 1200px);
  // Modern browsers
  font-size: clamp.fluid(16px, 24px, 320px, 1200px);
}

Min/Max Values

  • Supports px or rem units
  • One unit can be omitted (uses the other value's unit)
  • Both values must use the same unit (when both are specified)
@use 'pkg:sass-clamp' as clamp; // or 'sass-clamp' for legacy

// Both units specified (must match)
.text-1 { font-size: clamp.fluid(16px, 24px, 320px, 1200px); }
.text-2 { font-size: clamp.fluid(1rem, 1.5rem, 20rem, 75rem); }

// One unit omitted (24 => 24px, 1 => 1rem)
.text-3 { font-size: clamp.fluid(16px, 24, 320px, 1200px); }
.text-4 { font-size: clamp.fluid(1, 1.5rem, 20rem, 75rem); }

Viewport Values

  • Supports px or rem units
  • One unit can be omitted (uses the other value's unit)
  • Can mix px and rem units
// Mixed viewport units
.element {
  padding: clamp.fluid(16px, 32px, 20rem, 75rem);
}

Base Font Size ($base-font-size)

  • Specify the pixel equivalent of 1rem (without unit)
  • Used for px/rem conversions
  • Can be set globally or per function call
// Global configuration
@use 'pkg:sass-clamp' as clamp with ( // or 'sass-clamp' for legacy
  $default-base-font-size: 18
);

// Per function call
.text {
  font-size: clamp.fluid(1rem, 1.5rem, 20rem, 75rem, 18);
}

Responsive Behavior

Growing with Viewport

// Font size grows as viewport expands
.heading {
  font-size: clamp.fluid(16px, 24px, 320px, 1200px);
}

Shrinking with Viewport

// Sidebar width shrinks as viewport grows (more space for content)
.sidebar {
  width: clamp.fluid(300px, 200px, 768px, 1920px);
}

// Font size decreases on larger screens
.dense-text {
  font-size: clamp.fluid(18px, 14px, 320px, 1200px);
}

Limitations

  • Unitless values not supported: Properties like line-height, opacity, z-index that accept unitless values cannot be used with this function
  • px/rem only: Only px and rem units are supported for each values

License

MIT