av6-utils 1.0.1 → 1.0.4
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/index.d.mts +33 -7
- package/dist/index.d.ts +33 -7
- package/dist/index.js +40 -2
- package/dist/index.mjs +34 -1
- package/package.json +29 -22
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
interface CreateTransaction {
|
|
2
|
+
field: string;
|
|
3
|
+
changedFrom?: string | null;
|
|
4
|
+
changedTo?: string | null;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
interface IdValue {
|
|
8
|
+
id: number;
|
|
9
|
+
value: string;
|
|
10
|
+
}
|
|
11
|
+
type AuditKeys = keyof Deletevalues;
|
|
12
|
+
type WithoutAudit<T> = Omit<T, AuditKeys>;
|
|
13
|
+
interface Deletevalues {
|
|
14
|
+
isActive: boolean;
|
|
15
|
+
createdBy: number;
|
|
16
|
+
updatedBy: string;
|
|
17
|
+
deletedBy: string;
|
|
18
|
+
createdAt: Date;
|
|
19
|
+
updatedAt: Date;
|
|
20
|
+
deletedAt: Date | null;
|
|
21
|
+
}
|
|
22
|
+
|
|
1
23
|
declare function customOmit<T extends object, K extends keyof T>(obj: T, keys: K[]): {
|
|
2
24
|
rest: Omit<T, K>;
|
|
3
25
|
omitted: Pick<T, K>;
|
|
@@ -9,6 +31,15 @@ declare const getPattern: {
|
|
|
9
31
|
[key: string]: RegExp;
|
|
10
32
|
};
|
|
11
33
|
declare const interpolate: (template: string, vars: Record<string, unknown>) => string;
|
|
34
|
+
declare function capitalizeFirstLetter(title: string): string;
|
|
35
|
+
declare function toIdValue<T extends {
|
|
36
|
+
id: number;
|
|
37
|
+
}>(row: T | null | undefined, valueKey: keyof Omit<T, "id"> & string): IdValue | null;
|
|
38
|
+
declare function toPickFields<T, const K extends readonly (keyof T)[]>(row: T | null | undefined, keys: K): {
|
|
39
|
+
[P in K[number]]: T[P];
|
|
40
|
+
} | null;
|
|
41
|
+
declare function omitAudit<T extends object>(input: T | null | undefined): WithoutAudit<T>;
|
|
42
|
+
declare function omitAudit<T extends object>(input: Array<T | null | undefined>): Array<WithoutAudit<T>>;
|
|
12
43
|
|
|
13
44
|
type DiscountMode = "PERCENTAGE" | "AMOUNT";
|
|
14
45
|
type AdditionalDiscountMode = "PERCENTAGE" | "AMOUNT";
|
|
@@ -82,6 +113,7 @@ interface BillingCalcResult {
|
|
|
82
113
|
children: ChildCalculated[];
|
|
83
114
|
}
|
|
84
115
|
|
|
116
|
+
declare function applyRound(value: number, format: RoundFormat, precision?: number): number;
|
|
85
117
|
/**
|
|
86
118
|
* calculateBillingFromChildren (master-level additional discount applied AFTER child calculations)
|
|
87
119
|
* - Child: item discount -> tax (INCLUSIVE/EXCLUSIVE/NONE) -> coPay -> patient line net + line rounding
|
|
@@ -92,12 +124,6 @@ interface BillingCalcResult {
|
|
|
92
124
|
declare function calculateBillingFromChildren(inputs: ChildCalcInput[], masterExtra: MasterAdditionalDiscount, options?: CalcOptions): BillingCalcResult;
|
|
93
125
|
declare function calculateSingleChild(it: ChildCalcInput, coPayMode: CoPayMode, options?: CalcOptions): ChildCalculated;
|
|
94
126
|
|
|
95
|
-
interface CreateTransaction {
|
|
96
|
-
field: string;
|
|
97
|
-
changedFrom?: string | null;
|
|
98
|
-
changedTo?: string | null;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
127
|
/**
|
|
102
128
|
* Compares two objects (including nested objects) by flattening them,
|
|
103
129
|
* and returns an array of differences. The returned array contains objects
|
|
@@ -110,4 +136,4 @@ interface CreateTransaction {
|
|
|
110
136
|
*/
|
|
111
137
|
declare function findDifferences<T extends Record<string, any>>(obj1: T, obj2: T): CreateTransaction[];
|
|
112
138
|
|
|
113
|
-
export { type AdditionalDiscountMode, type BillingCalcResult, type CalcOptions, type ChildCalcInput, type ChildCalculated, type CoPayMode, type CoPayType, type DiscountMode, type MasterAdditionalDiscount, type MasterCalculated, RoundFormat, type TaxMethod, calculateBillingFromChildren, calculateSingleChild, customOmit, findDifferences, getDynamicValue, getPattern, interpolate, objectTo2DArray, toNumberOrNull };
|
|
139
|
+
export { type AdditionalDiscountMode, type BillingCalcResult, type CalcOptions, type ChildCalcInput, type ChildCalculated, type CoPayMode, type CoPayType, type DiscountMode, type MasterAdditionalDiscount, type MasterCalculated, RoundFormat, type TaxMethod, applyRound, calculateBillingFromChildren, calculateSingleChild, capitalizeFirstLetter, customOmit, findDifferences, getDynamicValue, getPattern, interpolate, objectTo2DArray, omitAudit, toIdValue, toNumberOrNull, toPickFields };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
interface CreateTransaction {
|
|
2
|
+
field: string;
|
|
3
|
+
changedFrom?: string | null;
|
|
4
|
+
changedTo?: string | null;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
interface IdValue {
|
|
8
|
+
id: number;
|
|
9
|
+
value: string;
|
|
10
|
+
}
|
|
11
|
+
type AuditKeys = keyof Deletevalues;
|
|
12
|
+
type WithoutAudit<T> = Omit<T, AuditKeys>;
|
|
13
|
+
interface Deletevalues {
|
|
14
|
+
isActive: boolean;
|
|
15
|
+
createdBy: number;
|
|
16
|
+
updatedBy: string;
|
|
17
|
+
deletedBy: string;
|
|
18
|
+
createdAt: Date;
|
|
19
|
+
updatedAt: Date;
|
|
20
|
+
deletedAt: Date | null;
|
|
21
|
+
}
|
|
22
|
+
|
|
1
23
|
declare function customOmit<T extends object, K extends keyof T>(obj: T, keys: K[]): {
|
|
2
24
|
rest: Omit<T, K>;
|
|
3
25
|
omitted: Pick<T, K>;
|
|
@@ -9,6 +31,15 @@ declare const getPattern: {
|
|
|
9
31
|
[key: string]: RegExp;
|
|
10
32
|
};
|
|
11
33
|
declare const interpolate: (template: string, vars: Record<string, unknown>) => string;
|
|
34
|
+
declare function capitalizeFirstLetter(title: string): string;
|
|
35
|
+
declare function toIdValue<T extends {
|
|
36
|
+
id: number;
|
|
37
|
+
}>(row: T | null | undefined, valueKey: keyof Omit<T, "id"> & string): IdValue | null;
|
|
38
|
+
declare function toPickFields<T, const K extends readonly (keyof T)[]>(row: T | null | undefined, keys: K): {
|
|
39
|
+
[P in K[number]]: T[P];
|
|
40
|
+
} | null;
|
|
41
|
+
declare function omitAudit<T extends object>(input: T | null | undefined): WithoutAudit<T>;
|
|
42
|
+
declare function omitAudit<T extends object>(input: Array<T | null | undefined>): Array<WithoutAudit<T>>;
|
|
12
43
|
|
|
13
44
|
type DiscountMode = "PERCENTAGE" | "AMOUNT";
|
|
14
45
|
type AdditionalDiscountMode = "PERCENTAGE" | "AMOUNT";
|
|
@@ -82,6 +113,7 @@ interface BillingCalcResult {
|
|
|
82
113
|
children: ChildCalculated[];
|
|
83
114
|
}
|
|
84
115
|
|
|
116
|
+
declare function applyRound(value: number, format: RoundFormat, precision?: number): number;
|
|
85
117
|
/**
|
|
86
118
|
* calculateBillingFromChildren (master-level additional discount applied AFTER child calculations)
|
|
87
119
|
* - Child: item discount -> tax (INCLUSIVE/EXCLUSIVE/NONE) -> coPay -> patient line net + line rounding
|
|
@@ -92,12 +124,6 @@ interface BillingCalcResult {
|
|
|
92
124
|
declare function calculateBillingFromChildren(inputs: ChildCalcInput[], masterExtra: MasterAdditionalDiscount, options?: CalcOptions): BillingCalcResult;
|
|
93
125
|
declare function calculateSingleChild(it: ChildCalcInput, coPayMode: CoPayMode, options?: CalcOptions): ChildCalculated;
|
|
94
126
|
|
|
95
|
-
interface CreateTransaction {
|
|
96
|
-
field: string;
|
|
97
|
-
changedFrom?: string | null;
|
|
98
|
-
changedTo?: string | null;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
127
|
/**
|
|
102
128
|
* Compares two objects (including nested objects) by flattening them,
|
|
103
129
|
* and returns an array of differences. The returned array contains objects
|
|
@@ -110,4 +136,4 @@ interface CreateTransaction {
|
|
|
110
136
|
*/
|
|
111
137
|
declare function findDifferences<T extends Record<string, any>>(obj1: T, obj2: T): CreateTransaction[];
|
|
112
138
|
|
|
113
|
-
export { type AdditionalDiscountMode, type BillingCalcResult, type CalcOptions, type ChildCalcInput, type ChildCalculated, type CoPayMode, type CoPayType, type DiscountMode, type MasterAdditionalDiscount, type MasterCalculated, RoundFormat, type TaxMethod, calculateBillingFromChildren, calculateSingleChild, customOmit, findDifferences, getDynamicValue, getPattern, interpolate, objectTo2DArray, toNumberOrNull };
|
|
139
|
+
export { type AdditionalDiscountMode, type BillingCalcResult, type CalcOptions, type ChildCalcInput, type ChildCalculated, type CoPayMode, type CoPayType, type DiscountMode, type MasterAdditionalDiscount, type MasterCalculated, RoundFormat, type TaxMethod, applyRound, calculateBillingFromChildren, calculateSingleChild, capitalizeFirstLetter, customOmit, findDifferences, getDynamicValue, getPattern, interpolate, objectTo2DArray, omitAudit, toIdValue, toNumberOrNull, toPickFields };
|
package/dist/index.js
CHANGED
|
@@ -21,15 +21,20 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
RoundFormat: () => RoundFormat,
|
|
24
|
+
applyRound: () => applyRound,
|
|
24
25
|
calculateBillingFromChildren: () => calculateBillingFromChildren,
|
|
25
26
|
calculateSingleChild: () => calculateSingleChild,
|
|
27
|
+
capitalizeFirstLetter: () => capitalizeFirstLetter,
|
|
26
28
|
customOmit: () => customOmit,
|
|
27
29
|
findDifferences: () => findDifferences,
|
|
28
30
|
getDynamicValue: () => getDynamicValue,
|
|
29
31
|
getPattern: () => getPattern,
|
|
30
32
|
interpolate: () => interpolate,
|
|
31
33
|
objectTo2DArray: () => objectTo2DArray,
|
|
32
|
-
|
|
34
|
+
omitAudit: () => omitAudit,
|
|
35
|
+
toIdValue: () => toIdValue,
|
|
36
|
+
toNumberOrNull: () => toNumberOrNull,
|
|
37
|
+
toPickFields: () => toPickFields
|
|
33
38
|
});
|
|
34
39
|
module.exports = __toCommonJS(index_exports);
|
|
35
40
|
|
|
@@ -151,6 +156,34 @@ var interpolate = (template, vars) => {
|
|
|
151
156
|
return key in vars ? String(vars[key]) : "";
|
|
152
157
|
});
|
|
153
158
|
};
|
|
159
|
+
function capitalizeFirstLetter(title) {
|
|
160
|
+
const value = title.toLowerCase();
|
|
161
|
+
return value.charAt(0).toUpperCase() + value.slice(1);
|
|
162
|
+
}
|
|
163
|
+
function toIdValue(row, valueKey) {
|
|
164
|
+
if (!row) return null;
|
|
165
|
+
return { id: row.id, value: String(row[valueKey] ?? "") };
|
|
166
|
+
}
|
|
167
|
+
function toPickFields(row, keys) {
|
|
168
|
+
if (!row) return null;
|
|
169
|
+
const out = {};
|
|
170
|
+
for (const key of keys) {
|
|
171
|
+
out[key] = row[key];
|
|
172
|
+
}
|
|
173
|
+
return out;
|
|
174
|
+
}
|
|
175
|
+
function omitAudit(input) {
|
|
176
|
+
const strip = (row) => {
|
|
177
|
+
if (row == null) return row;
|
|
178
|
+
const { isActive, createdBy, updatedBy, deletedBy, createdAt, updatedAt, deletedAt, ...rest } = row;
|
|
179
|
+
return rest;
|
|
180
|
+
};
|
|
181
|
+
if (Array.isArray(input)) {
|
|
182
|
+
return input.filter(Boolean).map((r) => strip(r));
|
|
183
|
+
}
|
|
184
|
+
if (input == null) return null;
|
|
185
|
+
return strip(input);
|
|
186
|
+
}
|
|
154
187
|
|
|
155
188
|
// src/types/calculation.ts
|
|
156
189
|
var RoundFormat = {
|
|
@@ -351,13 +384,18 @@ function findDifferences(obj1, obj2) {
|
|
|
351
384
|
// Annotate the CommonJS export names for ESM import in node:
|
|
352
385
|
0 && (module.exports = {
|
|
353
386
|
RoundFormat,
|
|
387
|
+
applyRound,
|
|
354
388
|
calculateBillingFromChildren,
|
|
355
389
|
calculateSingleChild,
|
|
390
|
+
capitalizeFirstLetter,
|
|
356
391
|
customOmit,
|
|
357
392
|
findDifferences,
|
|
358
393
|
getDynamicValue,
|
|
359
394
|
getPattern,
|
|
360
395
|
interpolate,
|
|
361
396
|
objectTo2DArray,
|
|
362
|
-
|
|
397
|
+
omitAudit,
|
|
398
|
+
toIdValue,
|
|
399
|
+
toNumberOrNull,
|
|
400
|
+
toPickFields
|
|
363
401
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -116,6 +116,34 @@ var interpolate = (template, vars) => {
|
|
|
116
116
|
return key in vars ? String(vars[key]) : "";
|
|
117
117
|
});
|
|
118
118
|
};
|
|
119
|
+
function capitalizeFirstLetter(title) {
|
|
120
|
+
const value = title.toLowerCase();
|
|
121
|
+
return value.charAt(0).toUpperCase() + value.slice(1);
|
|
122
|
+
}
|
|
123
|
+
function toIdValue(row, valueKey) {
|
|
124
|
+
if (!row) return null;
|
|
125
|
+
return { id: row.id, value: String(row[valueKey] ?? "") };
|
|
126
|
+
}
|
|
127
|
+
function toPickFields(row, keys) {
|
|
128
|
+
if (!row) return null;
|
|
129
|
+
const out = {};
|
|
130
|
+
for (const key of keys) {
|
|
131
|
+
out[key] = row[key];
|
|
132
|
+
}
|
|
133
|
+
return out;
|
|
134
|
+
}
|
|
135
|
+
function omitAudit(input) {
|
|
136
|
+
const strip = (row) => {
|
|
137
|
+
if (row == null) return row;
|
|
138
|
+
const { isActive, createdBy, updatedBy, deletedBy, createdAt, updatedAt, deletedAt, ...rest } = row;
|
|
139
|
+
return rest;
|
|
140
|
+
};
|
|
141
|
+
if (Array.isArray(input)) {
|
|
142
|
+
return input.filter(Boolean).map((r) => strip(r));
|
|
143
|
+
}
|
|
144
|
+
if (input == null) return null;
|
|
145
|
+
return strip(input);
|
|
146
|
+
}
|
|
119
147
|
|
|
120
148
|
// src/types/calculation.ts
|
|
121
149
|
var RoundFormat = {
|
|
@@ -315,13 +343,18 @@ function findDifferences(obj1, obj2) {
|
|
|
315
343
|
}
|
|
316
344
|
export {
|
|
317
345
|
RoundFormat,
|
|
346
|
+
applyRound,
|
|
318
347
|
calculateBillingFromChildren,
|
|
319
348
|
calculateSingleChild,
|
|
349
|
+
capitalizeFirstLetter,
|
|
320
350
|
customOmit,
|
|
321
351
|
findDifferences,
|
|
322
352
|
getDynamicValue,
|
|
323
353
|
getPattern,
|
|
324
354
|
interpolate,
|
|
325
355
|
objectTo2DArray,
|
|
326
|
-
|
|
356
|
+
omitAudit,
|
|
357
|
+
toIdValue,
|
|
358
|
+
toNumberOrNull,
|
|
359
|
+
toPickFields
|
|
327
360
|
};
|
package/package.json
CHANGED
|
@@ -1,22 +1,29 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "av6-utils",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"main": "dist/index.js",
|
|
5
|
-
"module": "dist/index.mjs",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
7
|
-
"description": "All utility function for av6 node js projects.",
|
|
8
|
-
"author": "Aniket Sarkar",
|
|
9
|
-
"license": "ISC",
|
|
10
|
-
"scripts": {
|
|
11
|
-
"build": "npm run format && tsup",
|
|
12
|
-
"format": "prettier --write **/*.ts"
|
|
13
|
-
},
|
|
14
|
-
"devDependencies": {
|
|
15
|
-
"tsup": "^8.5.0",
|
|
16
|
-
"typescript": "^5.9.2"
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "av6-utils",
|
|
3
|
+
"version": "1.0.4",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"module": "dist/index.mjs",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"description": "All utility function for av6 node js projects.",
|
|
8
|
+
"author": "Aniket Sarkar",
|
|
9
|
+
"license": "ISC",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "npm run format && tsup",
|
|
12
|
+
"format": "prettier --write **/*.ts"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"tsup": "^8.5.0",
|
|
16
|
+
"typescript": "^5.9.2",
|
|
17
|
+
"@types/express": "4.17.21",
|
|
18
|
+
"notistack": "^3.0.2",
|
|
19
|
+
"axios": "^1.8.4"
|
|
20
|
+
},
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"joi": "^17.13.3",
|
|
23
|
+
"express": "4.21.2",
|
|
24
|
+
"prettier": "^3.6.2",
|
|
25
|
+
"notistack": "^3.0.2",
|
|
26
|
+
"axios": "^1.8.4"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {}
|
|
29
|
+
}
|