1.1.3 ⢠Published 4 months ago
pragi-string v1.1.3
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 trimtruncate
: Configure text truncation with custom length and suffixexclude
: Array of words to exclude from case transformation
š License
This package is licensed under the MIT License.
Visit my portfolio: https://pragatheeswaran.vercel.app/