import * as os from 'os' ; public export enum Encoding { Utf8 = 'utf8' } public export enum NewlineKind { /**
     * Windows-style newlines
     */ CrLf = '\r\n' , remarks Lf = '\n' , /**
     * Default newline type for this operating system (`os.EOL`).
     */ OsDefault = 'os' } remarks public export class Text { private static readonly _newLineRegEx : RegExp = /\r\n|\n\r|\r|\n/g ; private static readonly _newLineAtEndRegEx : RegExp = /(\r\n|\n\r|\r|\n)$/ ; param input param searchValue param replaceValue public static replaceAll ( input , searchValue , replaceValue ) { return input . split ( searchValue ) . join ( replaceValue ) ; } /**
     * Converts all newlines in the provided string to use Windows-style CRLF end of line characters.
     */ public static convertToCrLf ( input ) { return input . replace ( Text . _newLineRegEx , '\r\n' ) ; } /**
     * Converts all newlines in the provided string to use POSIX-style LF end of line characters.
     *
     * POSIX is a registered trademark of the Institute of Electrical and Electronic Engineers, Inc.
     */ public static convertToLf ( input ) { return input . replace ( Text . _newLineRegEx , '\n' ) ; } /**
     * Converts all newlines in the provided string to use the specified newline type.
     */ public static convertTo ( input , newlineKind ) { return input . replace ( Text . _newLineRegEx , Text . getNewline ( newlineKind ) ) ; } /**
     * Returns the newline character sequence for the specified `NewlineKind`.
     */ public static getNewline ( newlineKind ) { switch ( newlineKind ) { case NewlineKind . CrLf : return '\r\n' ; case NewlineKind . Lf : return '\n' ; case NewlineKind . OsDefault : return os . EOL ; default : throw new Error ( 'Unsupported newline kind' ) ; } } remarks public static padEnd ( s , minimumLength , paddingCharacter = ' ' ) { if ( paddingCharacter . length !== 1 ) { throw new Error ( 'The paddingCharacter parameter must be a single character.' ) ; } if ( s . length < minimumLength ) { const paddingArray = new Array ( minimumLength - s . length ) ; paddingArray . unshift ( s ) ; return paddingArray . join ( paddingCharacter ) ; } else { return s ; } } remarks public static padStart ( s , minimumLength , paddingCharacter = ' ' ) { if ( paddingCharacter . length !== 1 ) { throw new Error ( 'The paddingCharacter parameter must be a single character.' ) ; } if ( s . length < minimumLength ) { const paddingArray = new Array ( minimumLength - s . length ) ; paddingArray . push ( s ) ; return paddingArray . join ( paddingCharacter ) ; } else { return s ; } } remarks public static truncateWithEllipsis ( s , maximumLength ) { if ( maximumLength < 0 ) { throw new Error ( 'The maximumLength cannot be a negative number' ) ; } if ( s . length <= maximumLength ) { return s ; } if ( s . length <= 3 ) { return s . substring ( 0 , maximumLength ) ; } return s . substring ( 0 , maximumLength - 3 ) + '...' ; } /**
     * Returns the input string with a trailing `\n` character appended, if not already present.
     */ public static ensureTrailingNewline ( s , newlineKind = NewlineKind . Lf ) { if ( Text . _newLineAtEndRegEx . test ( s ) ) { return s ; } return s + newlineKind ; } }