forstok-ui-lib 5.2.10 → 5.2.11
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/dist/index.d.ts +2 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +101 -101
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/assets/javascripts/function.ts +44 -34
package/package.json
CHANGED
|
@@ -2,50 +2,56 @@ import { ReactNode } from 'react';
|
|
|
2
2
|
import { TMessage, TMessageQuestion } from '../../components/message/typed';
|
|
3
3
|
|
|
4
4
|
export const getStorage = (name: string, type: string = 'string', defaultVal?: any, loadName: string = 'load') => {
|
|
5
|
-
let result: any
|
|
5
|
+
let result: any;
|
|
6
6
|
if (sessionStorage.getItem(loadName) !== null) {
|
|
7
|
-
result = sessionStorage.getItem(name) !== null ? sessionStorage.getItem(name) : defaultVal
|
|
7
|
+
result = sessionStorage.getItem(name) !== null ? sessionStorage.getItem(name) : defaultVal;
|
|
8
8
|
} else {
|
|
9
|
-
result = localStorage.getItem(name) !== null ? localStorage.getItem(name) : defaultVal
|
|
10
|
-
localStorage.getItem(name) !== null && sessionStorage.setItem(name, result)
|
|
9
|
+
result = localStorage.getItem(name) !== null ? localStorage.getItem(name) : defaultVal;
|
|
10
|
+
localStorage.getItem(name) !== null && sessionStorage.setItem(name, result);
|
|
11
11
|
}
|
|
12
12
|
switch (type) {
|
|
13
13
|
case 'boolean':
|
|
14
|
-
result = (result !== undefined && result !== 'undefined') ? (result === 'true') : false
|
|
15
|
-
break
|
|
14
|
+
result = (result !== undefined && result !== 'undefined') ? (result === 'true') : false;
|
|
15
|
+
break;
|
|
16
16
|
case 'number':
|
|
17
17
|
case 'integer':
|
|
18
|
-
result = (result !== undefined && result !== 'undefined') ? parseInt(result) : 0
|
|
19
|
-
break
|
|
18
|
+
result = (result !== undefined && result !== 'undefined') ? parseInt(result) : 0;
|
|
19
|
+
break;
|
|
20
20
|
case 'object':
|
|
21
21
|
case 'array':
|
|
22
|
-
result = (result !== undefined && result !== 'undefined') ? JSON.parse(result) : undefined
|
|
23
|
-
break
|
|
22
|
+
result = (result !== undefined && result !== 'undefined') ? JSON.parse(result) : undefined;
|
|
23
|
+
break;
|
|
24
24
|
default:
|
|
25
|
-
result = (result === undefined || result === 'undefined') ? '' : result
|
|
26
|
-
break
|
|
25
|
+
result = (result === undefined || result === 'undefined') ? '' : result;
|
|
26
|
+
break;
|
|
27
27
|
}
|
|
28
|
-
return result
|
|
28
|
+
return result;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
export const setStorage = (name: string, value?: any, only?: string) => {
|
|
32
32
|
if (value === undefined || value === null) {
|
|
33
|
-
return false
|
|
33
|
+
return false;
|
|
34
34
|
}
|
|
35
|
-
const _value: string = (typeof value !== 'string') ? ((typeof value === 'object') ? JSON.stringify(value) : value.toString()) : value
|
|
35
|
+
const _value: string = (typeof value !== 'string') ? ((typeof value === 'object') ? JSON.stringify(value) : value.toString()) : value;
|
|
36
36
|
switch (only) {
|
|
37
37
|
case 'session':
|
|
38
|
-
sessionStorage.setItem(name, _value)
|
|
38
|
+
sessionStorage.setItem(name, _value);
|
|
39
39
|
break
|
|
40
40
|
case 'local':
|
|
41
|
-
localStorage.setItem(name, _value)
|
|
41
|
+
localStorage.setItem(name, _value);
|
|
42
42
|
break
|
|
43
43
|
default:
|
|
44
|
-
sessionStorage.setItem(name, _value)
|
|
45
|
-
localStorage.setItem(name, _value)
|
|
44
|
+
sessionStorage.setItem(name, _value);
|
|
45
|
+
localStorage.setItem(name, _value);
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
export const removeStorage = (name: string) => {
|
|
50
|
+
localStorage.removeItem(name);
|
|
51
|
+
sessionStorage.removeItem(name);
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
|
|
49
55
|
export const debounce = (fn: Function, ms = 300) => {
|
|
50
56
|
let timeoutId: ReturnType<typeof setTimeout>;
|
|
51
57
|
return function (this: any, ...args: any[]) {
|
|
@@ -55,22 +61,22 @@ export const debounce = (fn: Function, ms = 300) => {
|
|
|
55
61
|
}
|
|
56
62
|
|
|
57
63
|
export const capitalize = (value?: string) => {
|
|
58
|
-
return value ? (value[0].toUpperCase() + value.substring(1)) : ''
|
|
64
|
+
return value ? (value[0].toUpperCase() + value.substring(1)) : '';
|
|
59
65
|
}
|
|
60
66
|
|
|
61
67
|
export const formatNumber = (n?: string | number, flag?: boolean) => {
|
|
62
|
-
const _flag = flag === undefined ? true : flag
|
|
63
|
-
let result:string = ''
|
|
68
|
+
const _flag = flag === undefined ? true : flag;
|
|
69
|
+
let result:string = '';
|
|
64
70
|
if (n !== '' && n !== null && n !== undefined) {
|
|
65
|
-
result = n?.toString().replaceAll(".", "")
|
|
71
|
+
result = n?.toString().replaceAll(".", "");
|
|
66
72
|
if (result.length === 2 && result.substring(0, 1) === "0") {
|
|
67
|
-
result = parseInt(result).toString()
|
|
73
|
+
result = parseInt(result).toString();
|
|
68
74
|
}
|
|
69
75
|
if (_flag) {
|
|
70
|
-
result = result.replace(/\D/g, "").replace(/\B(?=(\d{3})+(?!\d))/g, ".")
|
|
76
|
+
result = result.replace(/\D/g, "").replace(/\B(?=(\d{3})+(?!\d))/g, ".");
|
|
71
77
|
}
|
|
72
78
|
}
|
|
73
|
-
return result
|
|
79
|
+
return result;
|
|
74
80
|
}
|
|
75
81
|
|
|
76
82
|
export const generateMessage = (type: string, value: string | ReactNode, callback?: () => void, timer?: number) => {
|
|
@@ -78,9 +84,9 @@ export const generateMessage = (type: string, value: string | ReactNode, callbac
|
|
|
78
84
|
$type: type,
|
|
79
85
|
message: value,
|
|
80
86
|
timer: timer || (type === 'warning' ? 3000 : 2000)
|
|
81
|
-
}
|
|
82
|
-
callback && (result.callback = () => { callback() })
|
|
83
|
-
return result
|
|
87
|
+
};
|
|
88
|
+
callback && (result.callback = () => { callback() });
|
|
89
|
+
return result;
|
|
84
90
|
}
|
|
85
91
|
|
|
86
92
|
export const generateMessageQuestion = (type: string, title: string, subtitle: string, callback?: () => void, buttonSubmit?: string, cancelCallback?: () => void) => {
|
|
@@ -91,12 +97,16 @@ export const generateMessageQuestion = (type: string, title: string, subtitle: s
|
|
|
91
97
|
callback: callback,
|
|
92
98
|
buttonSubmit: buttonSubmit,
|
|
93
99
|
cancelCallback: cancelCallback
|
|
94
|
-
}
|
|
95
|
-
return result
|
|
100
|
+
};
|
|
101
|
+
return result;
|
|
96
102
|
}
|
|
97
103
|
|
|
98
104
|
export const currencyNumber = (value: number) => {
|
|
99
|
-
if(value === null)
|
|
100
|
-
|
|
101
|
-
else
|
|
105
|
+
if (value === null) {
|
|
106
|
+
return value;
|
|
107
|
+
} else if (typeof value == 'number') {
|
|
108
|
+
return value.toLocaleString('id-ID', {style: 'currency', currency: 'IDR', minimumFractionDigits: 0});
|
|
109
|
+
} else {
|
|
110
|
+
return value;
|
|
111
|
+
}
|
|
102
112
|
}
|