rps-jsonvalidator 1.0.7 → 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -1,11 +1,11 @@
1
- # general-libs-json-object-validator
2
-
3
- This library was generated with [Nx](https://nx.dev).
4
-
5
- ## Running unit tests
6
-
7
- Run `nx test general-libs-json-object-validator` to execute the unit tests via [Jest](https://jestjs.io).
8
-
9
- ## Running lint
10
-
11
- Run `nx lint general-libs-json-object-validator` to execute the lint via [ESLint](https://eslint.org/).
1
+ # general-libs-json-object-validator
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ ## Running unit tests
6
+
7
+ Run `nx test general-libs-json-object-validator` to execute the unit tests via [Jest](https://jestjs.io).
8
+
9
+ ## Running lint
10
+
11
+ Run `nx lint general-libs-json-object-validator` to execute the lint via [ESLint](https://eslint.org/).
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "rps-jsonvalidator",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "main": "./src/index.js",
5
- "typings": "./src/index.d.ts",
5
+ "types": "./src/index.d.ts",
6
6
  "dependencies": {},
7
7
  "peerDependencies": {
8
- "tslib": "^2.3.0"
8
+ "tslib": "2.4.0"
9
9
  }
10
10
  }
package/src/index.d.ts CHANGED
@@ -1 +1 @@
1
- export * from './lib/general-libs-json-object-validator';
1
+ export * from './lib/general-libs-json-object-validator';
package/src/index.js CHANGED
@@ -1,5 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./lib/general-libs-json-object-validator"), exports);
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./lib/general-libs-json-object-validator"), exports);
5
5
  //# sourceMappingURL=index.js.map
@@ -1,19 +1,20 @@
1
- export interface JSONObjectKeyAndTypeValidator {
2
- key: string;
3
- required: boolean;
4
- default?: variabletypes | (() => variabletypes);
5
- trim?: boolean;
6
- custom_validator?: (value: variabletypes) => boolean;
7
- lengths?: {
8
- min_len?: number;
9
- max_len?: number;
10
- len?: number;
11
- };
12
- type: 'string' | 'number' | 'boolean' | 'function' | 'object' | 'symbol' | 'any' | 'bigint';
13
- regex?: RegExp;
14
- error?: any;
15
- Extra?: JSONObjectKeyAndTypeValidator[];
16
- }
17
- declare type variabletypes = string | number | boolean | null | bigint | object;
18
- export declare function ValidateJSONObject(data: any, Validator: JSONObjectKeyAndTypeValidator[], strip_data?: boolean): boolean | any;
19
- export {};
1
+ export interface JSONObjectKeyAndTypeValidator {
2
+ key: string;
3
+ required: boolean;
4
+ default?: variabletypes | (() => variabletypes);
5
+ trim?: boolean;
6
+ custom_validator?: (value: variabletypes) => boolean;
7
+ lengths?: {
8
+ min_len?: number;
9
+ max_len?: number;
10
+ len?: number;
11
+ };
12
+ type: 'string' | 'number' | 'boolean' | 'function' | 'object' | 'symbol' | 'any' | 'bigint';
13
+ regex?: RegExp;
14
+ error?: any;
15
+ Extra?: JSONObjectKeyAndTypeValidator[];
16
+ }
17
+ declare type variabletypes = string | number | boolean | null | bigint | object;
18
+ export declare const BooleanNumberCheckRegex: RegExp;
19
+ export declare function ValidateJSONObject(data: any, Validator: JSONObjectKeyAndTypeValidator[], strip_data?: boolean): boolean | any;
20
+ export {};
@@ -1,74 +1,75 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ValidateJSONObject = void 0;
4
- function ValidateJSONObject(data, Validator, strip_data = false) {
5
- const temp = {};
6
- Validator.forEach((a) => {
7
- a.error;
8
- if (a.required ||
9
- (typeof data[a.key] !== 'undefined' && data[a.key] !== null)) {
10
- try {
11
- if (typeof data[a.key] === 'undefined') {
12
- throw a.error ? `${a.error} In Value Undefined` : `Please Enter Valid Value For Key ${a.key}`;
13
- }
14
- if (a.type === 'number' && isNaN(+data[a.key]) === true) {
15
- throw a.error || 'Type Mismatch';
16
- }
17
- else if (typeof data[a.key] !== a.type && a.type !== 'any') {
18
- throw a.error || 'Type Mismatch';
19
- }
20
- if (a.type === 'number') {
21
- data[a.key] = +data[a.key];
22
- }
23
- }
24
- catch (error) {
25
- if (typeof a.default === 'function') {
26
- data[a.key] = a.default();
27
- }
28
- else if (typeof a.default !== 'undefined') {
29
- data[a.key] = a.default;
30
- }
31
- else {
32
- throw error;
33
- }
34
- }
35
- if (a.regex || a.lengths) {
36
- let dataCC = data[a.key];
37
- if (typeof dataCC !== 'string') {
38
- dataCC = String(dataCC);
39
- }
40
- if (a.lengths) {
41
- if (a.lengths.max_len && a.lengths.max_len < dataCC.length) {
42
- throw a.error || `${a.key} Min Length Does Not Meet`;
43
- }
44
- if (a.lengths.min_len && a.lengths.min_len > dataCC.length) {
45
- throw a.error || `${a.key} Min Length Does Not Meet`;
46
- }
47
- if (a.lengths.len && a.lengths.len !== dataCC.length) {
48
- throw a.error || `${a.key} Length Does Not Meet`;
49
- }
50
- }
51
- if (a.regex) {
52
- if (a.regex.test(dataCC) === false) {
53
- throw a.error || `${a.key} Regexp MisMAtch`;
54
- }
55
- }
56
- }
57
- if (a.custom_validator) {
58
- const dd = a.custom_validator(data[a.key]);
59
- if (!!dd === false) {
60
- throw a.error || 'Custom Validator Error';
61
- }
62
- }
63
- if (a.Extra && Array.isArray(a.Extra)) {
64
- temp[a.key] = ValidateJSONObject(data[a.key], a.Extra, strip_data);
65
- }
66
- else {
67
- temp[a.key] = data[a.key];
68
- }
69
- }
70
- });
71
- return strip_data ? temp : true;
72
- }
73
- exports.ValidateJSONObject = ValidateJSONObject;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ValidateJSONObject = exports.BooleanNumberCheckRegex = void 0;
4
+ exports.BooleanNumberCheckRegex = /^[01]$/;
5
+ function ValidateJSONObject(data, Validator, strip_data = false) {
6
+ const temp = {};
7
+ Validator.forEach((a) => {
8
+ a.error;
9
+ if (a.required ||
10
+ (typeof data[a.key] !== 'undefined' && data[a.key] !== null)) {
11
+ try {
12
+ if (typeof data[a.key] === 'undefined') {
13
+ throw a.error ? `${a.error} In Value Undefined` : `Please Enter Valid Value For Key ${a.key}`;
14
+ }
15
+ if (a.type === 'number' && isNaN(+data[a.key]) === true) {
16
+ throw a.error || 'Type Mismatch';
17
+ }
18
+ else if (typeof data[a.key] !== a.type && a.type !== 'any') {
19
+ throw a.error || 'Type Mismatch';
20
+ }
21
+ if (a.type === 'number') {
22
+ data[a.key] = +data[a.key];
23
+ }
24
+ }
25
+ catch (error) {
26
+ if (typeof a.default === 'function') {
27
+ data[a.key] = a.default();
28
+ }
29
+ else if (typeof a.default !== 'undefined') {
30
+ data[a.key] = a.default;
31
+ }
32
+ else {
33
+ throw error;
34
+ }
35
+ }
36
+ if (a.regex || a.lengths) {
37
+ let dataCC = data[a.key];
38
+ if (typeof dataCC !== 'string') {
39
+ dataCC = String(dataCC);
40
+ }
41
+ if (a.lengths) {
42
+ if (a.lengths.max_len && a.lengths.max_len < dataCC.length) {
43
+ throw a.error || `${a.key} Min Length Does Not Meet`;
44
+ }
45
+ if (a.lengths.min_len && a.lengths.min_len > dataCC.length) {
46
+ throw a.error || `${a.key} Min Length Does Not Meet`;
47
+ }
48
+ if (a.lengths.len && a.lengths.len !== dataCC.length) {
49
+ throw a.error || `${a.key} Length Does Not Meet`;
50
+ }
51
+ }
52
+ if (a.regex) {
53
+ if (a.regex.test(dataCC) === false) {
54
+ throw a.error || `${a.key} Regexp MisMAtch`;
55
+ }
56
+ }
57
+ }
58
+ if (a.custom_validator) {
59
+ const dd = a.custom_validator(data[a.key]);
60
+ if (!!dd === false) {
61
+ throw a.error || 'Custom Validator Error';
62
+ }
63
+ }
64
+ if (a.Extra && Array.isArray(a.Extra)) {
65
+ temp[a.key] = ValidateJSONObject(data[a.key], a.Extra, strip_data);
66
+ }
67
+ else {
68
+ temp[a.key] = data[a.key];
69
+ }
70
+ }
71
+ });
72
+ return strip_data ? temp : true;
73
+ }
74
+ exports.ValidateJSONObject = ValidateJSONObject;
74
75
  //# sourceMappingURL=general-libs-json-object-validator.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"general-libs-json-object-validator.js","sourceRoot":"","sources":["../../../../../../packages/general-libs/json-object-validator/src/lib/general-libs-json-object-validator.ts"],"names":[],"mappings":";;;AA2BA,SAAgB,kBAAkB,CAChC,IAAS,EACT,SAA0C,EAC1C,UAAU,GAAG,KAAK;IAElB,MAAM,IAAI,GAAQ,EAAE,CAAC;IACrB,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;QACtB,CAAC,CAAC,KAAK,CAAA;QACP,IACE,CAAC,CAAC,QAAQ;YACV,CAAC,OAAO,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,WAAW,IAAI,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC,EAC5D;YACA,IAAI;gBACF,IAAI,OAAO,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,WAAW,EAAE;oBACtC,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,qBAAqB,CAAC,CAAC,CAAC,oCAAoC,CAAC,CAAC,GAAG,EAAE,CAAC;iBAC/F;gBACD,IAAI,CAAC,CAAC,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,IAAI,EAAE;oBACvD,MAAM,CAAC,CAAC,KAAK,IAAI,eAAe,CAAC;iBAClC;qBAAM,IAAI,OAAO,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,IAAI,KAAK,KAAK,EAAE;oBAC5D,MAAM,CAAC,CAAC,KAAK,IAAI,eAAe,CAAC;iBAClC;gBACD,IAAI,CAAC,CAAC,IAAI,KAAK,QAAQ,EAAE;oBACvB,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG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uB,CAAC;qBAClD;iBACF;gBACD,IAAI,CAAC,CAAC,KAAK,EAAE;oBACX,IAAI,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,KAAK,EAAE;wBAClC,MAAM,CAAC,CAAC,KAAK,IAAI,GAAG,CAAC,CAAC,GAAG,kBAAkB,CAAC;qBAC7C;iBACF;aACF;YACD,IAAI,CAAC,CAAC,gBAAgB,EAAE;gBACtB,MAAM,EAAE,GAAG,CAAC,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;gBAC3C,IAAI,CAAC,CAAC,EAAE,KAAK,KAAK,EAAE;oBAClB,MAAM,CAAC,CAAC,KAAK,IAAI,wBAAwB,CAAC;iBAC3C;aACF;YACD,IAAI,CAAC,CAAC,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE;gBACrC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;aACpE;iBAAM;gBACL,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;aAC3B;SACF;IACH,CAAC,CAAC,CAAC;IACH,OAAO,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;AAClC,CAAC;AArED,gDAqEC"}
1
+ {"version":3,"file":"general-libs-json-object-validator.js","sourceRoot":"","sources":["../../../../../../packages/general-libs/json-object-validator/src/lib/general-libs-json-object-validator.ts"],"names":[],"mappings":";;;AA2Ba,QAAA,uBAAuB,GAAG,QAAQ,CAAC;AAChD,SAAgB,kBAAkB,CAChC,IAAS,EACT,SAA0C,EAC1C,UAAU,GAAG,KAAK;IAElB,MAAM,IAAI,GAAQ,EAAE,CAAC;IACrB,S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