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

string-master-utils

v1.0.0

Published

A lightweight, zero-dependency TypeScript library for comprehensive string transformations and utilities

Downloads

115

Readme

string-master-utils

A lightweight, zero-dependency TypeScript library for comprehensive string transformations and utilities. Perfect for any project that needs robust string manipulation without external dependencies. Written in TypeScript with full type definitions included.

Features

  • 🚀 Zero Runtime Dependencies - No external packages required at runtime
  • 📦 Lightweight - Minimal footprint
  • 🎯 Production Ready - Well-tested and documented
  • 📚 Fully Documented - Complete JSDoc for all functions
  • 🔧 Type Safe - Written in TypeScript with full type definitions
  • 💪 TypeScript Support - Full TypeScript support with declaration files

Installation

npm install string-master-utils

Usage

TypeScript/ES Modules

import {
  toCamelCase,
  toSnakeCase,
  removeSpaces,
  countWords,
  generateSlug,
} from "string-master-utils";

// Use the functions
const result = toCamelCase("hello world"); // 'helloWorld'

Reference

Case Conversions

toCamelCase(str)

Converts a string to camelCase.

toCamelCase("hello world"); // 'helloWorld'
toCamelCase("hello-world"); // 'helloWorld'
toCamelCase("Hello World"); // 'helloWorld'
toCamelCase("hello_world_test"); // 'helloWorldTest'

toSnakeCase(str)

Converts a string to snake_case.

toSnakeCase("hello world"); // 'hello_world'
toSnakeCase("HelloWorld"); // 'hello_world'
toSnakeCase("hello-world"); // 'hello_world'
toSnakeCase("Hello World Test"); // 'hello_world_test'

toKebabCase(str)

Converts a string to kebab-case.

toKebabCase("hello world"); // 'hello-world'
toKebabCase("HelloWorld"); // 'hello-world'
toKebabCase("hello_world"); // 'hello-world'
toKebabCase("Hello World Test"); // 'hello-world-test'

toPascalCase(str)

Converts a string to PascalCase.

toPascalCase("hello world"); // 'HelloWorld'
toPascalCase("hello-world"); // 'HelloWorld'
toPascalCase("hello_world"); // 'HelloWorld'
toPascalCase("hello world test"); // 'HelloWorldTest'

toTitleCase(str)

Converts a string to Title Case (capitalizes first letter of each word).

toTitleCase("hello world"); // 'Hello World'
toTitleCase("hello-world"); // 'Hello-World'
toTitleCase("HELLO WORLD"); // 'Hello World'
toTitleCase("hello world test"); // 'Hello World Test'

toConstantCase(str)

Converts a string to CONSTANT_CASE (UPPER_SNAKE_CASE).

toConstantCase("hello world"); // 'HELLO_WORLD'
toConstantCase("HelloWorld"); // 'HELLO_WORLD'
toConstantCase("hello-world"); // 'HELLO_WORLD'
toConstantCase("hello world test"); // 'HELLO_WORLD_TEST'

toDotCase(str)

Converts a string to dot.case.

toDotCase("hello world"); // 'hello.world'
toDotCase("HelloWorld"); // 'hello.world'
toDotCase("hello-world"); // 'hello.world'
toDotCase("hello world test"); // 'hello.world.test'

Word & Character Cleaning

removeSpaces(str)

Removes all spaces from a string.

removeSpaces("hello world"); // 'helloworld'
removeSpaces("  test  string  "); // 'teststring'
removeSpaces("hello   world   test"); // 'helloworldtest'

removeExtraSpaces(str)

Removes extra spaces, keeping only single spaces between words.

removeExtraSpaces("hello    world"); // 'hello world'
removeExtraSpaces("  test   string  "); // 'test string'
removeExtraSpaces("hello   world   test"); // 'hello world test'

removeSpecialChars(str)

Removes all special characters from a string, keeping only alphanumeric characters and spaces.

removeSpecialChars("hello@world#123!"); // 'helloworld123'
removeSpecialChars("test-string_123"); // 'teststring123'
removeSpecialChars("price: $99.99"); // 'price 9999'

removeNumbers(str)

Removes all numbers from a string.

removeNumbers("hello123world456"); // 'helloworld'
removeNumbers("test123"); // 'test'
removeNumbers("abc123def456ghi"); // 'abcdefghi'

keepOnlyNumbers(str)

Keeps only numbers from a string, removing all other characters.

keepOnlyNumbers("hello123world456"); // '123456'
keepOnlyNumbers("price: $99.99"); // '9999'
keepOnlyNumbers("phone: (555) 123-4567"); // '5551234567'

trimAll(str)

Trims whitespace from the beginning and end of a string, and removes all internal whitespace.

trimAll("  hello world  "); // 'helloworld'
trimAll("  test   string  "); // 'teststring'
trimAll("  hello   world   test  "); // 'helloworldtest'

truncate(str, limit, suffix?)

Truncates a string to a specified length, optionally adding an ellipsis.

truncate("hello world", 5); // 'hello...'
truncate("hello world", 11); // 'hello world'
truncate("test", 10); // 'test'
truncate("long string here", 8, "..."); // 'long st...'
truncate("short", 10, "..."); // 'short'

String Info

countWords(str)

Counts the number of words in a string.

countWords("hello world"); // 2
countWords("hello   world   test"); // 3
countWords(""); // 0
countWords("  single  "); // 1

countChars(str, excludeWhitespace?)

Counts the number of characters in a string (excluding whitespace if specified).

countChars("hello world"); // 11
countChars("hello world", true); // 10
countChars("test"); // 4
countChars("  test  ", true); // 4

reverseString(str)

Reverses a string.

reverseString("hello"); // 'olleh'
reverseString("world"); // 'dlrow'
reverseString("test 123"); // '321 tset'

isEmpty(str)

Checks if a string is empty (has no characters).

isEmpty(""); // true
isEmpty("   "); // false (contains whitespace)
isEmpty("hello"); // false
isEmpty(null); // true
isEmpty(undefined); // true

isBlank(str)

Checks if a string is blank (empty or contains only whitespace).

isBlank(""); // true
isBlank("   "); // true
isBlank("\t\n"); // true
isBlank("hello"); // false
isBlank(null); // true
isBlank(undefined); // true

Advanced

randomString(length, charset?)

Generates a random string of specified length.

randomString(10); // 'aB3dEfG9hI' (random)
randomString(5, "0123456789"); // '38472' (random)
randomString(8, "abc"); // 'abcabcaa' (random)
randomString(6, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"); // 'XYZABC' (random)

generateSlug(str)

Generates a URL-friendly slug from a string.

generateSlug("Hello World!"); // 'hello-world'
generateSlug("This is a Test String"); // 'this-is-a-test-string'
generateSlug("JavaScript & TypeScript"); // 'javascript-typescript'
generateSlug("  Multiple   Spaces  "); // 'multiple-spaces'
generateSlug("Special@Chars#Here!"); // 'specialcharshere'

compareStrings(a, b, caseSensitive?)

Compares two strings and returns a comparison result.

compareStrings("apple", "banana"); // -1 (a < b)
compareStrings("banana", "apple"); // 1 (a > b)
compareStrings("hello", "hello"); // 0 (a === b)
compareStrings("Hello", "hello", true); // 1 (case-sensitive)
compareStrings("Hello", "hello", false); // 0 (case-insensitive)

normalizeUnicode(str)

Normalizes Unicode characters in a string (e.g., removes diacritics).

normalizeUnicode("café"); // 'cafe'
normalizeUnicode("naïve"); // 'naive'
normalizeUnicode("résumé"); // 'resume'
normalizeUnicode("Zürich"); // 'Zurich'
normalizeUnicode("São Paulo"); // 'Sao Paulo'

Complete Example

JavaScript

const strUtils = require("string-master-utils");

TypeScript

import * as strUtils from "string-master-utils";
// Case conversions
const camel = strUtils.toCamelCase('hello world'); // 'helloWorld'
const snake = strUtils.toSnakeCase('Hello World'); // 'hello_world'
const kebab = strUtils.toKebabCase('Hello World'); // 'hello-world'
const pascal = strUtils.toPascalCase('hello world'); // 'HelloWorld'
// Cleaning
const cleaned = strUtils.removeExtraSpaces('hello world'); // 'hello world'
const noSpecial = strUtils.removeSpecialChars('test@123!'); // 'test123'
const truncated = strUtils.truncate('long string', 8); // 'long st...'
// String info
const wordCount = strUtils.countWords('hello world test'); // 3
const charCount = strUtils.countChars('hello world', true); // 10
const reversed = strUtils.reverseString('hello'); // 'olleh'
// Advanced
const slug = strUtils.generateSlug('Hello World!'); // 'hello-world'
const random = strUtils.randomString(10); // 'aB3dEfG9hI'
const normalized = strUtils.normalizeUnicode('café'); // 'cafe'

Development

Building

The project is written in TypeScript. To build:

npm run build

This compiles TypeScript to JavaScript in the dist/ directory.

Testing

Run the test suite:

npm test

This will compile TypeScript and run all tests.

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Publishing to NPM

Steps to Publish

  1. Ensure you have an NPM account

    npm login
  2. Update version in package.json (if needed)

    npm version patch  # for bug fixes
    npm version minor  # for new features
    npm version major  # for breaking changes
  3. Run tests

    npm test
  4. Publish to NPM

    npm publish
  5. Verify publication

    • Check your package on npmjs.com
    • Test installation: npm install string-master-utils

Pre-publish Checklist

  • ✅ All tests pass
  • ✅ README.md is complete and accurate
  • ✅ package.json has correct name, version, and metadata
  • ✅ All functions are properly documented with JSDoc
  • ✅ No sensitive information in the package
  • ✅ .npmignore is configured correctly

Support

For issues, questions, or contributions, please open an issue on the GitHub repository.