/** * Options for title case conversion */ interface TitleCaseOptions { /** * Preserve known acronyms in uppercase (default: true) * @example PT, CV, TNI, POLRI */ preserveAcronyms?: boolean; /** * Strict mode forces lowercase before capitalizing (default: false) */ strict?: boolean; /** * Additional words to keep lowercase (extends default list) */ exceptions?: string[]; } /** * Options for abbreviation expansion */ interface ExpandOptions { /** * Filter abbreviations by category * - 'all': Expand all abbreviations (default) * - 'address': Only expand address abbreviations * - 'title': Only expand title abbreviations * - 'org': Only expand organization abbreviations */ mode?: 'all' | 'address' | 'title' | 'org'; /** * Custom abbreviation mappings (overrides built-in) */ customMap?: Record; /** * Preserve original case of expanded text (default: false) */ preserveCase?: boolean; } /** * Options for slug generation */ interface SlugifyOptions { /** * Separator character (default: '-') */ separator?: string; /** * Convert to lowercase (default: true) */ lowercase?: boolean; /** * Custom character replacements */ replacements?: Record; /** * Trim leading/trailing separators (default: true) */ trim?: boolean; } /** * Options for text sanitization */ interface SanitizeOptions { /** * Remove newline characters (default: false) */ removeNewlines?: boolean; /** * Remove extra spaces (default: true) */ removeExtraSpaces?: boolean; /** * Remove all punctuation (default: false) */ removePunctuation?: boolean; /** * Only allow specific characters (regex pattern) */ allowedChars?: string; /** * Trim leading/trailing whitespace (default: true) */ trim?: boolean; } /** * Options for string comparison */ interface CompareOptions { /** * Case-sensitive comparison (default: false) */ caseSensitive?: boolean; /** * Ignore whitespace differences (default: false) */ ignoreWhitespace?: boolean; /** * Ignore accent/diacritic marks (default: false) */ ignoreAccents?: boolean; } /** * Options for word extraction */ interface ExtractOptions { /** * Minimum word length to include */ minLength?: number; /** * Treat hyphenated words as single word (default: true) * @example 'anak-anak' is one word */ includeHyphenated?: boolean; /** * Convert extracted words to lowercase (default: false) */ lowercase?: boolean; } /** * Options for text truncation */ interface TruncateOptions { /** * Ellipsis string (default: '...') */ ellipsis?: string; /** * Truncate at word boundary (default: true) */ wordBoundary?: boolean; } /** * Options for text masking */ interface MaskOptions { /** * Masking pattern to apply * - `all`: Mask all characters (preserves spaces) * - `middle`: Keep start and end visible, mask middle * - `email`: Keep first 2 chars of local part and full domain */ pattern?: 'all' | 'middle' | 'email'; /** * Character to use for masking (default: '*') */ maskChar?: string; /** * Number of characters to keep visible at start (for 'middle' pattern, default: 2) */ visibleStart?: number; /** * Number of characters to keep visible at end (for 'middle' pattern, default: 2) */ visibleEnd?: number; /** * Optional separator to add between groups. * * @defaultValue undefined */ separator?: string; /** * @deprecated Use `visibleStart` instead. Deprecated in v0.7.0. */ start?: number; /** * @deprecated Use `visibleEnd` instead. Deprecated in v0.7.0. */ end?: number; /** * @deprecated Use `maskChar` instead. Deprecated in v0.7.0. */ char?: string; } /** * Capitalize the first letter of a string and lowercase the rest * * This function converts the first character to uppercase and all remaining * characters to lowercase. It handles empty strings, Unicode characters, * and multi-word strings (only first word is affected). * * @param text - The text to capitalize * @returns The capitalized text * * @example * Basic usage: * ```typescript * capitalize('joko') // → 'Joko' * capitalize('JOKO') // → 'Joko' * capitalize('jOKO') // → 'Joko' * ``` * * @example * Multi-word strings (only first word capitalized): * ```typescript * capitalize('joko widodo') // → 'Joko widodo' * capitalize('JOKO WIDODO') // → 'Joko widodo' * ``` * * @example * Edge cases: * ```typescript * capitalize('') // → '' * capitalize('a') // → 'A' * capitalize('123abc') // → '123abc' * ``` * * @public */ declare function capitalize(text: string): string; /** * Convert text to title case following Indonesian grammar rules * * This function capitalizes the first letter of each word while respecting * Indonesian language conventions: * - Keeps particles lowercase (di, ke, dari, untuk, dan, etc.) * - Preserves known acronyms in uppercase (PT, CV, TNI, DKI, etc.) * - Handles hyphenated words correctly (anak-anak → Anak-Anak) * - Normalizes whitespace automatically * * @param text - The text to convert to title case * @param options - Optional configuration * @returns The title-cased text with proper Indonesian grammar * * @example * Basic usage: * ```typescript * toTitleCase('joko widodo') * // → 'Joko Widodo' * * toTitleCase('JOKO WIDODO') * // → 'Joko Widodo' * ``` * * @example * Indonesian particles (kept lowercase): * ```typescript * toTitleCase('buku untuk anak dan orang tua') * // → 'Buku untuk Anak dan Orang Tua' * * toTitleCase('dari jakarta ke bandung') * // → 'Dari Jakarta ke Bandung' * // (first word always capitalized) * ``` * * @example * Acronyms (preserved in uppercase): * ```typescript * toTitleCase('pt bank bca tbk') * // → 'PT Bank BCA Tbk' * * toTitleCase('dki jakarta') * // → 'DKI Jakarta' * * toTitleCase('tni angkatan darat') * // → 'TNI Angkatan Darat' * ``` * * @example * Hyphenated words: * ```typescript * toTitleCase('anak-anak bermain') * // → 'Anak-Anak Bermain' * * toTitleCase('makan-makan di rumah') * // → 'Makan-Makan di Rumah' * ``` * * @example * With options: * ```typescript * toTitleCase('PT BCA', { preserveAcronyms: false }) * // → 'Pt Bca' * * toTitleCase('mobil dari jepang', { exceptions: ['jepang'] }) * // → 'Mobil dari jepang' * * toTitleCase('HELLO WORLD', { strict: true }) * // → 'Hello World' * ``` * * @public */ declare function toTitleCase(text: string, options?: TitleCaseOptions): string; /** * Convert text to sentence case (capitalize first letter of sentences only) * * This function capitalizes the first character of the text and the first * character after sentence-ending punctuation (. ! ?), while keeping * everything else in lowercase. * * **Sentence Detection Rules:** * - Period (.), exclamation (!), question mark (?) mark sentence endings * - Next letter after punctuation + space is capitalized * - Handles multiple spaces and newlines * - Does NOT treat abbreviations as sentence endings (e.g., "Dr. Smith") * * @param text - The text to convert to sentence case * @returns The sentence-cased text * * @example * Basic usage: * ```typescript * toSentenceCase('JOKO WIDODO ADALAH PRESIDEN') * // → 'Joko widodo adalah presiden' * * toSentenceCase('joko widodo adalah presiden') * // → 'Joko widodo adalah presiden' * ``` * * @example * Multiple sentences: * ```typescript * toSentenceCase('halo, apa kabar? baik-baik saja.') * // → 'Halo, apa kabar? Baik-baik saja.' * * toSentenceCase('jakarta. surabaya. bandung.') * // → 'Jakarta. Surabaya. Bandung.' * ``` * * @example * Different punctuation: * ```typescript * toSentenceCase('wow! amazing! fantastic!') * // → 'Wow! Amazing! Fantastic!' * * toSentenceCase('siapa nama anda? saya joko.') * // → 'Siapa nama anda? Saya joko.' * ``` * * @example * Edge cases: * ```typescript * toSentenceCase('') * // → '' * * toSentenceCase('hello') * // → 'Hello' * * toSentenceCase(' hello. world. ') * // → 'Hello. World.' * ``` * * @public */ declare function toSentenceCase(text: string): string; /** * Generate URL-safe slugs with Indonesian language support * * This function converts text into URL-friendly slugs by: * - Converting to lowercase (configurable) * - Replacing spaces with separators (default: hyphen) * - Replacing Indonesian conjunctions (& → dan, / → atau) * - Removing special characters * - Collapsing multiple separators * - Trimming leading/trailing separators * * **Character Handling:** * - Alphanumeric (a-z, A-Z, 0-9): Preserved * - Spaces: Replaced with separator * - Ampersand (&): Replaced with "dan" * - Slash (/): Replaced with "atau" * - Hyphens (-): Preserved as separators * - Other special chars: Removed * * @param text - The text to convert to slug * @param options - Optional configuration * @returns The URL-safe slug * * @example * Basic usage: * ```typescript * slugify('Cara Mudah Belajar TypeScript') * // → 'cara-mudah-belajar-typescript' * * slugify('HELLO WORLD') * // → 'hello-world' * ``` * * @example * Indonesian conjunctions: * ```typescript * slugify('Ibu & Anak: Tips Kesehatan') * // → 'ibu-dan-anak-tips-kesehatan' * * slugify('Baju Pria/Wanita') * // → 'baju-pria-atau-wanita' * * slugify('A & B / C') * // → 'a-dan-b-atau-c' * ``` * * @example * Special characters removed: * ```typescript * slugify('Harga Rp 100.000 (Diskon 20%)') * // → 'harga-rp-100000-diskon-20' * * slugify('Email: test@example.com') * // → 'email-testexamplecom' * ``` * * @example * Multiple spaces/separators collapsed: * ```typescript * slugify('Produk Terbaru - - - 2024') * // → 'produk-terbaru-2024' * * slugify(' Hello World ') * // → 'hello-world' * ``` * * @example * With options: * ```typescript * slugify('Hello World', { separator: '_' }) * // → 'hello_world' * * slugify('Hello World', { lowercase: false }) * // → 'Hello-World' * * slugify('C++ Programming', { * replacements: { 'C++': 'cpp' } * }) * // → 'cpp-programming' * * slugify('Hello-World', { trim: false }) * // → 'hello-world' (same, but won't trim if leading/trailing) * ``` * * @public */ declare function slugify(text: string, options?: SlugifyOptions): string; /** * Normalize all whitespace characters to single spaces * * This function: * - Collapses multiple spaces into one * - Converts tabs, newlines, and other whitespace to single space * - Trims leading and trailing whitespace * - Handles Unicode whitespace characters * * **Whitespace Characters Normalized:** * - Space (` `) * - Tab (`\t`) * - Newline (`\n`) * - Carriage return (`\r`) * - Form feed (`\f`) * - Vertical tab (`\v`) * - Non-breaking space (`\u00A0`) * - Other Unicode spaces * * @param text - The text to normalize * @returns Text with normalized whitespace * * @example * Basic usage: * ```typescript * normalizeWhitespace('hello world') * // → 'hello world' * * normalizeWhitespace('hello\tworld') * // → 'hello world' * ``` * * @example * Multiple types of whitespace: * ```typescript * normalizeWhitespace('hello\n\nworld') * // → 'hello world' * * normalizeWhitespace('hello\r\nworld') * // → 'hello world' * * normalizeWhitespace('line1\n\nline2\tword') * // → 'line1 line2 word' * ``` * * @example * Leading and trailing whitespace: * ```typescript * normalizeWhitespace(' hello world ') * // → 'hello world' * * normalizeWhitespace('\n\thello\t\n') * // → 'hello' * ``` * * @example * Edge cases: * ```typescript * normalizeWhitespace('') * // → '' * * normalizeWhitespace(' ') * // → '' * * normalizeWhitespace('hello') * // → 'hello' * ``` * * @public */ declare function normalizeWhitespace(text: string): string; /** * Remove or replace unwanted characters from text * * This function provides flexible text sanitization with options to: * - Remove newlines * - Remove extra spaces * - Remove punctuation * - Keep only allowed characters * - Trim leading/trailing whitespace * * @param text - The text to sanitize * @param options - Sanitization options * @returns The sanitized text * * @example * Remove extra spaces (default): * ```typescript * sanitize('hello world') * // → 'hello world' * ``` * * @example * Remove newlines: * ```typescript * sanitize('line1\nline2\nline3', { removeNewlines: true }) * // → 'line1 line2 line3' * ``` * * @example * Remove punctuation: * ```typescript * sanitize('Hello, World!', { removePunctuation: true }) * // → 'Hello World' * ``` * * @example * Allow only specific characters: * ```typescript * sanitize('ABC123!@#', { allowedChars: 'A-Za-z0-9' }) * // → 'ABC123' * * sanitize('Hello123!@#', { allowedChars: 'a-z' }) * // → 'ello' * ``` * * @example * Combined options: * ```typescript * sanitize(' Hello,\n World! ', { * removeNewlines: true, * removePunctuation: true, * removeExtraSpaces: true, * trim: true * }) * // → 'Hello World' * ``` * * @public */ declare function sanitize(text: string, options?: SanitizeOptions): string; /** * Remove diacritical marks (accents) from characters * * Converts accented characters to their base form: * - é → e * - ñ → n * - ü → u * - etc. * * Useful for: * - Search normalization * - Sorting/comparison * - URL generation * - Database queries * * @param text - The text to remove accents from * @returns Text with accents removed * * @example * Basic usage: * ```typescript * removeAccents('café') * // → 'cafe' * * removeAccents('résumé') * // → 'resume' * ``` * * @example * Various accents: * ```typescript * removeAccents('naïve') * // → 'naive' * * removeAccents('Zürich') * // → 'Zurich' * * removeAccents('São Paulo') * // → 'Sao Paulo' * ``` * * @example * Mixed text: * ```typescript * removeAccents('École française à Montréal') * // → 'Ecole francaise a Montreal' * ``` * * @public */ declare function removeAccents(text: string): string; /** * Expand Indonesian abbreviations to their full form * * This function expands common Indonesian abbreviations like: * - Address: Jl. → Jalan, Kec. → Kecamatan * - Titles: Dr. → Doktor, S.H. → Sarjana Hukum * - Honorifics: Bpk. → Bapak, Yth. → Yang Terhormat * - Organizations: PT. → Perseroan Terbatas * - Common: dll. → dan lain-lain * * **Features:** * - Case-insensitive matching (Jl. = jl. = JL.) * - Mode filtering (all, address, title, org) * - Custom mapping support * - Preserves surrounding text * - Multiple abbreviations in one string * * @param text - The text containing abbreviations to expand * @param options - Optional configuration * @returns Text with abbreviations expanded * * @example * Basic usage: * ```typescript * expandAbbreviation('Jl. Sudirman No. 123') * // → 'Jalan Sudirman Nomor 123' * * expandAbbreviation('Dr. Joko Widodo, S.H.') * // → 'Doktor Joko Widodo, Sarjana Hukum' * ``` * * @example * Address abbreviations: * ```typescript * expandAbbreviation('Kab. Bogor, Kec. Ciawi') * // → 'Kabupaten Bogor, Kecamatan Ciawi' * * expandAbbreviation('Jl. Merdeka Gg. 5 No. 10') * // → 'Jalan Merdeka Gang 5 Nomor 10' * ``` * * @example * Academic titles: * ```typescript * expandAbbreviation('Prof. Dr. Ir. Ahmad') * // → 'Profesor Doktor Insinyur Ahmad' * * expandAbbreviation('Saya lulusan S.T. dari ITB') * // → 'Saya lulusan Sarjana Teknik dari ITB' * ``` * * @example * Honorifics: * ```typescript * expandAbbreviation('Yth. Bpk. H. Ahmad') * // → 'Yang Terhormat Bapak Haji Ahmad' * ``` * * @example * Organizations: * ```typescript * expandAbbreviation('PT. Maju Jaya Tbk.') * // → 'Perseroan Terbatas Maju Jaya Terbuka' * ``` * * @example * Mode filtering: * ```typescript * expandAbbreviation('Dr. Joko di Jl. Sudirman', { mode: 'address' }) * // → 'Dr. Joko di Jalan Sudirman' * // Only expands address abbreviations * * expandAbbreviation('Prof. Dr. di Jl. Sudirman', { mode: 'title' }) * // → 'Profesor Doktor di Jl. Sudirman' * // Only expands title abbreviations * ``` * * @example * Custom mappings: * ```typescript * expandAbbreviation('BUMN adalah perusahaan negara', { * customMap: { 'BUMN': 'Badan Usaha Milik Negara' } * }) * // → 'Badan Usaha Milik Negara adalah perusahaan negara' * ``` * * @example * Case sensitivity: * ```typescript * expandAbbreviation('jl. sudirman') * // → 'Jalan sudirman' (default: preserves surrounding case) * * expandAbbreviation('JL. SUDIRMAN') * // → 'Jalan SUDIRMAN' * ``` * * @public */ declare function expandAbbreviation(text: string, options?: ExpandOptions): string; /** * Contract full forms to abbreviations (reverse of expand) * * @param text - The text containing full forms to contract * @param options - Optional configuration * @returns Text with full forms contracted * * @example * ```typescript * contractAbbreviation('Jalan Sudirman Nomor 123') * // → 'Jl. Sudirman No. 123' * * contractAbbreviation('Doktor Ahmad, Sarjana Hukum') * // → 'Dr. Ahmad, S.H.' * ``` * * @public */ declare function contractAbbreviation(text: string, options?: { mode?: 'all' | 'address' | 'title' | 'org'; }): string; /** * Filters common Indonesian profanity words by masking them. * * @param text - The text to filter * @param mask - The masking character (default: '*') * @returns Filtered text * * @example * ```typescript * profanityFilter('kamu anjing banget'); // 'kamu ****** banget' * ``` */ declare function profanityFilter(text: string, mask?: string): string; /** * Removes common Indonesian stopwords from text. * * @param text - The text to process * @returns Text with stopwords removed * * @example * ```typescript * removeStopwords('saya sedang makan nasi'); // 'makan nasi' * ``` */ declare function removeStopwords(text: string): string; /** * Normalizes informal Indonesian text to a more formal version. * This is a basic rule-based implementation. * * @param text - The text to normalize * @returns Formalized text * * @example * ```typescript * toFormal('gw lagi makan'); // 'saya sedang makan' * ``` */ declare function toFormal(text: string): string; /** * Detects if a text follows "alay" style (unconventional capitalization or number substitution). * * @param text - The text to check * @returns `true` if alay style detected, `false` otherwise * * @example * ```typescript * isAlay('AqU sAyAnG qMu'); // true * isAlay('Makan 4y4m'); // true * ``` */ declare function isAlay(text: string): boolean; /** * Truncate text to specified length, word-aware * * This function shortens text to a maximum length while: * - Respecting word boundaries (don't cut words in half) * - Adding ellipsis to indicate truncation * - Preserving original text if already short enough * - Accounting for ellipsis length in total character count * * **Features:** * - Smart word boundary detection * - Customizable ellipsis * - No truncation for short text * - Handles edge cases gracefully * * @param text - The text to truncate * @param maxLength - Maximum length of output (including ellipsis) * @param options - Optional configuration * @returns The truncated text with ellipsis if needed * * @example * Basic usage: * ```typescript * truncate('Ini adalah contoh text yang panjang', 20) * // → 'Ini adalah contoh...' * * truncate('Short text', 20) * // → 'Short text' (no truncation needed) * ``` * * @example * Word boundary handling: * ```typescript * truncate('Ini adalah contoh text yang panjang', 20, { wordBoundary: true }) * // → 'Ini adalah contoh...' (stops at word) * * truncate('Ini adalah contoh text yang panjang', 20, { wordBoundary: false }) * // → 'Ini adalah contoh t...' (cuts mid-word) * ``` * * @example * Custom ellipsis: * ```typescript * truncate('Ini adalah contoh text yang panjang', 20, { ellipsis: '…' }) * // → 'Ini adalah contoh…' * * truncate('Ini adalah contoh text yang panjang', 20, { ellipsis: ' [...]' }) * // → 'Ini adalah [...]' * ``` * * @example * Edge cases: * ```typescript * truncate('', 10) * // → '' * * truncate('Hello', 10) * // → 'Hello' * * truncate('Hello World', 11) * // → 'Hello World' (exact length, no ellipsis) * ``` * * @public */ declare function truncate(text: string, maxLength: number, options?: TruncateOptions): string; /** * Extract words from text, respecting Indonesian language rules * * This function splits text into individual words while: * - Respecting hyphenated words (anak-anak as single word) * - Filtering by minimum length * - Optional lowercase conversion * - Removing punctuation and special characters * * **Features:** * - Indonesian hyphenation support (anak-anak, buku-buku) * - Minimum word length filtering * - Case normalization * - Handles punctuation gracefully * * @param text - The text to extract words from * @param options - Optional configuration * @returns Array of extracted words * * @example * Basic usage: * ```typescript * extractWords('Anak-anak bermain di taman') * // → ['Anak-anak', 'bermain', 'di', 'taman'] * * extractWords('Hello, World! How are you?') * // → ['Hello', 'World', 'How', 'are', 'you'] * ``` * * @example * Hyphenated word handling: * ```typescript * extractWords('Anak-anak bermain di taman', { includeHyphenated: true }) * // → ['Anak-anak', 'bermain', 'di', 'taman'] * * extractWords('Anak-anak bermain di taman', { includeHyphenated: false }) * // → ['Anak', 'anak', 'bermain', 'di', 'taman'] * ``` * * @example * Minimum length filtering: * ```typescript * extractWords('Di rumah ada 3 kucing', { minLength: 3 }) * // → ['rumah', 'ada', 'kucing'] * // 'Di' (2 chars) and '3' (1 char) filtered out * * extractWords('a b cd def ghij', { minLength: 3 }) * // → ['def', 'ghij'] * ``` * * @example * Lowercase conversion: * ```typescript * extractWords('Hello WORLD', { lowercase: true }) * // → ['hello', 'world'] * * extractWords('Hello WORLD', { lowercase: false }) * // → ['Hello', 'WORLD'] * ``` * * @example * Combined options: * ```typescript * extractWords('Anak-Anak BERMAIN di Taman', { * includeHyphenated: true, * minLength: 3, * lowercase: true * }) * // → ['anak-anak', 'bermain', 'taman'] * // 'di' filtered out (< 3 chars) * ``` * * @example * Edge cases: * ```typescript * extractWords('') * // → [] * * extractWords(' ') * // → [] * * extractWords('!!!@@##') * // → [] * ``` * * @public */ declare function extractWords(text: string, options?: ExtractOptions): string[]; /** * Compare strings with Indonesian-aware normalization * * This function allows flexible string comparison with options to ignore * case, whitespace, and accents. Useful for search, filtering, and * validation. * * **Features:** * - Case-insensitive comparison (default: false) * - Whitespace normalization (ignore extra spaces) * - Accent removal (café == cafe) * - Null-safe (handles empty strings) * * @param str1 - First string to compare * @param str2 - Second string to compare * @param options - Comparison options * @returns True if strings match according to options * * @example * Basic matching: * ```typescript * compareStrings('Hello', 'Hello') // → true * compareStrings('Hello', 'hello') // → false * ``` * * @example * Case insensitive: * ```typescript * compareStrings('Hello', 'hello', { caseSensitive: false }) // → true * // Note: default is caseSensitive: false for convenience in many utils, * // but strict comparison usually defaults to true. * // Let's check the implementation default. * ``` * * @example * Ignore whitespace: * ```typescript * compareStrings(' Hello World ', 'Hello World', { ignoreWhitespace: true }) * // → true * ``` * * @example * Ignore accents: * ```typescript * compareStrings('café', 'cafe', { ignoreAccents: true }) * // → true * ``` * * @public */ declare function compareStrings(str1: string, str2: string, options?: CompareOptions): boolean; /** * Calculate similarity score between two strings (0-1) using Levenshtein distance * * This function measures the difference between two strings and returns a score * where 1.0 means identical and 0.0 means completely different. * * **Algorithm:** * Uses Levenshtein distance to calculate the minimum number of single-character * edits (insertions, deletions, substitutions) required to change one string * into the other. * * @param str1 - First string * @param str2 - Second string * @returns Similarity score between 0.0 and 1.0 * * @example * Basic Usage: * ```typescript * similarity('hello', 'hello') // → 1.0 (identical) * similarity('hello', 'hallo') // → 0.8 (1 edit / 5 length) * similarity('hello', 'world') // → 0.2 (4 edits / 5 length) * ``` * * @example * Case sensitivity: * Note: This function is case-sensitive. Use compareStrings options or * manual lowercasing if you need case-insensitive similarity. * * @public */ declare function similarity(str1: string, str2: string): number; /** * Mask sensitive text based on predefined patterns or custom configuration * * This function provides privacy-compliant data display by masking portions * of text while keeping certain parts visible. Supports multiple masking * patterns for different use cases. * * **Available Patterns:** * - `all`: Masks all characters (preserves spaces) * - `middle`: Keeps start and end characters visible, masks the middle * - `email`: Keeps first 2 chars of local part and full domain visible * * @param text - The text to mask * @param options - Masking configuration options * @returns The masked text * * @example * Mask all characters: * ```typescript * maskText('Budi Santoso', { pattern: 'all' }) * // → '**** *******' * * maskText('123456789', { pattern: 'all', maskChar: '#' }) * // → '#########' * ``` * * @example * Mask middle portion: * ```typescript * maskText('08123456789', { pattern: 'middle', visibleStart: 4, visibleEnd: 3 }) * // → '0812****789' * * maskText('ABCDEF', { pattern: 'middle' }) * // → 'AB**EF' (defaults: visibleStart=2, visibleEnd=2) * ``` * * @example * Mask email: * ```typescript * maskText('user@example.com', { pattern: 'email' }) * // → 'us**@example.com' * * maskText('a@test.com', { pattern: 'email' }) * // → 'a*@test.com' * ``` * * @example * Edge cases: * ```typescript * maskText('') * // → '' * * maskText('AB', { pattern: 'middle', visibleStart: 2, visibleEnd: 2 }) * // → '**' (string too short, mask all) * ``` * * @public */ declare function maskText(text: string, options?: MaskOptions): string; /** * Convert text to camelCase * * Treats spaces, hyphens, and underscores as word boundaries. * Strips all other special characters. First word is lowercase. * * @param text - The text to convert * @returns camelCase string * * @example * ```typescript * toCamelCase('hello-world') * // → 'helloWorld' * * toCamelCase('hello_world') * // → 'helloWorld' * * toCamelCase('Hello World') * // → 'helloWorld' * * toCamelCase('') * // → '' * ``` * * @public */ declare function toCamelCase(text: string): string; /** * Convert text to PascalCase * * Treats spaces, hyphens, and underscores as word boundaries. * Strips all other special characters. Every word is capitalized. * * @param text - The text to convert * @returns PascalCase string * * @example * ```typescript * toPascalCase('hello_world') * // → 'HelloWorld' * * toPascalCase('hello-world') * // → 'HelloWorld' * * toPascalCase('hello world') * // → 'HelloWorld' * * toPascalCase('') * // → '' * ``` * * @public */ declare function toPascalCase(text: string): string; /** * Convert text to snake_case * * Treats spaces, hyphens, and camelCase boundaries as word separators. * Strips all other special characters. All lowercase with underscores. * * @param text - The text to convert * @returns snake_case string * * @example * ```typescript * toSnakeCase('helloWorld') * // → 'hello_world' * * toSnakeCase('Hello-World') * // → 'hello_world' * * toSnakeCase('Hello World') * // → 'hello_world' * * toSnakeCase('') * // → '' * ``` * * @public */ declare function toSnakeCase(text: string): string; /** * Count the number of syllables in an Indonesian word * * Uses algorithm-based vowel counting with Indonesian dipthong awareness. * Works for both Indonesian and English text. * * **Syllable Detection Rules:** * - Each vowel group (a, i, u, e, o) counts as one syllable * - Dipthongs (ai, au, oi) count as a single vowel sound * - Silent 'e' at the end is handled * - Minimum 1 syllable for any word with letters * * @param text - The word or text to count syllables in * @returns The number of syllables * * @example * Indonesian words: * ```typescript * countSyllables('buku') * // → 2 (bu-ku) * * countSyllables('matahari') * // → 4 (ma-ta-ha-ri) * * countSyllables('pulau') * // → 2 (pu-lau, dipthong 'au' counts as one) * ``` * * @example * English words: * ```typescript * countSyllables('hello') * // → 2 (hel-lo) * * countSyllables('beautiful') * // → 3 (beau-ti-ful) * ``` * * @example * Edge cases: * ```typescript * countSyllables('') * // → 0 * * countSyllables('a') * // → 1 * * countSyllables('rhythm') * // → 1 (no vowels, minimum 1) * ``` * * @public */ declare function countSyllables(text: string): number; /** * ============================================================================ * INDONESIAN TEXT UTILITIES - CONSTANTS * ============================================================================ * * This file contains constants for Indonesian and English text processing: * - LOWERCASE_WORDS: Particles that stay lowercase in title case * - ACRONYMS: Abbreviations that stay UPPERCASE in title case * - ABBREVIATIONS: Full expansions of common Indonesian abbreviations * * ============================================================================ * MAINTENANCE GUIDE * ============================================================================ * * ## How to Add New Entries * * ### 1. LOWERCASE_WORDS (Particles) * * Add words that should remain lowercase in title case (except when first word). * * **Indonesian Grammar Rules (PUEBI):** * - Prepositions: di, ke, dari, untuk, dengan, pada, dalam, etc. * - Conjunctions: dan, atau, tetapi, serta, maupun, etc. * - Articles/particles: yang, sebagai, adalah, akan, telah, etc. * * **English Grammar Rules (Chicago Manual of Style):** * - Articles: a, an, the * - Conjunctions: and, or, but, nor, for, yet, so * - Short prepositions (<5 letters): at, by, in, of, on, to, up, etc. * * **Example Addition:** * ```typescript * export const LOWERCASE_WORDS = [ * // ... existing entries * 'bagi', // Indonesian: for/to (preposition) * 'antara', // Indonesian: between (preposition) * 'into', // English: preposition * ] as const; * ``` * * **Testing:** Add test case in `toTitleCase.test.ts`: * ```typescript * it('keeps "bagi" lowercase in middle', () => { * expect(toTitleCase('buku bagi pemula')).toBe('Buku bagi Pemula'); * }); * ``` * * ### 2. ACRONYMS (Always Uppercase) * * Add abbreviations that should always appear in UPPERCASE. * * **Categories:** * - Government & Military: TNI, POLRI, KPK, DPR, etc. * - Business Entities: PT, CV, BUMN, etc. * - Banks: BCA, BRI, BNI, etc. * - Services: BPJS, PLN, KTP, SIM, etc. * - Technology: IT, AI, API, SEO, etc. * - Education: UI, ITB, UGM, etc. * - International: UN, WHO, NATO, ASEAN, etc. * * **Validation Checklist:** * ✅ Is it commonly written in ALL CAPS? * ✅ Is it an official acronym (not just shortened word)? * ✅ Will it look wrong if title-cased (e.g., "Pt" instead of "PT")? * * **Example Addition:** * ```typescript * export const ACRONYMS = [ * // ... existing entries * 'OJK', // Otoritas Jasa Keuangan * 'BI', // Bank Indonesia * 'NASA', // National Aeronautics and Space Administration * ] as const; * ``` * * **Testing:** Add test case in `toTitleCase.test.ts`: * ```typescript * it('preserves OJK uppercase', () => { * expect(toTitleCase('ojk indonesia')).toBe('OJK Indonesia'); * }); * ``` * * ### 3. ABBREVIATIONS (Expansion Mapping) * * Add abbreviation → full form mappings for `expandAbbreviation()` function. * * **Categories (use comment headers):** * - Address: Jl., Gg., Kec., Kab., etc. * - Academic Titles: Dr., Ir., Prof., S.H., M.M., etc. * - Honorifics: Bpk., Yth., H., Hj., etc. * - Organizations: PT., CV., UD., etc. * - Common: dst., dll., a.n., etc. * - Contact Info: Tlp., HP., Fax, etc. * - Days/Months: Sen., Jan., Feb., etc. * - Units: kg., km., lt., etc. * * **Key Format Rules:** * - Include period if commonly written: `'Jl.'` not `'Jl'` * - Use proper capitalization: `'Jalan'` not `'jalan'` * - Keep it concise: Full form only, no explanations * * **Example Addition:** * ```typescript * export const ABBREVIATIONS: Record = { * // ... existing entries * * // ========== New Category Example ========== * 'Apt.': 'Apartemen', * 'Ruko': 'Rumah Toko', * 'Rukan': 'Rumah Kantor', * }; * ``` * * **Testing:** Add test case in `abbreviation.test.ts`: * ```typescript * it('expands Apt. to Apartemen', () => { * expect(expandAbbreviation('Apt. Sudirman')) * .toBe('Apartemen Sudirman'); * }); * ``` * * ============================================================================ * DATA SOURCES & REFERENCES * ============================================================================ * * When adding new entries, refer to these authoritative sources: * * **Indonesian Language:** * - PUEBI (Pedoman Umum Ejaan Bahasa Indonesia) * https://puebi.js.org/ * * - KBBI (Kamus Besar Bahasa Indonesia) * https://kbbi.kemdikbud.go.id/ * * - Wikipedia Indonesia - Daftar Singkatan * https://id.wikipedia.org/wiki/Daftar_singkatan_di_Indonesia * * **English Language:** * - Chicago Manual of Style (Title Case Rules) * https://www.chicagomanualofstyle.org/ * * - AP Stylebook * https://www.apstylebook.com/ * * **Government & Official:** * - Kemendagri (addresses, administrative divisions) * https://www.kemendagri.go.id/ * * - Kemenkumham (business entities) * https://www.kemenkumham.go.id/ * * - Kemendikbud (education, degrees) * https://www.kemdikbud.go.id/ * * ============================================================================ * CONTRIBUTION GUIDELINES * ============================================================================ * * **Before Adding:** * 1. ✅ Check if entry already exists (Ctrl+F) * 2. ✅ Verify spelling from official sources * 3. ✅ Ensure it's commonly used (not obscure) * 4. ✅ Choose correct category/section * * **After Adding:** * 1. ✅ Add corresponding test case * 2. ✅ Run tests: `npm test constants` * 3. ✅ Update this file's documentation if needed * 4. ✅ Add source reference in PR description * * **PR Template:** * ``` * ### Added Constants * * **Type:** [LOWERCASE_WORDS | ACRONYMS | ABBREVIATIONS] * * **Entries:** * - `OJK` - Otoritas Jasa Keuangan * - `BI` - Bank Indonesia * * **Source:** https://www.ojk.go.id/ * * **Test Coverage:** ✅ Added in toTitleCase.test.ts line 245 * * **Rationale:** * Commonly used financial regulatory bodies in Indonesian context. * ``` * * ============================================================================ * COMMON PITFALLS TO AVOID * ============================================================================ * * ❌ **Don't add brand-specific styling** (e.g., "iPhone" → keep user control) * ❌ **Don't add regional dialects** (stick to standard Indonesian/English) * ❌ **Don't add context-dependent acronyms** (e.g., "UI" = both User Interface & Universitas Indonesia) * ❌ **Don't add very rare/obscure terms** (focus on common usage) * ❌ **Don't forget the period** in ABBREVIATIONS (e.g., use `'Dr.'` not `'Dr'`) * ❌ **Don't mix singular/plural** in ABBREVIATIONS (choose one consistently) * * ✅ **Do keep entries alphabetically sorted** within categories * ✅ **Do use proper capitalization** in expanded forms * ✅ **Do add comments** for non-obvious entries * ✅ **Do verify against official sources** before adding * ✅ **Do write test cases** for new additions * * ============================================================================ * FUTURE EXTENSIBILITY * ============================================================================ * * **Planned Enhancements:** * * 1. **External Data Source Support:** * ```typescript * import customAcronyms from './data/custom-acronyms.json'; * export const ACRONYMS = [...DEFAULT_ACRONYMS, ...customAcronyms]; * ``` * * 2. **Context-Aware Acronyms:** * ```typescript * export const CONTEXT_ACRONYMS = { * 'UI': { * tech: 'UI', // User Interface * education: 'UI', // Universitas Indonesia * } * }; * ``` * * 3. **Locale-Specific Sets:** * ```typescript * export const LOWERCASE_WORDS = { * id: [...], // Indonesian * en: [...], // English * mixed: [...], // Combined (default) * }; * ``` * * 4. **Dynamic Loading:** * ```typescript * // Load additional acronyms from user config * export async function loadCustomConstants(url: string) { * const data = await fetch(url).then(r => r.json()); * return [...ACRONYMS, ...data.acronyms]; * } * ``` * * ============================================================================ * VERSIONING & CHANGELOG * ============================================================================ * * Track major additions here: * * - v0.2.0 (2024-12-18): Initial comprehensive dataset * - 50+ Indonesian particles * - 150+ acronyms (Indonesian + International) * - 80+ abbreviation mappings * * - v0.2.1 (TBD): Add financial sector acronyms (OJK, BI, etc.) * - v0.2.2 (TBD): Add technology company acronyms * * ============================================================================ */ /** * Indonesian and English lowercase particles * These words remain lowercase in title case (except when first word) * * Based on: * - Indonesian grammar (PUEBI) * - English title case rules (Chicago Manual of Style) */ declare const LOWERCASE_WORDS: readonly ["di", "ke", "dari", "pada", "dalam", "untuk", "dengan", "oleh", "kepada", "terhadap", "tentang", "tanpa", "hingga", "sampai", "sejak", "menuju", "melalui", "dan", "atau", "tetapi", "namun", "serta", "maupun", "melainkan", "sedangkan", "yang", "sebagai", "adalah", "ialah", "yaitu", "bahwa", "akan", "telah", "sudah", "belum", "a", "an", "the", "and", "or", "but", "nor", "for", "yet", "so", "as", "at", "by", "in", "of", "on", "to", "up", "via", "per", "off", "out"]; /** * Indonesian and international acronyms * These always remain UPPERCASE in title case */ declare const ACRONYMS: readonly ["DKI", "DIY", "TNI", "POLRI", "ABRI", "MPR", "DPR", "KPK", "BIN", "PT", "CV", "UD", "PD", "Tbk", "BUMN", "BUMD", "BCA", "BRI", "BNI", "BTN", "BSI", "BPD", "KTP", "NIK", "NPWP", "SIM", "STNK", "BPJS", "KIS", "KIP", "PKH", "PLN", "PDAM", "PGN", "KAI", "MRT", "LRT", "PBB", "PPh", "PPN", "BPHTB", "UI", "ITB", "UGM", "IPB", "ITS", "UNPAD", "UNDIP", "UNAIR", "UNS", "S.Pd", "S.H", "S.E", "S.T", "S.Kom", "S.Si", "S.Sos", "M.Pd", "M.M", "M.T", "M.Kom", "ATM", "POS", "SMS", "GPS", "WiFi", "USB", "PIN", "OTP", "QR", "IT", "AI", "ML", "API", "UI", "UX", "SEO", "SaaS", "CRM", "ERP", "CEO", "CFO", "CTO", "COO", "CMO", "HR", "PR", "VP", "GM", "UN", "WHO", "UNESCO", "NATO", "ASEAN", "APEC", "WTO", "IMF", "ICU", "ER", "MRI", "CT", "DNA", "RNA", "HIV", "AIDS", "COVID", "KM", "CM", "MM", "KG", "RPM", "MPH", "KPH", "IPO", "ATM", "ROI", "GDP", "VAT"]; /** * Indonesian abbreviations mapping * Organized by category for maintainability */ declare const ABBREVIATIONS: Record; export { ABBREVIATIONS, ACRONYMS, type CompareOptions, type ExtractOptions, LOWERCASE_WORDS, type MaskOptions, type SanitizeOptions, type SlugifyOptions, type TitleCaseOptions, type TruncateOptions, capitalize, compareStrings, contractAbbreviation, countSyllables, expandAbbreviation, extractWords, isAlay, maskText, normalizeWhitespace, profanityFilter, removeAccents, removeStopwords, sanitize, similarity, slugify, toCamelCase, toFormal, toPascalCase, toSentenceCase, toSnakeCase, toTitleCase, truncate };