forked from daniel-sc/ng-extract-i18n-merge
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
156719c
commit c26e9d6
Showing
2 changed files
with
16 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,7 @@ | ||
// Converts sequences of space, tabs and "section breaks" like linefeeds and | ||
// carriage returns to a single space, but leaving other space characters like | ||
// no-break-space (U+00A0) intact. | ||
// Refer to https://developer.mozilla.org/en-US/docs/Web/CSS/white-space-collapse#collapsing_of_white_space | ||
export function doCollapseWhitespace<T extends string | undefined>(destSourceText: T): T { | ||
let result = destSourceText | ||
?.replace(/\t+/g, ' ') // Convert tabs to spaces | ||
?.replace(/(\r\n|\n|\r)+/g, ' ') // Collapse "sequences of segment breaks" to a single space (no need to preserve line-breaks) | ||
?.replace(/ *([^\S ]+) */g, '$1') // Remove space before or after a "space-like" character that is not a space (e.g. no-break space). | ||
?.replace(/ {2,}/g, ' '); // Collapse sequences of spaces to a single space | ||
|
||
return result as T; | ||
return destSourceText?.replace(/[\n\r\t ]+/g, ' ') as T; | ||
} |