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

@adobe/helix-shared-string

v2.2.0

Published

Shared modules of the Helix Project - string

Readme

Helix Shared - String

A collection of utility functions for string manipulation, including multiline string handling, filename sanitization, path processing, and edit distance calculation.

Installation

npm install @adobe/helix-shared-string

Usage

import {
  multiline,
  splitByExtension,
  sanitizeName,
  sanitizePath,
  editDistance
} from '@adobe/helix-shared-string';

Functions

multiline(str)

Declares multiline strings with proper indentation handling. This function strips empty first and last lines, and removes common whitespace prefixes from all lines.

const text = multiline(`
  Hello
  World
    Indented
  Back
`);
// Result: "Hello\nWorld\n  Indented\nBack"

The function automatically detects and removes the common indentation level, making it perfect for template strings in code.

splitByExtension(name)

Splits a filename at the last dot, returning the base name and extension as a two-element array.

splitByExtension('document.txt');
// Returns: ['document', 'txt']

splitByExtension('archive.tar.gz');
// Returns: ['archive.tar', 'gz']

splitByExtension('README');
// Returns: ['README', '']

splitByExtension('.gitignore');
// Returns: ['.gitignore', '']

sanitizeName(name)

Sanitizes a string by:

  • Converting to lowercase
  • Normalizing all Unicode characters
  • Replacing all non-alphanumeric characters with dashes
  • Removing consecutive dashes
  • Removing leading and trailing dashes
sanitizeName('My Document');
// Returns: 'my-document'

sanitizeName('Föhren Smürd');
// Returns: 'fohren-smurd'

sanitizeName('.My 2. Document-');
// Returns: 'my-2-document'

sanitizePath(filepath, opts)

Sanitizes a file path using the same rules as sanitizeName, but only affects the basename. The directory path and extension are preserved.

sanitizePath('/Untitled Folder/My Document.docx');
// Returns: '/Untitled Folder/my-document.docx'

sanitizePath('Föhren Smürd.txt');
// Returns: 'fohren-smurd.txt'

sanitizePath('.My 2. Document!.docx');
// Returns: 'my-2-document.docx'

Options:

  • ignoreExtension (boolean): If true, treats the entire filename as the basename without preserving any extension
sanitizePath('.MyDocument', { ignoreExtension: true });
// Returns: 'mydocument'

editDistance(s0, s1)

Computes the Levenshtein edit distance between two strings using a recursive algorithm. Returns the minimum number of single-character edits (insertions, deletions, or substitutions) required to transform one string into another.

editDistance('foo', 'foo');
// Returns: 0

editDistance('foo', 'foo123');
// Returns: 3

editDistance('My Document', 'my-document');
// Returns: 3

editDistance('My 1. Document', 'my-1-document');
// Returns: 5

This function is optimized for relatively short strings like filenames and performs well even with moderately long inputs.