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

@seed-fe/slashify

v1.0.0-alpha.0

Published

Tiny utilities for trimming, padding, and joining strings with separators

Readme

@seed-fe/slashify

Tiny utilities for trimming, padding, and joining strings with separators (default: /).

This package is intentionally not a filesystem path library; it only manipulates separator characters at string boundaries (plus join boundaries when combining multiple inputs).

Installation

pnpm add @seed-fe/slashify
# or
npm install @seed-fe/slashify
# or
yarn add @seed-fe/slashify

Usage

import { ltrim, rtrim, trim, lpad, rpad, pad, join, normalize } from '@seed-fe/slashify';

// Remove separators
ltrim('/foo')         // → 'foo'
ltrim('///foo')       // → 'foo'
rtrim('foo/')         // → 'foo'
rtrim('foo///')       // → 'foo'
trim('/foo/')         // → 'foo'
trim('///foo///')     // → 'foo'

// Ensure separators
lpad('foo')           // → '/foo'
lpad('/foo')          // → '/foo'
rpad('foo')           // → 'foo/'
rpad('foo/')          // → 'foo/'
pad('foo')            // → '/foo/'
pad('/foo/')          // → '/foo/'

// Join (supports variadic and array forms)
join('foo', 'bar')        // → 'foo/bar'
join('/foo/', '/bar/')    // → '/foo/bar/'
join(['foo', 'bar'])      // → 'foo/bar'
join(['/foo', 'bar/'])    // → '/foo/bar/'

// Variadic multi-argument joining
trim('/foo', 'bar/')       // → 'foo/bar'
lpad('api', 'v1', 'users') // → '/api/v1/users'
rpad('foo', 'bar', 'baz')  // → 'foo/bar/baz/'

// Numeric ID auto-conversion
join('users', 123, 'profile')  // → 'users/123/profile'
join('/api/v1', 'posts', 456)  // → '/api/v1/posts/456'

// Smart normalization
normalize('foo/')              // → 'foo'
normalize('/foo/')             // → '/foo'       (preserves absolute path prefix)
normalize('//cdn.com/')        // → '//cdn.com'  (preserves protocol-relative prefix)
normalize('./foo/')            // → './foo'      (preserves relative path prefix)
normalize('../foo/')           // → '../foo'     (preserves parent directory prefix)
normalize('~/foo/')            // → '~/foo'      (preserves home directory prefix)
normalize('https://a.com/')    // → 'https://a.com' (preserves URL protocol)
normalize('foo//bar///')       // → 'foo/bar'   (normalizes redundant slashes)

API

Input Types

All functions support flexible input forms:

// Single string
ltrim('/foo')

// Variadic (multiple arguments)
join('foo', 'bar', 'baz')
trim('/foo', 'bar/')

// Array
ltrim(['/foo', 'bar'])

// Nested arrays
ltrim([['/foo'], ['bar', 'baz']])

// null/undefined/empty strings are automatically filtered
ltrim(['/foo', null, '', 'bar'])  // → 'foo/bar'

// Numbers are automatically converted to strings
join(['foo', 123, 'bar'])  // → 'foo/123/bar'
join('users', 456)         // → 'users/456'

// Other non-string types are silently filtered
join(['foo', {}, 'bar'])   // → 'foo/bar'

Options

All functions accept an optional options parameter (as the last argument):

interface SlashOptions {
  separator?: string;  // default '/'
}

// Using custom separator
ltrim('\\foo', { separator: '\\' })  // → 'foo'
join('foo', 'bar', { separator: '::' })  // → 'foo::bar'
join(['foo', 'bar'], { separator: '::' })  // → 'foo::bar'

Function List

| Function | Description | Example | |----------|-------------|---------| | ltrim | Remove all leading separators | ltrim('///foo')'foo' | | rtrim | Remove all trailing separators | rtrim('foo///')'foo' | | trim | Remove all leading and trailing separators | trim('///foo///')'foo' | | lpad | Ensure leading separator | lpad('foo')'/foo' | | rpad | Ensure trailing separator | rpad('foo')'foo/' | | pad | Ensure leading and trailing separators | pad('foo')'/foo/' | | join | Join and preserve leading/trailing characteristics | join('foo', 'bar')'foo/bar' | | normalize | Smart path normalization | normalize('./foo/')'./foo' |

Prefixes Preserved by normalize

The normalize function preserves the following meaningful prefixes:

| Prefix | Meaning | Example | |--------|---------|---------| | / | Absolute path | /foo//foo | | // | Protocol-relative URL | //cdn.com///cdn.com | | ./ | Current directory | ./foo/./foo | | ../ | Parent directory | ../foo/../foo | | ~/ | User home directory | ~/foo/~/foo | | x:// | URL protocol | https://a.com/https://a.com |

Important Behavior Notes

Pure Separator Input

When input contains only separators (e.g., /, //, ///), each function behaves as follows:

| Function | Input / | Input // | Description | |----------|-----------|------------|-------------| | trim | '' | '' | Empty after removing separators | | ltrim | '' | '' | Empty after removing separators | | rtrim | '' | '' | Empty after removing separators | | lpad | '' | '' | No actual content to pad | | rpad | '' | '' | No actual content to pad | | pad | '' | '' | No actual content to pad | | join | / | // | Preserves leading/trailing characteristics | | normalize | / | // | Preserves meaningful prefix |

Key Difference: normalize recognizes and preserves meaningful path prefixes, while other functions focus on separator operations.

When to Use normalize

If you need to preserve semantic path prefixes (such as root /, protocol-relative //, relative paths ./ ../, home directory ~/), use normalize instead of trim.

// Need to preserve root directory semantics
normalize('/')     // → '/'
trim('/')          // → ''

// Need to preserve protocol-relative prefix
normalize('//')    // → '//'
trim('//')         // → ''

Not-Related projects

License

MIT