@contrail/util 1.1.5-alpha-compression-1 → 1.1.5-alpha.1

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.
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.decompressBuffer = exports.convertBase64ToBuffer = exports.convertBufferToBase64 = exports.compressObjectIntoBuffer = exports.decompressFromBase64 = exports.compressToBase64 = void 0;
13
- const zlib_1 = require("zlib");
13
+ const zlib = require('zlib');
14
14
  function compressToBase64(obj) {
15
15
  return __awaiter(this, void 0, void 0, function* () {
16
16
  return compressObjectIntoBuffer(obj).then((buffer) => convertBufferToBase64(buffer));
@@ -27,7 +27,7 @@ exports.decompressFromBase64 = decompressFromBase64;
27
27
  function compressObjectIntoBuffer(obj) {
28
28
  const json = obj === undefined ? JSON.stringify(null) : JSON.stringify(obj);
29
29
  return new Promise((resolve, reject) => {
30
- zlib_1.default.gzip(json, (err, buffer) => {
30
+ zlib.gzip(json, (err, buffer) => {
31
31
  if (err)
32
32
  reject(err);
33
33
  else
@@ -46,7 +46,7 @@ function convertBase64ToBuffer(base64) {
46
46
  exports.convertBase64ToBuffer = convertBase64ToBuffer;
47
47
  function decompressBuffer(buffer) {
48
48
  return new Promise((resolve, reject) => {
49
- zlib_1.default.gunzip(buffer, (err, result) => {
49
+ zlib.gunzip(buffer, (err, result) => {
50
50
  if (err)
51
51
  reject(err);
52
52
  else
@@ -5,4 +5,5 @@ export declare class StringUtil {
5
5
  static convertToTitleCase(str: any): any;
6
6
  static isString(value: any): boolean;
7
7
  static isArray(value: any): boolean;
8
+ static getStringSizeInMB(str: string): number;
8
9
  }
@@ -67,5 +67,9 @@ class StringUtil {
67
67
  static isArray(value) {
68
68
  return Array.isArray(value);
69
69
  }
70
+ static getStringSizeInMB(str) {
71
+ const bytes = new TextEncoder().encode(str).length;
72
+ return bytes / (1024 * 1024);
73
+ }
70
74
  }
71
75
  exports.StringUtil = StringUtil;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/util",
3
- "version": "1.1.5-alpha-compression-1",
3
+ "version": "1.1.5-alpha.1",
4
4
  "description": "General javascript utilities",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -38,7 +38,7 @@
38
38
  "testEnvironment": "node"
39
39
  },
40
40
  "dependencies": {
41
- "@contrail/types": "^3.0.74",
41
+ "@contrail/types": "^3.0.95",
42
42
  "lodash": "^4.17.21"
43
43
  }
44
44
  }