zavadil-ts-common 1.2.33 → 1.2.35

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,9 +1,12 @@
1
- import { ObjectUtil } from "./ObjectUtil";
1
+ export class StringUtil {
2
2
 
3
- export class StringUtil extends ObjectUtil {
3
+ static toString(s: any) {
4
+ return typeof s === 'string' ? s : s?.toString?.() ?? '';
5
+ }
4
6
 
5
7
  static isEmpty(str: string | null | undefined): boolean {
6
- return ObjectUtil.isEmpty(str) || str?.length === 0;
8
+ if (typeof str !== 'string') return StringUtil.isEmpty(StringUtil.toString(str));
9
+ return str.length === 0;
7
10
  }
8
11
 
9
12
  static notEmpty(str: string | null | undefined): boolean {
@@ -9,6 +9,12 @@ describe('testing StringUtil', () => {
9
9
  expect(StringUtil.getNonEmpty('', null, undefined, 'test')).toBe('test');
10
10
  expect(StringUtil.getNonEmpty('', 'test', undefined, 'test2')).toBe('test');
11
11
  });
12
+ test('getNonEmpty', () => {
13
+ expect(StringUtil.getNonEmpty('test')).toBe('test');
14
+ expect(StringUtil.getNonEmpty('', 'test')).toBe('test');
15
+ expect(StringUtil.getNonEmpty('', null, undefined, 'test')).toBe('test');
16
+ expect(StringUtil.getNonEmpty('', 'test', undefined, 'test2')).toBe('test');
17
+ });
12
18
  });
13
19
 
14
20
  describe('testing JsonUtil', () => {