File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -144,3 +144,23 @@ function sortByEnumPos(e: any, arr: any[]) {
144
144
return index1 - index2 ;
145
145
} ) ;
146
146
}
147
+
148
+ const ESCAPE_CHARACTERS = [ '\n' , '\r' , '\t' ] ;
149
+ const ESCAPE_CHARACTERS_STRING = [ '\\n' , '\\r' , '\\t' ] ;
150
+
151
+ export function hasPreEscapeCharacters ( str : string ) : boolean {
152
+ return ESCAPE_CHARACTERS . some ( char => str . includes ( char ) ) ;
153
+ }
154
+ export function replaceStringEscapeCharacters ( str : string , toEscaped : boolean = true ) : string {
155
+ if ( toEscaped ) {
156
+ ESCAPE_CHARACTERS . forEach ( ( char , index ) => {
157
+ str = str . replace ( char , ESCAPE_CHARACTERS_STRING [ index ] ) ;
158
+ } ) ;
159
+
160
+ } else {
161
+ ESCAPE_CHARACTERS_STRING . forEach ( ( char , index ) => {
162
+ str = str . replace ( char , ESCAPE_CHARACTERS [ index ] ) ;
163
+ } ) ;
164
+ }
165
+ return str ;
166
+ }
You can’t perform that action at this time.
0 commit comments