zavadil-ts-common 1.2.67 → 1.2.69

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  export declare class ObjectUtil {
2
- static isEmpty(obj: any): boolean;
2
+ static isEmpty(obj: any): obj is null | undefined;
3
3
  static notEmpty(obj: any): boolean;
4
4
  static clone<T>(obj: T): T;
5
5
  static getNestedValue(obj: any, path: string): string;
@@ -1,12 +1,12 @@
1
1
  export declare class StringUtil {
2
2
  static toString(s: any): string;
3
- static isEmpty(str: string | null | undefined): boolean;
3
+ static isEmpty(str: string | null | undefined): str is null | undefined;
4
4
  static notEmpty(str: string | null | undefined): str is string;
5
- static isBlank(str: string | null | undefined): boolean;
5
+ static isBlank(str: string | null | undefined): str is null | undefined | "";
6
6
  static notBlank(str: string | null | undefined): str is string;
7
7
  static substr(str: string | null | undefined, start: number, length?: number): string;
8
8
  static replace(str: string | null | undefined, find?: null | string, replace?: string): string;
9
- static containsLineBreaks(str: string | null | undefined): boolean;
9
+ static containsLineBreaks(str: string | null | undefined): str is string;
10
10
  static trimLeadingSlashes(str: string | null): string;
11
11
  static trimTrailingSlashes(str: string | null): string;
12
12
  static trimSlashes(str: string | null): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zavadil-ts-common",
3
- "version": "1.2.67",
3
+ "version": "1.2.69",
4
4
  "description": "Common types and components for Typescript UI apps.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",
@@ -2,7 +2,7 @@ import {StringUtil} from "./StringUtil";
2
2
 
3
3
  export class ObjectUtil {
4
4
 
5
- static isEmpty(obj: any) {
5
+ static isEmpty(obj: any): obj is null | undefined {
6
6
  return obj === undefined || obj === null;
7
7
  }
8
8
 
@@ -1,11 +1,13 @@
1
+ import {ObjectUtil} from "./ObjectUtil";
2
+
1
3
  export class StringUtil {
2
4
 
3
5
  static toString(s: any): string {
4
6
  return typeof s === 'string' ? s : s?.toString?.() ?? '';
5
7
  }
6
8
 
7
- static isEmpty(str: string | null | undefined): boolean {
8
- if (typeof str !== 'string') return StringUtil.isEmpty(StringUtil.toString(str));
9
+ static isEmpty(str: string | null | undefined): str is null | undefined {
10
+ if (ObjectUtil.isEmpty(str)) return true;
9
11
  return str.length === 0;
10
12
  }
11
13
 
@@ -13,7 +15,7 @@ export class StringUtil {
13
15
  return !StringUtil.isEmpty(str);
14
16
  }
15
17
 
16
- static isBlank(str: string | null | undefined): boolean {
18
+ static isBlank(str: string | null | undefined): str is null | undefined | "" {
17
19
  return StringUtil.isEmpty(StringUtil.safeTrim(str));
18
20
  }
19
21
 
@@ -30,13 +32,11 @@ export class StringUtil {
30
32
 
31
33
  static replace(str: string | null | undefined, find?: null | string, replace?: string): string {
32
34
  if (this.isEmpty(str) || this.isEmpty(find)) return '';
33
-
34
- // @ts-ignore
35
35
  return str.replace(find, String(replace));
36
36
  }
37
37
 
38
- static containsLineBreaks(str: string | null | undefined): boolean {
39
- if (str === null || str === undefined || str.trim().length === 0) return false;
38
+ static containsLineBreaks(str: string | null | undefined): str is string {
39
+ if (StringUtil.isBlank(str)) return false;
40
40
  return str.includes("\n");
41
41
  }
42
42
 
@@ -72,7 +72,7 @@ export class StringUtil {
72
72
  }
73
73
 
74
74
  static safeTrim(str: string | null | undefined): string {
75
- if (StringUtil.isEmpty(str) || !str) return '';
75
+ if (StringUtil.isEmpty(str)) return '';
76
76
  return str.trim();
77
77
  }
78
78