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 🙏

© 2024 – Pkg Stats / Ryan Hefner

string-utilss

v1.0.4

Published

A collection of useful string manipulation functions.

Downloads

272

Readme

string-utilss

A collection of useful string manipulation functions for JavaScript/TypeScript. The library provides simple utilities for converting, formatting, and manipulating strings, such as converting between camelCase, kebab-case, snake_case, title case, and more.

Table of Contents

Installation

To install the package, use npm:

npm install string-utilss

Usage

You can import the functions you need and use them as follows:

import { 
    capitalize,
    reverse,
    truncate,
    toCamelCase,
    toKebabCase,
    camelToSnake,
    snakeToCamel,
    countOccurrences,
    removeWhitespace,
    isPalindrome,
    wordCount,
    extractEmails,
    extractNumbers,
    replaceAll,
    normalize,
    slugify,
    toTitleCase
} from 'string-utilss';

// Example usage
const result = toCamelCase('hello world'); 
console.log(result); // Output: 'helloWorld'

Functions

Basic String Operations

capitalize(str: string): string Capitalizes the first letter of the string.

reverse(str: string): string Reverses the string.

truncate(str: string, maxLength: number): string Truncates the string to a specified length, adding ... if necessary.

toCamelCase(str: string): string Converts a string to camelCase.

toKebabCase(str: string): string Converts a string to kebab-case (hyphenated lowercase words).

camelToSnake(str: string): string Converts a camelCase string to snake_case.

snakeToCamel(str: string): string Converts a snake_case string to camelCase.

countOccurrences(str: string, substring: string): number Counts the occurrences of a substring within a string.


Advanced String Operations

removeWhitespace(str: string, removeAll: boolean): string Removes all whitespace or reduces multiple spaces to a single space.

  • removeAll = true: removes all whitespace characters.
  • removeAll = false: replaces multiple spaces with a single space.

isPalindrome(str: string): boolean Checks if a string is a palindrome (reads the same forwards and backwards).

**wordCount(str: string): number Counts the number of words in a string.

removeSpecialChars(str: string): string Removes all non-alphanumeric characters from the string.


Regex-Based Operations

extractEmails(str: string): string[] Extracts all email addresses from a string.

extractNumbers(str: string): number[] Extracts all numbers from a string.

replaceAll(str: string, search: string, replacement: string): string Replaces all occurrences of a substring with a replacement string.


Internationalization (i18n) Utilities

normalize(str: string): string Normalizes accented characters to their base form (removes diacritical marks).

slugify(str: string): string Converts a string into a URL-friendly slug (lowercase with hyphens).

toTitleCase(str: string): string Converts a string to Title Case (capitalizes the first letter of each word).

Contributing

We welcome contributions! To contribute, please follow these steps:

  1. Fork the repository: Click the "Fork" button at the top of this repository page to create a copy under your GitHub account.
  2. Clone your fork: Clone the repository to your local machine.
    git clone https://github.com/your-username/string-utilss.git

License

This project is licensed under the MIT License