@contrail/util 1.1.9-alpha → 1.1.9-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.
@@ -2,28 +2,16 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.decompressFromString = exports.compressIntoString = void 0;
4
4
  const fflate_1 = require("fflate");
5
- const bufferToString = (buffer) => {
6
- let result = '';
7
- for (let value of buffer)
8
- result += String.fromCharCode(value);
9
- return result;
10
- };
11
- const stringToBuffer = (str) => {
12
- let result = new Uint8Array(str.length);
13
- for (let i = 0; i < str.length; ++i)
14
- result[i] = str.charCodeAt(i);
15
- return result;
16
- };
17
5
  function compressIntoString(obj) {
18
- const json = obj === null || obj === undefined ? null : obj;
19
- const buffer = stringToBuffer(JSON.stringify(json));
6
+ const jsonStr = JSON.stringify(obj === undefined ? null : obj);
7
+ const buffer = new TextEncoder().encode(jsonStr);
20
8
  const compressed = (0, fflate_1.compressSync)(buffer);
21
- return bufferToString(compressed);
9
+ return Buffer.from(compressed).toString('base64');
22
10
  }
23
11
  exports.compressIntoString = compressIntoString;
24
12
  function decompressFromString(str) {
25
- const buffer = stringToBuffer(str);
26
- const decompressed = (0, fflate_1.decompressSync)(buffer);
13
+ const compressed = Buffer.from(str, 'base64');
14
+ const decompressed = (0, fflate_1.decompressSync)(compressed);
27
15
  const originalText = new TextDecoder().decode(decompressed);
28
16
  return JSON.parse(originalText);
29
17
  }
@@ -28,17 +28,17 @@ function determineChangesIfEqual(target, priorSourceValues, newSourceValues, pro
28
28
  }
29
29
  exports.determineChangesIfEqual = determineChangesIfEqual;
30
30
  function areItemPropertyValuesEqual(property, itemOne, itemTwo) {
31
- var _a, _b;
31
+ var _a, _b, _c, _d;
32
32
  const propertyKey = getPropertyKey(property);
33
- const propertyValueOne = itemOne[propertyKey];
34
- const propertyValueTwo = itemTwo[propertyKey];
33
+ const propertyValueOne = (_a = itemOne[propertyKey]) !== null && _a !== void 0 ? _a : null;
34
+ const propertyValueTwo = (_b = itemTwo[propertyKey]) !== null && _b !== void 0 ? _b : null;
35
35
  if (property.propertyType === types_1.PropertyType.MultiSelect) {
36
36
  const propertyValueOneAsArray = getMultiSelectValueAsArray(propertyValueOne);
37
37
  const propertyValueTwoAsArray = getMultiSelectValueAsArray(propertyValueTwo);
38
38
  return areArraysEqualIgnoreOrder(propertyValueOneAsArray, propertyValueTwoAsArray);
39
39
  }
40
40
  if (property.propertyType === types_1.PropertyType.SizeRange) {
41
- const isOfSameSizeRangeTemplate = ((_a = itemOne === null || itemOne === void 0 ? void 0 : itemOne.sizeRangeTemplate) === null || _a === void 0 ? void 0 : _a.id) === ((_b = itemTwo === null || itemTwo === void 0 ? void 0 : itemTwo.sizeRangeTemplate) === null || _b === void 0 ? void 0 : _b.id);
41
+ const isOfSameSizeRangeTemplate = ((_c = itemOne === null || itemOne === void 0 ? void 0 : itemOne.sizeRangeTemplate) === null || _c === void 0 ? void 0 : _c.id) === ((_d = itemTwo === null || itemTwo === void 0 ? void 0 : itemTwo.sizeRangeTemplate) === null || _d === void 0 ? void 0 : _d.id);
42
42
  if (!isOfSameSizeRangeTemplate)
43
43
  return false;
44
44
  return areSizeRangesEqual(propertyValueOne, propertyValueTwo);
@@ -5,5 +5,6 @@ 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 decodeEncodedString(encodedString: string): string;
8
9
  static getStringSizeInMB(str: string): number;
9
10
  }
@@ -67,6 +67,16 @@ class StringUtil {
67
67
  static isArray(value) {
68
68
  return Array.isArray(value);
69
69
  }
70
+ static decodeEncodedString(encodedString) {
71
+ return encodedString.replace(/_COMMA_/g, ',').replace(/%[0-9A-Fa-f]{2}/g, (match) => {
72
+ try {
73
+ return decodeURIComponent(match);
74
+ }
75
+ catch (_a) {
76
+ return match;
77
+ }
78
+ });
79
+ }
70
80
  static getStringSizeInMB(str) {
71
81
  const bytes = new TextEncoder().encode(str).length;
72
82
  return bytes / (1024 * 1024);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/util",
3
- "version": "1.1.9-alpha",
3
+ "version": "1.1.9-alpha-1",
4
4
  "description": "General javascript utilities",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",