@thejob/util 1.0.0
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/cjs/common/constants.d.ts +2 -0
- package/dist/cjs/common/constants.d.ts.map +1 -0
- package/dist/cjs/common/constants.js +2 -0
- package/dist/cjs/common/index.d.ts +4 -0
- package/dist/cjs/common/index.d.ts.map +1 -0
- package/dist/cjs/common/index.js +19 -0
- package/dist/cjs/common/types.d.ts +2 -0
- package/dist/cjs/common/types.d.ts.map +1 -0
- package/dist/cjs/common/types.js +17 -0
- package/dist/cjs/common/utils.d.ts +95 -0
- package/dist/cjs/common/utils.d.ts.map +1 -0
- package/dist/cjs/common/utils.js +402 -0
- package/dist/cjs/completeness/completeness.d.ts +2 -0
- package/dist/cjs/completeness/completeness.d.ts.map +1 -0
- package/dist/cjs/completeness/completeness.js +119 -0
- package/dist/cjs/completeness/index.d.ts +2 -0
- package/dist/cjs/completeness/index.d.ts.map +1 -0
- package/dist/cjs/completeness/index.js +17 -0
- package/dist/cjs/date/index.d.ts +2 -0
- package/dist/cjs/date/index.d.ts.map +1 -0
- package/dist/cjs/date/index.js +17 -0
- package/dist/cjs/date/utils.d.ts +14 -0
- package/dist/cjs/date/utils.d.ts.map +1 -0
- package/dist/cjs/date/utils.js +70 -0
- package/dist/cjs/index.d.ts +7 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +22 -0
- package/dist/cjs/job/index.d.ts +2 -0
- package/dist/cjs/job/index.d.ts.map +1 -0
- package/dist/cjs/job/index.js +17 -0
- package/dist/cjs/job/utils.d.ts +2 -0
- package/dist/cjs/job/utils.d.ts.map +1 -0
- package/dist/cjs/job/utils.js +2 -0
- package/dist/cjs/job-application/index.d.ts +2 -0
- package/dist/cjs/job-application/index.d.ts.map +1 -0
- package/dist/cjs/job-application/index.js +17 -0
- package/dist/cjs/job-application/utils.d.ts +3 -0
- package/dist/cjs/job-application/utils.d.ts.map +1 -0
- package/dist/cjs/job-application/utils.js +19 -0
- package/dist/cjs/user/index.d.ts +2 -0
- package/dist/cjs/user/index.d.ts.map +1 -0
- package/dist/cjs/user/index.js +17 -0
- package/dist/cjs/user/utils.d.ts +8 -0
- package/dist/cjs/user/utils.d.ts.map +1 -0
- package/dist/cjs/user/utils.js +18 -0
- package/dist/esm/common/constants.d.ts +2 -0
- package/dist/esm/common/constants.d.ts.map +1 -0
- package/dist/esm/common/constants.js +1 -0
- package/dist/esm/common/index.d.ts +4 -0
- package/dist/esm/common/index.d.ts.map +1 -0
- package/dist/esm/common/index.js +3 -0
- package/dist/esm/common/types.d.ts +2 -0
- package/dist/esm/common/types.d.ts.map +1 -0
- package/dist/esm/common/types.js +16 -0
- package/dist/esm/common/utils.d.ts +95 -0
- package/dist/esm/common/utils.d.ts.map +1 -0
- package/dist/esm/common/utils.js +372 -0
- package/dist/esm/completeness/completeness.d.ts +2 -0
- package/dist/esm/completeness/completeness.d.ts.map +1 -0
- package/dist/esm/completeness/completeness.js +118 -0
- package/dist/esm/completeness/index.d.ts +2 -0
- package/dist/esm/completeness/index.d.ts.map +1 -0
- package/dist/esm/completeness/index.js +1 -0
- package/dist/esm/date/index.d.ts +2 -0
- package/dist/esm/date/index.d.ts.map +1 -0
- package/dist/esm/date/index.js +1 -0
- package/dist/esm/date/utils.d.ts +14 -0
- package/dist/esm/date/utils.d.ts.map +1 -0
- package/dist/esm/date/utils.js +61 -0
- package/dist/esm/index.d.ts +7 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +6 -0
- package/dist/esm/job/index.d.ts +2 -0
- package/dist/esm/job/index.d.ts.map +1 -0
- package/dist/esm/job/index.js +1 -0
- package/dist/esm/job/utils.d.ts +2 -0
- package/dist/esm/job/utils.d.ts.map +1 -0
- package/dist/esm/job/utils.js +1 -0
- package/dist/esm/job-application/index.d.ts +2 -0
- package/dist/esm/job-application/index.d.ts.map +1 -0
- package/dist/esm/job-application/index.js +1 -0
- package/dist/esm/job-application/utils.d.ts +3 -0
- package/dist/esm/job-application/utils.d.ts.map +1 -0
- package/dist/esm/job-application/utils.js +15 -0
- package/dist/esm/user/index.d.ts +2 -0
- package/dist/esm/user/index.d.ts.map +1 -0
- package/dist/esm/user/index.js +1 -0
- package/dist/esm/user/utils.d.ts +8 -0
- package/dist/esm/user/utils.d.ts.map +1 -0
- package/dist/esm/user/utils.js +14 -0
- package/package.json +52 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/common/constants.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/common/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./types"), exports);
|
|
18
|
+
__exportStar(require("./constants"), exports);
|
|
19
|
+
__exportStar(require("./utils"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/common/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// import { UserDetailType } from "@thejob/schema";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
// export type CompletenessScore = {
|
|
5
|
+
// score: number;
|
|
6
|
+
// completedSteps: number;
|
|
7
|
+
// totalSteps: number;
|
|
8
|
+
// children?: CompletenessScore[];
|
|
9
|
+
// meta?: {
|
|
10
|
+
// steps: string[];
|
|
11
|
+
// completed: string[];
|
|
12
|
+
// incomplete: string[];
|
|
13
|
+
// };
|
|
14
|
+
// };
|
|
15
|
+
// export type TProfileCompleteness = Partial<
|
|
16
|
+
// Record<UserDetailType, CompletenessScore>
|
|
17
|
+
// >;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { ProficiencyLevel, TLocationValue, TMobileNumberSchema, TName, TUserCompletenessSchema, TUserSchema } from "@thejob/schema";
|
|
2
|
+
import { AnySchema } from "yup";
|
|
3
|
+
export declare const removeEmpty: (obj: any) => any;
|
|
4
|
+
export declare const deepEqual: (obj1: unknown, obj2: unknown) => boolean;
|
|
5
|
+
export declare const getYupDefaults: <T>(schema: AnySchema) => T;
|
|
6
|
+
export declare const getFormDefaultValues: (inputValue: any, // TODO: Use react hook form default values type definition,,
|
|
7
|
+
onComplete?: (data: any) => void) => () => Promise<any>;
|
|
8
|
+
export declare const proficiencyLevelToRating: (level: ProficiencyLevel) => number;
|
|
9
|
+
export declare const slugify: (str: string) => string;
|
|
10
|
+
export declare const getShortId: (size?: number) => string;
|
|
11
|
+
export declare const minifyString: (seed: string, length?: number) => string;
|
|
12
|
+
/**
|
|
13
|
+
* Extracts the ID from a given string pattern.
|
|
14
|
+
* Assumes the ID is the last segment after the final hyphen.
|
|
15
|
+
*
|
|
16
|
+
* @param input - The string to extract the ID from.
|
|
17
|
+
* @returns The extracted ID or null if not found.
|
|
18
|
+
*/
|
|
19
|
+
export declare const extractShortID: (slug: string) => string | null | undefined;
|
|
20
|
+
type AllResults<T extends unknown[]> = {
|
|
21
|
+
[K in keyof T]: T[K] extends Promise<infer U> ? U | {
|
|
22
|
+
error: any;
|
|
23
|
+
} : never;
|
|
24
|
+
};
|
|
25
|
+
export declare const allResults: <T extends unknown[]>(promises: readonly [...T]) => Promise<AllResults<T>>;
|
|
26
|
+
export declare const sleep: (duration: number) => Promise<unknown>;
|
|
27
|
+
export declare const hasOtherValue: (input: any) => boolean;
|
|
28
|
+
export declare const fromWithOtherValue: (input: any, displayFn?: (value: any) => any) => any;
|
|
29
|
+
export declare const isJSON: (value: any) => boolean;
|
|
30
|
+
export declare const displayByName: (option: any) => any;
|
|
31
|
+
export declare const displayLocation: (location: TLocationValue, display: "address" | "medium" | "small") => string;
|
|
32
|
+
/**
|
|
33
|
+
* Generates a random integer between two given values (inclusive).
|
|
34
|
+
*
|
|
35
|
+
* @param {number} min - The minimum value (inclusive).
|
|
36
|
+
* @param {number} max - The maximum value (inclusive).
|
|
37
|
+
* @returns {number} A random integer between min and max.
|
|
38
|
+
*/
|
|
39
|
+
export declare const getRandomInt: (min: number, max: number) => number;
|
|
40
|
+
/**
|
|
41
|
+
* Generates a random floating-point number between two given values (inclusive).
|
|
42
|
+
*
|
|
43
|
+
* @param {number} min - The minimum value (inclusive).
|
|
44
|
+
* @param {number} max - The maximum value (inclusive).
|
|
45
|
+
* @returns {number} A random floating-point number between min and max.
|
|
46
|
+
*/
|
|
47
|
+
export declare const getRandomFloat: (min: number, max: number) => number;
|
|
48
|
+
export declare const displayNameLabel: (name: TName | string, type?: "full" | "first" | "last") => string;
|
|
49
|
+
export declare const displayMobileNumberLabel: (mobileNumber: TMobileNumberSchema, options?: {
|
|
50
|
+
countryName?: boolean;
|
|
51
|
+
}) => string;
|
|
52
|
+
export declare const toPositiveWholeNumber: (value: any) => number;
|
|
53
|
+
export declare const formatNumberToKMB: (num: number) => string;
|
|
54
|
+
export declare const formatCountWithLabel: (count: number, options: {
|
|
55
|
+
singularLabel: string;
|
|
56
|
+
pluralLabel: string;
|
|
57
|
+
zeroCountLabel?: string;
|
|
58
|
+
}) => string;
|
|
59
|
+
/**
|
|
60
|
+
* Recursively parses a dirty fields object to detect if the form or a specific field is dirty.
|
|
61
|
+
*
|
|
62
|
+
* @param dirtyFields The object representing the dirty state of form fields.
|
|
63
|
+
* @param fieldName (Optional) The name of a specific field to check for dirtiness.
|
|
64
|
+
* @returns True if the form or the specified field is dirty, false otherwise.
|
|
65
|
+
*/
|
|
66
|
+
export declare const isFormDirty: (dirtyFields: any, //PickFrom<FormState<any>, "dirtyFields">,
|
|
67
|
+
fieldName?: string) => boolean;
|
|
68
|
+
interface ErrorDetail {
|
|
69
|
+
value: number;
|
|
70
|
+
path: string;
|
|
71
|
+
type: string;
|
|
72
|
+
params: Record<string, any>;
|
|
73
|
+
errors: string[];
|
|
74
|
+
inner: ErrorDetail[];
|
|
75
|
+
name: string;
|
|
76
|
+
message: string;
|
|
77
|
+
}
|
|
78
|
+
interface InputObject {
|
|
79
|
+
value: Record<string, any>;
|
|
80
|
+
errors: string[];
|
|
81
|
+
inner: ErrorDetail[];
|
|
82
|
+
name: string;
|
|
83
|
+
message: string;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Extracts the root path of each error within the 'inner' property of the input object.
|
|
87
|
+
*
|
|
88
|
+
* @param data The input object containing error details.
|
|
89
|
+
* @returns An array of strings, where each string is the root path of an error.
|
|
90
|
+
*/
|
|
91
|
+
export declare const getErrorRootPaths: <T>(data: InputObject) => Array<keyof T>;
|
|
92
|
+
export declare const getRequiredUserInformation: (completeness: TUserCompletenessSchema, skip?: Array<keyof TUserCompletenessSchema>) => never[];
|
|
93
|
+
export declare const getRequiredInformationByUser: (user: Partial<TUserSchema>, completeness: TUserCompletenessSchema) => never[];
|
|
94
|
+
export {};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,MAAM,CAAC;CACzB,KACA,MASF,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,GACtB,aAAa,GAAG,EAAE,0CAA0C;AAC5D,YAAY,MAAM,KACjB,OA+BF,CAAC;AAEF,UAAU,WAAW;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,KAAK,EAAE,WAAW,EAAE,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,UAAU,WAAW;IACnB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3B,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,KAAK,EAAE,WAAW,EAAE,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAAI,CAAC,EAAE,MAAM,WAAW,KAAG,KAAK,CAAC,MAAM,CAAC,CAgBrE,CAAC;AAEF,eAAO,MAAM,0BAA0B,GACrC,cAAc,uBAAuB,EACrC,OAAM,KAAK,CAAC,MAAM,uBAAuB,CAAM,YAUhD,CAAC;AAEF,eAAO,MAAM,4BAA4B,GACvC,MAAM,OAAO,CAAC,WAAW,CAAC,EAC1B,cAAc,uBAAuB,YAUtC,CAAC"}
|
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getRequiredInformationByUser = exports.getRequiredUserInformation = exports.getErrorRootPaths = exports.isFormDirty = exports.formatCountWithLabel = exports.formatNumberToKMB = exports.toPositiveWholeNumber = exports.displayMobileNumberLabel = exports.displayNameLabel = exports.getRandomFloat = exports.getRandomInt = exports.displayLocation = exports.displayByName = exports.isJSON = exports.fromWithOtherValue = exports.hasOtherValue = exports.sleep = exports.allResults = exports.extractShortID = exports.minifyString = exports.getShortId = exports.slugify = exports.proficiencyLevelToRating = exports.getFormDefaultValues = exports.getYupDefaults = exports.deepEqual = exports.removeEmpty = void 0;
|
|
4
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
5
|
+
const schema_1 = require("@thejob/schema");
|
|
6
|
+
const nanoid_1 = require("nanoid");
|
|
7
|
+
const removeEmpty = (obj) => {
|
|
8
|
+
// Check if the value is an object and not null
|
|
9
|
+
if (obj !== null && typeof obj === "object") {
|
|
10
|
+
// Iterate over each key in the object
|
|
11
|
+
for (const key in obj) {
|
|
12
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
13
|
+
const value = obj[key];
|
|
14
|
+
// Recursively remove empty properties from nested objects
|
|
15
|
+
if (typeof value === "object" && value !== null) {
|
|
16
|
+
obj[key] = (0, exports.removeEmpty)(value);
|
|
17
|
+
}
|
|
18
|
+
// Remove the property if it's null, undefined, or an empty string, array, or object
|
|
19
|
+
if (value === null ||
|
|
20
|
+
value === undefined ||
|
|
21
|
+
value === "" ||
|
|
22
|
+
(typeof value === "object" && Object.keys(value).length === 0)) {
|
|
23
|
+
delete obj[key];
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return obj;
|
|
29
|
+
};
|
|
30
|
+
exports.removeEmpty = removeEmpty;
|
|
31
|
+
const deepEqual = (obj1, obj2) => {
|
|
32
|
+
return (JSON.stringify((0, exports.removeEmpty)(obj1)) === JSON.stringify((0, exports.removeEmpty)(obj2)));
|
|
33
|
+
};
|
|
34
|
+
exports.deepEqual = deepEqual;
|
|
35
|
+
// export const getYupDefaults = <T>(schema: any) => {
|
|
36
|
+
// const defaultValues: any = {};
|
|
37
|
+
// for (const key in schema.fields) {
|
|
38
|
+
// const field = schema.fields[key];
|
|
39
|
+
// if (field?.type === "object") {
|
|
40
|
+
// defaultValues[key] = getYupDefaults(field); // Recursively get defaults for nested objects
|
|
41
|
+
// } else {
|
|
42
|
+
// defaultValues[key] = field.default ? field.getDefault() : undefined; // Use `getDefault` to get default value
|
|
43
|
+
// }
|
|
44
|
+
// }
|
|
45
|
+
// return defaultValues as T;
|
|
46
|
+
// };
|
|
47
|
+
const replaceEmptyObjectsWithNull = (obj) => {
|
|
48
|
+
if (typeof obj !== "object" || obj === null) {
|
|
49
|
+
return obj;
|
|
50
|
+
}
|
|
51
|
+
if (Array.isArray(obj)) {
|
|
52
|
+
return obj.map((item) => replaceEmptyObjectsWithNull(item));
|
|
53
|
+
}
|
|
54
|
+
const newObj = {};
|
|
55
|
+
let isEmpty = true;
|
|
56
|
+
for (const key in obj) {
|
|
57
|
+
if (obj.hasOwnProperty(key)) {
|
|
58
|
+
const value = replaceEmptyObjectsWithNull(obj[key]);
|
|
59
|
+
newObj[key] = value;
|
|
60
|
+
if (typeof value === "object" &&
|
|
61
|
+
value !== null &&
|
|
62
|
+
Object.keys(value).length > 0) {
|
|
63
|
+
isEmpty = false;
|
|
64
|
+
}
|
|
65
|
+
else if (typeof value !== "undefined" &&
|
|
66
|
+
value !== null &&
|
|
67
|
+
value !== "") {
|
|
68
|
+
isEmpty = false;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return isEmpty && Object.keys(obj).length > 0 ? null : newObj;
|
|
73
|
+
};
|
|
74
|
+
const getYupDefaults = (schema) => {
|
|
75
|
+
const defaultValues = schema.getDefault();
|
|
76
|
+
return replaceEmptyObjectsWithNull(defaultValues);
|
|
77
|
+
};
|
|
78
|
+
exports.getYupDefaults = getYupDefaults;
|
|
79
|
+
const getFormDefaultValues = (inputValue, // TODO: Use react hook form default values type definition,,
|
|
80
|
+
onComplete = () => null) => {
|
|
81
|
+
const isCallable = typeof inputValue === "function";
|
|
82
|
+
return async () => {
|
|
83
|
+
const values = isCallable ? await inputValue() : inputValue;
|
|
84
|
+
onComplete(values);
|
|
85
|
+
return values;
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
exports.getFormDefaultValues = getFormDefaultValues;
|
|
89
|
+
const proficiencyLevelToRating = (level) => {
|
|
90
|
+
switch (level) {
|
|
91
|
+
case schema_1.ProficiencyLevel.BasicAwareness:
|
|
92
|
+
return 1;
|
|
93
|
+
case schema_1.ProficiencyLevel.Beginner:
|
|
94
|
+
return 2;
|
|
95
|
+
case schema_1.ProficiencyLevel.Intermediate:
|
|
96
|
+
return 3;
|
|
97
|
+
case schema_1.ProficiencyLevel.Advanced:
|
|
98
|
+
return 4;
|
|
99
|
+
case schema_1.ProficiencyLevel.Expert:
|
|
100
|
+
return 5;
|
|
101
|
+
default:
|
|
102
|
+
return 0;
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
exports.proficiencyLevelToRating = proficiencyLevelToRating;
|
|
106
|
+
const slugify = (str) => {
|
|
107
|
+
str = str?.trim(); // trim leading/trailing white space
|
|
108
|
+
str = str
|
|
109
|
+
?.replace(/([a-z0-9])([A-Z])/g, "$1-$2") // Convert camelCase to camel-Case
|
|
110
|
+
.toLowerCase() // convert string to lowercase
|
|
111
|
+
.replace(/[^a-z0-9 -]/g, "") // remove any non-alphanumeric characters
|
|
112
|
+
.replace(/\s+/g, "-") // replace spaces with hyphens
|
|
113
|
+
.replace(/-+/g, "-"); // remove consecutive hyphens
|
|
114
|
+
return str;
|
|
115
|
+
};
|
|
116
|
+
exports.slugify = slugify;
|
|
117
|
+
const getShortId = (size = 12) => {
|
|
118
|
+
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
119
|
+
const nanoid = (0, nanoid_1.customAlphabet)(alphabet, 12);
|
|
120
|
+
return nanoid(size);
|
|
121
|
+
};
|
|
122
|
+
exports.getShortId = getShortId;
|
|
123
|
+
const minifyString = (seed, length = 10) => {
|
|
124
|
+
let alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
|
125
|
+
function createRandom() {
|
|
126
|
+
let a = 1664525;
|
|
127
|
+
let c = 1013904223;
|
|
128
|
+
let m = Math.pow(2, 32);
|
|
129
|
+
let state = 0;
|
|
130
|
+
for (let i = 0; i < seed.length; i++) {
|
|
131
|
+
state += seed.charCodeAt(i);
|
|
132
|
+
}
|
|
133
|
+
return function () {
|
|
134
|
+
state = (a * state + c) % m;
|
|
135
|
+
return state;
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
let random = createRandom();
|
|
139
|
+
let generatedString = "";
|
|
140
|
+
for (let i = 0; i < length; i++) {
|
|
141
|
+
let randomIndex = random() % alphabet.length;
|
|
142
|
+
generatedString += alphabet[randomIndex];
|
|
143
|
+
}
|
|
144
|
+
return generatedString;
|
|
145
|
+
};
|
|
146
|
+
exports.minifyString = minifyString;
|
|
147
|
+
/**
|
|
148
|
+
* Extracts the ID from a given string pattern.
|
|
149
|
+
* Assumes the ID is the last segment after the final hyphen.
|
|
150
|
+
*
|
|
151
|
+
* @param input - The string to extract the ID from.
|
|
152
|
+
* @returns The extracted ID or null if not found.
|
|
153
|
+
*/
|
|
154
|
+
const extractShortID = (slug) => {
|
|
155
|
+
// Match the last hyphen followed by one or more characters
|
|
156
|
+
const match = slug.match(/-(\w+)$/);
|
|
157
|
+
// Return the first capturing group if a match is found
|
|
158
|
+
return match ? match[1] : null;
|
|
159
|
+
};
|
|
160
|
+
exports.extractShortID = extractShortID;
|
|
161
|
+
const allResults = async (promises) => {
|
|
162
|
+
const results = await Promise.allSettled(promises);
|
|
163
|
+
return results.map((result) => result.status === "fulfilled" ? result.value : { error: result.reason });
|
|
164
|
+
};
|
|
165
|
+
exports.allResults = allResults;
|
|
166
|
+
const sleep = async (duration) => {
|
|
167
|
+
return new Promise((resolve) => {
|
|
168
|
+
setTimeout(() => {
|
|
169
|
+
resolve({});
|
|
170
|
+
}, duration);
|
|
171
|
+
});
|
|
172
|
+
};
|
|
173
|
+
exports.sleep = sleep;
|
|
174
|
+
const hasOtherValue = (input) => {
|
|
175
|
+
return (input?.value === "others" ||
|
|
176
|
+
(Array.isArray(input?.value) && input?.value.includes("others")));
|
|
177
|
+
};
|
|
178
|
+
exports.hasOtherValue = hasOtherValue;
|
|
179
|
+
const fromWithOtherValue = (input, displayFn = (value) => value) => {
|
|
180
|
+
if (!input)
|
|
181
|
+
return "Not avaiable";
|
|
182
|
+
if ((0, exports.hasOtherValue)(input)) {
|
|
183
|
+
return input.otherValue || "Not Available";
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
return displayFn(input);
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
exports.fromWithOtherValue = fromWithOtherValue;
|
|
190
|
+
const isJSON = (value) => {
|
|
191
|
+
try {
|
|
192
|
+
JSON.parse(value);
|
|
193
|
+
return true;
|
|
194
|
+
}
|
|
195
|
+
catch (error) {
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
exports.isJSON = isJSON;
|
|
200
|
+
const displayByName = (option) => {
|
|
201
|
+
return option?.name;
|
|
202
|
+
};
|
|
203
|
+
exports.displayByName = displayByName;
|
|
204
|
+
const displayLocation = (location, display) => {
|
|
205
|
+
const { city, state, country, address } = location || {};
|
|
206
|
+
let keywords = [];
|
|
207
|
+
if (display === "address") {
|
|
208
|
+
keywords = [address];
|
|
209
|
+
}
|
|
210
|
+
else if (display === "medium") {
|
|
211
|
+
keywords = [city, state, country];
|
|
212
|
+
}
|
|
213
|
+
else if (display === "small") {
|
|
214
|
+
keywords = [city, country];
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
keywords = [country];
|
|
218
|
+
}
|
|
219
|
+
const result = keywords.filter((value) => !!value).join(", ");
|
|
220
|
+
return result || "Not Available";
|
|
221
|
+
};
|
|
222
|
+
exports.displayLocation = displayLocation;
|
|
223
|
+
/**
|
|
224
|
+
* Generates a random integer between two given values (inclusive).
|
|
225
|
+
*
|
|
226
|
+
* @param {number} min - The minimum value (inclusive).
|
|
227
|
+
* @param {number} max - The maximum value (inclusive).
|
|
228
|
+
* @returns {number} A random integer between min and max.
|
|
229
|
+
*/
|
|
230
|
+
const getRandomInt = (min, max) => {
|
|
231
|
+
if (min > max) {
|
|
232
|
+
throw new Error("Min value must be less than or equal to max value.");
|
|
233
|
+
}
|
|
234
|
+
const minCeiled = Math.ceil(min);
|
|
235
|
+
const maxFloored = Math.floor(max);
|
|
236
|
+
return Math.floor(Math.random() * (maxFloored - minCeiled + 1)) + minCeiled;
|
|
237
|
+
};
|
|
238
|
+
exports.getRandomInt = getRandomInt;
|
|
239
|
+
/**
|
|
240
|
+
* Generates a random floating-point number between two given values (inclusive).
|
|
241
|
+
*
|
|
242
|
+
* @param {number} min - The minimum value (inclusive).
|
|
243
|
+
* @param {number} max - The maximum value (inclusive).
|
|
244
|
+
* @returns {number} A random floating-point number between min and max.
|
|
245
|
+
*/
|
|
246
|
+
const getRandomFloat = (min, max) => {
|
|
247
|
+
if (min > max) {
|
|
248
|
+
throw new Error("Min value must be less than or equal to max value.");
|
|
249
|
+
}
|
|
250
|
+
return Math.random() * (max - min) + min;
|
|
251
|
+
};
|
|
252
|
+
exports.getRandomFloat = getRandomFloat;
|
|
253
|
+
const displayNameLabel = (name, type = "full") => {
|
|
254
|
+
if (!name) {
|
|
255
|
+
return "Not available";
|
|
256
|
+
}
|
|
257
|
+
if (typeof name === "string") {
|
|
258
|
+
return name;
|
|
259
|
+
}
|
|
260
|
+
const { first, last } = name;
|
|
261
|
+
if (type === "full") {
|
|
262
|
+
return `${first} ${last}`;
|
|
263
|
+
}
|
|
264
|
+
else if (type === "first") {
|
|
265
|
+
return first;
|
|
266
|
+
}
|
|
267
|
+
else if (type === "last") {
|
|
268
|
+
return last;
|
|
269
|
+
}
|
|
270
|
+
else {
|
|
271
|
+
return "Render Failed";
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
exports.displayNameLabel = displayNameLabel;
|
|
275
|
+
const displayMobileNumberLabel = (mobileNumber, options) => {
|
|
276
|
+
const { number, country } = mobileNumber;
|
|
277
|
+
const { name, dial_code } = country;
|
|
278
|
+
if (!options?.countryName) {
|
|
279
|
+
return `${dial_code} ${number}`;
|
|
280
|
+
}
|
|
281
|
+
return `${name} (${dial_code}) ${number}`;
|
|
282
|
+
};
|
|
283
|
+
exports.displayMobileNumberLabel = displayMobileNumberLabel;
|
|
284
|
+
const toPositiveWholeNumber = (value) => {
|
|
285
|
+
if (typeof value !== "number") {
|
|
286
|
+
return 0;
|
|
287
|
+
}
|
|
288
|
+
const wholePercentage = Math.round(value); // Round to the nearest whole number
|
|
289
|
+
return wholePercentage < 0 ? 0 : wholePercentage; // Ensure the value is positive
|
|
290
|
+
};
|
|
291
|
+
exports.toPositiveWholeNumber = toPositiveWholeNumber;
|
|
292
|
+
const formatNumberToKMB = (num) => {
|
|
293
|
+
if (num < 1000) {
|
|
294
|
+
return num.toString();
|
|
295
|
+
}
|
|
296
|
+
else if (num < 1000000) {
|
|
297
|
+
return (num / 1000).toFixed(1) + "K";
|
|
298
|
+
}
|
|
299
|
+
else if (num < 1000000000) {
|
|
300
|
+
return (num / 1000000).toFixed(1) + "M";
|
|
301
|
+
}
|
|
302
|
+
else {
|
|
303
|
+
return (num / 1000000000).toFixed(1) + "B";
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
exports.formatNumberToKMB = formatNumberToKMB;
|
|
307
|
+
const formatCountWithLabel = (count, options) => {
|
|
308
|
+
const { singularLabel, pluralLabel, zeroCountLabel } = options;
|
|
309
|
+
if (count === undefined || count === 0) {
|
|
310
|
+
return zeroCountLabel || `No ${pluralLabel}`;
|
|
311
|
+
}
|
|
312
|
+
else {
|
|
313
|
+
const formattedCount = (0, exports.formatNumberToKMB)(count);
|
|
314
|
+
const label = count > 1 ? pluralLabel : singularLabel;
|
|
315
|
+
return `${formattedCount} ${label}`;
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
exports.formatCountWithLabel = formatCountWithLabel;
|
|
319
|
+
/**
|
|
320
|
+
* Recursively parses a dirty fields object to detect if the form or a specific field is dirty.
|
|
321
|
+
*
|
|
322
|
+
* @param dirtyFields The object representing the dirty state of form fields.
|
|
323
|
+
* @param fieldName (Optional) The name of a specific field to check for dirtiness.
|
|
324
|
+
* @returns True if the form or the specified field is dirty, false otherwise.
|
|
325
|
+
*/
|
|
326
|
+
const isFormDirty = (dirtyFields, //PickFrom<FormState<any>, "dirtyFields">,
|
|
327
|
+
fieldName) => {
|
|
328
|
+
if (fieldName) {
|
|
329
|
+
const field = dirtyFields[fieldName];
|
|
330
|
+
if (typeof field === "boolean") {
|
|
331
|
+
return field;
|
|
332
|
+
}
|
|
333
|
+
else if (typeof field === "object" && field !== null) {
|
|
334
|
+
// If the field is an object or array, recursively check its contents
|
|
335
|
+
return (0, exports.isFormDirty)(field);
|
|
336
|
+
}
|
|
337
|
+
return false; // FieldName not found or not a boolean/object
|
|
338
|
+
}
|
|
339
|
+
// If no fieldName is provided, check the entire form
|
|
340
|
+
for (const key in dirtyFields) {
|
|
341
|
+
if (Object.prototype.hasOwnProperty.call(dirtyFields, key)) {
|
|
342
|
+
const value = dirtyFields[key];
|
|
343
|
+
if (typeof value === "boolean") {
|
|
344
|
+
if (value === true) {
|
|
345
|
+
return true; // Found a dirty boolean field
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
else if (typeof value === "object" && value !== null) {
|
|
349
|
+
// Recursively check nested objects or arrays
|
|
350
|
+
if ((0, exports.isFormDirty)(value)) {
|
|
351
|
+
return true;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
return false; // No dirty fields found
|
|
357
|
+
};
|
|
358
|
+
exports.isFormDirty = isFormDirty;
|
|
359
|
+
/**
|
|
360
|
+
* Extracts the root path of each error within the 'inner' property of the input object.
|
|
361
|
+
*
|
|
362
|
+
* @param data The input object containing error details.
|
|
363
|
+
* @returns An array of strings, where each string is the root path of an error.
|
|
364
|
+
*/
|
|
365
|
+
const getErrorRootPaths = (data) => {
|
|
366
|
+
const rootPaths = [];
|
|
367
|
+
if (data && Array.isArray(data.inner)) {
|
|
368
|
+
data.inner.forEach((errorDetail) => {
|
|
369
|
+
if (errorDetail.path) {
|
|
370
|
+
// The root path is typically the first part before the dot
|
|
371
|
+
const rootPath = errorDetail.path.split(".")[0];
|
|
372
|
+
if (rootPath && !rootPaths.includes(rootPath)) {
|
|
373
|
+
rootPaths.push(rootPath);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
return rootPaths;
|
|
379
|
+
};
|
|
380
|
+
exports.getErrorRootPaths = getErrorRootPaths;
|
|
381
|
+
const getRequiredUserInformation = (completeness, skip = []) => {
|
|
382
|
+
try {
|
|
383
|
+
schema_1.UserCompletenessSchema.omit(skip).validateSync(completeness, {
|
|
384
|
+
abortEarly: false,
|
|
385
|
+
});
|
|
386
|
+
return [];
|
|
387
|
+
}
|
|
388
|
+
catch (error) {
|
|
389
|
+
return (0, exports.getErrorRootPaths)(error);
|
|
390
|
+
}
|
|
391
|
+
};
|
|
392
|
+
exports.getRequiredUserInformation = getRequiredUserInformation;
|
|
393
|
+
const getRequiredInformationByUser = (user, completeness) => {
|
|
394
|
+
if (user.experienceLevel === schema_1.ExperienceLevel.Student ||
|
|
395
|
+
user.experienceLevel === schema_1.ExperienceLevel.Entry) {
|
|
396
|
+
return (0, exports.getRequiredUserInformation)(completeness, ["workExperiences"]);
|
|
397
|
+
}
|
|
398
|
+
else {
|
|
399
|
+
return (0, exports.getRequiredUserInformation)(completeness);
|
|
400
|
+
}
|
|
401
|
+
};
|
|
402
|
+
exports.getRequiredInformationByUser = getRequiredInformationByUser;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"completeness.d.ts","sourceRoot":"","sources":["../../../src/completeness/completeness.ts"],"names":[],"mappings":""}
|