@contrail/util 1.0.47 → 1.0.49

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/README.md CHANGED
@@ -1 +1 @@
1
- Authentication libraries for contrail/vibe platform.
1
+ Authentication libraries for contrail/vibe platform.
@@ -12,7 +12,6 @@ exports.EXTENSION_IDENTIFIER_VALIDATION_BAD_CHARACTERS = `Invalid extension iden
12
12
  class BadIdentifierException extends Error {
13
13
  }
14
14
  exports.BadIdentifierException = BadIdentifierException;
15
- ;
16
15
  class AppUtil {
17
16
  static parseActionIdentifier(actionIdentifier) {
18
17
  {
@@ -35,7 +34,7 @@ class AppUtil {
35
34
  return {
36
35
  appIdentifier: `@${identifierParts[1]}`,
37
36
  versionId: identifierParts[2],
38
- actionNameIdentifier: identifierParts[3]
37
+ actionNameIdentifier: identifierParts[3],
39
38
  };
40
39
  }
41
40
  }
@@ -62,7 +61,7 @@ class AppUtil {
62
61
  }
63
62
  return {
64
63
  appIdentifier: `@${identifierParts[1]}`,
65
- extensionIdentifier: identifierParts[2]
64
+ extensionIdentifier: identifierParts[2],
66
65
  };
67
66
  }
68
67
  }
@@ -1,4 +1,4 @@
1
- import { getIsoDatePart } from "./getIsoDatePart/getIsoDatePart";
1
+ import { getIsoDatePart } from './getIsoDatePart/getIsoDatePart';
2
2
  export declare class DateUtil {
3
3
  static getIsoDatePart: typeof getIsoDatePart;
4
4
  }
@@ -1,4 +1,4 @@
1
- import { TypeProperty } from "@contrail/types";
1
+ import { TypeProperty } from '@contrail/types';
2
2
  export declare function applyChangesIfEqual(target: any, priorSourceValues: any, newSourceValues: any, properties: any): void;
3
3
  export declare function determineChangesIfEqual(target: any, priorSourceValues: any, newSourceValues: any, properties: any): any;
4
4
  export declare function areItemPropertyValuesEqual(property: TypeProperty, itemOne: any, itemTwo: any): boolean;
@@ -8,18 +8,24 @@ function getObjectDiffs(before, after, prefix) {
8
8
  }
9
9
  const beforeProperties = Object.getOwnPropertyNames(before);
10
10
  const afterProperties = Object.getOwnPropertyNames(after);
11
- const addedProperties = afterProperties.filter(value => !beforeProperties.includes(value));
12
- const deletedProperties = beforeProperties.filter(value => !afterProperties.includes(value));
13
- const commonProperties = beforeProperties.filter(value => afterProperties.includes(value));
14
- addedProperties.forEach(addedProperty => {
11
+ const addedProperties = afterProperties.filter((value) => !beforeProperties.includes(value));
12
+ const deletedProperties = beforeProperties.filter((value) => !afterProperties.includes(value));
13
+ const commonProperties = beforeProperties.filter((value) => afterProperties.includes(value));
14
+ addedProperties.forEach((addedProperty) => {
15
15
  diffs.push(getObjectDiff(null, after[addedProperty], prefix + addedProperty));
16
16
  });
17
- deletedProperties.forEach(deletedProperty => {
17
+ deletedProperties.forEach((deletedProperty) => {
18
18
  diffs.push(getObjectDiff(before[deletedProperty], null, prefix + deletedProperty));
19
19
  });
20
- commonProperties.forEach(commonProperty => {
21
- const beforeVal = before[commonProperty];
22
- const afterVal = after[commonProperty];
20
+ commonProperties.forEach((commonProperty) => {
21
+ let beforeVal = before[commonProperty];
22
+ if (beforeVal === undefined || beforeVal === '') {
23
+ beforeVal = null;
24
+ }
25
+ let afterVal = after[commonProperty];
26
+ if (afterVal === undefined || afterVal === '') {
27
+ afterVal = null;
28
+ }
23
29
  if (beforeVal === afterVal) {
24
30
  return;
25
31
  }
@@ -77,7 +83,7 @@ function sortFunc(x, y) {
77
83
  if (x === y)
78
84
  return 0;
79
85
  else
80
- return (x > y) ? 1 : -1;
86
+ return x > y ? 1 : -1;
81
87
  }
82
88
  function isObject(object) {
83
89
  return object != null && typeof object === 'object';
@@ -2,6 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isObject = void 0;
4
4
  function isObject(item) {
5
- return (item && typeof item === 'object' && !Array.isArray(item));
5
+ return item && typeof item === 'object' && !Array.isArray(item);
6
6
  }
7
7
  exports.isObject = isObject;
@@ -7,6 +7,7 @@ export { ObjectDiff } from './compareDeep/compareDeep';
7
7
  export declare class ObjectUtil {
8
8
  static getByPath(obj: any, path: string, def?: any): any;
9
9
  static setByPath(obj: any, path: string, value: any): void;
10
+ static chunk(array: any[], size: number): any[];
10
11
  static isObject: typeof isObject;
11
12
  static mergeDeep: typeof mergeDeep;
12
13
  static cloneDeep: typeof cloneDeep;
@@ -8,10 +8,7 @@ const compareDeep_1 = require("./compareDeep/compareDeep");
8
8
  const applyChangesIfEqual_1 = require("./applyChangesIfEqual/applyChangesIfEqual");
9
9
  class ObjectUtil {
10
10
  static getByPath(obj, path, def = null) {
11
- const pathUnits = path
12
- .replace(/\[/g, '.')
13
- .replace(/]/g, '')
14
- .split('.');
11
+ const pathUnits = path.replace(/\[/g, '.').replace(/]/g, '').split('.');
15
12
  pathUnits.forEach((level) => {
16
13
  if (obj) {
17
14
  obj = obj[level];
@@ -33,6 +30,13 @@ class ObjectUtil {
33
30
  }
34
31
  o[a[0]] = value;
35
32
  }
33
+ static chunk(array, size) {
34
+ const chunked = [];
35
+ for (let i = 0; i < array.length; i = i + size) {
36
+ chunked.push(array.slice(i, i + size));
37
+ }
38
+ return chunked;
39
+ }
36
40
  }
37
41
  exports.ObjectUtil = ObjectUtil;
38
42
  ObjectUtil.isObject = isObject_1.isObject;
@@ -50,13 +50,15 @@ class StringUtil {
50
50
  return str;
51
51
  }
52
52
  str = str.replace(/-/g, ' ');
53
- return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function (word, index) {
53
+ return str
54
+ .replace(/(?:^\w|[A-Z]|\b\w)/g, function (word, index) {
54
55
  return index === 0 ? word.toLowerCase() : word.toUpperCase();
55
- }).replace(/\s+/g, '');
56
+ })
57
+ .replace(/\s+/g, '');
56
58
  }
57
59
  static convertToTitleCase(str) {
58
60
  const camelCase = this.convertToCamelCase(str);
59
- const withSpaces = camelCase.replace(/([A-Z])/g, " $1");
61
+ const withSpaces = camelCase.replace(/([A-Z])/g, ' $1');
60
62
  return withSpaces.charAt(0).toUpperCase() + withSpaces.slice(1);
61
63
  }
62
64
  static isString(value) {
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@contrail/util",
3
- "version": "1.0.47",
3
+ "version": "1.0.49",
4
4
  "description": "General javascript utilities",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
7
7
  "scripts": {
8
8
  "build": "tsc",
9
9
  "format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
10
+ "format-check": "prettier --check \"src/**/*.ts\" \"src/**/*.js\"",
10
11
  "lint": "tslint -p tsconfig.json",
11
12
  "test": "jest"
12
13
  },
@@ -16,7 +17,7 @@
16
17
  "devDependencies": {
17
18
  "@types/jest": "^23.3.14",
18
19
  "jest": "^29.3.1",
19
- "prettier": "^1.19.1",
20
+ "prettier": "^3.2.5",
20
21
  "ts-jest": "^29.0.3",
21
22
  "tslint": "^5.11.0",
22
23
  "tslint-config-prettier": "^1.18.0",