av6-utils 1.0.1 → 1.0.2

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 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";
@@ -92,12 +123,6 @@ interface BillingCalcResult {
92
123
  declare function calculateBillingFromChildren(inputs: ChildCalcInput[], masterExtra: MasterAdditionalDiscount, options?: CalcOptions): BillingCalcResult;
93
124
  declare function calculateSingleChild(it: ChildCalcInput, coPayMode: CoPayMode, options?: CalcOptions): ChildCalculated;
94
125
 
95
- interface CreateTransaction {
96
- field: string;
97
- changedFrom?: string | null;
98
- changedTo?: string | null;
99
- }
100
-
101
126
  /**
102
127
  * Compares two objects (including nested objects) by flattening them,
103
128
  * and returns an array of differences. The returned array contains objects
@@ -110,4 +135,4 @@ interface CreateTransaction {
110
135
  */
111
136
  declare function findDifferences<T extends Record<string, any>>(obj1: T, obj2: T): CreateTransaction[];
112
137
 
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 };
138
+ 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, 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";
@@ -92,12 +123,6 @@ interface BillingCalcResult {
92
123
  declare function calculateBillingFromChildren(inputs: ChildCalcInput[], masterExtra: MasterAdditionalDiscount, options?: CalcOptions): BillingCalcResult;
93
124
  declare function calculateSingleChild(it: ChildCalcInput, coPayMode: CoPayMode, options?: CalcOptions): ChildCalculated;
94
125
 
95
- interface CreateTransaction {
96
- field: string;
97
- changedFrom?: string | null;
98
- changedTo?: string | null;
99
- }
100
-
101
126
  /**
102
127
  * Compares two objects (including nested objects) by flattening them,
103
128
  * and returns an array of differences. The returned array contains objects
@@ -110,4 +135,4 @@ interface CreateTransaction {
110
135
  */
111
136
  declare function findDifferences<T extends Record<string, any>>(obj1: T, obj2: T): CreateTransaction[];
112
137
 
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 };
138
+ 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, capitalizeFirstLetter, customOmit, findDifferences, getDynamicValue, getPattern, interpolate, objectTo2DArray, omitAudit, toIdValue, toNumberOrNull, toPickFields };
package/dist/index.js CHANGED
@@ -23,13 +23,17 @@ __export(index_exports, {
23
23
  RoundFormat: () => RoundFormat,
24
24
  calculateBillingFromChildren: () => calculateBillingFromChildren,
25
25
  calculateSingleChild: () => calculateSingleChild,
26
+ capitalizeFirstLetter: () => capitalizeFirstLetter,
26
27
  customOmit: () => customOmit,
27
28
  findDifferences: () => findDifferences,
28
29
  getDynamicValue: () => getDynamicValue,
29
30
  getPattern: () => getPattern,
30
31
  interpolate: () => interpolate,
31
32
  objectTo2DArray: () => objectTo2DArray,
32
- toNumberOrNull: () => toNumberOrNull
33
+ omitAudit: () => omitAudit,
34
+ toIdValue: () => toIdValue,
35
+ toNumberOrNull: () => toNumberOrNull,
36
+ toPickFields: () => toPickFields
33
37
  });
34
38
  module.exports = __toCommonJS(index_exports);
35
39
 
@@ -151,6 +155,34 @@ var interpolate = (template, vars) => {
151
155
  return key in vars ? String(vars[key]) : "";
152
156
  });
153
157
  };
158
+ function capitalizeFirstLetter(title) {
159
+ const value = title.toLowerCase();
160
+ return value.charAt(0).toUpperCase() + value.slice(1);
161
+ }
162
+ function toIdValue(row, valueKey) {
163
+ if (!row) return null;
164
+ return { id: row.id, value: String(row[valueKey] ?? "") };
165
+ }
166
+ function toPickFields(row, keys) {
167
+ if (!row) return null;
168
+ const out = {};
169
+ for (const key of keys) {
170
+ out[key] = row[key];
171
+ }
172
+ return out;
173
+ }
174
+ function omitAudit(input) {
175
+ const strip = (row) => {
176
+ if (row == null) return row;
177
+ const { isActive, createdBy, updatedBy, deletedBy, createdAt, updatedAt, deletedAt, ...rest } = row;
178
+ return rest;
179
+ };
180
+ if (Array.isArray(input)) {
181
+ return input.filter(Boolean).map((r) => strip(r));
182
+ }
183
+ if (input == null) return null;
184
+ return strip(input);
185
+ }
154
186
 
155
187
  // src/types/calculation.ts
156
188
  var RoundFormat = {
@@ -353,11 +385,15 @@ function findDifferences(obj1, obj2) {
353
385
  RoundFormat,
354
386
  calculateBillingFromChildren,
355
387
  calculateSingleChild,
388
+ capitalizeFirstLetter,
356
389
  customOmit,
357
390
  findDifferences,
358
391
  getDynamicValue,
359
392
  getPattern,
360
393
  interpolate,
361
394
  objectTo2DArray,
362
- toNumberOrNull
395
+ omitAudit,
396
+ toIdValue,
397
+ toNumberOrNull,
398
+ toPickFields
363
399
  });
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 = {
@@ -317,11 +345,15 @@ export {
317
345
  RoundFormat,
318
346
  calculateBillingFromChildren,
319
347
  calculateSingleChild,
348
+ capitalizeFirstLetter,
320
349
  customOmit,
321
350
  findDifferences,
322
351
  getDynamicValue,
323
352
  getPattern,
324
353
  interpolate,
325
354
  objectTo2DArray,
326
- toNumberOrNull
355
+ omitAudit,
356
+ toIdValue,
357
+ toNumberOrNull,
358
+ toPickFields
327
359
  };
package/package.json CHANGED
@@ -1,22 +1,29 @@
1
- {
2
- "name": "av6-utils",
3
- "version": "1.0.1",
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
- "peerDependencies": {},
19
- "dependencies": {
20
- "prettier": "^3.6.2"
21
- }
22
- }
1
+ {
2
+ "name": "av6-utils",
3
+ "version": "1.0.2",
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
+ }