zavadil-ts-common 1.2.75 → 1.2.77

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.
@@ -16,6 +16,7 @@ export declare class StringUtil {
16
16
  static safeTrim(str: string | null | undefined): string;
17
17
  static safeLowercase(str: string | null | undefined): string;
18
18
  static safeUppercase(str: string | null | undefined): string;
19
+ static capitalizeFirstLetter(str: string | null | undefined): string;
19
20
  static toBigInt(str: string | null): bigint | null;
20
21
  static getNonEmpty(...args: Array<string | null | undefined>): string;
21
22
  static getNonBlank(...args: Array<string | null | undefined>): string;
@@ -3,4 +3,5 @@ export declare class UrlUtil {
3
3
  static extractParamFromUrl(url: string, name: string): string | null;
4
4
  static paramExistsInUrl(url: string, name: string): boolean;
5
5
  static extractHostFromUrl(url: string): string | null;
6
+ static extractDomainFromUrl(url: string): string | null;
6
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zavadil-ts-common",
3
- "version": "1.2.75",
3
+ "version": "1.2.77",
4
4
  "description": "Common types and components for Typescript UI apps.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",
@@ -4,7 +4,7 @@ import {StringUtil} from "./StringUtil";
4
4
  export class OAuthUtil {
5
5
 
6
6
  static isValidToken(token?: TokenResponsePayloadBase | null): boolean {
7
- return token !== undefined && token !== null && StringUtil.notEmpty(token.token) && !OAuthUtil.isTokenExpired(token);
7
+ return token !== undefined && token !== null && StringUtil.notBlank(token.token) && !OAuthUtil.isTokenExpired(token);
8
8
  }
9
9
 
10
10
  static isTokenExpired(token?: TokenResponsePayloadBase | null): boolean {
@@ -85,6 +85,11 @@ export class StringUtil {
85
85
  return StringUtil.toString(str).toUpperCase();
86
86
  }
87
87
 
88
+ static capitalizeFirstLetter(str: string | null | undefined): string {
89
+ if (StringUtil.isBlank(str)) return '';
90
+ return StringUtil.safeUppercase(str.charAt(0)) + StringUtil.safeLowercase(StringUtil.substr(str, 1));
91
+ }
92
+
88
93
  static toBigInt(str: string | null): bigint | null {
89
94
  if (this.isEmpty(str)) return null;
90
95
 
@@ -16,9 +16,15 @@ export class UrlUtil {
16
16
  static paramExistsInUrl(url: string, name: string): boolean {
17
17
  return StringUtil.notBlank(UrlUtil.extractParamFromUrl(url, name));
18
18
  }
19
+
19
20
  static extractHostFromUrl(url: string): string | null {
20
21
  if (StringUtil.isBlank(url)) return null;
21
22
  return new URL(url).host;
22
23
  }
23
24
 
25
+ static extractDomainFromUrl(url: string): string | null {
26
+ const host = UrlUtil.extractHostFromUrl(url);
27
+ if (StringUtil.isBlank(host)) return null;
28
+ return host.split('.').slice(-2).join('.');
29
+ }
24
30
  }
@@ -1,6 +1,4 @@
1
- import { StringUtil } from '../src/util/StringUtil';
2
- import {JsonUtil} from "../src/util/JsonUtil";
3
- import {RestClient} from "../src";
1
+ import { StringUtil, JsonUtil, RestClient } from '../src';
4
2
 
5
3
  describe('testing StringUtil', () => {
6
4
  test('isEmpty', () => {
@@ -23,6 +21,13 @@ describe('testing StringUtil', () => {
23
21
  expect(StringUtil.getNonEmpty('', null, undefined, 'test')).toBe('test');
24
22
  expect(StringUtil.getNonEmpty('', 'test', undefined, 'test2')).toBe('test');
25
23
  });
24
+ test('capitalizeFirstLetter', () => {
25
+ expect(StringUtil.capitalizeFirstLetter('test')).toBe('Test');
26
+ expect(StringUtil.capitalizeFirstLetter('TesT')).toBe('Test');
27
+ expect(StringUtil.capitalizeFirstLetter('')).toBe('');
28
+ expect(StringUtil.capitalizeFirstLetter(null)).toBe('');
29
+
30
+ });
26
31
  });
27
32
 
28
33
  describe('testing JsonUtil', () => {