UNPKG

symfony-style-console

Version:

Use the style and utilities of the Symfony Console in Node.js

148 lines (147 loc) 5.61 kB
/** * Represents an arbitrary object literal */ export interface ArbitraryObjectLiteral { [s: string]: any; } /** * Represents an object literal with arbitrary strings as values */ export interface StringHash { [s: string]: string; } /** * Count occurrences of `needle` in `haystack`. Doesn't count overlapped substrings. * * @param haystack The string to search in * @param needle The substring to search for * @param offset The offset where to start counting. If the offset is negative, counting starts from the end of the string. * @param length The maximum length after the specified offset to search for the substring. A negative length counts from the end of haystack. */ export declare function countOccurences(haystack: string, needle: string, offset?: number, length?: number): number | false; /** * Generates an array containing the integer values starting with `from` and ending with `to`. * * @param from The lower bound * @param to The upper bound */ export declare function range(from: number, to: number): number[]; /** * Formats a string. * * This is a port of PHP's [`sprintf`](https://secure.php.net/manual/de/function.sprintf.php) function. * * @param format The formatting template * @param args The values to merge into the template */ export declare function sprintf(format: string, ...args: any[]): string; /** * Creates a human-friendly representation of a number of bytes. * * @param memory The number of bytes to format */ export declare function formatMemory(memory: number): string; import OutputFormatterInterface from '../Formatter/OutputFormatterInterface'; /** * Removes `<...>` formatting and ANSI escape sequences from a string. * * @param formatter The formatter instance in charge to resolve `<...>` formatting * @param str The string to perform the removing on */ export declare function removeDecoration(formatter: OutputFormatterInterface, str: string): string; /** * Get the length of a string ignoring `<...>` formatting and ANSI escape sequences. * * @param formatter The formatter instance in charge to resolve `<...>` formatting * @param str The string whose length to determine */ export declare function lengthWithoutDecoration(formatter: OutputFormatterInterface, str: string): number; /** * Creates an object literal with key/value pairs of the given `obj` swapped. * * @param obj The object whose keys and values to use */ export declare function flipObject(obj: ArbitraryObjectLiteral): ArbitraryObjectLiteral; /** * Checks if `item` is contained by `arr`. * * @param arr The array to search in * @param item The item to search for */ export declare function arrContains(arr: any[], item: any): boolean; /** * Creates a human-friendly representation of a number of seconds. * * @param secs The number of seconds to format */ export declare function formatTime(secs: number): string; /** * The available variants to pad a string */ export declare type PAD_TYPE = 'STR_PAD_LEFT' | 'STR_PAD_RIGHT' | 'STR_PAD_BOTH'; /** * Pads a string to a certain length with another string. * * @param input The string to pad * @param padLength The desired length of the resulting string * @param padString The string to use as padding material * @param padType Where to pad the string */ export declare function strPad(input: string, padLength: number, padString: string, padType?: PAD_TYPE): string; /** * Replaces elements from passed arrays into the first array recursively. (non-destructive) * * @param arr The array to patch * @param args The arrays to merge into `arr` */ export declare function arrayReplaceRecursive(arr: any[], ...args: any[][]): any[]; /** * Creates an array filled with a value. * * @param startIndex The index to start filling at. Previous values will be `undefined`. * @param num The number elements to insert * @param value The element to fill the array with */ export declare function arrayFill<T>(startIndex: number, num: number, value: T): T[]; /** * Cuts a string into an array of chunks of given length. * * @param string The string to cut * @param splitLength The length of the resulting chunks */ export declare function chunkString(string: string, splitLength?: number): string[] | false; /** * Strips HTML tags from a string. * * @param input The string to sanitize * @param allowed A string containing a set of allowed tags. Example: `<a><strong><em>` */ export declare function stripTags(input: string, allowed?: string): string; /** * Trims the end of a string. * * @param str The string to trim * @param charlist The characters to trim. Everything that can go into a regex character class is allowed. */ export declare function trimEnd(str: string, charlist?: string): string; /** * Non-recursively replaces a set of values inside a string. * * @param str The string to perform replacements on * @param replacePairs An object that maps strings to their respective replacements */ export declare function safeReplace(str: string, replacePairs: StringHash): string; /** * Wraps a string to a given number of characters. * * Note that, as opposed to PHP's wordwrap, this always cuts words which are too long for one line. * * @param str The string to wrap * @param width The maximum length of a line * @param breakSequence The character(s) to use as line breaks */ export declare function wordwrap(str: string, width?: number, breakSequence?: string): string; /** * Returns the current timestamp in seconds. */ export declare function time(): number;