@tewtawanc/loops-utils 1.0.1 → 1.0.3

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
@@ -33,7 +33,7 @@ interface StockSkuParams extends InventorySkuParams {
33
33
  * Normalize SKU component to ensure valid SKU string:
34
34
  * - Trims whitespace from both ends
35
35
  * - Converts to uppercase for consistency
36
- * - Replaces spaces with underscores
36
+ * - Replaces spaces and hyphens with underscores (for consistent word separation)
37
37
  * - Removes special characters except / (for codes like C/P) and _ (word separator)
38
38
  * - Removes consecutive underscores
39
39
  * - Removes leading/trailing underscores
@@ -136,5 +136,23 @@ declare function isValidStockSku(sku: string): boolean;
136
136
  * // Returns: "HD6600B H5490205B C/P 25kg Pallet"
137
137
  */
138
138
  declare function generateInventoryName(params: InventorySkuParams): string;
139
+ /**
140
+ * Nullable params for SKU generation (used in validation/matching)
141
+ */
142
+ interface NullableSkuParams {
143
+ grade?: string | null;
144
+ lotNumber?: string | null;
145
+ materialCode?: string | null;
146
+ netWeight?: number | null;
147
+ packageType?: string | null;
148
+ }
149
+ /**
150
+ * Build SKU from nullable params (for validation/matching)
151
+ * Converts null/undefined to empty string and calls generateInventorySku
152
+ *
153
+ * @example
154
+ * buildSkuFromParams({ grade: 'HD6600B', lotNumber: null, ... })
155
+ */
156
+ declare function buildSkuFromParams(params: NullableSkuParams): string;
139
157
 
140
- export { type InventorySkuParams, type StockSkuParams, extractInventorySku, formatWeight, generateInventoryName, generateInventorySku, generateStockSku, isValidInventorySku, isValidStockSku, normalizeSkuComponent, parseInventorySku, parseStockSku };
158
+ export { type InventorySkuParams, type NullableSkuParams, type StockSkuParams, buildSkuFromParams, extractInventorySku, formatWeight, generateInventoryName, generateInventorySku, generateStockSku, isValidInventorySku, isValidStockSku, normalizeSkuComponent, parseInventorySku, parseStockSku };
package/dist/index.d.ts CHANGED
@@ -33,7 +33,7 @@ interface StockSkuParams extends InventorySkuParams {
33
33
  * Normalize SKU component to ensure valid SKU string:
34
34
  * - Trims whitespace from both ends
35
35
  * - Converts to uppercase for consistency
36
- * - Replaces spaces with underscores
36
+ * - Replaces spaces and hyphens with underscores (for consistent word separation)
37
37
  * - Removes special characters except / (for codes like C/P) and _ (word separator)
38
38
  * - Removes consecutive underscores
39
39
  * - Removes leading/trailing underscores
@@ -136,5 +136,23 @@ declare function isValidStockSku(sku: string): boolean;
136
136
  * // Returns: "HD6600B H5490205B C/P 25kg Pallet"
137
137
  */
138
138
  declare function generateInventoryName(params: InventorySkuParams): string;
139
+ /**
140
+ * Nullable params for SKU generation (used in validation/matching)
141
+ */
142
+ interface NullableSkuParams {
143
+ grade?: string | null;
144
+ lotNumber?: string | null;
145
+ materialCode?: string | null;
146
+ netWeight?: number | null;
147
+ packageType?: string | null;
148
+ }
149
+ /**
150
+ * Build SKU from nullable params (for validation/matching)
151
+ * Converts null/undefined to empty string and calls generateInventorySku
152
+ *
153
+ * @example
154
+ * buildSkuFromParams({ grade: 'HD6600B', lotNumber: null, ... })
155
+ */
156
+ declare function buildSkuFromParams(params: NullableSkuParams): string;
139
157
 
140
- export { type InventorySkuParams, type StockSkuParams, extractInventorySku, formatWeight, generateInventoryName, generateInventorySku, generateStockSku, isValidInventorySku, isValidStockSku, normalizeSkuComponent, parseInventorySku, parseStockSku };
158
+ export { type InventorySkuParams, type NullableSkuParams, type StockSkuParams, buildSkuFromParams, extractInventorySku, formatWeight, generateInventoryName, generateInventorySku, generateStockSku, isValidInventorySku, isValidStockSku, normalizeSkuComponent, parseInventorySku, parseStockSku };
package/dist/index.js CHANGED
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
+ buildSkuFromParams: () => buildSkuFromParams,
23
24
  extractInventorySku: () => extractInventorySku,
24
25
  formatWeight: () => formatWeight,
25
26
  generateInventoryName: () => generateInventoryName,
@@ -33,7 +34,7 @@ __export(index_exports, {
33
34
  });
34
35
  module.exports = __toCommonJS(index_exports);
35
36
  function normalizeSkuComponent(component) {
36
- return component.trim().toUpperCase().replace(/\s+/g, "_").replace(/[^A-Z0-9/_]/g, "").replace(/_+/g, "_").replace(/^_+|_+$/g, "");
37
+ return component.trim().toUpperCase().replace(/[\s-]+/g, "_").replace(/[^A-Z0-9/_]/g, "").replace(/_+/g, "_").replace(/^_+|_+$/g, "");
37
38
  }
38
39
  function formatWeight(weight) {
39
40
  if (Number.isInteger(weight)) {
@@ -109,8 +110,18 @@ function generateInventoryName(params) {
109
110
  const capitalizedPackageType = packageType.toLowerCase().split("_").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
110
111
  return `${grade} ${lotNumber} ${materialCode} ${netWeight}kg ${capitalizedPackageType}`;
111
112
  }
113
+ function buildSkuFromParams(params) {
114
+ return generateInventorySku({
115
+ grade: params.grade || "",
116
+ lotNumber: params.lotNumber || "",
117
+ materialCode: params.materialCode || "",
118
+ netWeight: params.netWeight ?? 0,
119
+ packageType: params.packageType || "PL"
120
+ });
121
+ }
112
122
  // Annotate the CommonJS export names for ESM import in node:
113
123
  0 && (module.exports = {
124
+ buildSkuFromParams,
114
125
  extractInventorySku,
115
126
  formatWeight,
116
127
  generateInventoryName,
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  // src/index.ts
2
2
  function normalizeSkuComponent(component) {
3
- return component.trim().toUpperCase().replace(/\s+/g, "_").replace(/[^A-Z0-9/_]/g, "").replace(/_+/g, "_").replace(/^_+|_+$/g, "");
3
+ return component.trim().toUpperCase().replace(/[\s-]+/g, "_").replace(/[^A-Z0-9/_]/g, "").replace(/_+/g, "_").replace(/^_+|_+$/g, "");
4
4
  }
5
5
  function formatWeight(weight) {
6
6
  if (Number.isInteger(weight)) {
@@ -76,7 +76,17 @@ function generateInventoryName(params) {
76
76
  const capitalizedPackageType = packageType.toLowerCase().split("_").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
77
77
  return `${grade} ${lotNumber} ${materialCode} ${netWeight}kg ${capitalizedPackageType}`;
78
78
  }
79
+ function buildSkuFromParams(params) {
80
+ return generateInventorySku({
81
+ grade: params.grade || "",
82
+ lotNumber: params.lotNumber || "",
83
+ materialCode: params.materialCode || "",
84
+ netWeight: params.netWeight ?? 0,
85
+ packageType: params.packageType || "PL"
86
+ });
87
+ }
79
88
  export {
89
+ buildSkuFromParams,
80
90
  extractInventorySku,
81
91
  formatWeight,
82
92
  generateInventoryName,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tewtawanc/loops-utils",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Shared utilities for Loops warehouse management system",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",