kcommons 18.16.5 → 18.16.7

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/build/index.d.ts CHANGED
@@ -148,6 +148,7 @@ export * from "./utils/generateId.util";
148
148
  export * from "./utils/calculateToleranceRange.util";
149
149
  export * from "./utils/getFileExtension.util";
150
150
  export * from "./utils/stripQueryParams.util";
151
+ export * from "./utils/uomNormalization.util";
151
152
  export * from "./typings/verification_apis/pincode.typings";
152
153
  export * from "./typings/verification_apis/gstVerification.typings";
153
154
  export * from "./typings/verification_apis/udyamVerification.typings";
package/build/index.js CHANGED
@@ -174,6 +174,7 @@ __exportStar(require("./utils/generateId.util"), exports);
174
174
  __exportStar(require("./utils/calculateToleranceRange.util"), exports);
175
175
  __exportStar(require("./utils/getFileExtension.util"), exports);
176
176
  __exportStar(require("./utils/stripQueryParams.util"), exports);
177
+ __exportStar(require("./utils/uomNormalization.util"), exports);
177
178
  // Verification APIs
178
179
  __exportStar(require("./typings/verification_apis/pincode.typings"), exports);
179
180
  __exportStar(require("./typings/verification_apis/gstVerification.typings"), exports);
@@ -6,6 +6,7 @@ import { INestedEntityApprovalChainEntry } from "../../entityApprovalChainEntry.
6
6
  import { INestedEntityApprovalChainEntryLog } from "../../entityApprovalChainEntryLog.typings";
7
7
  import { INestedItem } from "../../item.typings";
8
8
  import { INestedMRN, INestedMRNItem } from "../../mrn.typings";
9
+ import { INestedQualityClearanceDocument } from "../../qcd.typings";
9
10
  import { INestedSupplierInvoice, INestedSupplierInvoiceItem } from "../../supplierInvoice.typings";
10
11
  import { INestedUser } from "../../user.typings";
11
12
  import { INestedPo, INestedPOItem } from "./po.typings";
@@ -142,6 +143,7 @@ export interface IInvoiceMatchingRecordMetafields {
142
143
  imr_items_pending_quantity: Record<string, number | null>;
143
144
  approval_logs: INestedEntityApprovalChainEntryLog[] | null;
144
145
  associated_po_items: INestedPOItem[] | null;
146
+ associated_qcd: INestedQualityClearanceDocument | null;
145
147
  }
146
148
  export declare enum INVOICE_MATCHING_RECORD_METAFIELDS_INCLUDE {
147
149
  vendor_data = "vendor_data",
@@ -0,0 +1,30 @@
1
+ import { UOM_ABBREVIATIONS } from "../constants/uom.constants";
2
+ /**
3
+ * Normalizes any UOM string to its standard abbreviation
4
+ * Handles case variations, full names, abbreviations, and common typos
5
+ * @param uom Input UOM string
6
+ * @returns Standard UOM_ABBREVIATIONS enum value or the input if no match found
7
+ */
8
+ export declare function normalizeUOM(uom: string | undefined): UOM_ABBREVIATIONS | string;
9
+ /**
10
+ * Compares two UOM strings for equivalence
11
+ * Handles all variations and normalizations
12
+ * @param uom1 First UOM
13
+ * @param uom2 Second UOM
14
+ * @returns true if UOMs are equivalent
15
+ */
16
+ export declare function areUOMsEquivalent(uom1: string | undefined, uom2: string | undefined): boolean;
17
+ /**
18
+ * Checks if two UOMs can be converted to each other
19
+ * @param uom1 Source UOM
20
+ * @param uom2 Target UOM
21
+ * @returns true if a conversion exists
22
+ */
23
+ export declare function canConvertBetweenUOMs(uom1: string | undefined, uom2: string | undefined): boolean;
24
+ /**
25
+ * Gets the conversion factor between two UOMs
26
+ * @param fromUOM Source UOM
27
+ * @param toUOM Target UOM
28
+ * @returns Conversion factor or null if no conversion exists
29
+ */
30
+ export declare function getConversionFactor(fromUOM: string | undefined, toUOM: string | undefined): number | null;
@@ -0,0 +1,259 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeUOM = normalizeUOM;
4
+ exports.areUOMsEquivalent = areUOMsEquivalent;
5
+ exports.canConvertBetweenUOMs = canConvertBetweenUOMs;
6
+ exports.getConversionFactor = getConversionFactor;
7
+ const uom_constants_1 = require("../constants/uom.constants");
8
+ // Maps common variations to standard UOM abbreviations
9
+ const VARIATION_MAPPINGS = {
10
+ // Weight - KGS
11
+ KG: uom_constants_1.UOM_ABBREVIATIONS.KGS,
12
+ KGS: uom_constants_1.UOM_ABBREVIATIONS.KGS,
13
+ "K.G.S": uom_constants_1.UOM_ABBREVIATIONS.KGS,
14
+ KGM: uom_constants_1.UOM_ABBREVIATIONS.KGS,
15
+ KILOGRAM: uom_constants_1.UOM_ABBREVIATIONS.KGS,
16
+ KILOGRAMS: uom_constants_1.UOM_ABBREVIATIONS.KGS,
17
+ KIL: uom_constants_1.UOM_ABBREVIATIONS.KGS,
18
+ // Weight - Grams
19
+ GM: uom_constants_1.UOM_ABBREVIATIONS.GMS,
20
+ GMS: uom_constants_1.UOM_ABBREVIATIONS.GMS,
21
+ GRAM: uom_constants_1.UOM_ABBREVIATIONS.GMS,
22
+ GRAMME: uom_constants_1.UOM_ABBREVIATIONS.GMS,
23
+ GRAMMES: uom_constants_1.UOM_ABBREVIATIONS.GMS,
24
+ GRAMS: uom_constants_1.UOM_ABBREVIATIONS.GMS,
25
+ // Weight - Metric Ton
26
+ MT: uom_constants_1.UOM_ABBREVIATIONS.MTS,
27
+ MTS: uom_constants_1.UOM_ABBREVIATIONS.MTS,
28
+ TONNE: uom_constants_1.UOM_ABBREVIATIONS.MTS,
29
+ TONNES: uom_constants_1.UOM_ABBREVIATIONS.MTS,
30
+ METRICTON: uom_constants_1.UOM_ABBREVIATIONS.MTS,
31
+ "METRIC TON": uom_constants_1.UOM_ABBREVIATIONS.MTS,
32
+ METRICTONS: uom_constants_1.UOM_ABBREVIATIONS.MTS,
33
+ // Weight - Ton
34
+ TON: uom_constants_1.UOM_ABBREVIATIONS.TON,
35
+ TONS: uom_constants_1.UOM_ABBREVIATIONS.TON,
36
+ // Weight - Quintal
37
+ QTL: uom_constants_1.UOM_ABBREVIATIONS.QTL,
38
+ QUINTAL: uom_constants_1.UOM_ABBREVIATIONS.QTL,
39
+ QUINTALS: uom_constants_1.UOM_ABBREVIATIONS.QTL,
40
+ // Volume - Liters
41
+ L: uom_constants_1.UOM_ABBREVIATIONS.LTR,
42
+ LTR: uom_constants_1.UOM_ABBREVIATIONS.LTR,
43
+ LITER: uom_constants_1.UOM_ABBREVIATIONS.LTR,
44
+ LITERS: uom_constants_1.UOM_ABBREVIATIONS.LTR,
45
+ LITRE: uom_constants_1.UOM_ABBREVIATIONS.LTR,
46
+ LITRES: uom_constants_1.UOM_ABBREVIATIONS.LTR,
47
+ // Volume - Milliliters
48
+ ML: uom_constants_1.UOM_ABBREVIATIONS.MLT,
49
+ MLT: uom_constants_1.UOM_ABBREVIATIONS.MLT,
50
+ MILLILITER: uom_constants_1.UOM_ABBREVIATIONS.MLT,
51
+ MILLILITERS: uom_constants_1.UOM_ABBREVIATIONS.MLT,
52
+ MILILITRE: uom_constants_1.UOM_ABBREVIATIONS.MLT,
53
+ // Volume - Kiloliters
54
+ KL: uom_constants_1.UOM_ABBREVIATIONS.KLR,
55
+ KLR: uom_constants_1.UOM_ABBREVIATIONS.KLR,
56
+ KILOLITER: uom_constants_1.UOM_ABBREVIATIONS.KLR,
57
+ KILOLITERS: uom_constants_1.UOM_ABBREVIATIONS.KLR,
58
+ KILOLITRE: uom_constants_1.UOM_ABBREVIATIONS.KLR,
59
+ // Length - Meters
60
+ M: uom_constants_1.UOM_ABBREVIATIONS.MTR,
61
+ MTR: uom_constants_1.UOM_ABBREVIATIONS.MTR,
62
+ METER: uom_constants_1.UOM_ABBREVIATIONS.MTR,
63
+ METERS: uom_constants_1.UOM_ABBREVIATIONS.MTR,
64
+ METRE: uom_constants_1.UOM_ABBREVIATIONS.MTR,
65
+ METRES: uom_constants_1.UOM_ABBREVIATIONS.MTR,
66
+ // Length - Centimeters
67
+ CM: uom_constants_1.UOM_ABBREVIATIONS.CMS,
68
+ CMS: uom_constants_1.UOM_ABBREVIATIONS.CMS,
69
+ CENTIMETER: uom_constants_1.UOM_ABBREVIATIONS.CMS,
70
+ CENTIMETERS: uom_constants_1.UOM_ABBREVIATIONS.CMS,
71
+ "CENTI METER": uom_constants_1.UOM_ABBREVIATIONS.CMS,
72
+ // Length - Kilometers
73
+ KM: uom_constants_1.UOM_ABBREVIATIONS.KME,
74
+ KME: uom_constants_1.UOM_ABBREVIATIONS.KME,
75
+ KILOMETER: uom_constants_1.UOM_ABBREVIATIONS.KME,
76
+ KILOMETERS: uom_constants_1.UOM_ABBREVIATIONS.KME,
77
+ KILOMETRE: uom_constants_1.UOM_ABBREVIATIONS.KME,
78
+ // Length - Yards
79
+ YD: uom_constants_1.UOM_ABBREVIATIONS.YDS,
80
+ YDS: uom_constants_1.UOM_ABBREVIATIONS.YDS,
81
+ YARD: uom_constants_1.UOM_ABBREVIATIONS.YDS,
82
+ YARDS: uom_constants_1.UOM_ABBREVIATIONS.YDS,
83
+ // Pieces/Count
84
+ PC: uom_constants_1.UOM_ABBREVIATIONS.PCS,
85
+ PCS: uom_constants_1.UOM_ABBREVIATIONS.PCS,
86
+ PIECE: uom_constants_1.UOM_ABBREVIATIONS.PCS,
87
+ PIECES: uom_constants_1.UOM_ABBREVIATIONS.PCS,
88
+ EA: uom_constants_1.UOM_ABBREVIATIONS.EA,
89
+ EACH: uom_constants_1.UOM_ABBREVIATIONS.EA,
90
+ NOS: uom_constants_1.UOM_ABBREVIATIONS.NOS,
91
+ NO: uom_constants_1.UOM_ABBREVIATIONS.NOS,
92
+ NUMBER: uom_constants_1.UOM_ABBREVIATIONS.NOS,
93
+ NUMBERS: uom_constants_1.UOM_ABBREVIATIONS.NOS,
94
+ UNT: uom_constants_1.UOM_ABBREVIATIONS.UNT,
95
+ UNIT: uom_constants_1.UOM_ABBREVIATIONS.UNT,
96
+ UNITS: uom_constants_1.UOM_ABBREVIATIONS.UNT,
97
+ // Dozen
98
+ DZ: uom_constants_1.UOM_ABBREVIATIONS.DZ,
99
+ DOZEN: uom_constants_1.UOM_ABBREVIATIONS.DZ,
100
+ DOZENS: uom_constants_1.UOM_ABBREVIATIONS.DZ,
101
+ // Gross/Count variations
102
+ GRS: uom_constants_1.UOM_ABBREVIATIONS.GRS,
103
+ GROSS: uom_constants_1.UOM_ABBREVIATIONS.GRS,
104
+ TGM: uom_constants_1.UOM_ABBREVIATIONS.TGM,
105
+ "TEN GROSS": uom_constants_1.UOM_ABBREVIATIONS.TGM,
106
+ GGK: uom_constants_1.UOM_ABBREVIATIONS.GGK,
107
+ "GREAT GROSS": uom_constants_1.UOM_ABBREVIATIONS.GGK,
108
+ // Area
109
+ SQM: uom_constants_1.UOM_ABBREVIATIONS.SQM,
110
+ "SQUARE METER": uom_constants_1.UOM_ABBREVIATIONS.SQM,
111
+ "SQUARE METRE": uom_constants_1.UOM_ABBREVIATIONS.SQM,
112
+ SQF: uom_constants_1.UOM_ABBREVIATIONS.SQF,
113
+ "SQUARE FEET": uom_constants_1.UOM_ABBREVIATIONS.SQF,
114
+ "SQUARE FOOT": uom_constants_1.UOM_ABBREVIATIONS.SQF,
115
+ SQY: uom_constants_1.UOM_ABBREVIATIONS.SQY,
116
+ "SQUARE YARD": uom_constants_1.UOM_ABBREVIATIONS.SQY,
117
+ "SQUARE YARDS": uom_constants_1.UOM_ABBREVIATIONS.SQY,
118
+ // Packaging
119
+ BAG: uom_constants_1.UOM_ABBREVIATIONS.BAG,
120
+ BAGS: uom_constants_1.UOM_ABBREVIATIONS.BAG,
121
+ BOX: uom_constants_1.UOM_ABBREVIATIONS.BOX,
122
+ BOXES: uom_constants_1.UOM_ABBREVIATIONS.BOX,
123
+ BAL: uom_constants_1.UOM_ABBREVIATIONS.BAL,
124
+ BALE: uom_constants_1.UOM_ABBREVIATIONS.BAL,
125
+ BALES: uom_constants_1.UOM_ABBREVIATIONS.BAL,
126
+ CTN: uom_constants_1.UOM_ABBREVIATIONS.CTN,
127
+ CARTON: uom_constants_1.UOM_ABBREVIATIONS.CTN,
128
+ CARTONS: uom_constants_1.UOM_ABBREVIATIONS.CTN,
129
+ BTL: uom_constants_1.UOM_ABBREVIATIONS.BTL,
130
+ BOTTLE: uom_constants_1.UOM_ABBREVIATIONS.BTL,
131
+ BOTTLES: uom_constants_1.UOM_ABBREVIATIONS.BTL,
132
+ CAN: uom_constants_1.UOM_ABBREVIATIONS.CAN,
133
+ CANS: uom_constants_1.UOM_ABBREVIATIONS.CAN,
134
+ DRM: uom_constants_1.UOM_ABBREVIATIONS.DRM,
135
+ DRUM: uom_constants_1.UOM_ABBREVIATIONS.DRM,
136
+ DRUMS: uom_constants_1.UOM_ABBREVIATIONS.DRM,
137
+ TUB: uom_constants_1.UOM_ABBREVIATIONS.TUB,
138
+ TUBE: uom_constants_1.UOM_ABBREVIATIONS.TUB,
139
+ TUBES: uom_constants_1.UOM_ABBREVIATIONS.TUB,
140
+ ROL: uom_constants_1.UOM_ABBREVIATIONS.ROL,
141
+ ROLL: uom_constants_1.UOM_ABBREVIATIONS.ROL,
142
+ ROLLS: uom_constants_1.UOM_ABBREVIATIONS.ROL,
143
+ PAC: uom_constants_1.UOM_ABBREVIATIONS.PAC,
144
+ PACK: uom_constants_1.UOM_ABBREVIATIONS.PAC,
145
+ PACKS: uom_constants_1.UOM_ABBREVIATIONS.PAC,
146
+ BUN: uom_constants_1.UOM_ABBREVIATIONS.BUN,
147
+ BUNCH: uom_constants_1.UOM_ABBREVIATIONS.BUN,
148
+ BUNCHES: uom_constants_1.UOM_ABBREVIATIONS.BUN,
149
+ BDL: uom_constants_1.UOM_ABBREVIATIONS.BDL,
150
+ BUNDLE: uom_constants_1.UOM_ABBREVIATIONS.BDL,
151
+ BUNDLES: uom_constants_1.UOM_ABBREVIATIONS.BDL,
152
+ SET: uom_constants_1.UOM_ABBREVIATIONS.SET,
153
+ SETS: uom_constants_1.UOM_ABBREVIATIONS.SET,
154
+ PRS: uom_constants_1.UOM_ABBREVIATIONS.PRS,
155
+ PAIR: uom_constants_1.UOM_ABBREVIATIONS.PRS,
156
+ PAIRS: uom_constants_1.UOM_ABBREVIATIONS.PRS,
157
+ PAA: uom_constants_1.UOM_ABBREVIATIONS.PAA,
158
+ BOU: uom_constants_1.UOM_ABBREVIATIONS.BOU,
159
+ "BILLION OF UNITS": uom_constants_1.UOM_ABBREVIATIONS.BOU,
160
+ BKL: uom_constants_1.UOM_ABBREVIATIONS.BKL,
161
+ BUCKLE: uom_constants_1.UOM_ABBREVIATIONS.BKL,
162
+ BUCKLES: uom_constants_1.UOM_ABBREVIATIONS.BKL,
163
+ // Other
164
+ OTH: uom_constants_1.UOM_ABBREVIATIONS.OTH,
165
+ OTHER: uom_constants_1.UOM_ABBREVIATIONS.OTH,
166
+ OTHERS: uom_constants_1.UOM_ABBREVIATIONS.OTH,
167
+ // Volume - Cubic
168
+ CCM: uom_constants_1.UOM_ABBREVIATIONS.CCM,
169
+ "CUBIC CENTIMETER": uom_constants_1.UOM_ABBREVIATIONS.CCM,
170
+ CBM: uom_constants_1.UOM_ABBREVIATIONS.CBM,
171
+ "CUBIC METER": uom_constants_1.UOM_ABBREVIATIONS.CBM,
172
+ "CUBIC METRE": uom_constants_1.UOM_ABBREVIATIONS.CBM,
173
+ // Special
174
+ TBS: uom_constants_1.UOM_ABBREVIATIONS.TBS,
175
+ TABLET: uom_constants_1.UOM_ABBREVIATIONS.TBS,
176
+ TABLETS: uom_constants_1.UOM_ABBREVIATIONS.TBS,
177
+ THD: uom_constants_1.UOM_ABBREVIATIONS.THD,
178
+ THOUSAND: uom_constants_1.UOM_ABBREVIATIONS.THD,
179
+ THOUSANDS: uom_constants_1.UOM_ABBREVIATIONS.THD,
180
+ UGS: uom_constants_1.UOM_ABBREVIATIONS.UGS,
181
+ "US GALLON": uom_constants_1.UOM_ABBREVIATIONS.UGS,
182
+ };
183
+ /**
184
+ * Normalizes any UOM string to its standard abbreviation
185
+ * Handles case variations, full names, abbreviations, and common typos
186
+ * @param uom Input UOM string
187
+ * @returns Standard UOM_ABBREVIATIONS enum value or the input if no match found
188
+ */
189
+ function normalizeUOM(uom) {
190
+ if (!uom)
191
+ return "";
192
+ // Clean the input: trim, uppercase, remove common separators
193
+ const cleaned = uom
194
+ .trim()
195
+ .toUpperCase()
196
+ .replace(/[.\-_]/g, " ")
197
+ .replace(/\s+/g, " ")
198
+ .trim();
199
+ // Direct lookup in variations mapping
200
+ if (VARIATION_MAPPINGS[cleaned]) {
201
+ return VARIATION_MAPPINGS[cleaned];
202
+ }
203
+ // If exact match to standard abbreviation, return it
204
+ if (Object.values(uom_constants_1.UOM_ABBREVIATIONS).includes(cleaned)) {
205
+ return cleaned;
206
+ }
207
+ // Check against full forms in UOMS array
208
+ const fullFormMatch = uom_constants_1.UOMS.find((uom) => uom.full_form.toUpperCase() === cleaned);
209
+ if (fullFormMatch) {
210
+ return fullFormMatch.short_form;
211
+ }
212
+ // If no match found, return the cleaned version (or original)
213
+ return uom;
214
+ }
215
+ /**
216
+ * Compares two UOM strings for equivalence
217
+ * Handles all variations and normalizations
218
+ * @param uom1 First UOM
219
+ * @param uom2 Second UOM
220
+ * @returns true if UOMs are equivalent
221
+ */
222
+ function areUOMsEquivalent(uom1, uom2) {
223
+ if (!uom1 && !uom2)
224
+ return true;
225
+ if (!uom1 || !uom2)
226
+ return false;
227
+ const normalized1 = normalizeUOM(uom1);
228
+ const normalized2 = normalizeUOM(uom2);
229
+ return normalized1 === normalized2;
230
+ }
231
+ /**
232
+ * Checks if two UOMs can be converted to each other
233
+ * @param uom1 Source UOM
234
+ * @param uom2 Target UOM
235
+ * @returns true if a conversion exists
236
+ */
237
+ function canConvertBetweenUOMs(uom1, uom2) {
238
+ if (!uom1 || !uom2)
239
+ return false;
240
+ const normalized1 = normalizeUOM(uom1);
241
+ const normalized2 = normalizeUOM(uom2);
242
+ return uom_constants_1.UOM_CONVERSIONS_LIST.some((conv) => (conv.from_uom === normalized1 && conv.to_uom === normalized2) ||
243
+ (conv.from_uom === normalized2 && conv.to_uom === normalized1));
244
+ }
245
+ /**
246
+ * Gets the conversion factor between two UOMs
247
+ * @param fromUOM Source UOM
248
+ * @param toUOM Target UOM
249
+ * @returns Conversion factor or null if no conversion exists
250
+ */
251
+ function getConversionFactor(fromUOM, toUOM) {
252
+ var _a;
253
+ if (!fromUOM || !toUOM)
254
+ return null;
255
+ const normalized1 = normalizeUOM(fromUOM);
256
+ const normalized2 = normalizeUOM(toUOM);
257
+ const conversion = uom_constants_1.UOM_CONVERSIONS_LIST.find((conv) => conv.from_uom === normalized1 && conv.to_uom === normalized2);
258
+ return (_a = conversion === null || conversion === void 0 ? void 0 : conversion.conversion_factor) !== null && _a !== void 0 ? _a : null;
259
+ }
@@ -0,0 +1,30 @@
1
+ import { UOM_ABBREVIATIONS } from "../constants/uom.constants";
2
+ /**
3
+ * Normalizes any UOM string to its standard abbreviation
4
+ * Handles case variations, full names, abbreviations, and common typos
5
+ * @param uom Input UOM string
6
+ * @returns Standard UOM_ABBREVIATIONS enum value or the input if no match found
7
+ */
8
+ export declare function normalizeUOM(uom: string | undefined): UOM_ABBREVIATIONS | string;
9
+ /**
10
+ * Compares two UOM strings for equivalence
11
+ * Handles all variations and normalizations
12
+ * @param uom1 First UOM
13
+ * @param uom2 Second UOM
14
+ * @returns true if UOMs are equivalent
15
+ */
16
+ export declare function areUOMsEquivalent(uom1: string | undefined, uom2: string | undefined): boolean;
17
+ /**
18
+ * Checks if two UOMs can be converted to each other
19
+ * @param uom1 Source UOM
20
+ * @param uom2 Target UOM
21
+ * @returns true if a conversion exists
22
+ */
23
+ export declare function canConvertBetweenUOMs(uom1: string | undefined, uom2: string | undefined): boolean;
24
+ /**
25
+ * Gets the conversion factor between two UOMs
26
+ * @param fromUOM Source UOM
27
+ * @param toUOM Target UOM
28
+ * @returns Conversion factor or null if no conversion exists
29
+ */
30
+ export declare function getConversionFactor(fromUOM: string | undefined, toUOM: string | undefined): number | null;
@@ -0,0 +1,259 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeUOM = normalizeUOM;
4
+ exports.areUOMsEquivalent = areUOMsEquivalent;
5
+ exports.canConvertBetweenUOMs = canConvertBetweenUOMs;
6
+ exports.getConversionFactor = getConversionFactor;
7
+ const uom_constants_1 = require("../constants/uom.constants");
8
+ // Maps common variations to standard UOM abbreviations
9
+ const VARIATION_MAPPINGS = {
10
+ // Weight - KGS
11
+ KG: uom_constants_1.UOM_ABBREVIATIONS.KGS,
12
+ KGS: uom_constants_1.UOM_ABBREVIATIONS.KGS,
13
+ "K.G.S": uom_constants_1.UOM_ABBREVIATIONS.KGS,
14
+ KGM: uom_constants_1.UOM_ABBREVIATIONS.KGS,
15
+ KILOGRAM: uom_constants_1.UOM_ABBREVIATIONS.KGS,
16
+ KILOGRAMS: uom_constants_1.UOM_ABBREVIATIONS.KGS,
17
+ KIL: uom_constants_1.UOM_ABBREVIATIONS.KGS,
18
+ // Weight - Grams
19
+ GM: uom_constants_1.UOM_ABBREVIATIONS.GMS,
20
+ GMS: uom_constants_1.UOM_ABBREVIATIONS.GMS,
21
+ GRAM: uom_constants_1.UOM_ABBREVIATIONS.GMS,
22
+ GRAMME: uom_constants_1.UOM_ABBREVIATIONS.GMS,
23
+ GRAMMES: uom_constants_1.UOM_ABBREVIATIONS.GMS,
24
+ GRAMS: uom_constants_1.UOM_ABBREVIATIONS.GMS,
25
+ // Weight - Metric Ton
26
+ MT: uom_constants_1.UOM_ABBREVIATIONS.MTS,
27
+ MTS: uom_constants_1.UOM_ABBREVIATIONS.MTS,
28
+ TONNE: uom_constants_1.UOM_ABBREVIATIONS.MTS,
29
+ TONNES: uom_constants_1.UOM_ABBREVIATIONS.MTS,
30
+ METRICTON: uom_constants_1.UOM_ABBREVIATIONS.MTS,
31
+ "METRIC TON": uom_constants_1.UOM_ABBREVIATIONS.MTS,
32
+ METRICTONS: uom_constants_1.UOM_ABBREVIATIONS.MTS,
33
+ // Weight - Ton
34
+ TON: uom_constants_1.UOM_ABBREVIATIONS.TON,
35
+ TONS: uom_constants_1.UOM_ABBREVIATIONS.TON,
36
+ // Weight - Quintal
37
+ QTL: uom_constants_1.UOM_ABBREVIATIONS.QTL,
38
+ QUINTAL: uom_constants_1.UOM_ABBREVIATIONS.QTL,
39
+ QUINTALS: uom_constants_1.UOM_ABBREVIATIONS.QTL,
40
+ // Volume - Liters
41
+ L: uom_constants_1.UOM_ABBREVIATIONS.LTR,
42
+ LTR: uom_constants_1.UOM_ABBREVIATIONS.LTR,
43
+ LITER: uom_constants_1.UOM_ABBREVIATIONS.LTR,
44
+ LITERS: uom_constants_1.UOM_ABBREVIATIONS.LTR,
45
+ LITRE: uom_constants_1.UOM_ABBREVIATIONS.LTR,
46
+ LITRES: uom_constants_1.UOM_ABBREVIATIONS.LTR,
47
+ // Volume - Milliliters
48
+ ML: uom_constants_1.UOM_ABBREVIATIONS.MLT,
49
+ MLT: uom_constants_1.UOM_ABBREVIATIONS.MLT,
50
+ MILLILITER: uom_constants_1.UOM_ABBREVIATIONS.MLT,
51
+ MILLILITERS: uom_constants_1.UOM_ABBREVIATIONS.MLT,
52
+ MILILITRE: uom_constants_1.UOM_ABBREVIATIONS.MLT,
53
+ // Volume - Kiloliters
54
+ KL: uom_constants_1.UOM_ABBREVIATIONS.KLR,
55
+ KLR: uom_constants_1.UOM_ABBREVIATIONS.KLR,
56
+ KILOLITER: uom_constants_1.UOM_ABBREVIATIONS.KLR,
57
+ KILOLITERS: uom_constants_1.UOM_ABBREVIATIONS.KLR,
58
+ KILOLITRE: uom_constants_1.UOM_ABBREVIATIONS.KLR,
59
+ // Length - Meters
60
+ M: uom_constants_1.UOM_ABBREVIATIONS.MTR,
61
+ MTR: uom_constants_1.UOM_ABBREVIATIONS.MTR,
62
+ METER: uom_constants_1.UOM_ABBREVIATIONS.MTR,
63
+ METERS: uom_constants_1.UOM_ABBREVIATIONS.MTR,
64
+ METRE: uom_constants_1.UOM_ABBREVIATIONS.MTR,
65
+ METRES: uom_constants_1.UOM_ABBREVIATIONS.MTR,
66
+ // Length - Centimeters
67
+ CM: uom_constants_1.UOM_ABBREVIATIONS.CMS,
68
+ CMS: uom_constants_1.UOM_ABBREVIATIONS.CMS,
69
+ CENTIMETER: uom_constants_1.UOM_ABBREVIATIONS.CMS,
70
+ CENTIMETERS: uom_constants_1.UOM_ABBREVIATIONS.CMS,
71
+ "CENTI METER": uom_constants_1.UOM_ABBREVIATIONS.CMS,
72
+ // Length - Kilometers
73
+ KM: uom_constants_1.UOM_ABBREVIATIONS.KME,
74
+ KME: uom_constants_1.UOM_ABBREVIATIONS.KME,
75
+ KILOMETER: uom_constants_1.UOM_ABBREVIATIONS.KME,
76
+ KILOMETERS: uom_constants_1.UOM_ABBREVIATIONS.KME,
77
+ KILOMETRE: uom_constants_1.UOM_ABBREVIATIONS.KME,
78
+ // Length - Yards
79
+ YD: uom_constants_1.UOM_ABBREVIATIONS.YDS,
80
+ YDS: uom_constants_1.UOM_ABBREVIATIONS.YDS,
81
+ YARD: uom_constants_1.UOM_ABBREVIATIONS.YDS,
82
+ YARDS: uom_constants_1.UOM_ABBREVIATIONS.YDS,
83
+ // Pieces/Count
84
+ PC: uom_constants_1.UOM_ABBREVIATIONS.PCS,
85
+ PCS: uom_constants_1.UOM_ABBREVIATIONS.PCS,
86
+ PIECE: uom_constants_1.UOM_ABBREVIATIONS.PCS,
87
+ PIECES: uom_constants_1.UOM_ABBREVIATIONS.PCS,
88
+ EA: uom_constants_1.UOM_ABBREVIATIONS.EA,
89
+ EACH: uom_constants_1.UOM_ABBREVIATIONS.EA,
90
+ NOS: uom_constants_1.UOM_ABBREVIATIONS.NOS,
91
+ NO: uom_constants_1.UOM_ABBREVIATIONS.NOS,
92
+ NUMBER: uom_constants_1.UOM_ABBREVIATIONS.NOS,
93
+ NUMBERS: uom_constants_1.UOM_ABBREVIATIONS.NOS,
94
+ UNT: uom_constants_1.UOM_ABBREVIATIONS.UNT,
95
+ UNIT: uom_constants_1.UOM_ABBREVIATIONS.UNT,
96
+ UNITS: uom_constants_1.UOM_ABBREVIATIONS.UNT,
97
+ // Dozen
98
+ DZ: uom_constants_1.UOM_ABBREVIATIONS.DZ,
99
+ DOZEN: uom_constants_1.UOM_ABBREVIATIONS.DZ,
100
+ DOZENS: uom_constants_1.UOM_ABBREVIATIONS.DZ,
101
+ // Gross/Count variations
102
+ GRS: uom_constants_1.UOM_ABBREVIATIONS.GRS,
103
+ GROSS: uom_constants_1.UOM_ABBREVIATIONS.GRS,
104
+ TGM: uom_constants_1.UOM_ABBREVIATIONS.TGM,
105
+ "TEN GROSS": uom_constants_1.UOM_ABBREVIATIONS.TGM,
106
+ GGK: uom_constants_1.UOM_ABBREVIATIONS.GGK,
107
+ "GREAT GROSS": uom_constants_1.UOM_ABBREVIATIONS.GGK,
108
+ // Area
109
+ SQM: uom_constants_1.UOM_ABBREVIATIONS.SQM,
110
+ "SQUARE METER": uom_constants_1.UOM_ABBREVIATIONS.SQM,
111
+ "SQUARE METRE": uom_constants_1.UOM_ABBREVIATIONS.SQM,
112
+ SQF: uom_constants_1.UOM_ABBREVIATIONS.SQF,
113
+ "SQUARE FEET": uom_constants_1.UOM_ABBREVIATIONS.SQF,
114
+ "SQUARE FOOT": uom_constants_1.UOM_ABBREVIATIONS.SQF,
115
+ SQY: uom_constants_1.UOM_ABBREVIATIONS.SQY,
116
+ "SQUARE YARD": uom_constants_1.UOM_ABBREVIATIONS.SQY,
117
+ "SQUARE YARDS": uom_constants_1.UOM_ABBREVIATIONS.SQY,
118
+ // Packaging
119
+ BAG: uom_constants_1.UOM_ABBREVIATIONS.BAG,
120
+ BAGS: uom_constants_1.UOM_ABBREVIATIONS.BAG,
121
+ BOX: uom_constants_1.UOM_ABBREVIATIONS.BOX,
122
+ BOXES: uom_constants_1.UOM_ABBREVIATIONS.BOX,
123
+ BAL: uom_constants_1.UOM_ABBREVIATIONS.BAL,
124
+ BALE: uom_constants_1.UOM_ABBREVIATIONS.BAL,
125
+ BALES: uom_constants_1.UOM_ABBREVIATIONS.BAL,
126
+ CTN: uom_constants_1.UOM_ABBREVIATIONS.CTN,
127
+ CARTON: uom_constants_1.UOM_ABBREVIATIONS.CTN,
128
+ CARTONS: uom_constants_1.UOM_ABBREVIATIONS.CTN,
129
+ BTL: uom_constants_1.UOM_ABBREVIATIONS.BTL,
130
+ BOTTLE: uom_constants_1.UOM_ABBREVIATIONS.BTL,
131
+ BOTTLES: uom_constants_1.UOM_ABBREVIATIONS.BTL,
132
+ CAN: uom_constants_1.UOM_ABBREVIATIONS.CAN,
133
+ CANS: uom_constants_1.UOM_ABBREVIATIONS.CAN,
134
+ DRM: uom_constants_1.UOM_ABBREVIATIONS.DRM,
135
+ DRUM: uom_constants_1.UOM_ABBREVIATIONS.DRM,
136
+ DRUMS: uom_constants_1.UOM_ABBREVIATIONS.DRM,
137
+ TUB: uom_constants_1.UOM_ABBREVIATIONS.TUB,
138
+ TUBE: uom_constants_1.UOM_ABBREVIATIONS.TUB,
139
+ TUBES: uom_constants_1.UOM_ABBREVIATIONS.TUB,
140
+ ROL: uom_constants_1.UOM_ABBREVIATIONS.ROL,
141
+ ROLL: uom_constants_1.UOM_ABBREVIATIONS.ROL,
142
+ ROLLS: uom_constants_1.UOM_ABBREVIATIONS.ROL,
143
+ PAC: uom_constants_1.UOM_ABBREVIATIONS.PAC,
144
+ PACK: uom_constants_1.UOM_ABBREVIATIONS.PAC,
145
+ PACKS: uom_constants_1.UOM_ABBREVIATIONS.PAC,
146
+ BUN: uom_constants_1.UOM_ABBREVIATIONS.BUN,
147
+ BUNCH: uom_constants_1.UOM_ABBREVIATIONS.BUN,
148
+ BUNCHES: uom_constants_1.UOM_ABBREVIATIONS.BUN,
149
+ BDL: uom_constants_1.UOM_ABBREVIATIONS.BDL,
150
+ BUNDLE: uom_constants_1.UOM_ABBREVIATIONS.BDL,
151
+ BUNDLES: uom_constants_1.UOM_ABBREVIATIONS.BDL,
152
+ SET: uom_constants_1.UOM_ABBREVIATIONS.SET,
153
+ SETS: uom_constants_1.UOM_ABBREVIATIONS.SET,
154
+ PRS: uom_constants_1.UOM_ABBREVIATIONS.PRS,
155
+ PAIR: uom_constants_1.UOM_ABBREVIATIONS.PRS,
156
+ PAIRS: uom_constants_1.UOM_ABBREVIATIONS.PRS,
157
+ PAA: uom_constants_1.UOM_ABBREVIATIONS.PAA,
158
+ BOU: uom_constants_1.UOM_ABBREVIATIONS.BOU,
159
+ "BILLION OF UNITS": uom_constants_1.UOM_ABBREVIATIONS.BOU,
160
+ BKL: uom_constants_1.UOM_ABBREVIATIONS.BKL,
161
+ BUCKLE: uom_constants_1.UOM_ABBREVIATIONS.BKL,
162
+ BUCKLES: uom_constants_1.UOM_ABBREVIATIONS.BKL,
163
+ // Other
164
+ OTH: uom_constants_1.UOM_ABBREVIATIONS.OTH,
165
+ OTHER: uom_constants_1.UOM_ABBREVIATIONS.OTH,
166
+ OTHERS: uom_constants_1.UOM_ABBREVIATIONS.OTH,
167
+ // Volume - Cubic
168
+ CCM: uom_constants_1.UOM_ABBREVIATIONS.CCM,
169
+ "CUBIC CENTIMETER": uom_constants_1.UOM_ABBREVIATIONS.CCM,
170
+ CBM: uom_constants_1.UOM_ABBREVIATIONS.CBM,
171
+ "CUBIC METER": uom_constants_1.UOM_ABBREVIATIONS.CBM,
172
+ "CUBIC METRE": uom_constants_1.UOM_ABBREVIATIONS.CBM,
173
+ // Special
174
+ TBS: uom_constants_1.UOM_ABBREVIATIONS.TBS,
175
+ TABLET: uom_constants_1.UOM_ABBREVIATIONS.TBS,
176
+ TABLETS: uom_constants_1.UOM_ABBREVIATIONS.TBS,
177
+ THD: uom_constants_1.UOM_ABBREVIATIONS.THD,
178
+ THOUSAND: uom_constants_1.UOM_ABBREVIATIONS.THD,
179
+ THOUSANDS: uom_constants_1.UOM_ABBREVIATIONS.THD,
180
+ UGS: uom_constants_1.UOM_ABBREVIATIONS.UGS,
181
+ "US GALLON": uom_constants_1.UOM_ABBREVIATIONS.UGS,
182
+ };
183
+ /**
184
+ * Normalizes any UOM string to its standard abbreviation
185
+ * Handles case variations, full names, abbreviations, and common typos
186
+ * @param uom Input UOM string
187
+ * @returns Standard UOM_ABBREVIATIONS enum value or the input if no match found
188
+ */
189
+ function normalizeUOM(uom) {
190
+ if (!uom)
191
+ return "";
192
+ // Clean the input: trim, uppercase, remove common separators
193
+ const cleaned = uom
194
+ .trim()
195
+ .toUpperCase()
196
+ .replace(/[.\-_]/g, " ")
197
+ .replace(/\s+/g, " ")
198
+ .trim();
199
+ // Direct lookup in variations mapping
200
+ if (VARIATION_MAPPINGS[cleaned]) {
201
+ return VARIATION_MAPPINGS[cleaned];
202
+ }
203
+ // If exact match to standard abbreviation, return it
204
+ if (Object.values(uom_constants_1.UOM_ABBREVIATIONS).includes(cleaned)) {
205
+ return cleaned;
206
+ }
207
+ // Check against full forms in UOMS array
208
+ const fullFormMatch = uom_constants_1.UOMS.find((uom) => uom.full_form.toUpperCase() === cleaned);
209
+ if (fullFormMatch) {
210
+ return fullFormMatch.short_form;
211
+ }
212
+ // If no match found, return the cleaned version (or original)
213
+ return uom;
214
+ }
215
+ /**
216
+ * Compares two UOM strings for equivalence
217
+ * Handles all variations and normalizations
218
+ * @param uom1 First UOM
219
+ * @param uom2 Second UOM
220
+ * @returns true if UOMs are equivalent
221
+ */
222
+ function areUOMsEquivalent(uom1, uom2) {
223
+ if (!uom1 && !uom2)
224
+ return true;
225
+ if (!uom1 || !uom2)
226
+ return false;
227
+ const normalized1 = normalizeUOM(uom1);
228
+ const normalized2 = normalizeUOM(uom2);
229
+ return normalized1 === normalized2;
230
+ }
231
+ /**
232
+ * Checks if two UOMs can be converted to each other
233
+ * @param uom1 Source UOM
234
+ * @param uom2 Target UOM
235
+ * @returns true if a conversion exists
236
+ */
237
+ function canConvertBetweenUOMs(uom1, uom2) {
238
+ if (!uom1 || !uom2)
239
+ return false;
240
+ const normalized1 = normalizeUOM(uom1);
241
+ const normalized2 = normalizeUOM(uom2);
242
+ return uom_constants_1.UOM_CONVERSIONS_LIST.some((conv) => (conv.from_uom === normalized1 && conv.to_uom === normalized2) ||
243
+ (conv.from_uom === normalized2 && conv.to_uom === normalized1));
244
+ }
245
+ /**
246
+ * Gets the conversion factor between two UOMs
247
+ * @param fromUOM Source UOM
248
+ * @param toUOM Target UOM
249
+ * @returns Conversion factor or null if no conversion exists
250
+ */
251
+ function getConversionFactor(fromUOM, toUOM) {
252
+ var _a;
253
+ if (!fromUOM || !toUOM)
254
+ return null;
255
+ const normalized1 = normalizeUOM(fromUOM);
256
+ const normalized2 = normalizeUOM(toUOM);
257
+ const conversion = uom_constants_1.UOM_CONVERSIONS_LIST.find((conv) => conv.from_uom === normalized1 && conv.to_uom === normalized2);
258
+ return (_a = conversion === null || conversion === void 0 ? void 0 : conversion.conversion_factor) !== null && _a !== void 0 ? _a : null;
259
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kcommons",
3
- "version": "18.16.5",
3
+ "version": "18.16.7",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",