forstok-ui-lib 5.2.3 → 5.2.5

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": "forstok-ui-lib",
3
- "version": "5.2.3",
3
+ "version": "5.2.5",
4
4
  "description": "Forstok UI Components Library",
5
5
  "path": "dist",
6
6
  "main": "dist/index.js",
@@ -8,9 +8,7 @@
8
8
  "types": "dist/index.d.ts",
9
9
  "scripts": {
10
10
  "test": "echo \"Error: no test specified\" && exit 1",
11
- "build": "rollup -c --bundleConfigAsCjs",
12
- "patch": "npm run build && npm version patch && npm publish",
13
- "master": "git add . && git commit -m 'patch' && git push origin master"
11
+ "build": "rollup -c --bundleConfigAsCjs"
14
12
  },
15
13
  "repository": {
16
14
  "type": "git",
@@ -1,2 +1,4 @@
1
1
  export * from './stylesheets/bases.styles';
2
- export * from './stylesheets/shares.styles';
2
+ export * from './stylesheets/shares.styles';
3
+
4
+ export * from './javascripts/function';
@@ -1,6 +1,63 @@
1
1
  import { ReactNode } from 'react';
2
2
  import { TMessage, TMessageQuestion } from '../../components/message/typed';
3
3
 
4
+ export const getStorage = (name: string, type: string = 'string', defaultVal?: any, loadName: string = 'load') => {
5
+ let result: any
6
+ if (sessionStorage.getItem(loadName) !== null) {
7
+ result = sessionStorage.getItem(name) !== null ? sessionStorage.getItem(name) : defaultVal
8
+ } else {
9
+ result = localStorage.getItem(name) !== null ? localStorage.getItem(name) : defaultVal
10
+ localStorage.getItem(name) !== null && sessionStorage.setItem(name, result)
11
+ }
12
+ switch (type) {
13
+ case 'boolean':
14
+ result = (result !== undefined && result !== 'undefined') ? (result === 'true') : false
15
+ break
16
+ case 'number':
17
+ case 'integer':
18
+ result = (result !== undefined && result !== 'undefined') ? parseInt(result) : 0
19
+ break
20
+ case 'object':
21
+ case 'array':
22
+ result = (result !== undefined && result !== 'undefined') ? JSON.parse(result) : undefined
23
+ break
24
+ default:
25
+ result = (result === undefined || result === 'undefined') ? '' : result
26
+ break
27
+ }
28
+ return result
29
+ }
30
+
31
+ export const setStorage = (name: string, value?: any, only?: string) => {
32
+ if (value === undefined || value === null) {
33
+ return false
34
+ }
35
+ const _value: string = (typeof value !== 'string') ? ((typeof value === 'object') ? JSON.stringify(value) : value.toString()) : value
36
+ switch (only) {
37
+ case 'session':
38
+ sessionStorage.setItem(name, _value)
39
+ break
40
+ case 'local':
41
+ localStorage.setItem(name, _value)
42
+ break
43
+ default:
44
+ sessionStorage.setItem(name, _value)
45
+ localStorage.setItem(name, _value)
46
+ }
47
+ }
48
+
49
+ export const debounce = (fn: Function, ms = 300) => {
50
+ let timeoutId: ReturnType<typeof setTimeout>;
51
+ return function (this: any, ...args: any[]) {
52
+ clearTimeout(timeoutId);
53
+ timeoutId = setTimeout(() => fn.apply(this, args), ms);
54
+ };
55
+ }
56
+
57
+ export const capitalize = (value?: string) => {
58
+ return value ? (value[0].toUpperCase() + value.substring(1)) : ''
59
+ }
60
+
4
61
  export const formatNumber = (n?: string | number, flag?: boolean) => {
5
62
  const _flag = flag === undefined ? true : flag
6
63
  let result:string = ''