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

truncate-path

v1.0.3

Published

Smart and effective path truncation.

Downloads

11

Readme

Why

Sometimes you need to display truncated paths in your application. This module does just that. It also works perfectly for urls too!

let truncatePath = require('truncate-path');

let file = '/your/very/very/long/path-to/my-modules/test-module/node_modules/chokidar/types/index.d.ts';

console.log("Local File:", truncatePath(file, 10));


let url="https://cdn.pixabay.com/download/audio/2023/04/03/audio_047543feac.mp3?filename=relaxing-145038.mp3&g-recaptcha-response=03ADUVZwAycgBPXsjVYD2lKzJNgZQdBFMeLK9oxBVA4hBSQCFriPkOOwz19q6Copxw41AnkONr4T7ekwCTWZDBcON-fbd4AHSJ6Xnro0h19hM5LaXXak6G6_o-y5pHhB3Bcx_mUMOa2dPQP4lXUBKqPN4idD2-e8G7UdhEHGcy-XT_8EIANjVtyHFO7SHHji4WkGGnJGYdQVQlKlXMkYrwrIAe7ILR6aWWFu-f42tbghVh3vmm9ls1tv1yKJEWqblV4bNL-CaK47yLiAZt7PlruJELzcsb6yVpDTOtLK4hznimRAUPKzl9DN7t7GrRacprKIAsJBnHZF4zCiqClxJsAPdXsJCI66frxZ0VP5EQvg19ur7mwoJC9rwhMRPuLh8fgulTt8i1svGn6zMsj737VwlP3ak4kYlWftnV1H2N3Wt9u1GsUSbVtVAMi2RKYg0vRIB_Pgzq2aEV7GtWcGJ87qTk-wLiQ_FIo9qg_XJaRBUnwEhThnxql95hpp7e1AMsD0LUlksSBuWmGvI2lJbj0Z3FIKWQnwU78Q&remote_template=1";

console.log("Long URL:", truncatePath(url));

This outputs:

Local File: /your/[..]/index.d.ts

Long URL: //cdn.pixabay.com/download/audio/[..]/audio_047543feac.mp3

API

truncatePath( file, [length] )

The default length is 40 characters.

Please note that the path generated is not always the length defined but the closest (complete) path that can be generated.

By complete path, we mean that directory and file names are not split midway.

As such "/this/that/those/file.ext" can never be "/this/that/th[...]/fi.ext" or something like that. Because that would be a very ugly path indeed!

Enjoy!