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

str-string-helper

v1.0.5

Published

A powerful TypeScript utility library for advanced string manipulation.

Readme

🏆 Str String Helper

A powerful TypeScript utility library for advanced string manipulation, inspired by Laravel's Str helper. This package provides an intuitive API for handling strings with chaining support.


📦 Installation

Install the package via NPM:

npm install str-string-helper

Or via Yarn:

yarn add str-string-helper

🚀 Getting Started

📌 Import the Library

import { Str } from 'str-string-helper';

🔥 Quick Examples

✅ Generate a Random String

const randomStr = Str.random(12).get();
console.log(randomStr); // Example: 'A1b2C3d4E5F6'

✅ Manipulating Strings

const result = Str.from('Hello World!').lowercase().sanitize().get();
console.log(result); // "helloworld"

🎯 Features & Examples

🔢 Generate Random Strings with mix character

console.log(Str.random(16).get());
// Output: Random alphanumeric string of length 16

🔢 Generate Random Number

console.log(Str.randomNumber(16).get());
// Output: Random number of length 16

🔢 Generate Random Strings

console.log(Str.randomString(16).get());
// Output: Random alphanumeric string of length 16

🛠️ String Formatting

Convert Case

console.log(Str.from('hello world').capitalize().get());
// Output: 'Hello world'

Convert to StudlyCase

console.log(Str.from('foo_bar').studly().get());
// Output: 'FooBar'

Convert to Snake Case

console.log(Str.from('fooBar').snake().get());
// Output: 'foo_bar'

Convert to Base64

console.log(Str.from('Doracone').toBase64().get());
// Output: 'TGFydfYXZlbA=='

📝 String Modification

Replace Substring

console.log(Str.from('The Framework').substrReplace(' Doracone', 3, 0).get());
// Output: 'The Doracone Framework'

Remove HTML Tags

console.log(Str.from('<a href="https://doracone.com"><b>Manna</b></a>').stripTags().get());
// Output: 'Manna'

🔍 String Validation & Checking

Starts With

console.log(Str.from('This is my name').startsWith('This'));
// Output: true

Ends With

console.log(Str.from('disney world').whenEndsWith('world', (str) => str.capitalize()).get());
// Output: 'Disney World'

🔀 String Transformations

Split String

console.log(Str.from('one, two, three').split(/[,\s]+/).get());
// Output: ['one', 'two', 'three']

Wrap String

console.log(Str.from('Doracone').wrap('"').get());
// Output: '"Doracone"'

🤖 Conditional String Operations

Apply Changes If Condition is Met

console.log(Str.from('doracone').whenExactly('doracone', (str) => str.capitalize()).get());
// Output: 'Doracone'
console.log(Str.from('framework').whenNotExactly('doracone', (str) => str.capitalize()).get());
// Output: 'Framework'

🎭 Special Operations

Trim Extra Spaces

console.log(Str.from('    Doracone    framework    ').squish().get());
// Output: 'Doracone framework'

Append a Prefix

console.log(Str.from('this/string').start('/').get());
// Output: '/this/string'

🔍 Complete API Reference

🏗️ String Creation

  • Str.random(length: number): Str → Generate a random alphanumeric string.
  • Str.from(value: string): Str → Create a wrapper instance for chaining operations.

🏷️ Case Conversion

  • .lowercase(): this → Convert to lowercase.
  • .uppercase(): this → Convert to uppercase.
  • .capitalize(): this → Capitalize the first letter.
  • .studly(): this → Convert to StudlyCase.
  • .snake(): this → Convert to snake_case.

🔧 String Manipulation

  • .replace(search: string | RegExp, replace: string): this → Replace substring.
  • .replaceAll(search: string | RegExp, replace: string): this → Replace all occurrences.
  • .substr(start: number, length?: number): this → Extract substring.
  • .substrReplace(replace: string, start: number, length?: number): this → Replace substring.
  • .squish(): this → Trim extra spaces.
  • .wrap(before?: string, after?: string): this → Wrap the string.

🔍 String Checking

  • .contains(search: string): boolean → Check if the string contains a substring.
  • .startsWith(search: string): boolean → Check if it starts with a given string.
  • .endsWith(search: string): boolean → Check if it ends with a given string.

🔀 Transformations

  • .split(pattern: RegExp): string[] → Split string by pattern.
  • .stripTags(allowedTags?: string): this → Remove HTML tags.
  • .toBase64(): this → Convert to Base64.

🤖 Conditional Modifiers

  • .when(condition: boolean, callback: (str: Str) => Str): this → Apply transformation if condition is met.
  • .whenExactly(match: string, callback: (str: Str) => Str): this → Apply transformation if string exactly matches.
  • .whenNotExactly(match: string, callback: (str: Str) => Str): this → Apply transformation if string does not match.
  • .whenStartsWith(match: string, callback: (str: Str) => Str): this → Apply transformation if starts with.
  • .whenEndsWith(match: string, callback: (str: Str) => Str): this → Apply transformation if ends with.

📤 Output

  • .get(): string → Retrieve the final string value.

🛠️ Running Tests

Run unit tests with Jest:

npm test

📜 License

Released under the MIT License.

🚀 Happy Coding!