1.1.3 • Published 4 months ago

pragi-string v1.1.3

Weekly downloads
-
License
MIT
Repository
-
Last release
4 months ago

pragiString

šŸš€ A simple utility to transform text into different capitalization styles!

šŸ“¦ Installation

Install using npm or yarn:

npm install pragi-string

✨ Features

  • Transform text into various cases (title, sentence, camel, snake, kebab, etc.)
  • ✨ Smart text truncation with customizable length and suffix
  • šŸ” Intelligent whitespace trimming
  • šŸŽÆ Exclude specific words from case transformations
  • šŸ› ļø Convenient method-based API (e.g., pragiString.titleCase())
  • šŸ“¦ CLI tool for quick transformations
  • šŸ”’ Full TypeScript support

šŸ”„ Usage

Importing the Package

JavaScript

const pragiString = require("pragi-string");

TypeScript

import { pragiString } from "pragi-string";

šŸ›  Text Transformations

// Method-based API for better readability
pragiString.titleCase("hello world");  // Hello World
pragiString.camelCase("hello world");  // helloWorld
pragiString.snakeCase("hello world");  // hello_world

⚔ Smart Features

1ļøāƒ£ Text Truncation

// Truncate with custom length and suffix
pragiString.titleCase("this is a very long text", { 
  truncate: { length: 10, suffix: "..." } 
});
// Output: "This Is..." (truncates before case transformation)

// Custom suffix
pragiString.titleCase("this is a very long text", { 
  truncate: { length: 12, suffix: " [...]" } 
});
// Output: "This Is [...]"

2ļøāƒ£ Intelligent Trimming

// Automatically handles various whitespace scenarios
pragiString.titleCase("  hello   world  ", { trim: true });
// Output: "Hello World"

// Trim specific characters
pragiString.titleCase("***hello***world***", { 
  trim: { chars: "*" } 
});
// Output: "Hello World"

3ļøāƒ£ Word Exclusions

// Exclude specific words from case transformation
pragiString.titleCase("the quick brown fox", { 
  exclude: ["the", "of", "and"] 
});
// Output: "the Quick Brown Fox"

// Combine with other features
pragiString.titleCase("  the quick brown fox  ", { 
  exclude: ["the"],
  trim: true,
  truncate: { length: 15, suffix: "..." }
});
// Output: "the Quick Brown..."

4ļøāƒ£ Number Conversions

// Convert numbers to words
pragiString.toWords(42);  // "forty two"
pragiString.toWords(1234);  // "one thousand two hundred thirty four"

// Convert words to numbers
pragiString.toNumbers("forty two");  // 42
pragiString.toNumbers("one thousand two hundred thirty four");  // 1234

// Convert to ordinal numbers
pragiString.toOrdinal(1);  // "1st"
pragiString.toOrdinal(42);  // "42nd"

// Roman numeral conversions
pragiString.toRoman(42);  // "XLII"
pragiString.fromRoman("XLII");  // 42

// Humanize large numbers
pragiString.humanizeNumber(1234567);  // "1.2M"

// Time and duration formatting
pragiString.humanizeDuration(3665);  // "1 hour, 1 minute, 5 seconds"
pragiString.toDigitalTime(3665);  // "01:01:05"

šŸ› ļø Options

Trim Whitespace

console.log(pragiString("  hello world  ", "titlecase", { trim: true }));
// Output: "Hello World"

Exclude Words from Capitalization

console.log(pragiString("hello world example", "titlecase", { excludeWords: ["world"] }));
// Output: Hello world Example

šŸš€ CLI Usage

You can use pragiString as a command-line tool after installing it globally:

npm install -g pragi-string

Convert Text

pragi-string "hello world" uppercase
# Output: HELLO WORLD

Trim Before Conversion

pragi-string "   hello world   " titlecase --trim
# Output: Hello World

Exclude Specific Words

pragi-string "hello world example" titlecase --exclude world
# Output: Hello world Example

šŸ›  API Reference

Methods

Each transformation is available as a direct method:

  • pragiString.titleCase(text: string, options?: PragiOptions)
  • pragiString.sentenceCase(text: string, options?: PragiOptions)
  • pragiString.camelCase(text: string, options?: PragiOptions)
  • pragiString.snakeCase(text: string, options?: PragiOptions)
  • pragiString.kebabCase(text: string, options?: PragiOptions)
  • pragiString.upperCase(text: string, options?: PragiOptions)
  • pragiString.lowerCase(text: string, options?: PragiOptions)

Options

interface PragiOptions {
  trim?: boolean | { chars?: string };
  truncate?: {
    length: number;
    suffix?: string;
  };
  exclude?: string[];
}
  • trim: Enable trimming (boolean) or specify characters to trim
  • truncate: Configure text truncation with custom length and suffix
  • exclude: Array of words to exclude from case transformation

šŸ“œ License

This package is licensed under the MIT License.


Visit my portfolio: https://pragatheeswaran.vercel.app/