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

@lutlelk-tools/string

v1.0.0

Published

String utilities including validation, transformation, formatting, encoding, and generation functions

Readme

@lutlelk-tools/string

A comprehensive string utility library for TypeScript/JavaScript with validation, transformation, formatting, encoding, and generation capabilities.

Installation

npm install @lutlelk-tools/string
# or
pnpm add @lutlelk-tools/string
# or
yarn add @lutlelk-tools/string

Usage

Import the entire package

import { toCamelCase, slugify, isEmail, mask } from '@lutlelk-tools/string'

toCamelCase('hello-world') // => "helloWorld"
slugify('Hello World!') // => "hello-world"
isEmail('[email protected]') // => true

Import specific functions (tree-shaking supported)

import { toKebabCase, capitalize, generateUUID } from '@lutlelk-tools/string'

toKebabCase('helloWorld') // => "hello-world"
capitalize('hello') // => "Hello"
generateUUID() // => "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx"

API

Validation

isBlank(value: unknown): boolean

Check if value is blank (null, undefined, or empty string).

isBlank('') // => true
isBlank('   ') // => true
isBlank(null) // => true
isBlank('hello') // => false

isEmail(value: string): boolean

Check if value is a valid email address.

isEmail('[email protected]') // => true
isEmail('invalid-email') // => false

isUrl(value: string): boolean

Check if value is a valid URL.

isUrl('https://example.com') // => true
isUrl('not-a-url') // => false

isPhone(value: string, pattern?: RegExp): boolean

Check if value is a valid phone number.

isPhone('13800138000') // => true
isPhone('12345') // => false

isUUID(value: string): boolean

Check if value is a valid UUID.

isUUID('550e8400-e29b-41d4-a716-446655440000') // => true
isUUID('not-a-uuid') // => false

isHex(value: string): boolean

Check if value is a hexadecimal string.

isHex('ff00ff') // => true
isHex('xyz') // => false

isBase64(value: string): boolean

Check if value is a valid Base64 string.

isBase64('SGVsbG8gV29ybGQ=') // => true
isBase64('not-base64!') // => false

isJson(value: string): boolean

Check if value is valid JSON.

isJson('{"name":"John"}') // => true
isJson('not-json') // => false

isNumeric(value: string): boolean

Check if value is numeric.

isNumeric('123.45') // => true
isNumeric('abc') // => false

isAlpha(value: string): boolean

Check if value contains only letters.

isAlpha('hello') // => true
isAlpha('hello123') // => false

isAlphanumeric(value: string): boolean

Check if value contains only letters and numbers.

isAlphanumeric('hello123') // => true
isAlphanumeric('hello!') // => false

isLowercase(value: string): boolean

Check if value is all lowercase.

isLowercase('hello') // => true
isLowercase('Hello') // => false

isUppercase(value: string): boolean

Check if value is all uppercase.

isUppercase('HELLO') // => true
isUppercase('Hello') // => false

Query

startsWith(value: string, search: string, position?: number): boolean

Check if string starts with search string.

startsWith('hello world', 'hello') // => true
startsWith('hello world', 'world') // => false

endsWith(value: string, search: string, length?: number): boolean

Check if string ends with search string.

endsWith('hello world', 'world') // => true
endsWith('hello world', 'hello') // => false

includes(value: string, search: string, position?: number): boolean

Check if string contains search string.

includes('hello world', 'world') // => true
includes('hello world', 'test') // => false

contains(value: string, search: string): boolean

Check if string contains search string (alias for includes).

contains('hello world', 'world') // => true

equals(value: string, other: string, ignoreCase?: boolean): boolean

Check if two strings are equal.

equals('hello', 'hello') // => true
equals('hello', 'HELLO', true) // => true
equals('hello', 'HELLO') // => false

Case Conversion

toCamelCase(value: string): string

Convert string to camelCase.

toCamelCase('hello-world') // => "helloWorld"
toCamelCase('hello_world') // => "helloWorld"
toCamelCase('Hello World') // => "helloWorld"

toPascalCase(value: string): string

Convert string to PascalCase.

toPascalCase('hello-world') // => "HelloWorld"
toPascalCase('hello_world') // => "HelloWorld"

toKebabCase(value: string): string

Convert string to kebab-case.

toKebabCase('helloWorld') // => "hello-world"
toKebabCase('HelloWorld') // => "hello-world"

toSnakeCase(value: string): string

Convert string to snake_case.

toSnakeCase('helloWorld') // => "hello_world"
toSnakeCase('HelloWorld') // => "hello_world"

toCapitalCase(value: string): string

Convert string to Capital Case.

toCapitalCase('hello-world') // => "Hello World"
toCapitalCase('hello_world') // => "Hello World"

toSentenceCase(value: string): string

Convert string to sentence case.

toSentenceCase('HELLO WORLD') // => "Hello world"
toSentenceCase('hello world') // => "Hello world"

toLowerCase(value: string): string

Convert string to lowercase.

toLowerCase('HELLO WORLD') // => "hello world"

toUpperCase(value: string): string

Convert string to uppercase.

toUpperCase('hello world') // => "HELLO WORLD"

toTitleCase(value: string): string

Convert string to title case.

toTitleCase('hello world') // => "Hello World"
toTitleCase('HELLO WORLD') // => "Hello World"

Trimming

trim(value: string, chars?: string): string

Remove characters from both ends of string.

trim('  hello  ') // => "hello"
trim('---hello---', '-') // => "hello"
trim('***hello***', '*') // => "hello"

trimStart(value: string, chars?: string): string

Remove characters from start of string.

trimStart('  hello  ') // => "hello  "
trimStart('---hello---', '-') // => "hello---"

trimEnd(value: string, chars?: string): string

Remove characters from end of string.

trimEnd('  hello  ') // => "  hello"
trimEnd('---hello---', '-') // => "---hello"

Padding

pad(value: string, length: number, char?: string): string

Pad string on both sides.

pad('hello', 10) // => "  hello   "
pad('hello', 10, '*') // => "**hello***"

padStart(value: string, length: number, char?: string): string

Pad string at the start.

padStart('hello', 10) // => "     hello"
padStart('hello', 10, '0') // => "00000hello"

padEnd(value: string, length: number, char?: string): string

Pad string at the end.

padEnd('hello', 10) // => "hello     "
padEnd('hello', 10, '0') // => "hello00000"

Manipulation

truncate(value: string, length: number, omission?: string): string

Truncate string to specified length.

truncate('hello world', 5) // => "he..."
truncate('hello world', 8, '...') // => "hello..."
truncate('hello', 10) // => "hello"

repeat(value: string, count: number): string

Repeat string count times.

repeat('hello', 3) // => "hellohellohello"
repeat('ab', 2) // => "abab"

replace(value: string, search: string | RegExp, replacement: string): string

Replace first occurrence of search string.

replace('hello world', 'world', 'there') // => "hello there"
replace('hello world', /o/, 'a') // => "hella world"

replaceAll(value: string, search: string | RegExp, replacement: string): string

Replace all occurrences of search string.

replaceAll('hello world', 'l', 'x') // => "hexxo worxd"
replaceAll('hello world', /o/g, 'a') // => "hella warld"

slice(value: string, start?: number, end?: number): string

Extract section of string.

slice('hello world', 0, 5) // => "hello"
slice('hello world', 6) // => "world"
slice('hello world', -5) // => "world"

substring(value: string, start: number, end?: number): string

Extract characters from string between indices.

substring('hello world', 0, 5) // => "hello"
substring('hello world', 6) // => "world"

split(value: string, separator: string | RegExp, limit?: number): string[]

Split string into array.

split('hello world', ' ') // => ["hello", "world"]
split('a,b,c', ',') // => ["a", "b", "c"]

join(values: string[], separator?: string): string

Join array of strings.

join(['hello', 'world'], ' ') // => "hello world"
join(['a', 'b', 'c'], ',') // => "a,b,c"

reverse(value: string): string

Reverse string.

reverse('hello') // => "olleh"
reverse('world') // => "dlrow"

Character Operations

capitalize(value: string): string

Capitalize first character.

capitalize('hello') // => "Hello"
capitalize('hello world') // => "Hello world"

uncapitalize(value: string): string

Uncapitalize first character.

uncapitalize('Hello') // => "hello"
uncapitalize('Hello World') // => "hello World"

length(value: string): number

Get string length.

length('hello') // => 5
length('hello world') // => 11

size(value: string): number

Get string size (alias for length).

size('hello') // => 5

charAt(value: string, index: number): string

Get character at index.

charAt('hello', 0) // => "h"
charAt('hello', 4) // => "o"

charCodeAt(value: string, index: number): number

Get character code at index.

charCodeAt('hello', 0) // => 104
charCodeAt('hello', 4) // => 111

Position

indexOf(value: string, search: string, fromIndex?: number): number

Get index of first occurrence.

indexOf('hello world', 'world') // => 6
indexOf('hello world', 'test') // => -1

lastIndexOf(value: string, search: string, fromIndex?: number): number

Get index of last occurrence.

lastIndexOf('hello world hello', 'hello') // => 12
lastIndexOf('hello world', 'test') // => -1

Counting

count(value: string, search: string): number

Count occurrences of substring.

count('hello world hello', 'hello') // => 2
count('hello world', 'l') // => 3

countWords(value: string): number

Count words in string.

countWords('hello world') // => 2
countWords('  hello   world  ') // => 2

countChars(value: string, char: string): number

Count occurrences of character.

countChars('hello', 'l') // => 2
countChars('hello world', 'o') // => 2

Slicing

first(value: string, n?: number): string

Get first n characters.

first('hello world') // => "h"
first('hello world', 5) // => "hello"

last(value: string, n?: number): string

Get last n characters.

last('hello world') // => "d"
last('hello world', 5) // => "world"

initial(value: string, n?: number): string

Get all but last n characters.

initial('hello world') // => "hello worl"
initial('hello world', 6) // => "hello"

rest(value: string, n?: number): string

Get all but first n characters.

rest('hello world') // => "ello world"
rest('hello world', 6) // => "world"

nth(value: string, index: number): string

Get character at index.

nth('hello', 0) // => "h"
nth('hello', 4) // => "o"

Insert/Remove

insert(value: string, index: number, substring: string): string

Insert substring at index.

insert('hello world', 5, ' beautiful') // => "hello beautiful world"
insert('hello', 0, 'say ') // => "say hello"

remove(value: string, search: string | RegExp): string

Remove first occurrence.

remove('hello world', 'world') // => "hello "
remove('hello world', /o/) // => "hella world"

removeAll(value: string, search: string | RegExp): string

Remove all occurrences.

removeAll('hello world hello', 'hello') // => " world "
removeAll('hello world', /l/g) // => "heo word"

Extraction

before(value: string, search: string): string

Get substring before search string.

before('hello world', 'world') // => "hello "
before('hello world', 'test') // => "hello world"

after(value: string, search: string): string

Get substring after search string.

after('hello world', 'hello') // => " world"
after('hello world', 'test') // => ""

between(value: string, start: string, end: string): string

Get substring between start and end.

between('hello [world] test', '[', ']') // => "world"
between('hello (world) test', '(', ')') // => "world"

Splitting

words(value: string, pattern?: RegExp): string[]

Split string into words.

words('hello world') // => ["hello", "world"]
words('hello-world', /[-\s]+/) // => ["hello", "world"]

chars(value: string): string[]

Split string into characters.

chars('hello') // => ["h", "e", "l", "l", "o"]

lines(value: string): string[]

Split string into lines.

lines('hello\nworld') // => ["hello", "world"]
lines('hello\r\nworld') // => ["hello", "world"]

Template

template(value: string, data: Record<string, unknown>): string

Replace {{key}} placeholders.

template('Hello {{name}}!', { name: 'John' }) // => "Hello John!"
template('Age: {{age}}', { age: 30 }) // => "Age: 30"

interpolate(value: string, data: Record<string, unknown>): string

Replace ${key} placeholders.

interpolate('Hello ${name}!', { name: 'John' }) // => "Hello John!"
interpolate('Age: ${age}', { age: 30 }) // => "Age: 30"

format(value: string, ...args: unknown[]): string

Format string with positional arguments.

format('Hello {0}!', 'John') // => "Hello John!"
format('{0} + {1} = {2}', 1, 2, 3) // => "1 + 2 = 3"

Formatting

slugify(value: string): string

Convert string to URL-friendly slug.

slugify('Hello World!') // => "hello-world"
slugify('This is a Test') // => "this-is-a-test"

Escaping

escape(value: string): string

Escape HTML special characters.

escape('<div>hello</div>') // => "&lt;div&gt;hello&lt;/div&gt;"
escape('"hello"') // => "&quot;hello&quot;"

unescape(value: string): string

Unescape HTML special characters.

unescape('&lt;div&gt;hello&lt;/div&gt;') // => "<div>hello</div>"
unescape('&quot;hello&quot;') // => "\"hello\""

escapeRegExp(value: string): string

Escape special regex characters.

escapeRegExp('hello.world') // => "hello\\.world"
escapeRegExp('[test]') // => "\\[test\\]"

stripTags(value: string): string

Remove HTML tags.

stripTags('<div>hello</div>') // => "hello"
stripTags('<p>test</p>') // => "test"

stripHtml(value: string): string

Remove HTML and decode entities.

stripHtml('<div>hello</div>') // => "hello"
stripHtml('&amp;') // => "&"

Encoding

encodeBase64(value: string): string

Encode string to Base64.

encodeBase64('hello world') // => "aGVsbG8gd29ybGQ="
encodeBase64('你好') // => "5L2g5aW9"

decodeBase64(value: string): string

Decode Base64 string.

decodeBase64('aGVsbG8gd29ybGQ=') // => "hello world"
decodeBase64('5L2g5aW9') // => "你好"

encodeURI(value: string): string

Encode URI component.

encodeURI('hello world') // => "hello%20world"
encodeURI('你好') // => "%E4%BD%A0%E5%A5%BD"

decodeURI(value: string): string

Decode URI component.

decodeURI('hello%20world') // => "hello world"
decodeURI('%E4%BD%A0%E5%A5%BD') // => "你好"

Hash

hashCode(value: string): number

Get hash code of string.

hashCode('hello') // => 99162322
hashCode('world') // => 113318802

Generation

generateUUID(): string

Generate a random UUID.

generateUUID() // => "550e8400-e29b-41d4-a716-446655440000"

random(length?: number): string

Generate random alphanumeric string.

random() // => "aB3xY9zP2kL8mN4"
random(8) // => "xY9zP2kL"

randomNumeric(length?: number): string

Generate random numeric string.

randomNumeric() // => "1234567890123456"
randomNumeric(8) // => "12345678"

randomAlpha(length?: number): string

Generate random alphabetic string.

randomAlpha() // => "aBxYzPkLmN"
randomAlpha(8) // => "xYzPkLmN"

randomAlphaNumeric(length?: number): string

Generate random alphanumeric string (alias for random).

randomAlphaNumeric() // => "aB3xY9zP2kL8mN4"

randomHex(length?: number): string

Generate random hexadecimal string.

randomHex() // => "a3f2b9c4d8e1f6a7"
randomHex(8) // => "a3f2b9c4"

Masking

mask(value: string, visibleChars?: number, maskChar?: string): string

Mask string with visible characters at end.

mask('1234567890') // => "******7890"
mask('1234567890', 4, '*') // => "******7890"
mask('hello world', 2, '#') // => "#########ld"

maskEmail(email: string, maskChar?: string): string

Mask email address.

maskEmail('[email protected]') // => "jo******@example.com"
maskEmail('[email protected]', '#') // => "te**@example.com"

maskPhone(phone: string, maskChar?: string): string

Mask phone number.

maskPhone('13800138000') // => "138****8000"
maskPhone('1234567890', '#') // => "123####890"

Abbreviation

abbreviate(value: string, length?: number): string

Abbreviate string.

abbreviate('hello world') // => "hello worl."
abbreviate('hello', 10) // => "hello"

initials(value: string): string

Get initials from string.

initials('John Doe') // => "JD"
initials('hello world test') // => "hwt"

Case Swapping

swapCase(value: string): string

Swap case of all characters.

swapCase('Hello World') // => "hELLO wORLD"
swapCase('ABC') // => "abc"

Shuffling

shuffle(value: string): string

Shuffle characters in string.

shuffle('hello') // => "loleh" (random order)

Prefix/Suffix

ensurePrefix(value: string, prefix: string): string

Ensure string starts with prefix.

ensurePrefix('world', 'hello ') // => "hello world"
ensurePrefix('hello world', 'hello ') // => "hello world"

ensureSuffix(value: string, suffix: string): string

Ensure string ends with suffix.

ensureSuffix('hello', ' world') // => "hello world"
ensureSuffix('hello world', ' world') // => "hello world"

stripPrefix(value: string, prefix: string): string

Remove prefix if present.

stripPrefix('hello world', 'hello ') // => "world"
stripPrefix('world', 'hello ') // => "world"

stripSuffix(value: string, suffix: string): string

Remove suffix if present.

stripSuffix('hello world', ' world') // => "hello"
stripSuffix('hello', ' world') // => "hello"

Indentation

dedent(value: string): string

Remove common indentation.

dedent('  hello\n  world') // => "hello\nworld"

indent(value: string, indent?: string, count?: number): string

Add indentation to each line.

indent('hello\nworld', '  ') // => "  hello\n  world"
indent('hello\nworld', '  ', 2) // => "    hello\n    world"

wrap(value: string, width?: number, separator?: string): string

Wrap text to specified width.

wrap('hello world this is a test', 10)
// => "hello\nworld\nthis is a\ntest"

Utility

toString(value: StringInput): string

Convert value to string.

toString(123) // => "123"
toString(null) // => ""
toString(undefined) // => ""
toString(true) // => "true"

License

MIT