Modules@robinpath/string
string

@robinpath/string

0.1.1Node.jsPublic

String manipulation utilities: case conversion, slugify, truncate, pad, reverse, and more

String

String manipulation utilities: case conversion, slugify, truncate, pad, reverse, and more

Package: @robinpath/string | Category: Utility | Type: Utility

Authentication

No authentication required. All functions are available immediately.

Use Cases

Use the string module when you need to:

  • Capitalize the first letter of a string -- Use string.capitalize to perform this operation
  • Convert a string to camelCase -- Use string.camelCase to perform this operation
  • Convert a string to snake_case -- Use string.snakeCase to perform this operation
  • Convert a string to kebab-case -- Use string.kebabCase to perform this operation
  • Convert a string to PascalCase -- Use string.pascalCase to perform this operation

Quick Reference

FunctionDescriptionReturns
capitalizeCapitalize the first letter of a stringString with first letter capitalized
camelCaseConvert a string to camelCasecamelCase string
snakeCaseConvert a string to snake_casesnake_case string
kebabCaseConvert a string to kebab-casekebab-case string
pascalCaseConvert a string to PascalCasePascalCase string
titleCaseCapitalize the first letter of each wordTitle Case string
slugifyConvert a string to a URL-friendly slugURL-friendly slug
truncateTruncate a string to a maximum length with a suffixTruncated string
padStartPad the start of a string to a target lengthPadded string
padEndPad the end of a string to a target lengthPadded string
reverseReverse a stringReversed string
wordCountCount the number of words in a stringNumber of words
containsCheck if a string contains a substringTrue if the string contains the substring
repeatRepeat a string N timesRepeated string
replaceAllReplace all occurrences of a search string with a replacementString with all occurrences replaced

Functions

capitalize

Capitalize the first letter of a string

Module: string | Returns: string -- String with first letter capitalized

string.capitalize "hello"
ParameterTypeRequiredDescription
strstringYesThe string to capitalize

camelCase

Convert a string to camelCase

Module: string | Returns: string -- camelCase string

string.camelCase "hello world"
ParameterTypeRequiredDescription
strstringYesThe string to convert

snakeCase

Convert a string to snake_case

Module: string | Returns: string -- snake_case string

string.snakeCase "helloWorld"
ParameterTypeRequiredDescription
strstringYesThe string to convert

kebabCase

Convert a string to kebab-case

Module: string | Returns: string -- kebab-case string

string.kebabCase "helloWorld"
ParameterTypeRequiredDescription
strstringYesThe string to convert

pascalCase

Convert a string to PascalCase

Module: string | Returns: string -- PascalCase string

string.pascalCase "hello world"
ParameterTypeRequiredDescription
strstringYesThe string to convert

titleCase

Capitalize the first letter of each word

Module: string | Returns: string -- Title Case string

string.titleCase "hello world"
ParameterTypeRequiredDescription
strstringYesThe string to convert

slugify

Convert a string to a URL-friendly slug

Module: string | Returns: string -- URL-friendly slug

string.slugify "Hello World!"
ParameterTypeRequiredDescription
strstringYesThe string to slugify

truncate

Truncate a string to a maximum length with a suffix

Module: string | Returns: string -- Truncated string

string.truncate "Hello World" 8
ParameterTypeRequiredDescription
strstringYesThe string to truncate
maxLengthnumberYesMaximum length
suffixstringNoSuffix to append (default: '...')

padStart

Pad the start of a string to a target length

Module: string | Returns: string -- Padded string

string.padStart "5" 3 "0"
ParameterTypeRequiredDescription
strstringYesThe string to pad
targetLengthnumberYesTarget length
padCharstringNoPad character (default: space)

padEnd

Pad the end of a string to a target length

Module: string | Returns: string -- Padded string

string.padEnd "hi" 5 "."
ParameterTypeRequiredDescription
strstringYesThe string to pad
targetLengthnumberYesTarget length
padCharstringNoPad character (default: space)

reverse

Reverse a string

Module: string | Returns: string -- Reversed string

string.reverse "hello"
ParameterTypeRequiredDescription
strstringYesThe string to reverse

wordCount

Count the number of words in a string

Module: string | Returns: number -- Number of words

string.wordCount "hello world"
ParameterTypeRequiredDescription
strstringYesThe string to count words in

contains

Check if a string contains a substring

Module: string | Returns: boolean -- True if the string contains the substring

string.contains "hello world" "world"
ParameterTypeRequiredDescription
strstringYesThe string to search in
substringstringYesThe substring to search for

repeat

Repeat a string N times

Module: string | Returns: string -- Repeated string

string.repeat "ab" 3
ParameterTypeRequiredDescription
strstringYesThe string to repeat
countnumberYesNumber of repetitions

replaceAll

Replace all occurrences of a search string with a replacement

Module: string | Returns: string -- String with all occurrences replaced

string.replaceAll "hello world" "o" "0"
ParameterTypeRequiredDescription
strstringYesThe input string
searchstringYesThe string to search for
replacementstringYesThe replacement string

Error Handling

All functions throw on failure. Common errors:

ErrorCause
(standard errors)Check function parameters and authentication
@desc "Capitalize and validate result"
do
  set $result as string.capitalize "hello"
  if $result != null
    print "Success"
  else
    print "No result"
  end
enddo

Recipes

1. Multi-step String workflow

Chain multiple string operations together.

@desc "Capitalize, camel case, and more"
do
  set $r_capitalize as string.capitalize "hello"
  set $r_camelCase as string.camelCase "hello world"
  set $r_snakeCase as string.snakeCase "helloWorld"
  print "All operations complete"
enddo

2. Safe capitalize with validation

Check results before proceeding.

@desc "Capitalize and validate result"
do
  set $result as string.capitalize "hello"
  if $result != null
    print "Success: " + $result
  else
    print "Operation returned no data"
  end
enddo

Related Modules

  • json -- JSON module for complementary functionality

Versions (1)

VersionTagPublished
0.1.1latest1 months ago
Install
$ robinpath add @robinpath/string

Collaborators

Dumitru Balaban
Dumitru Balaban
@dumitru
View all @robinpath modules
Version0.1.1
LicenseMIT
Unpacked Size4.8 KB
Versions1
Weekly Downloads21
Total Downloads21
Stars0
Last Publish1 months ago
Created1 months ago

Category

utilities