Skip to content

Commit

Permalink
feat(common): add Strings#isNonBlank()
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
  • Loading branch information
petermetz committed Oct 22, 2021
1 parent 28c97d3 commit 8d7d247
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/cactus-common/src/main/typescript/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,17 @@ export class Strings {
return source.replace(new RegExp(searchValue, "gm"), replaceValue);
}

public static isString(val: any): boolean {
public static isString(val: any): val is string {
return typeof val === "string" || val instanceof String;
}

public static isNonBlank(val: unknown): val is string {
if (!Strings.isString(val)) {
return false;
}
return val.trim().length > 0;
}

public static dropNonPrintable(val: string): string {
const fnTag = "Strings#dropNonPrintable()";
Checks.truthy(Strings.isString(val), `${fnTag} Strings.isString(val)`);
Expand Down

0 comments on commit 8d7d247

Please sign in to comment.