File tree Expand file tree Collapse file tree
libraries/node-core-library/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -74,3 +74,10 @@ class Path {
7474 static isUnder ( childPath : string , parentFolderPath : string ) : boolean ;
7575}
7676
77+ // @public
78+ class Text {
79+ static convertToCrLf ( input : string ) : string ;
80+ static convertToLf ( input : string ) : string ;
81+ static replaceAll ( input : string , searchValue : string , replaceValue : string ) : string ;
82+ }
83+
Original file line number Diff line number Diff line change 1+ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
2+ // See LICENSE in the project root for license information.
3+
4+ /**
5+ * Operations for working with strings that contain text.
6+ *
7+ * @remarks
8+ * The utilities provided by this class are intended to be simple, small, and very
9+ * broadly applicable.
10+ *
11+ * @public
12+ */
13+ export class Text {
14+ private static readonly _newLineRegEx : RegExp = / \r \n | \n \r | \r | \n / g;
15+
16+ /**
17+ * Returns the same thing as targetString.replace(searchValue, replaceValue), except that
18+ * all matches are replaced, rather than just the first match.
19+ * @param input - The string to be modified
20+ * @param searchValue - The value to search for
21+ * @param replaceValue - The replacement text
22+ */
23+ public static replaceAll ( input : string , searchValue : string , replaceValue : string ) : string {
24+ return input . split ( searchValue ) . join ( replaceValue ) ;
25+ }
26+
27+ /**
28+ * Converts all newlines in the provided string to use Windows-style CRLF end of line characters.
29+ */
30+ public static convertToCrLf ( input : string ) : string {
31+ return input . replace ( Text . _newLineRegEx , '\r\n' ) ;
32+ }
33+
34+ /**
35+ * Converts all newlines in the provided string to use Unix-style LF end of line characters.
36+ */
37+ public static convertToLf ( input : string ) : string {
38+ return input . replace ( Text . _newLineRegEx , '\n' ) ;
39+ }
40+
41+ }
Original file line number Diff line number Diff line change @@ -23,4 +23,5 @@ export { PackageJsonLookup } from './PackageJsonLookup';
2323export {
2424 LockFile
2525} from './LockFile' ;
26- export { Path } from './Path' ;
26+ export { Path } from './Path' ;
27+ export { Text } from './Text' ;
You can’t perform that action at this time.
0 commit comments