string

utils. Namespace

string

Description:
  • A collection of string manipulation utilities. Provides functions for string formatting, slugification, truncation, and HTML stripping. These functions are useful for preparing strings for display, storage, or further processing. They help ensure strings are in a consistent format, making them easier to work with in applications

Methods

(static) capitalize(str) → {string}

Description:
  • Converts the first character of a string to uppercase.
Example
const capitalized = string.capitalize('hello world');
console.log(capitalized); // Outputs: Hello world
Parameters:
Name Type Description
str string The input string.
Returns:
or empty string if input is not a string.
Type
string

(static) slugify(str) → {string}

Description:
  • Converts a string into a URL-friendly "slug".
Example
const slug = string.slugify('Hello World! This is a test.');
console.log(slug); // Outputs: hello-world-this-is-a-test
Parameters:
Name Type Description
str string The input string.
Returns:
or empty string if input is not a string.
Type
string

(static) stripHtml(htmlString) → {string}

Description:
  • Removes all HTML tags from a string.
Example
const cleanString = string.stripHtml('<p>This is <strong>bold</strong> text.</p>');
console.log(cleanString); // Outputs: This is bold text.
Parameters:
Name Type Description
htmlString string The input string containing HTML.
Returns:
or empty string if input is not a string.
Type
string

(static) truncate(str, length, suffixopt) → {string}

Description:
  • Truncates a string to a maximum length without cutting words in half.
Example
const truncated = string.truncate('This is a long string that needs to be truncated.', 30);
console.log(truncated); // Outputs: This is a long string that...
Parameters:
Name Type Attributes Default Description
str string The input string.
length number The maximum length.
suffix string <optional>
'...' The suffix to append if truncated.
Returns:
or empty string if input is not a string.
Type
string