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

@piadina/relabelr

v0.0.1

Published

Smart label duplication and name conflict resolution with customizable copy formats.

Readme

relabelr

Smart label duplication and name conflict resolution with customizable copy formats.

My LabelMy Label Copy, My Label Copy (1), My Label (2), etc.

Features

  • 🔄 Smart incrementing: Automatically detects existing copy numbers and increments them
  • 🎨 Multiple formats: Support for different copy suffix styles
  • 📁 File extension aware: Preserves file extensions when incrementing
  • 🛡️ Type safe: Full TypeScript support with proper type definitions
  • Performance: Efficient collision detection using Set for O(1) lookups
  • 🌐 Universal: Works in browser and Node.js
  • 📦 Lightweight: Zero dependencies

Install

npm install @piadina/relabelr
# or
yarn add @piadina/relabelr

Quick Start

import { relabelr, incrementFileName, COPY_FORMATS } from '@piadina/relabelr';

// Basic usage
const uniqueLabel = relabelr('My Document', ['My Document', 'My Document copy']);
// Result: "My Document copy 2"

// With custom format
const uniqueLabel2 = relabelr('My Document', ['My Document'], COPY_FORMATS.PARENTHESES);
// Result: "My Document Copy (1)"

Copy Formats

Predefined Formats

// Default: "copy", "copy 2", "copy 3"
COPY_FORMATS.DEFAULT

// Capitalized: "Copy", "Copy 2", "Copy 3"  
COPY_FORMATS.CAPITALIZED

// Start with one: "copy 1", "copy 2", "copy 3"
COPY_FORMATS.START_WITH_ONE

// Parentheses: "Copy (1)", "Copy (2)", "Copy (3)"
COPY_FORMATS.PARENTHESES

// Numbers only: "(1)", "(2)", "(3)"
COPY_FORMATS.NUMBERS_ONLY

Custom Formats

const customFormat: CopyFormat = {
  copyWord: 'duplicate',
  firstCopyFormat: '{copyWord}',           // "duplicate" 
  numberedCopyFormat: '{copyWord}-{number}', // "duplicate-2", "duplicate-3"
};

incrementFileName('Document', customFormat);
// Result: "Document duplicate"

API Reference

relabelr(proposedLabel, existingLabels, copyFormat?)

Generates a unique label by checking against existing labels and appending copy suffixes as needed.

Parameters:

  • proposedLabel: string - The desired label name
  • existingLabels: string[] - Array of existing labels to check against
  • copyFormat?: CopyFormat - Optional copy format (defaults to COPY_FORMATS.DEFAULT)

Returns: string - A unique label that doesn't conflict with existing labels

incrementFileName(name, copyFormat?)

Increments a file name by adding or incrementing a copy suffix.

Parameters:

  • name: string - The file name to increment
  • copyFormat?: CopyFormat - Optional copy format (defaults to COPY_FORMATS.DEFAULT)

Returns: string - The incremented file name

Examples

File Name Incrementing

import { incrementFileName, COPY_FORMATS } from '@piadina/relabelr';

// Default format
incrementFileName('document.pdf');        // "document copy.pdf"
incrementFileName('document copy.pdf');   // "document copy 2.pdf" 
incrementFileName('document copy 5.pdf'); // "document copy 6.pdf"

// Parentheses format
incrementFileName('document.pdf', COPY_FORMATS.PARENTHESES);     // "document Copy (1).pdf"
incrementFileName('document Copy (1).pdf', COPY_FORMATS.PARENTHESES); // "document Copy (2).pdf"

Label Generation with Collision Detection

import { relabelr, COPY_FORMATS } from '@piadina/relabelr';

const existingLabels = ['Report', 'Report copy', 'Report copy 3'];

// Find next available name  
relabelr('Report', existingLabels);
// Result: "Report copy 2" (fills the gap)

// Use different format
relabelr('Report', ['Report'], COPY_FORMATS.PARENTHESES);
// Result: "Report Copy (1)"