@dvrd/dvr-controls 1.1.10 → 1.1.12

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dvrd/dvr-controls",
3
- "version": "1.1.10",
3
+ "version": "1.1.12",
4
4
  "description": "Custom web controls",
5
5
  "main": "index.ts",
6
6
  "files": [
@@ -7,13 +7,13 @@ import {debug, getSetting} from "./miscUtil";
7
7
 
8
8
  let jwtToken: string | null = null;
9
9
 
10
- export const getJwt = (): string | null => {
10
+ export const getJwt = (cookieName: string = 'JWT'): string | null => {
11
11
  if (jwtToken && jwtToken.length) return jwtToken;
12
12
 
13
13
  const jwt = getJwtFromStorage();
14
14
  if (jwt && jwt.length) return jwt;
15
15
 
16
- const cookieJwt = Cookies.get('JWT');
16
+ const cookieJwt = Cookies.get(cookieName);
17
17
  if (cookieJwt && cookieJwt.length)
18
18
  return cookieJwt;
19
19
  return null;
@@ -102,7 +102,7 @@ export const downloadFile = (blob: Blob, fileName: string) => {
102
102
  link.click();
103
103
  };
104
104
 
105
- export const downloadRequiredFile = (path: string | { default: string }, fileName?: string) => {
105
+ export const downloadRequiredFile = (path: string | {default: string}, fileName?: string) => {
106
106
  if (typeof path !== 'string') path = path.default;
107
107
  const name = getFileName(path, fileName);
108
108
  const link = document.createElement('a');
@@ -147,11 +147,14 @@ export function nullify<T extends string | Array<any> | Set<any> | number | bigi
147
147
  else if (value instanceof Set)
148
148
  return value.size ? value : null;
149
149
  return null;
150
- };
150
+ }
151
151
 
152
- export const undefine = (value?: string | null): string | undefined => {
153
- return value?.length ? value : undefined;
154
- };
152
+ export function undefine<T>(value?: T | null): T | undefined {
153
+ if (value === null || value === undefined) return undefined;
154
+ if (value.hasOwnProperty('length') && !(value as unknown as {length: number}).length) return undefined;
155
+ if (value instanceof Set && !value.size) return undefined;
156
+ return value;
157
+ }
155
158
 
156
159
  export const sanitizeHtml = (html: string) => {
157
160
  return DOMPurify().sanitize(html);