bfg-common 1.2.168 → 1.2.169

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/utils/base64.ts +29 -3
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bfg-common",
3
3
  "private": false,
4
- "version": "1.2.168",
4
+ "version": "1.2.169",
5
5
  "scripts": {
6
6
  "build": "nuxt build",
7
7
  "dev": "nuxt dev --port=3002",
package/utils/base64.ts CHANGED
@@ -1,8 +1,34 @@
1
+ // export const base64 = {
2
+ // encode: function <T>(data: T): string {
3
+ // return btoa(JSON.stringify(data))
4
+ // },
5
+ // decode: function <T>(data: string): T | '' {
6
+ // if (!data) return ''
7
+ //
8
+ // return JSON.parse(atob(data))
9
+ // },
10
+ // }
11
+
1
12
  export const base64 = {
2
13
  encode: function <T>(data: T): string {
3
- return btoa(JSON.stringify(data))
14
+ const st = JSON.stringify(data)
15
+ return btoa(
16
+ encodeURIComponent(st).replace(/%([0-9A-F]{2})/g, function (_match, p1) {
17
+ return String.fromCharCode(parseInt(p1, 16))
18
+ })
19
+ )
4
20
  },
5
- decode: function <T>(data: string): T {
6
- return JSON.parse(atob(data))
21
+ decode: function <T>(data: string): T | '' {
22
+ if (!data) return ''
23
+
24
+ return JSON.parse(
25
+ decodeURIComponent(
26
+ Array.prototype.map
27
+ .call(atob(data), function (c) {
28
+ return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2)
29
+ })
30
+ .join('')
31
+ )
32
+ )
7
33
  },
8
34
  }