Skip to content

Commit

Permalink
feat(common): add utility class Strings with replaceAll
Browse files Browse the repository at this point in the history
This is a method that is used pretty often but not included
in the Javascript language itself.
What the method does is what you would expect, it finds
all occurrences of a substring and replaces all of them with
another one. The deafult Javascript String.replace function
only does this with the first occurrence by default so it is not
a good solution.

Signed-off-by: Peter Somogyvari <[email protected]>
  • Loading branch information
petermetz authored and sfuji822 committed Jun 17, 2020
1 parent a58c81e commit 3986aed
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/cactus-common/src/main/typescript/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export { LoggerProvider } from "./logging/logger-provider";
export { Logger, ILoggerOptions } from "./logging/logger";
export { LogLevelDesc } from "loglevel";
export { Objects } from "./objects";
export { Strings } from "./strings";
9 changes: 9 additions & 0 deletions packages/cactus-common/src/main/typescript/strings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export class Strings {
public static replaceAll(
source: string,
searchValue: string,
replaceValue: string
): string {
return source.replace(new RegExp(searchValue, "gm"), replaceValue);
}
}

0 comments on commit 3986aed

Please sign in to comment.