@smartsoft001/utils 1.0.693 → 1.0.698

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
@@ -93,11 +93,11 @@ Methods:
93
93
  Methods:
94
94
  <table>
95
95
  <tr>
96
- <td>valid<T>(value: T, spec: { criteria: any }): boolean</td>
96
+ <td>valid<T>(value: T, spec: { criteria: any }, custom: ISpecificationCustom = null): boolean</td>
97
97
  <td>checking if the value meets the specifications</td>
98
98
  </tr>
99
99
  <tr>
100
- <td>invalid<T>(value: T, spec: { criteria: any }): boolean</td>
100
+ <td>invalid<T>(value: T, spec: { criteria: any }, custom: ISpecificationCustom = null): boolean</td>
101
101
  <td>checking if the object does not meet the specifications</td>
102
102
  </tr>
103
103
  <tr>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smartsoft001/utils",
3
- "version": "1.0.693",
3
+ "version": "1.0.698",
4
4
  "peerDependencies": {
5
5
  "@angular/common": "^8.2.14",
6
6
  "@angular/core": "^8.2.14"
@@ -1,20 +1,26 @@
1
+ export interface ISpecificationCustom {
2
+ $root?: any;
3
+ }
4
+ export declare const SPECIFICATION_ROOT_KEY = "$root.";
1
5
  export declare class SpecificationService {
2
6
  /**
3
7
  * Checking if the value meets the specifications
4
8
  * @param value {object} - object to check
5
9
  * @param spec {ISpecificatio} - specification
10
+ * @param custom {ISpecificationCustom} - custom data for valid
6
11
  */
7
12
  static valid<T>(value: T, spec: {
8
13
  criteria: any;
9
- }): boolean;
14
+ }, custom?: ISpecificationCustom): boolean;
10
15
  /**
11
16
  * Checking if the object does not meet the specifications
12
17
  * @param value {object} - object to check
13
18
  * @param spec {ISpecificatio} - specification
19
+ * @param custom {ISpecificationCustom} - custom data for invalid
14
20
  */
15
21
  static invalid<T>(value: T, spec: {
16
22
  criteria: any;
17
- }): boolean;
23
+ }, custom?: ISpecificationCustom): boolean;
18
24
  /**
19
25
  * Convert specification to sql
20
26
  * @param spec {ISpecificatio} - specification
@@ -1,19 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SpecificationService = void 0;
3
+ exports.SpecificationService = exports.SPECIFICATION_ROOT_KEY = void 0;
4
+ exports.SPECIFICATION_ROOT_KEY = "$root.";
4
5
  class SpecificationService {
5
6
  /**
6
7
  * Checking if the value meets the specifications
7
8
  * @param value {object} - object to check
8
9
  * @param spec {ISpecificatio} - specification
10
+ * @param custom {ISpecificationCustom} - custom data for valid
9
11
  */
10
- static valid(value, spec) {
12
+ static valid(value, spec, custom = null) {
11
13
  const keys = Object.keys(spec.criteria);
12
14
  if (!value)
13
15
  return false;
14
16
  for (let index = 0; index < keys.length; index++) {
15
17
  const key = keys[index];
16
- if (spec.criteria[key] !== value[key])
18
+ if (key.indexOf(exports.SPECIFICATION_ROOT_KEY) === 0 && (custom === null || custom === void 0 ? void 0 : custom.$root)) {
19
+ if (spec.criteria[key] !== (custom === null || custom === void 0 ? void 0 : custom.$root[key.replace(exports.SPECIFICATION_ROOT_KEY, '')]))
20
+ return false;
21
+ }
22
+ else if (spec.criteria[key] !== value[key])
17
23
  return false;
18
24
  }
19
25
  return true;
@@ -22,9 +28,10 @@ class SpecificationService {
22
28
  * Checking if the object does not meet the specifications
23
29
  * @param value {object} - object to check
24
30
  * @param spec {ISpecificatio} - specification
31
+ * @param custom {ISpecificationCustom} - custom data for invalid
25
32
  */
26
- static invalid(value, spec) {
27
- return !SpecificationService.valid(value, spec);
33
+ static invalid(value, spec, custom = null) {
34
+ return !SpecificationService.valid(value, spec, custom);
28
35
  }
29
36
  /**
30
37
  * Convert specification to sql
@@ -1 +1 @@
1
- {"version":3,"file":"specification.service.js","sourceRoot":"","sources":["../../../../../../../../libs/shared/utils/src/lib/services/specification/specification.service.ts"],"names":[],"mappings":";;;AAAA,MAAa,oBAAoB;IAC7B;;;;OAIG;IACH,MAAM,CAAC,KAAK,CAAI,KAAQ,EAAE,IAAuB;QA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C"}
1
+ {"version":3,"file":"specification.service.js","sourceRoot":"","sources":["../../../../../../../../libs/shared/utils/src/lib/services/specification/specification.service.ts"],"names":[],"mappings":";;;AAIa,QAAA,sBAAsB,GAAG,QAAQ,CAAC;AAE/C,MAAa,oBAAoB;IAC7B;;;;;OAKG;IACH,MAAM,CAAC,KAAK,CAAI,KAAQ,EAAE,IAAuB,EAAE,SAA+B,IAAI;QAClF,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAExC,IAAI,CAAC,KAAK;YAAE,OAAO,KAAK,CAAC;QAEzB,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;YAC9C,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;YAExB,IAAI,GAAG,CAAC,OAAO,CAAC,8BAAsB,CAAC,KAAK,CAAC,KAAI,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,KAAK,CAAA,EAAE;gBAC5D,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAK,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,8BAAsB,EAAE,EAAE,CAAC,CAAC,CAAA;oBAAE,OAAO,KAAK,CAAC;aACnG;iBAAM,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,KAAK,CAAC,GAAG,CAAC;gBAAE,OAAO,KAAK,CAAC;SAC9D;QAED,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,OAAO,CAAI,KAAQ,EAAE,IAAuB,EAAE,SAA+B,IAAI;QACpF,OAAO,CAAC,oBAAoB,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IAC5D,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,cAAc,CAAC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