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

simple-string-utils

v1.0.3

Published

A lightweight utility library for common string manipulation tasks.

Downloads

1

Readme

Simple String Utils

A lightweight utility library for common string manipulation tasks.

Installation

Install the package using npm:

npm install simple-string-utils

Usage

Import the desired functions from the library and use them in your JavaScript code:

javascript

const {
    reverseString,
    capitalizeString,
    countWords,
    truncateString,
    camelCase,
    kebabCase,
    snakeCase,
    isPalindrome,
    removeWhitespace,
    repeatString,
    replaceSubstring,
    randomString
} = require('simple-string-utils');


const reversed = reverseString('hello world');
console.log(reversed); // Output: 'dlrow olleh'

const capitalized = capitalizeString('hello world');
console.log(capitalized); // Output: 'Hello world'

const wordCount = countWords('hello world');
console.log(wordCount); // Output: 2

const truncated = truncateString('hello world', 5);
console.log(truncated); // Output: 'hello...'

const camelCased = camelCase('hello world');
console.log(camelCased); // Output: 'helloWorld'

const kebabCased = kebabCase('hello world');
console.log(kebabCased); // Output: 'hello-world'

const snakeCased = snakeCase('hello world');
console.log(snakeCased); // Output: 'hello_world'

console.log(isPalindrome('A man, a plan, a canal, Panama!')); // Output: true
console.log(removeWhitespace('Hello, World!')); // Output: 'Hello,World!'
console.log(repeatString('abc', 3)); // Output: 'abcabcabc'
console.log(replaceSubstring('Hello, World!', 'World', 'Universe')); // Output: 'Hello, Universe!'
console.log(randomString(10)); // Output: A random string of 10 characters, e.g., 'Gs8fhKj1Mq'

Functions

reverseString(str) Reverses the given string.

Parameters:

str (String): The input string to reverse. Returns: A new string with the characters in reverse order.

capitalizeString(str) Capitalizes the first character of the given string.

Parameters:

str (String): The input string to capitalize. Returns: A new string with the first character capitalized.

countWords(str) Counts the number of words in the given string.

Parameters:

str (String): The input string to count words in. Returns: The number of words in the input string.

truncateString(str, maxLength) Truncates the given string to the specified maximum length.

Parameters:

str (String): The input string to truncate. maxLength (Number): The maximum allowed length for the output string. Returns: A new string truncated to the specified maximum length, with '...' added if the input string is longer than the maximum length.

camelCase(str) Converts the given string to camel case.

Parameters:

str (String): The input string to convert. Returns: A new string in camel case format.

kebabCase(str) Converts the given string to kebab case.

Parameters:

str (String): The input string to convert. Returns: A new string in kebab case format.

snakeCase(str) Converts the given string to snake case.

Parameters:

str (String): The input string to convert. Returns: A new string in snake case format.

isPalindrome(str) Checks if the given string is a palindrome (ignoring whitespace, punctuation, and letter case).

Parameters:

str (String): The input string to check. Returns: true if the string is a palindrome, false otherwise.

removeWhitespace(str) Removes all whitespace characters from the given string.

Parameters:

str (String): The input string to remove whitespace from. Returns: A new string with all whitespace characters removed.

repeatString(str, times) Repeats the given string n times.

Parameters:

str (String): The input string to repeat. times (Number): The number of times to repeat the string. Returns: A new string with the input string repeated the specified number of times.

replaceSubstring(str, oldSubstring, newSubstring) Replaces all occurrences of a substring with a new substring.

Parameters:

str (String): The input string to process. oldSubstring (String): The substring to be replaced. newSubstring (String): The substring to replace the old substring with. Returns: A new string with all occurrences of the old substring replaced with the new substring.

randomString(length) Generates a random string of a given length.

Parameters:

length (Number): The desired length of the random string. Returns: A new random string of the specified length, composed of uppercase and lowercase letters and digits.