@capillarytech/cap-ui-utils 2.0.2 → 2.0.4

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/index.js CHANGED
@@ -9,3 +9,4 @@ export { default as loadable, FORCE_REFRESH_NOTIFIER, FORCE_REFRESH_SECONDS } fr
9
9
  export { default as GTMTracker } from './utils/gtmTracker';
10
10
  export { default as compileHandlebars } from './utils/compileHandlebars';
11
11
  export { default as sanitizeTemplateWithRegexp } from "./utils/contentSanitizationHelper";
12
+ export { default as decompressJsonObject } from "./utils/zlibDataDecompress";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capillarytech/cap-ui-utils",
3
- "version": "2.0.2",
3
+ "version": "2.0.4",
4
4
  "description": "Utility functions shared accross all the modules",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -8,12 +8,14 @@
8
8
  },
9
9
  "author": "Rajshekar",
10
10
  "dependencies": {
11
+ "base64-js": "^1.5.1",
12
+ "handlebars": "4.0.11",
13
+ "lodash": "4.17.11",
14
+ "moment-timezone": "^0.5.25",
11
15
  "react": "^18.2.0",
12
16
  "react-ga": "^3.3.1",
17
+ "react-intl": "6.6.6",
13
18
  "tti-polyfill": "^0.2.2",
14
- "moment-timezone": "^0.5.25",
15
- "react-intl": "2.7.2",
16
- "lodash": "4.17.11",
17
- "handlebars": "4.0.11"
19
+ "zlib": "^1.0.5"
18
20
  }
19
21
  }
@@ -0,0 +1,38 @@
1
+ import zlib from 'zlib';
2
+ import base64 from 'base64-js';
3
+
4
+ const decompressData = (data) => new Promise((resolve, reject) => {
5
+ zlib.gunzip(data, (err, buffer) => {
6
+ if (err) {
7
+ return reject(err);
8
+ }
9
+ resolve(buffer);
10
+ });
11
+ });
12
+
13
+ // Function to decode base64 to buffer
14
+ function decodeBase64(base64String) {
15
+ return Buffer.from(base64.toByteArray(base64String));
16
+ }
17
+
18
+ // Function to decompress base64-encoded compressed JSON string
19
+ const decompressJsonObject = async (base64Compressed) => {
20
+ try {
21
+ // Decode the base64 string to buffer
22
+ if (base64Compressed && typeof base64Compressed === 'string') {
23
+ const compressedBuffer = decodeBase64(base64Compressed);
24
+ // // Decompress the buffer
25
+ const decompressedBuffer = await decompressData(compressedBuffer);
26
+ // Convert buffer to string
27
+ const jsonString = decompressedBuffer.toString();
28
+ // // Parse JSON string to object
29
+ const jsonObject = JSON.parse(jsonString);
30
+ return jsonObject;
31
+ }
32
+ return base64Compressed;
33
+ } catch (error) {
34
+ throw error;
35
+ }
36
+ };
37
+
38
+ export default decompressJsonObject;