UNPKG

@kakasoo/proto-typescript

Version:

Utility types and implementations based on JavaScript prototypes.

118 lines 7.83 kB
import { ArrayType, StringType } from '../types'; import { ReadonlyOrNot } from '../types/primitive.type'; export declare namespace StringPrototype { function slice<Container extends string, Start extends number, End extends number>(container: Container, start?: Start, end?: End): StringType.Slice<Container, Start, End>; /** * Returns the position of the first occurrence of a substring. * @param searchString The substring to search for in the string * @param position The index at which to begin searching the String object. If omitted, search starts at the beginning of the string. */ function indexOf<Container extends string, SearchString extends string = '', Position extends number = 0>(container: Container, searchString?: SearchString, position?: Position): StringType.IndexOf<Container, SearchString, Position>; /** * Returns a String value that is made from count copies appended together. If count is 0, * the empty string is returned. * @param count number of copies to append */ function repeat<Container extends string, Counter extends number>(container: Container, counter: Counter): StringType.Repeat<Container, Counter>; /** * Returns true if the sequence of elements of searchString converted to a String is the * same as the corresponding elements of this object (converted to a String) starting at * position. Otherwise returns false. */ function startsWith<Container extends string, SearchString extends string, Position extends number>(container: Container, searchString: SearchString, position?: Position): StringType.StartsWith<Container, SearchString, Position>; /** * Returns true if the sequence of elements of searchString converted to a String is the * same as the corresponding elements of this object (converted to a String) starting at * endPosition – length(this). Otherwise returns false. */ function endsWith<Container extends string, SearchString extends string, EndPosition extends number>(container: Container, searchString: SearchString, endPosition?: EndPosition): StringType.EndsWith<Container, SearchString, EndPosition>; /** * Returns the substring at the specified location within a String object. * @param start The zero-based index number indicating the beginning of the substring. * @param end Zero-based index number indicating the end of the substring. The substring includes the characters up to, but not including, the character indicated by end. * If end is omitted, the characters from start through the end of the original string are returned. */ function substring<Conatiner extends string, Start extends number, End extends number | never = never>(container: Conatiner, start: Start, end?: End): StringType.Substring<Conatiner, Start, End>; /** * Converts all the alphabetic characters in a string to lowercase. */ function toLowerCase<Conatiner extends string>(container: Conatiner): Lowercase<Conatiner>; /** * Converts all the alphabetic characters in a string to uppercase. */ function toUpperCase<Conatiner extends string>(container: Conatiner): Uppercase<Conatiner>; /** * Pads the current string with a given string (possibly repeated) so that the resulting string reaches a given length. * The padding is applied from the start (left) of the current string. * * @param targetLength The length of the resulting string once the current string has been padded. * If this parameter is smaller than the current string's length, the current string will be returned as it is. * * @param padString The string to pad the current string with. * If this string is too long, it will be truncated and the left-most part will be applied. * The default value for this parameter is " " (U+0020). */ function padStart<Conatiner extends string, TargetLength extends number, PadString extends string>(container: Conatiner, targetLength: TargetLength, padString: PadString): StringType.PadStart<Conatiner, TargetLength, PadString>; /** * Pads the current string with a given string (possibly repeated) so that the resulting string reaches a given length. * The padding is applied from the end (right) of the current string. * * @param targetLength The length of the resulting string once the current string has been padded. * If this parameter is smaller than the current string's length, the current string will be returned as it is. * * @param padString The string to pad the current string with. * If this string is too long, it will be truncated and the left-most part will be applied. * The default value for this parameter is " " (U+0020). */ function padEnd<Conatiner extends string, TargetLength extends number, PadString extends string>(container: Conatiner, targetLength: TargetLength, padString: PadString): StringType.PadEnd<Conatiner, TargetLength, PadString>; /** * Returns true if searchString appears as a substring of the result of converting this * object to a String, at one or more positions that are * greater than or equal to position; otherwise, returns false. * @param searchString search string * @param position If position is undefined, 0 is assumed, so as to search all of the String. * * @todo support position parameter */ function includes<Container extends string, SearchString extends string, Position extends number>(container: Container, searchString: SearchString, position?: Position): StringType.Includes<Container, SearchString, Position>; /** * Removes the leading white space and line terminator characters from a string. * @param container * @returns */ function trimStart<Conatiner extends string>(container: Conatiner): StringType.TrimStart<Conatiner>; /** * Removes the trailing white space and line terminator characters from a string. * @param container * @returns */ function trimEnd<Conatiner extends string>(container: Conatiner): StringType.TrimEnd<Conatiner>; /** * Removes the leading and trailing white space and line terminator characters from a string. * @param container * @returns */ function trim<Conatiner extends string>(container: Conatiner): StringType.Trim<Conatiner>; /** * Returns a string that contains the concatenation of two or more strings. * @param strings The strings to append to the end of the string. */ function concat<Container extends string, Strings extends ReadonlyOrNot<string[]>>(container: Container, ...strings: Strings): ArrayType.Join<[Container, ...Strings], ''>; /** * Returns a new String consisting of the single UTF-16 code unit located at the specified index. * @param index The zero-based index of the desired code unit. A negative index will count back from the last item. */ function at<Container extends string, Index extends number>(container: Container, index: Index): StringType.At<Container, Index>; /** * type-safe split. * @example StringPrototype.split('abcde', 'c', 1) // ['ab'] * * @param container original string value. * @param splitter An object that can split a string. * @param limit A value used to limit the number of elements returned in the array. * * @todo support `RegExp` as splitter */ function split<Container extends string, Splitter extends string = '', Limit extends number = ArrayType.Length<StringType.Split<Container, Splitter>>>(container: Container, splitter: Splitter, limit?: Limit): StringType.Split<Container, Splitter, Limit>; } //# sourceMappingURL=string.prototype.d.ts.map