/** * Copyright 2026 - present Nazmul Hassan * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { n as MD_TO_TEXT_RULES, t as LOWERCASE } from "./constants-BPeq21eD.cjs"; import { $n as Join, Mr as Split, Rr as $Countries, T as Nullable, nr as LooseLiteral } from "./index-Dx3yeNwR.cjs"; //#region src/types/string.d.ts declare global { interface String { toLowerCase(): string; /** * * Converts all the alphabetic characters in a string to lowercase. * * @typeParam `Lower` - A type-level flag. If `'T'`, returns the lowercase string type (`Lowercase`). Otherwise, returns literal `Lower` (must be Lowercase type). * * @remarks * - This augmentation only affects TypeScript type inference. * - Runtime behavior remains identical to the standard `toLowerCase()` method. */ toLowerCase>(): Lower extends 'T' ? Lowercase : Lower; toUpperCase(): string; /** * * Converts all the alphabetic characters in a string to uppercase. * * @typeParam `Upper` - A type-level flag. If `'T'`, returns the uppercase string type (`Uppercase`). Otherwise, returns literal `Upper` (must be Uppercase type). * * @remarks * - This augmentation only affects TypeScript type inference. * - Runtime behavior remains identical to the standard `toUpperCase()` method. */ toUpperCase>(): Upper extends 'T' ? Uppercase : Upper; } } /** - Options for generating anagrams. */ interface AnagramOptions { /** * Maximum number of anagrams to generate. * Defaults to `100`. Pass `"all"` to return all possible anagrams. */ limit?: number | 'all'; /** * Optional dictionary array of strings for validating anagrams. * - Pass `false` (default) to skip dictionary lookup. * - Pass an array of strings to include only anagrams present in that array. * - Dictionary lookup is case-insensitive; internally, a cached lowercase `Set` is used for performance. * - Duplicate entries in the dictionary are ignored. */ dictionary?: false | string[]; } /** - Options for `capitalizeString` function. */ interface CapitalizeOptions { /** If true, capitalizes the first letter of each word (space separated). Defaults to `false`. */ capitalizeEachFirst?: boolean; /** If true, ensures that the whole string is capitalized. Defaults to `false`. */ capitalizeAll?: boolean; /** If true, ensures that the rest of the string is lowercase. Defaults to `true`. */ lowerCaseRest?: boolean; } /** - Configuration options for ID generation. */ interface RandomIdOptions { /** A string to prepend to the ID. Default is an empty string. */ prefix?: string; /** A string to append to the ID. Default is an empty string.*/ suffix?: string; /** Whether to include the current timestamp in the ID. Default is `false`. */ timeStamp?: boolean; /** The length of the random alphanumeric string. Default is `16`. */ length?: number; /** The separator to use between parts of the ID. Default is an empty string. */ separator?: string; /** Specifies the case for the full id (this includes alphanumeric string and suffix+prefix). Default is `null`. */ caseOption?: Nullable<'upper' | 'lower'>; } /** - Case formats for converting a string */ type CaseFormat = 'camelCase' | 'snake_case' | 'kebab-case' | 'PascalCase' | 'Title Case' | 'Sentence case' | 'UPPERCASE' | 'lowercase'; /** * Options for `convertStringCase`. */ interface StringCaseOptions { /** * Preserve acronym-like tokens (tokens that are ALL UPPERCASE with length >= 2) * when converting to PascalCase / Title Case / camelCase (mid tokens). * * Behavior summary: * - PascalCase: keep acronyms intact (API -> API). * - camelCase: first token acronyms are lowercased entirely (API -> api), * subsequent token acronyms are preserved (API -> API). * - Title Case: acronym tokens are preserved (API). * - snake_case / kebab-case: tokens are lowercased (xml-http-request). */ preserveAcronyms?: boolean; } /** Options for masking a string. */ interface MaskOptions { /** Number of characters to keep at the start. Defaults to `1`. */ start?: number; /** Number of characters to keep at the end. Defaults to `1`. */ end?: number; /** Character to use for masking. Defaults to `*`. */ maskCharacter?: string; /** Whether to trim all whitespace characters before masking. Defaults to `false`. */ trim?: boolean; } /** Options for truncating a string */ interface TruncateOptions { /** The maximum length of the truncated string. Defaults to `100`. */ maxLength?: number; /** The string to append to the truncated string. Defaults to `'...'`. */ suffix?: string; /** Whether to trim all whitespace characters from the string before truncating. Defaults to `false`. */ trim?: boolean; } /** Formatted query string as `?${string}` = `?key=value&...` or empty string. */ type QueryString = `?${string}` | ''; /** Full country name */ type CountryName = $Countries['country_name']; /** Country code, e.g. `"880" | "973" | "994" | "1-242" ...` */ type CountryCode = $Countries['country_code']; /** ISO country country codes (3-character), e.g. `"BGD" | "BRB" | "BLR" ...` */ type CountryISO = $Countries['iso_code']; /** ISO country country codes (2-character), e.g. `"BD" | "BB" | "BY" ...` */ type CountryShortISO = $Countries['iso_code_short']; /** ISO 2 character country code or any string */ type Country = LooseLiteral; /** Lowercase prepositions, articles, conjunctions, and auxiliary verbs ({@link LOWERCASE}) */ type $LowerCaseWord = (typeof LOWERCASE)[number]; /** Ensure early inference and string constraint. */ type $EnsureString = Str extends string ? Str : never; /** Check if a string literal `Str` contains a substring `SubStr` */ type Includes = Str extends `${string}${SubStr}${string}` ? true : false; /** Trim leading space from a string literal */ type $TrimLeft = Str extends ` ${infer R}` ? $TrimLeft : Str; /** Trim trailing space from a string literal */ type $TrimRight = Str extends `${infer L} ` ? $TrimRight : Str; /** Trim leading and trailing spaces from a string literal */ type Trim = $TrimRight<$TrimLeft>; /** Default delimiter characters */ type $DefaultDelimiters = ' ' | '-' | '_' | '.' | '/'; /** Turn user delim string like "*+," into '*, +, ,' union */ type $UserDelimiters = Del extends '' ? never : Del extends `${infer C}${infer R}` ? C | $UserDelimiters : never; /** Is char `C` a delimiter (either default or user-provided)? */ type $IsDelimiter = C extends $DefaultDelimiters ? true : C extends $UserDelimiters ? true : false; /** Insert space before capital letters: "helloWorld" -> "hello World" */ type $SpaceBeforeCaps = Str extends `${infer F}${infer R}` ? R extends Uncapitalize ? `${F}${$SpaceBeforeCaps}` : `${F} ${$SpaceBeforeCaps}` : Str; /** Replace delimiter(s) with space(s) */ type $ReplaceDelimiters = Str extends `${infer F}${infer R}` ? $IsDelimiter extends true ? $ReplaceDelimiters : $ReplaceDelimiters : Acc; /** Normalize {@link $DefaultDelimiters} or {@link $UserDelimiters} `Del` in a string literal `Str` with space(s) */ type $NormalizeString = Trim<$ReplaceDelimiters<$SpaceBeforeCaps, Del, '', false>>; /** Lowercase all the words in a tuple */ type $LowercaseWords = T extends [infer H extends string, ...infer R extends string[]] ? [Lowercase, ...$LowercaseWords] : []; /** Uppercase all the words in a tuple */ type $UppercaseWords = T extends [infer H extends string, ...infer R extends string[]] ? [Uppercase>, ...$UppercaseWords] : []; /** Capitalize (first letter capital) all the words in a tuple */ type $CapitalizeWords = T extends [infer H extends string, ...infer R extends string[]] ? [Capitalize>, ...$CapitalizeWords] : []; /** Capitalize (first letter capital) all the words in a tuple */ type $TitleCaseWords = T extends [infer H extends string, ...infer R extends string[]] ? [H extends $LowerCaseWord ? Lowercase : Capitalize>, ...$TitleCaseWords] : []; /** * - Converts a string literal `Str` into `camelCase`, using optional custom delimiters `Del` alongside {@link $DefaultDelimiters}. * @remarks TypeScript supports up to ~45 characters for reliable literal inference. */ type CamelCase = Split<$NormalizeString, ' '> extends [infer F extends string, ...infer R extends string[]] ? `${Lowercase}${Join<$CapitalizeWords, ''>}` : ''; /** * - Converts a string literal `Str` into `snake_case`, using optional custom delimiters `Del` alongside {@link $DefaultDelimiters}. * @remarks TypeScript supports up to ~45 characters for reliable literal inference. */ type SnakeCase = Join<$LowercaseWords, ' '>>, '_'>; /** * - Converts a string literal `Str` into `kebab-case`, using optional custom delimiters `Del` alongside {@link $DefaultDelimiters}. * @remarks TypeScript supports up to ~45 characters for reliable literal inference. */ type KebabCase = Join<$LowercaseWords, ' '>>, '-'>; /** * - Converts a string literal `Str` into `PascalCase`, using optional custom delimiters `Del` alongside {@link $DefaultDelimiters}. * @remarks TypeScript supports up to ~45 characters for reliable literal inference. */ type PascalCase = Join<$CapitalizeWords, ' '>>, ''>; /** * - Converts a string literal `Str` into `Pascal_Snake_Case`, using optional custom delimiters `Del` alongside {@link $DefaultDelimiters}. * @remarks TypeScript supports up to ~45 characters for reliable literal inference. */ type PascalSnakeCase = Join<$CapitalizeWords, ' '>>, '_'>; /** * - Converts a string literal `Str` into `CONSTANT_CASE`, using optional custom delimiters `Del` alongside {@link $DefaultDelimiters}. * @remarks TypeScript supports up to ~45 characters for reliable literal inference. */ type ConstantCase = Join<$UppercaseWords, ' '>>, '_'>; /** * - Converts a string literal `Str` into `Train-Case`, using optional custom delimiters `Del` alongside {@link $DefaultDelimiters}. * @remarks TypeScript supports up to ~45 characters for reliable literal inference. */ type TrainCase = Join<$CapitalizeWords, ' '>>, '-'>; /** * - Converts a string literal `Str` into `Dot.Case`/`dot.case`, using optional custom delimiters `Del` alongside {@link $DefaultDelimiters}. * @remarks TypeScript supports up to ~45 characters for reliable literal inference. */ type DotCase = Join, ' '>, '.'>; /** * - Converts a string literal `Str` into `path/case`, using optional custom delimiters `Del` alongside {@link $DefaultDelimiters}. * @remarks TypeScript supports up to ~45 characters for reliable literal inference. */ type PathCase = Join<$LowercaseWords, ' '>>, '/'>; /** * - Converts a string literal `Str` into `Title Case`, using optional custom delimiters `Del` alongside {@link $DefaultDelimiters}. * @remarks * - TypeScript supports up to ~45 characters for reliable literal inference. * - Lowercase auxiliaries, prepositions, articles and conjunctions unless they are at the beginning. */ type TitleCase = Split<$NormalizeString, ' '> extends [infer F extends string, ...infer R extends string[]] ? `${Capitalize>} ${Join<$TitleCaseWords, ' '>}` : ' '; /** * - Converts a string literal `Str` into `Sentence case`, using optional custom delimiters `Del` alongside {@link $DefaultDelimiters}. * @remarks It will lowercase: auxiliaries, prepositions, articles and conjunctions unless they are at the beginning. */ type SentenceCase = Split<$NormalizeString, ' '> extends [infer F extends string, ...infer R extends string[]] ? `${Capitalize>} ${Join<$LowercaseWords, ' '>}` : ' '; /** Helper type to convert an empty string to `string` while maintaining the literal type otherwise. */ type $WidenEmpty = T extends '' ? string : T; /** Matches any non-Latin character. */ type SpecialCharacter = Lowercase & Uppercase; /** Evaluates whether a string consists only of Latin alphabet characters. */ type IsAlphabet = T extends `${infer Head}${infer Tail}` ? Head extends SpecialCharacter ? false : IsAlphabet : true; /** Restricts a string to Latin-only characters; otherwise resolves to never. */ type Alphabet = IsAlphabet extends true ? T : never; /** Types related to string diffing and similarity calculations. */ type DiffLineType = 'added' | 'removed' | 'unchanged' | 'modified'; /** Represents a single line's diff status between two strings, including the type of difference and the content of the line in both original and modified strings. */ type DiffLine = UnchangedOrModifiedDiffLine | AddedDiffLine | RemovedDiffLine; /** Represents the details of a single line in the diff, including its content and line number. */ interface DiffLineDetails { /** The content of the original line, omitted for `added` lines. */ original: string; /** The content of the modified line, omitted for `removed` lines. */ modified: string; /** The line number in the original string (1-based), omitted for `added` lines. */ originalLineNum: number; /** The line number in the modified string (1-based), omitted for `removed` lines. */ modifiedLineNum: number; } /** Represents an unchanged or modified line, including both original and modified content and their respective line numbers. */ interface UnchangedOrModifiedDiffLine extends DiffLineDetails { /** The type of difference, either `'unchanged'` or `'modified'`. */ type: 'unchanged' | 'modified'; } /** Represents an added line, including only its content and line number in the modified string. */ interface AddedDiffLine extends Omit { /** The type of difference, fixed to `'added'`. */ type: 'added'; } /** Represents a removed line, including only its content and line number in the original string. */ interface RemovedDiffLine extends Omit { /** The type of difference, fixed to `'removed'`. */ type: 'removed'; } /** Statistics summarizing the diff results, including counts of added, removed, changed, and unchanged lines. */ interface DiffStats { /** Total number of lines that were added in the modified string compared to the original. */ linesAdded: number; /** Total number of lines that were removed from the original string in the modified version. */ linesRemoved: number; /** Total number of lines that were modified (changed content) between the original and modified strings. */ linesChanged: number; /** Total number of lines that remained unchanged between the original and modified strings. */ linesUnchanged: number; } /** The result of a line-level diff operation, including an array of line differences and summary statistics. */ interface DiffResult { /** An array of line differences, where each line is categorized as 'added', 'removed', 'unchanged', or 'modified'. */ lines: DiffLine[]; /** Statistics summarizing the diff results, including counts of added, removed, changed, and unchanged lines. */ stats: DiffStats; } /** A single character annotated with a `highlighted` flag indicating whether it differs from the other string in a diff operation. */ interface HighlightedText { /** The text content of the character. */ text: string; /** Whether the character is different from the other string in a diff operation. */ highlighted: boolean; } /** Result of a character-level diff, mapping each character in both strings to a `highlighted` flag. */ interface CharDiffResult { /** An array of characters from the original string, each annotated with a `highlighted` flag indicating whether it differs from the modified string. */ original: HighlightedText[]; /** An array of characters from the modified string, each annotated with a `highlighted` flag indicating whether it differs from the original string. */ modified: HighlightedText[]; } /** Options for `htmlToText` utility. */ interface HtmlToTextOptions { /** * Converts `
` tags into line breaks. * * @default true */ brToNewLine?: boolean; /** * Inserts line breaks before and after common block-level HTML elements. * * This helps preserve the original document structure instead of merging * paragraphs, headings, list items, table rows, and other block elements into a single line. * * @default true */ blockToNewLine?: boolean; /** * Decodes a small set of common HTML entities. * * Supported entities include: `&`, `<`, `>`, `"`, `'`, ` `, * decimal numeric entities (`{`) and hexadecimal entities (`😀`). * * @default true */ decodeEntities?: boolean; /** * Removes the contents of `