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

stringlab_jk

v1.0.3

Published

A lightweight string manipulation utility library for JavaScript and TypeScript

Downloads

15

Readme

🧪 stringlab 🧪

A lightweight utility library providing a comprehensive collection of string manipulation functions for JavaScript and TypeScript projects. 🚀


📦 Features

  • 🔄 Convert between different string cases (camelCase, snake_case, PascalCase, etc.)
  • 💡 Measure string similarity using Levenshtein distance
  • 🧹 Sanitize and transform strings (escape HTML, slugify, truncate, etc.)
  • 🛠️ Various utility functions (reverse, pad, extract, and more)

🚀 Installation

To get started, simply install the package with npm:

npm install stringlab

📚 Usage

Here's how you can start using stringlab:

import {
  toTitleCase,
  camelCaseToWords,
  stringSimilarity,
  truncateToLength,
  slugify,
  escapeHTML,
  capitalizeFirst,
  reverseString,
  removeExtraSpaces,
  isPalindrome,
  countOccurrences,
  truncateWords,
  toSnakeCase,
  getSubstring,
  isAlphaNumeric,
  toPascalCase,
  isEmpty,
  padEndString,
  containsSubstring,
  toSpaceWords,
  toPascalCaseWithSpaces,
} from 'stringlab';

console.log(toTitleCase('hello world')); // "Hello World"
console.log(camelCaseToWords('camelCaseExample')); // "Camel Case Example"
console.log(stringSimilarity('hello', 'helo')); // 0.8
console.log(truncateToLength('This is a long sentence.', 10)); // "This is a..."
console.log(slugify('Hello World!')); // "hello-world"
console.log(escapeHTML('<div>"Test"</div>')); // "&lt;div&gt;&quot;Test&quot;&lt;/div&gt;"

📄 API Reference 🧑‍💻

1. toTitleCase(str: string): string 🎓

Converts a string to title case (capitalizes the first letter of each word).

console.log(toTitleCase('hello world')); // "Hello World"

2. camelCaseToWords(str: string): string 🐍

Converts a camelCase string to a space-separated string.

console.log(camelCaseToWords('camelCaseExample')); // "Camel Case Example"

3. stringSimilarity(str1: string, str2: string): number 🧮

Calculates the similarity between two strings (Levenshtein distance), returning a value between 0 and 1.

console.log(stringSimilarity('hello', 'helo')); // 0.8

4. truncateToLength(str: string, length: number): string ✂️

Truncates a string to a specific length and appends '...' if necessary.

console.log(truncateToLength('This is a long sentence.', 10)); // "This is a..."

5. slugify(str: string): string 🔗

Converts a string into a URL-friendly slug.

console.log(slugify('Hello World!')); // "hello-world"

6. escapeHTML(str: string): string 🧼

Escapes HTML special characters.

console.log(escapeHTML('<div>"Test"</div>'));
// "&lt;div&gt;&quot;Test&quot;&lt;/div&gt;"

7. capitalizeFirst(str: string): string

Capitalizes the first letter of a string.

console.log(capitalizeFirst('hello')); // "Hello"

8. reverseString(str: string): string 🔄

Reverses the input string.

console.log(reverseString('hello')); // "olleh"

9. removeExtraSpaces(str: string): string 💨

Removes leading, trailing, and multiple consecutive spaces.

console.log(removeExtraSpaces('  Hello    World  ')); // "Hello World"

10. isPalindrome(str: string): boolean 🧐

Checks if a string is a palindrome (case-insensitive, ignoring non-alphanumeric characters).

console.log(isPalindrome('A man a plan a canal Panama')); // true

11. countOccurrences(str: string, substr: string): number 🔢

Counts how many times a substring appears in the string.

console.log(countOccurrences('hello hello', 'hello')); // 2

12. truncateWords(str: string, numWords: number): string ✂️

Truncates a string to a specified number of words.

console.log(truncateWords('This is a long sentence.', 3)); // "This is a..."

13. toSnakeCase(str: string): string 🐍

Converts a string to snake_case.

console.log(toSnakeCase('Hello World!')); // "hello_world"

14. getSubstring(str: string, start: number, end?: number): string 📏

Extracts a substring from a string between the specified indices.

console.log(getSubstring('hello world', 0, 5)); // "hello"

15. isAlphaNumeric(str: string): boolean 🔠

Checks if a string contains only letters and numbers.

console.log(isAlphaNumeric('abc123')); // true

16. toPascalCase(str: string): string 🏰

Converts a string to PascalCase.

console.log(toPascalCase('hello world')); // "HelloWorld"

17. isEmpty(str: string): boolean 🧹

Checks if a string is empty or contains only whitespace.

console.log(isEmpty('    ')); // true

18. padEndString(str: string, length: number, char?: string): string

Pads the end of a string to a given length with a specified character.

console.log(padEndString('hello', 10, '-')); // "hello-----"

19. containsSubstring(str: string, substr: string): boolean 🔍

Checks if a string contains a specific substring.

console.log(containsSubstring('hello world', 'world')); // true

20. toSpaceWords(str: string): string 💬

Converts hyphenated words into space-separated words.

console.log(toSpaceWords('hello-world')); // "hello world"

21. toPascalCaseWithSpaces(str: string): string 🏰

Converts a string to PascalCase while keeping spaces between words.

console.log(toPascalCaseWithSpaces('hello world')); // "Hello World"

📝 License

ISC License.


📢 Author

Created by jella_komal.