@esvndev/es-react-config-setting 1.0.71 → 1.0.73

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,4 +1,4 @@
1
1
  import { key_format } from "../../shared/type";
2
2
  export declare const GLOBAL_WINDOW_VARIABLE: Record<string, any>;
3
3
  export declare const INIT_CONFIG_SETTING: () => void;
4
- export declare const key_conf: (key: string, type?: key_format) => any;
4
+ export declare const get_conf: (key: string, type?: key_format) => any;
package/dist/index.d.ts CHANGED
@@ -5,9 +5,11 @@ interface ISettingApp {
5
5
  eventClose?: (obj: any) => void;
6
6
  isOpen: boolean;
7
7
  }
8
+ type key_format = 'text' | 'int' | 'decimal' | 'byte' | 'object';
8
9
 
9
10
  declare const SettingApp: (props: ISettingApp) => react_jsx_runtime.JSX.Element;
10
11
 
11
12
  declare const INIT_CONFIG_SETTING: () => void;
13
+ declare const get_conf: (key: string, type?: key_format) => any;
12
14
 
13
- export { INIT_CONFIG_SETTING, SettingApp };
15
+ export { INIT_CONFIG_SETTING, SettingApp, get_conf };
package/dist/index.js CHANGED
@@ -19035,6 +19035,54 @@ const INIT_CONFIG_SETTING = () => {
19035
19035
  _FETCH_AND_UPDATE();
19036
19036
  }, TIME_RELOAD);
19037
19037
  };
19038
+ function base64ToBytesLength(base64String) {
19039
+ const base64 = base64String.split(',').pop() ?? '';
19040
+ const len = base64.length;
19041
+ const padding = (base64.endsWith('==') ? 2 : base64.endsWith('=') ? 1 : 0);
19042
+ return Math.floor((len * 3) / 4) - padding;
19043
+ }
19044
+ //get data by key
19045
+ const get_conf = (key, type) => {
19046
+ let _ = null;
19047
+ if (GLOBAL_WINDOW_VARIABLE && GLOBAL_WINDOW_VARIABLE[key]) {
19048
+ if (type === undefined) {
19049
+ GLOBAL_WINDOW_VARIABLE[key].type;
19050
+ }
19051
+ switch (type) {
19052
+ case "text":
19053
+ _ = GLOBAL_WINDOW_VARIABLE[key].value;
19054
+ break;
19055
+ case "int":
19056
+ try {
19057
+ _ = parseInt(GLOBAL_WINDOW_VARIABLE[key].value);
19058
+ }
19059
+ catch (ex) { }
19060
+ break;
19061
+ case "decimal":
19062
+ try {
19063
+ _ = parseFloat(GLOBAL_WINDOW_VARIABLE[key].value);
19064
+ }
19065
+ catch (ex) { }
19066
+ break;
19067
+ case "byte":
19068
+ try {
19069
+ _ = base64ToBytesLength(GLOBAL_WINDOW_VARIABLE[key].value);
19070
+ }
19071
+ catch (ex) { }
19072
+ break;
19073
+ case "object":
19074
+ try {
19075
+ _ = JSON.parse(GLOBAL_WINDOW_VARIABLE[key].value);
19076
+ }
19077
+ catch (ex) { }
19078
+ break;
19079
+ default:
19080
+ _ = GLOBAL_WINDOW_VARIABLE[key].value;
19081
+ break;
19082
+ }
19083
+ }
19084
+ return _;
19085
+ };
19038
19086
  const _FETCH_AND_UPDATE = () => {
19039
19087
  GetSettingConfigClient((data) => {
19040
19088
  try {
@@ -19042,7 +19090,7 @@ const _FETCH_AND_UPDATE = () => {
19042
19090
  TIME_RELOAD = (data?.timeupdate < 5000 || data?.timeupdate > 300000) ? 5000 : data?.timeupdate;
19043
19091
  }
19044
19092
  if (data?.status && data?.isupdate && data?.data) {
19045
- localStorage.setItem("init_config_setting", JSON.stringify(data.data));
19093
+ localStorage.setItem("app_config_setting", JSON.stringify(data.data));
19046
19094
  localStorage.setItem("app_config_setting_version", data.version);
19047
19095
  _LOAD_(data.data);
19048
19096
  }
@@ -19056,7 +19104,7 @@ const _FETCH_AND_UPDATE = () => {
19056
19104
  const _LOAD_ = (data) => {
19057
19105
  let _ = {};
19058
19106
  if (!data) {
19059
- const _json = localStorage.getItem("init_config_setting");
19107
+ const _json = localStorage.getItem("app_config_setting");
19060
19108
  try {
19061
19109
  _ = JSON.parse(_json ?? '{}');
19062
19110
  }
@@ -19075,4 +19123,5 @@ registerLicense('ORg4AjUWIQA/Gnt2VVhiQlFadVlJXmJWf1FpTGpQdk5yd19DaVZUTX1dQl9hSXl
19075
19123
 
19076
19124
  exports.INIT_CONFIG_SETTING = INIT_CONFIG_SETTING;
19077
19125
  exports.SettingApp = SettingApp;
19126
+ exports.get_conf = get_conf;
19078
19127
  //# sourceMappingURL=index.js.map