Installation

Learn how to install and configure @visulima/string in your project.

Last updated:

Installation

Package Manager

Install @visulima/string using your preferred package manager:

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

Requirements

  • Node.js >= 22.13.0 <= 25.x
  • TypeScript >= 5.0 (for TypeScript projects)

TypeScript Configuration

Basic Setup

The library works out of the box with TypeScript. Import functions as needed:

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

Enhanced Native String Types

For enhanced type-safe native string operations, configure your tsconfig.json:

tsconfig.json
{
    "compilerOptions": {
        "types": ["@visulima/string/native-string-types"]
    }
}

Alternatively, add a triple-slash reference in your TypeScript files:

/// <reference types="@visulima/string/native-string-types" />

This enables advanced type inference for native string methods:

const str = "Hello, World!";

// Type-safe operations with literal type inference
str.charAt<typeof str, 0>(); // type: 'H'
str.slice<typeof str, 0, 5>(); // type: 'Hello'
str.split<typeof str, ", ">(); // type: ['Hello', 'World!']

Module Imports

Full Import

Import all functions from the main entry point:

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

Subpath Imports

Import specific modules for better tree-shaking:

// Case conversion
import { camelCase } from "@visulima/string/case/camel-case";
import { pascalCase } from "@visulima/string/case/pascal-case";

// String utilities
import { slugify } from "@visulima/string/slugify";
import { truncate } from "@visulima/string/truncate";
import { wordWrap } from "@visulima/string/word-wrap";

// String width
import { getStringWidth } from "@visulima/string/get-string-width";

// Text alignment
import { alignText } from "@visulima/string/align-text";

// Outdent
import { outdent } from "@visulima/string/outdent";

Case Conversion Bundle

Import all case conversion functions:

import {
    camelCase,
    pascalCase,
    snakeCase,
    kebabCase,
    constantCase,
    dotCase,
    pathCase,
    titleCase,
    sentenceCase,
    // ... and more
} from "@visulima/string/case";

ESM and CommonJS

The package supports both ESM and CommonJS:

import { camelCase } from "@visulima/string";

CommonJS

const { camelCase } = require("@visulima/string");

Testing Utilities

For Vitest integration, import the custom matchers:

import { expect, describe, it } from "vitest";
import { toEqualAnsi } from "@visulima/string/test/vitest";
import { formatAnsiString, compareAnsiStrings } from "@visulima/string/test/utils";

// Extend Vitest with custom matchers
expect.extend({ toEqualAnsi });

describe("ANSI string tests", () => {
    it("should match colored strings", () => {
        expect(actual).toEqualAnsi(expected);
    });
});

Bundle Size

The library is designed for optimal bundle size:

  • Tree-shakeable exports
  • Minimal dependencies
  • Efficient implementations
  • Subpath imports for targeted usage

Use subpath imports to include only what you need:

// Only imports camelCase function and its dependencies
import { camelCase } from "@visulima/string/case/camel-case";

Browser Compatibility

Works in all modern browsers that support:

  • ES2020 features
  • Unicode property escapes in regex
  • BigInt (for some advanced features)

Verification

Verify the installation by running a simple test:

import { camelCase } from "@visulima/string";

console.log(camelCase("hello-world")); // Output: 'helloWorld'

Next Steps

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