Getting Started

A robust string manipulation library providing utilities for common string operations with support for multiple languages and scripts.

Last updated:

Getting Started

@visulima/string is a comprehensive TypeScript library for string manipulation, providing utilities for case conversion, text formatting, internationalization, and advanced string operations.

Key Features

Case Conversion

Transform strings between multiple case styles with intelligent handling of acronyms and multi-language support:

  • camelCase, PascalCase, snake_case, kebab-case
  • CONSTANT_CASE, dot.case, path/case
  • Title Case with smart minor word handling
  • Sentence case, Train-Case, and more

Unicode and Multi-Language Support

Full support for international text processing:

  • CJK Scripts (Japanese, Korean, Chinese)
  • European Scripts (Cyrillic, Greek, Latin)
  • RTL Scripts (Arabic, Hebrew)
  • Indic Scripts (Devanagari, Bengali, Tamil)
  • Southeast Asian (Thai, Lao, Khmer)

String Width and Truncation

Accurate visual width calculation and intelligent truncation:

  • Unicode-aware width calculation
  • ANSI escape code handling
  • Smart truncation with ellipsis support
  • Emoji and zero-width character support

Text Formatting

Advanced text formatting utilities:

  • Word wrapping with multiple modes
  • Text alignment (left, center, right)
  • Indentation removal (outdent)
  • ANSI color code preservation

Additional Features

  • String analysis: count occurrences and detect text direction
  • Slugification with transliteration
  • Levenshtein distance calculation
  • String similarity comparison
  • Advanced string replacement with ignore ranges
  • Type-safe native string extensions

Quick Start

Installation

npm install @visulima/string
yarn add @visulima/string
pnpm add @visulima/string

Basic Usage

import { camelCase, slugify, truncate, wordWrap } from "@visulima/string";

// Case conversion
camelCase("hello-world"); // 'helloWorld'

// Slugification
slugify("Hello World!"); // 'hello-world'

// Truncation
truncate("A very long string", 10); // 'A very lo…'

// Word wrapping
wordWrap("This is a long text that needs wrapping", { width: 20 });

Next Steps

TypeScript Support

The library is written in TypeScript and provides comprehensive type definitions:

import type { CaseOptions, TruncateOptions } from "@visulima/string";

const options: CaseOptions = {
    locale: "en",
    knownAcronyms: ["API", "URL"],
    cache: true,
};

Performance

The library is optimized for performance with:

  • Precompiled regex patterns
  • Smart caching mechanisms
  • Efficient string processing
  • Minimal memory allocations

Browser and Node.js Support

Works seamlessly in both environments:

  • Node.js >= 18.0.0
  • All modern browsers
  • TypeScript >= 5.0
Support

Contribute to our work and keep us going

Community is the heart of open source. The success of our packages wouldn't be possible without the incredible contributions of users, testers, and developers who collaborate with us every day.Want to get involved? Here are some tips on how you can make a meaningful impact on our open source projects.

Ready to help us out?

Be sure to check out the package's contribution guidelines first. They'll walk you through the process on how to properly submit an issue or pull request to our repositories.

Submit a pull request

Found something to improve? Fork the repo, make your changes, and open a PR. We review every contribution and provide feedback to help you get merged.

Good first issues

Simple issues suited for people new to open source development, and often a good place to start working on a package.
View good first issues