import type { RandomSource } from './number'; import type { ExtractParams } from './types'; /** `length` characters of `charset` read by code point, each drawn from `random`; pass `cryptoRandom` for secrets, whose 53 bits keep the bias below charset size / 2^53. */ export declare function randomString(length: number, charset?: string, random?: RandomSource): string; /** remove accents and diacritics */ export declare function normalizeAccents(str: string): string; export declare function escapeRegExp(str: string): string; /** * converts a string into a slug * @param {string} str * @param {object} [options] * @param {string} [options.replace] the string to replace non-alphanumeric characters with (default='-'). * @param {boolean} [options.lower] convert the string to lowercase (default=true). * @param {boolean} [options.trim] trim leading/trailing whitespace (default=true). * @param {boolean} [options.deduplicate] deduplicate successives `replace` char (default=true) */ export declare function slugify(str: string, { deduplicate, lower, replace, trim, }?: { deduplicate?: boolean; lower?: boolean; replace?: string; trim?: boolean; }): string; /** * Initials of a name, for avatars and monograms. Words are split by {@link splitWords}, so * separators, camelCase and non-Latin scripts all work. Accents are kept - an initial is the * name as written, not a slug of it; reach for {@link slugify} when you want it folded to ASCII. * @param {string|string[]} name one string (`'Ada Lovelace'`) or its parts (`['Ada', 'Lovelace']`) * @param {object} [options] * @param {number} [options.max] how many characters to return (default=2). * @param {boolean} [options.pad] top a single-word name up to `max` from its own letters, so * `'ada'` reads as `AD` rather than a lone `A` (default=true). * @example getInitials('Ada Lovelace') // 'AL' * @example getInitials('ada-lovelace') // 'AL' * @example getInitials('José Álvarez') // 'JÁ' * @example getInitials('kaynooo') // 'KA' * @example getInitials('kaynooo', { pad: false }) // 'K' * @example getInitials('International Business Machines', { max: 3 }) // 'IBM' */ export declare function getInitials(name: string | string[], { max, pad, }?: { max?: number; pad?: boolean; }): string; export declare function capitalize(str: string): string; /** Splits on `separator`, trimming each item and dropping the empty ones: `' a, ,b '` gives `['a', 'b']`. */ export declare function splitList(text: string, separator?: string | RegExp): string[]; export interface SearchOptions { /** Tells `A` from `a`. Defaults to false. */ caseSensitive?: boolean; /** Tells `é` from `e`. Defaults to false. */ accentSensitive?: boolean; } /** Whether any value contains the query, case and accents folded unless `options` say otherwise. */ export declare function searchOne(query: string, ...values: string[]): boolean; export declare function searchOne(query: string, values: string[], options?: SearchOptions): boolean; /** Whether every value contains the query, case and accents folded unless `options` say otherwise. */ export declare function searchAll(query: string, ...values: string[]): boolean; export declare function searchAll(query: string, values: string[], options?: SearchOptions): boolean; /** whether every whitespace-separated term of the query is spread through one of the values, in order */ export declare function searchFuzzy(query: string, ...values: string[]): boolean; export declare function searchFuzzy(query: string, values: string[], options?: SearchOptions): boolean; /** * remove JavaScript/TypeScript/JSONC comments from code * handles single-line (//) and multi-line (/* *\/) comments while preserving string literals */ export declare function removeComments(content: string): string; export declare function escapeXml(unsafe: string): string; /** Escapes what HTML treats specially, the backtick included since IE once read one as an attribute delimiter. Use `escapeXml` for XML, which spells the apostrophe `'`. */ export declare function escapeHtml(text: string): string; /** Base64 of text's UTF-8 bytes, so any character encodes where `btoa` throws past Latin-1, or of bytes as they are; `url` gives the url-safe alphabet without padding. */ export declare function base64Encode(input: string | BufferSource, url?: boolean): string; /** The bytes behind base64, in either alphabet, with or without padding; throws when it is not base64. */ export declare function base64DecodeBytes(encoded: string): Uint8Array; /** The UTF-8 text behind base64, in either alphabet, with or without padding; throws when it is not base64 or not UTF-8. */ export declare function base64Decode(encoded: string): string; /** Quotes a CSV field holding a quote, the delimiter or a line break, doubling its quotes. */ export declare function escapeCSV(value: string | number, delimiter?: string): string; export declare function commonPrefixLength(str1: string, str2: string): number; export declare function commonPrefix(str1: string, str2: string): string; /** edits turning one string into the other, a swap of two neighbours counting as one edit like an insertion, deletion or substitution */ export declare function editDistance(str1: string, str2: string): number; export interface ClosestMatchOptions { /** Most edits a match may be away. Defaults to a third of the query, at least 1. */ maxDistance?: number; /** Tells `A` from `a`. Defaults to false, like `searchOne`. */ caseSensitive?: boolean; } /** the candidate nearest the query, for a "did you mean", or undefined when none is within `maxDistance` edits (a third of the query by default) */ export declare function closestMatch(query: string, candidates: Iterable, maxDistanceOrOptions?: number | ClosestMatchOptions): string | undefined; export declare function getUUIDFromIri(iri: string): string | null; /** A text progress bar; throws a RangeError for a NaN value, a non-finite bound or a `totalChars` that is not a non-negative integer, and clamps an infinite `value` into the range. */ export declare function renderProgressBar(value: number, min: number, max: number, { emptyChar, endChar, fillChar, startChar, tipChar, totalChars }?: { emptyChar?: string | undefined; endChar?: string | undefined; fillChar?: string | undefined; startChar?: string | undefined; tipChar?: string | undefined; totalChars?: number | undefined; }): string; export interface PluralOptions { /** The plural form for a word the rules get wrong, like `children`. */ plural?: string; /** Whether a count of zero reads singular (`0 rule`, French style) or plural (`0 rules`). */ zero?: 'singular' | 'plural'; } /** handle common pluralization rules; zero reads singular unless `zero: 'plural'` */ export declare function plural(singular: string, count?: number, { plural: pluralForm, zero }?: PluralOptions): string; /** `1 rule`, `3 rules`: a count and the word it agrees with; zero reads plural unless `zero: 'singular'` */ export declare function counted(count: number, singular: string, { zero, ...options }?: PluralOptions): string; /** `base`, then `base_2`, `base_3`: the first name nothing in `taken` already holds */ export declare function uniqueName(base: string, taken: ReadonlySet | readonly string[], { separator, start }?: { separator?: string | undefined; start?: number | undefined; }): string; export declare function minifyUUID(uuid: string): string; export declare function expandUUID(minified: string): string; export declare function splitWords(str: string | string[]): string[]; export type CaseType = 'kebab' | 'snake' | 'camel' | 'pascal' | 'constant' | 'title'; export declare function toCamel(input: string | string[]): string; export declare function toKebab(input: string | string[]): string; export declare function toSnake(input: string | string[]): string; export declare function toPascal(input: string | string[]): string; export declare function toConstant(input: string | string[]): string; export declare function toTitle(input: string | string[]): string; export declare function getFrenchOrdinalSuffix(rank: string): "er" | "nd" | "ème"; export interface TruncateOptions { /** Defaults to `...`. */ suffix?: string; /** Counts the suffix within `len`, so the result never exceeds it. Defaults to false. */ includeSuffix?: boolean; /** Cuts at the last whitespace before the limit, when there is one. Defaults to false. */ wordBoundary?: boolean; } /** Cuts `str` past `len` characters and appends the suffix; with `includeSuffix` the result never exceeds `len`, even when the suffix alone would. */ export declare function truncate(str: string, len: number, suffixOrOptions?: string | TruncateOptions): string; export declare function stripHtml(str: string): string; /** Replaces each `{key}` in one pass, so a value is inserted as is: its `$&` or `{other}` text is never read as a pattern or a variable. */ export declare function renderTemplate(str: T, variables: ExtractParams): string; export type MaskKey = 'creditCard' | 'custom' | 'dbUrl' | 'email' | 'gitToken' | 'iban' | 'ip' | 'mac' | 'pem' | 'phone' | 'token' | 'url'; export interface MaskCustomRule { pattern: RegExp; replacer: (match: string) => string; } export interface MaskRange { end: number; key: MaskKey; /** only present when `keepOriginals: true` */ original?: string; start: number; } export interface MaskOptions { creditCard?: boolean; custom?: MaskCustomRule[]; dbUrl?: boolean; email?: boolean; gitToken?: boolean; iban?: boolean; ip?: boolean; /** * keep the original matched text in `ranges[].original`. * defaults to `false` because the masked result should not carry the raw secrets. */ keepOriginals?: boolean; mac?: boolean; mode?: 'mask' | 'redact'; pem?: boolean; phone?: boolean; replace?: string; token?: boolean; url?: boolean; } export interface MaskResult { hits: Record; ranges: MaskRange[]; result: string; } export declare function mask(str: string, { creditCard, custom, dbUrl, email, gitToken, iban, ip, keepOriginals, mac, mode, pem, phone, replace: char, token, url, }?: MaskOptions): MaskResult; export interface MaskEnvOptions extends MaskOptions { /** mask each value with `mask` instead of dropping it, so the file keeps its shape */ maskValues?: boolean; } export interface MaskEnvResult { keys: string[]; result: string; } /** * strips a `.env` down to the keys it declares, keeping blank lines, comments and `export` prefixes. * `maskValues` keeps the values instead, run through `mask`. A commented-out assignment loses its value * like a live one, and a line that declares nothing at all is dropped rather than passed through. */ export declare function maskEnv(str: string, { maskValues, ...options }?: MaskEnvOptions): MaskEnvResult; /** * repairs text whose utf-8 bytes were read as cp1252 and written back: `Æbleflæsk` -> `Æbleflæsk`. * all or nothing, so a string that is not mojibake all the way through comes back untouched. */ export declare function repairMojibake(str: string): string; export interface TextSpan { text: string; offset: number; } /** Every run of non-whitespace, with where it starts in `text`. */ export declare function tokenizeWords(text: string): TextSpan[]; /** Every line, blank ones included, with where it starts in `text`; the `\r` of a `\r\n` ending is left out of the line. A trailing newline ends the last line rather than starting an empty one. */ export declare function tokenizeLines(text: string): TextSpan[]; /** Sentences with where each starts, split by the locale's own rules rather than by punctuation. */ export declare function splitSentences(text: string, locale?: string): TextSpan[]; /** * Joins adjacent spans until each carries at least `minLength` non-whitespace characters. * * Spans must be contiguous, the way [splitSentences] returns them: merging concatenates their text * and keeps the first offset, so a gap between two spans would be lost. */ export declare function mergeSpans(spans: TextSpan[], minLength: number): TextSpan[]; /** A span's bounds with its surrounding whitespace excluded, or null when it holds none. */ export declare function trimSpan(span: TextSpan): [number, number] | null; export interface Excerpt { text: string; offset: number; length: number; } /** * A window of `text` around one span, for showing an error in context. * * `offset` indexes the excerpt rather than the source, and counts the ellipsis when one was added, * so `excerpt.text.slice(offset, offset + length)` is always the span itself. */ export declare function excerptAround(text: string, offset: number, length: number, { radius, ellipsis }?: { ellipsis?: string | undefined; radius?: number | undefined; }): Excerpt; //# sourceMappingURL=text.d.ts.map