@adaas/a-utils 0.0.6 → 0.0.8
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/dist/src/global/A_Error.class.d.ts +2 -2
- package/dist/src/global/A_Error.class.js +10 -1
- package/dist/src/global/A_Error.class.js.map +1 -1
- package/dist/src/helpers/A_Common.helper.d.ts +4 -2
- package/dist/src/helpers/A_Common.helper.js +15 -3
- package/dist/src/helpers/A_Common.helper.js.map +1 -1
- package/package.json +1 -1
- package/src/global/A_Error.class.ts +17 -4
- package/src/helpers/A_Common.helper.ts +17 -4
|
@@ -5,9 +5,9 @@ export declare class A_Error extends Error {
|
|
|
5
5
|
description: string;
|
|
6
6
|
originalError?: Error | any;
|
|
7
7
|
link?: string;
|
|
8
|
-
constructor(params: A_TYPES__Error | Error | AxiosError | any);
|
|
8
|
+
constructor(params: A_TYPES__Error | Error | AxiosError | string | any);
|
|
9
9
|
get id(): string | undefined;
|
|
10
|
-
protected identifyErrorType(error: Error | AxiosError | A_TYPES__Error): void;
|
|
10
|
+
protected identifyErrorType(error: Error | AxiosError | A_TYPES__Error | string | any): void;
|
|
11
11
|
get compilingData(): A_TYPES__Error;
|
|
12
12
|
toJSON(): A_TYPES__Error;
|
|
13
13
|
}
|
|
@@ -5,7 +5,9 @@ const axios_1 = require("axios");
|
|
|
5
5
|
const errors_constants_1 = require("../constants/errors.constants");
|
|
6
6
|
class A_Error extends Error {
|
|
7
7
|
constructor(params) {
|
|
8
|
-
super(
|
|
8
|
+
super(typeof params === 'string'
|
|
9
|
+
? params :
|
|
10
|
+
(params === null || params === void 0 ? void 0 : params.message) || 'Oops... Something went wrong');
|
|
9
11
|
this.identifyErrorType(params);
|
|
10
12
|
}
|
|
11
13
|
get id() {
|
|
@@ -13,6 +15,13 @@ class A_Error extends Error {
|
|
|
13
15
|
}
|
|
14
16
|
identifyErrorType(error) {
|
|
15
17
|
var _a, _b, _c;
|
|
18
|
+
if (typeof error === 'string') {
|
|
19
|
+
this.message = error;
|
|
20
|
+
this.code = errors_constants_1.A_CONSTANTS__ERROR_CODES.UNEXPECTED_ERROR;
|
|
21
|
+
this.description = 'If you see this error please let us know.';
|
|
22
|
+
this.link = 'https://support.adaas.org/error/' + this.id;
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
16
25
|
if (error.code &&
|
|
17
26
|
error.description &&
|
|
18
27
|
error.serverCode) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"A_Error.class.js","sourceRoot":"","sources":["../../../src/global/A_Error.class.ts"],"names":[],"mappings":";;;AACA,iCAAmC;AAEnC,oEAAyE;AAGzE,MAAa,OAAQ,SAAQ,KAAK;IAQ9B,YACI,
|
|
1
|
+
{"version":3,"file":"A_Error.class.js","sourceRoot":"","sources":["../../../src/global/A_Error.class.ts"],"names":[],"mappings":";;;AACA,iCAAmC;AAEnC,oEAAyE;AAGzE,MAAa,OAAQ,SAAQ,KAAK;IAQ9B,YACI,MAA0D;QAE1D,KAAK,CACD,OAAO,MAAM,KAAK,QAAQ;YACtB,CAAC,CAAC,MAAM,CAAC,CAAC;YACV,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,OAAO,KAAI,8BAA8B,CACxD,CAAC;QAEF,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAEnC,CAAC;IAGD,IAAI,EAAE;QACF,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;IAClC,CAAC;IAGS,iBAAiB,CAAC,KAAyD;;QACjF,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC5B,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;YACrB,IAAI,CAAC,IAAI,GAAG,2CAAwB,CAAC,gBAAgB,CAAC;YACtD,IAAI,CAAC,WAAW,GAAG,2CAA2C,CAAC;YAC/D,IAAI,CAAC,IAAI,GAAG,kCAAkC,GAAG,IAAI,CAAC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pC,IAAI,CAAC,IAAI,GAAG,kCAAkC,GAAG,IAAI,CAAC,EAAE,CAAC;QAC7D,CAAC;IACL,CAAC;IAGD,IAAI,aAAa;QACb,OAAO;YACH,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,aAAa,EAAE,IAAI,CAAC,aAAa;SACpC,CAAA;IACL,CAAC;IAED,MAAM;QACF,OAAO,IAAI,CAAC,aAAa,CAAC;IAC9B,CAAC;CACJ;AA/ED,0BA+EC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { A_TYPES__DeepPartial } from "../types/A_Common.types";
|
|
2
2
|
export declare class A_CommonHelper {
|
|
3
|
-
static resolve(): Promise<
|
|
3
|
+
static resolve(): Promise<void>;
|
|
4
4
|
static omitArrayProperties<T, S extends string>(array: Array<T>, fields: string[]): Omit<T, S>[];
|
|
5
5
|
static sanitizeHTML(html: string): string;
|
|
6
6
|
/**
|
|
@@ -33,7 +33,9 @@ export declare class A_CommonHelper {
|
|
|
33
33
|
static removeLeadingZeros(formattedNumber: any): string;
|
|
34
34
|
static toUpperSnakeCase(str: string): string;
|
|
35
35
|
static toCamelCase(str: string): string;
|
|
36
|
-
static
|
|
36
|
+
static toPascalCase(str: string): string;
|
|
37
|
+
static toKebabCase(str: string): string;
|
|
38
|
+
static isObject(item: unknown): item is Record<string, any>;
|
|
37
39
|
static deepMerge<T = any>(target: any, source: any, visited?: Map<any, any>): T;
|
|
38
40
|
static deepClone<T>(target: T): T;
|
|
39
41
|
static deepCloneAndMerge<T>(target: A_TYPES__DeepPartial<T>, source: T): T;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.A_CommonHelper = void 0;
|
|
4
|
+
const A_Error_class_1 = require("../global/A_Error.class");
|
|
4
5
|
class A_CommonHelper {
|
|
5
6
|
static resolve() {
|
|
6
|
-
return new Promise((resolve) => resolve(
|
|
7
|
+
return new Promise((resolve) => resolve());
|
|
7
8
|
}
|
|
8
9
|
static omitArrayProperties(array, fields) {
|
|
9
10
|
return array;
|
|
@@ -82,12 +83,23 @@ class A_CommonHelper {
|
|
|
82
83
|
return str
|
|
83
84
|
.replace(/([a-z])([A-Z])/g, '$1_$2') // Handle lowercase followed by uppercase
|
|
84
85
|
.replace(/[-\s]([A-Z])/g, '_$1') // Handle non-alphabetical followed by uppercase
|
|
85
|
-
.replace(
|
|
86
|
+
.replace(/-/g, '_')
|
|
86
87
|
.toUpperCase();
|
|
87
88
|
}
|
|
88
89
|
static toCamelCase(str) {
|
|
89
90
|
return str.toLowerCase().replace(/_([a-z])/g, (match, letter) => letter.toUpperCase());
|
|
90
91
|
}
|
|
92
|
+
static toPascalCase(str) {
|
|
93
|
+
const camelCase = this.toCamelCase(str);
|
|
94
|
+
return camelCase.charAt(0).toUpperCase() + camelCase.slice(1);
|
|
95
|
+
}
|
|
96
|
+
static toKebabCase(str) {
|
|
97
|
+
return str
|
|
98
|
+
.replace(/([a-z])([A-Z])/g, '$1-$2') // Handle lowercase followed by uppercase
|
|
99
|
+
.replace(/[_\s]([A-Z])/g, '-$1') // Handle non-alphabetical followed by uppercase
|
|
100
|
+
.replace(/_/g, '-')
|
|
101
|
+
.toLowerCase();
|
|
102
|
+
}
|
|
91
103
|
static isObject(item) {
|
|
92
104
|
return item !== null && typeof item === 'object' && !Array.isArray(item);
|
|
93
105
|
}
|
|
@@ -195,7 +207,7 @@ class A_CommonHelper {
|
|
|
195
207
|
return clone;
|
|
196
208
|
}
|
|
197
209
|
// For any other cases
|
|
198
|
-
throw new
|
|
210
|
+
throw new A_Error_class_1.A_Error('Unable to clone the object. Unsupported type.');
|
|
199
211
|
}
|
|
200
212
|
}
|
|
201
213
|
exports.A_CommonHelper = A_CommonHelper;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"A_Common.helper.js","sourceRoot":"","sources":["../../../src/helpers/A_Common.helper.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"A_Common.helper.js","sourceRoot":"","sources":["../../../src/helpers/A_Common.helper.ts"],"names":[],"mappings":";;;AAAA,2DAAkD;AAGlD,MAAa,cAAc;IAEvB,MAAM,CAAC,OAAO;QACV,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;IACrD,CAAC;IAED,MAAM,CAAC,mBAAmB,CAAsB,KAAe,EAAE,MAAgB;QAE7E,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,MAAM,CAAC,YAAY,CAAC,IAAY;QAC5B,wEAAwE;QACxE,MAAM,KAAK,GAAG,iCAAiC,CAAC;QAEhD,gDAAgD;QAChD,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACnC,CAAC;IAKD;;;;;;OAMG;IACH,MAAM,CAAC,eAAe,CAAC,UAAe,EAAE,WAAgB;QACpD,IAAI,OAAO,GAAG,UAAU,CAAC;QAEzB,+BAA+B;QAC/B,OAAO,OAAO,EAAE,CAAC;YACb,IAAI,OAAO,KAAK,WAAW,EAAE,CAAC;gBAC1B,OAAO,IAAI,CAAC;YAChB,CAAC;YACD,OAAO,GAAG,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;QAC7C,CAAC;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;IAGD;;;;;;OAMG;IACH,MAAM,CAAC,cAAc,CACjB,KAAQ,EACR,KAAe;QAIf,uCAAuC;QACvC,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;QAEjD,mDAAmD;QACnD,SAAS,gBAAgB,CAAC,MAAmC,EAAE,QAAkB;YAC7E,MAAM,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;YAC5B,IAAI,QAA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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adaas/a-utils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "A-Utils is a set of utilities that are used across the ADAAS ecosystem. This package is designed to be a collection of utilities that are used across the ADAAS ecosystem.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -13,11 +13,16 @@ export class A_Error extends Error {
|
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
constructor(
|
|
16
|
-
params: A_TYPES__Error | Error | AxiosError | any
|
|
16
|
+
params: A_TYPES__Error | Error | AxiosError | string | any
|
|
17
17
|
) {
|
|
18
|
-
super(
|
|
18
|
+
super(
|
|
19
|
+
typeof params === 'string'
|
|
20
|
+
? params :
|
|
21
|
+
params?.message || 'Oops... Something went wrong'
|
|
22
|
+
);
|
|
23
|
+
|
|
19
24
|
this.identifyErrorType(params);
|
|
20
|
-
|
|
25
|
+
|
|
21
26
|
}
|
|
22
27
|
|
|
23
28
|
|
|
@@ -26,7 +31,15 @@ export class A_Error extends Error {
|
|
|
26
31
|
}
|
|
27
32
|
|
|
28
33
|
|
|
29
|
-
protected identifyErrorType(error: Error | AxiosError | A_TYPES__Error) {
|
|
34
|
+
protected identifyErrorType(error: Error | AxiosError | A_TYPES__Error | string | any) {
|
|
35
|
+
if (typeof error === 'string') {
|
|
36
|
+
this.message = error;
|
|
37
|
+
this.code = A_CONSTANTS__ERROR_CODES.UNEXPECTED_ERROR;
|
|
38
|
+
this.description = 'If you see this error please let us know.';
|
|
39
|
+
this.link = 'https://support.adaas.org/error/' + this.id;
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
30
43
|
|
|
31
44
|
if ((error as A_TYPES__ServerError).code &&
|
|
32
45
|
(error as A_TYPES__ServerError).description &&
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { A_Error } from "../global/A_Error.class";
|
|
1
2
|
import { A_TYPES__DeepPartial } from "../types/A_Common.types";
|
|
2
3
|
|
|
3
4
|
export class A_CommonHelper {
|
|
4
5
|
|
|
5
6
|
static resolve() {
|
|
6
|
-
return new Promise<
|
|
7
|
+
return new Promise<void>((resolve) => resolve());
|
|
7
8
|
}
|
|
8
9
|
|
|
9
10
|
static omitArrayProperties<T, S extends string>(array: Array<T>, fields: string[]): Omit<T, S>[] {
|
|
@@ -106,7 +107,7 @@ export class A_CommonHelper {
|
|
|
106
107
|
return str
|
|
107
108
|
.replace(/([a-z])([A-Z])/g, '$1_$2') // Handle lowercase followed by uppercase
|
|
108
109
|
.replace(/[-\s]([A-Z])/g, '_$1') // Handle non-alphabetical followed by uppercase
|
|
109
|
-
.replace(
|
|
110
|
+
.replace(/-/g, '_')
|
|
110
111
|
.toUpperCase();
|
|
111
112
|
}
|
|
112
113
|
|
|
@@ -115,8 +116,20 @@ export class A_CommonHelper {
|
|
|
115
116
|
}
|
|
116
117
|
|
|
117
118
|
|
|
119
|
+
static toPascalCase(str: string): string {
|
|
120
|
+
const camelCase = this.toCamelCase(str);
|
|
121
|
+
return camelCase.charAt(0).toUpperCase() + camelCase.slice(1);
|
|
122
|
+
}
|
|
118
123
|
|
|
119
|
-
static
|
|
124
|
+
static toKebabCase(str: string): string {
|
|
125
|
+
return str
|
|
126
|
+
.replace(/([a-z])([A-Z])/g, '$1-$2') // Handle lowercase followed by uppercase
|
|
127
|
+
.replace(/[_\s]([A-Z])/g, '-$1') // Handle non-alphabetical followed by uppercase
|
|
128
|
+
.replace(/_/g, '-')
|
|
129
|
+
.toLowerCase();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
static isObject(item: unknown): item is Record<string, any> {
|
|
120
133
|
return item !== null && typeof item === 'object' && !Array.isArray(item);
|
|
121
134
|
}
|
|
122
135
|
|
|
@@ -247,6 +260,6 @@ export class A_CommonHelper {
|
|
|
247
260
|
}
|
|
248
261
|
|
|
249
262
|
// For any other cases
|
|
250
|
-
throw new
|
|
263
|
+
throw new A_Error('Unable to clone the object. Unsupported type.');
|
|
251
264
|
}
|
|
252
265
|
}
|