@adaas/a-utils 0.0.7 → 0.0.9
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/.nvmrc +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- 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 +14 -2
- package/dist/src/helpers/A_Common.helper.js.map +1 -1
- package/dist/src/helpers/A_ID.helper.d.ts +17 -0
- package/dist/src/helpers/A_ID.helper.js +26 -0
- package/dist/src/helpers/A_ID.helper.js.map +1 -0
- package/index.ts +1 -0
- package/package.json +1 -1
- package/src/global/A_Error.class.ts +17 -4
- package/src/helpers/A_Common.helper.ts +16 -3
- package/src/helpers/A_ID.helper.ts +32 -0
- package/tests/default.test.ts +15 -2
package/.nvmrc
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
v22.20.0
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { A_CommonHelper } from './src/helpers/A_Common.helper';
|
|
2
|
+
export { A_IdentityHelper } from './src/helpers/A_ID.helper';
|
|
2
3
|
export { A_ScheduleHelper } from './src/helpers/A_Schedule.helper';
|
|
3
4
|
export { A_Error } from './src/global/A_Error.class';
|
|
4
5
|
export { A_ServerError } from './src/global/A_ServerError.class';
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// ====================== EXPORTS ======================
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.A_CONSTANTS__ERROR_CODES = exports.A_Polyfills = exports.A_ScheduleObject = exports.ASEID = exports.A_ServerError = exports.A_Error = exports.A_ScheduleHelper = exports.A_CommonHelper = void 0;
|
|
4
|
+
exports.A_CONSTANTS__ERROR_CODES = exports.A_Polyfills = exports.A_ScheduleObject = exports.ASEID = exports.A_ServerError = exports.A_Error = exports.A_ScheduleHelper = exports.A_IdentityHelper = exports.A_CommonHelper = void 0;
|
|
5
5
|
// --- Helpers ---
|
|
6
6
|
var A_Common_helper_1 = require("./src/helpers/A_Common.helper");
|
|
7
7
|
Object.defineProperty(exports, "A_CommonHelper", { enumerable: true, get: function () { return A_Common_helper_1.A_CommonHelper; } });
|
|
8
|
+
var A_ID_helper_1 = require("./src/helpers/A_ID.helper");
|
|
9
|
+
Object.defineProperty(exports, "A_IdentityHelper", { enumerable: true, get: function () { return A_ID_helper_1.A_IdentityHelper; } });
|
|
8
10
|
var A_Schedule_helper_1 = require("./src/helpers/A_Schedule.helper");
|
|
9
11
|
Object.defineProperty(exports, "A_ScheduleHelper", { enumerable: true, get: function () { return A_Schedule_helper_1.A_ScheduleHelper; } });
|
|
10
12
|
// --- Global ---
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";AAEA,wDAAwD;;;AAGxD,kBAAkB;AAClB,iEAA+D;AAAtD,iHAAA,cAAc,OAAA;AACvB,qEAAmE;AAA1D,qHAAA,gBAAgB,OAAA;AAGzB,iBAAiB;AACjB,4DAAqD;AAA5C,wGAAA,OAAO,OAAA;AAChB,wEAAiE;AAAxD,oHAAA,aAAa,OAAA;AAEtB,wDAAiD;AAAxC,oGAAA,KAAK,OAAA;AAEd,8EAAuE;AAA9D,0HAAA,gBAAgB,OAAA;AAIzB,wDAEiC;AAD7B,0GAAA,WAAW,OAAA;AAGf,oBAAoB;AACpB,qEAA4E;AAAnE,4HAAA,wBAAwB,OAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";AAEA,wDAAwD;;;AAGxD,kBAAkB;AAClB,iEAA+D;AAAtD,iHAAA,cAAc,OAAA;AACvB,yDAA6D;AAApD,+GAAA,gBAAgB,OAAA;AACzB,qEAAmE;AAA1D,qHAAA,gBAAgB,OAAA;AAGzB,iBAAiB;AACjB,4DAAqD;AAA5C,wGAAA,OAAO,OAAA;AAChB,wEAAiE;AAAxD,oHAAA,aAAa,OAAA;AAEtB,wDAAiD;AAAxC,oGAAA,KAAK,OAAA;AAEd,8EAAuE;AAA9D,0HAAA,gBAAgB,OAAA;AAIzB,wDAEiC;AAD7B,0GAAA,WAAW,OAAA;AAGf,oBAAoB;AACpB,qEAA4E;AAAnE,4HAAA,wBAAwB,OAAA"}
|
|
@@ -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,kCAA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AAC,QAAQ,CAAC;YACpC,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;
|
|
@@ -88,6 +89,17 @@ class A_CommonHelper {
|
|
|
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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,CAAC;QAED,gBAAgB;QAChB,IAAI,MAAM,YAAY,MAAM,EAAE,CAAC;YAC3B,MAAM,KAAK,GAAG,EAAO,CAAC;YACtB,KAAK,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;gBACvB,IACI,MAAM,CAAC,GAAG,CAAC,KAAK,IAAI;;wBAEpB,MAAM,CAAC,GAAG,CAAC,KAAK,SAAS;oBAEzB,KAAK,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,GAAU,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;;oBAErE,KAAK,CAAC,GAAU,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;YACxD,CAAC;YAED,KAAK,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;gBACvB,IACI,MAAM,CAAC,GAAG,CAAC,KAAK,SAAS;;wBAEzB,MAAM,CAAC,GAAG,CAAC,KAAK,IAAI;oBAEpB,KAAK,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;;oBAE9D,KAAK,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;YACjD,CAAC;YACD,OAAO,KAAK,CAAC;QACjB,CAAC;QAED,sBAAsB;QACtB,MAAM,IAAI,uBAAO,CAAC,+CAA+C,CAAC,CAAC;IACvE,CAAC;CACJ;AArQD,wCAqQC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type A_ID_TYPES__TimeId_Parts = {
|
|
2
|
+
timestamp: Date;
|
|
3
|
+
random: string;
|
|
4
|
+
};
|
|
5
|
+
export declare class A_IdentityHelper {
|
|
6
|
+
/**
|
|
7
|
+
* Generates a short, time-based unique ID.
|
|
8
|
+
* Encodes current time (ms since epoch) and random bits in base36.
|
|
9
|
+
* Example: "mb4f1g-7f9a1c"
|
|
10
|
+
*/
|
|
11
|
+
static generateTimeId(parts?: A_ID_TYPES__TimeId_Parts): string;
|
|
12
|
+
/**
|
|
13
|
+
* Parses a short ID back into its parts.
|
|
14
|
+
* Returns an object with the original timestamp (as Date) and random string.
|
|
15
|
+
*/
|
|
16
|
+
static parseTimeId(id: string): A_ID_TYPES__TimeId_Parts;
|
|
17
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.A_IdentityHelper = void 0;
|
|
4
|
+
class A_IdentityHelper {
|
|
5
|
+
/**
|
|
6
|
+
* Generates a short, time-based unique ID.
|
|
7
|
+
* Encodes current time (ms since epoch) and random bits in base36.
|
|
8
|
+
* Example: "mb4f1g-7f9a1c"
|
|
9
|
+
*/
|
|
10
|
+
static generateTimeId(parts = { timestamp: new Date(), random: Math.random().toString(36).slice(2, 8) }) {
|
|
11
|
+
const time = parts.timestamp.getTime().toString(36); // base36-encoded timestamp
|
|
12
|
+
const random = parts.random; // use provided random string
|
|
13
|
+
return `${time}-${random}`;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Parses a short ID back into its parts.
|
|
17
|
+
* Returns an object with the original timestamp (as Date) and random string.
|
|
18
|
+
*/
|
|
19
|
+
static parseTimeId(id) {
|
|
20
|
+
const [timePart, randomPart] = id.split('-');
|
|
21
|
+
const timestamp = new Date(parseInt(timePart, 36));
|
|
22
|
+
return { timestamp, random: randomPart };
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.A_IdentityHelper = A_IdentityHelper;
|
|
26
|
+
//# sourceMappingURL=A_ID.helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"A_ID.helper.js","sourceRoot":"","sources":["../../../src/helpers/A_ID.helper.ts"],"names":[],"mappings":";;;AAOA,MAAa,gBAAgB;IACzB;;;;KAIC;IACD,MAAM,CAAC,cAAc,CACjB,QAAkC,EAAE,SAAS,EAAE,IAAI,IAAI,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE;QAE3G,MAAM,IAAI,GAAG,KAAK,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,2BAA2B;QAChF,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,6BAA6B;QAC1D,OAAO,GAAG,IAAI,IAAI,MAAM,EAAE,CAAC;IAC/B,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,WAAW,CAAC,EAAU;QACzB,MAAM,CAAC,QAAQ,EAAE,UAAU,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC7C,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC;QACnD,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC;IAC7C,CAAC;CAEJ;AAxBD,4CAwBC"}
|
package/index.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adaas/a-utils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
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>[] {
|
|
@@ -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
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
|
|
2
|
+
export type A_ID_TYPES__TimeId_Parts = {
|
|
3
|
+
timestamp: Date;
|
|
4
|
+
random: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
export class A_IdentityHelper {
|
|
9
|
+
/**
|
|
10
|
+
* Generates a short, time-based unique ID.
|
|
11
|
+
* Encodes current time (ms since epoch) and random bits in base36.
|
|
12
|
+
* Example: "mb4f1g-7f9a1c"
|
|
13
|
+
*/
|
|
14
|
+
static generateTimeId(
|
|
15
|
+
parts: A_ID_TYPES__TimeId_Parts = { timestamp: new Date(), random: Math.random().toString(36).slice(2, 8) }
|
|
16
|
+
): string {
|
|
17
|
+
const time = parts.timestamp.getTime().toString(36); // base36-encoded timestamp
|
|
18
|
+
const random = parts.random; // use provided random string
|
|
19
|
+
return `${time}-${random}`;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Parses a short ID back into its parts.
|
|
24
|
+
* Returns an object with the original timestamp (as Date) and random string.
|
|
25
|
+
*/
|
|
26
|
+
static parseTimeId(id: string): A_ID_TYPES__TimeId_Parts {
|
|
27
|
+
const [timePart, randomPart] = id.split('-');
|
|
28
|
+
const timestamp = new Date(parseInt(timePart, 36));
|
|
29
|
+
return { timestamp, random: randomPart };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
}
|
package/tests/default.test.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { A_CommonHelper } from '@adaas/a-utils/helpers/A_Common.helper';
|
|
2
|
+
import { A_IdentityHelper } from '@adaas/a-utils/helpers/A_ID.helper';
|
|
2
3
|
import { A_ScheduleHelper } from '@adaas/a-utils/helpers/A_Schedule.helper';
|
|
3
4
|
import { A_TYPES__DeepPartial } from '@adaas/a-utils/types/A_Common.types';
|
|
4
5
|
import { config } from 'dotenv';
|
|
@@ -147,8 +148,6 @@ describe('CommonHelper Tests', () => {
|
|
|
147
148
|
|
|
148
149
|
const merged = A_CommonHelper.deepCloneAndMerge(t2, t);
|
|
149
150
|
|
|
150
|
-
console.log('merged: ', merged)
|
|
151
|
-
|
|
152
151
|
expect(merged.a).toBe('a');
|
|
153
152
|
expect(merged.b).toBe('bb');
|
|
154
153
|
expect(merged.c.d).toBe('ddd');
|
|
@@ -157,4 +156,18 @@ describe('CommonHelper Tests', () => {
|
|
|
157
156
|
expect((merged as any).some.d).toBe('dd');
|
|
158
157
|
expect(merged.f('names')).toBe('names');
|
|
159
158
|
});
|
|
159
|
+
it('should generate and then parse Unique time based IDs', async () => {
|
|
160
|
+
const id = A_IdentityHelper.generateTimeId();
|
|
161
|
+
const parts = A_IdentityHelper.parseTimeId(id);
|
|
162
|
+
|
|
163
|
+
expect(id).toBeDefined();
|
|
164
|
+
expect(parts.timestamp).toBeInstanceOf(Date);
|
|
165
|
+
expect(parts.random).toHaveLength(6);
|
|
166
|
+
|
|
167
|
+
// Check that the timestamp is recent (within the last minute)
|
|
168
|
+
const now = Date.now();
|
|
169
|
+
const timestamp = parts.timestamp.getTime();
|
|
170
|
+
expect(timestamp).toBeLessThanOrEqual(now);
|
|
171
|
+
expect(timestamp).toBeGreaterThan(now - 60000); // within the last minute
|
|
172
|
+
});
|
|
160
173
|
});
|