@grafosoft/excel-validator 1.0.8 → 1.0.9

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/README.md CHANGED
@@ -121,7 +121,7 @@ const jsonValidator = [
121
121
  type: "string-empty",
122
122
  url: "api/v1/codesystem/accounts",
123
123
  prop: "code",
124
- validation: "string(20)",
124
+ validation: "code(20)",
125
125
  },
126
126
  "string(255)",
127
127
  "$string(30)",
@@ -242,7 +242,7 @@ const jsonValidator = [
242
242
  type: "string-empty",
243
243
  url: "api/v1/codesystem/contacts",
244
244
  prop: "code",
245
- validation: "string(20)",
245
+ validation: "code(20)",
246
246
  },
247
247
  "$string(255)",
248
248
  "$string(50)",
@@ -284,7 +284,7 @@ const jsonValidator = [
284
284
  prop: "id",
285
285
  },
286
286
  "$string(6)",
287
- "int",
287
+ "bool",
288
288
  {
289
289
  type: "fetch",
290
290
  url: "api/v1/valueset/taxTypes",
@@ -298,7 +298,7 @@ const jsonValidator = [
298
298
  ```ts
299
299
  const jsonValidator = [
300
300
  "int",
301
- "string(20)",
301
+ "code(20)",
302
302
  {
303
303
  type: "fetch",
304
304
  url: "api/v1/valueset/identificationTypes",
@@ -70,6 +70,9 @@ function ExcelLayout({ initData, jsonValidator, isBalances = false, }) {
70
70
  if (/^string\([^()]+\)$/.test(normalizedRule)) {
71
71
  return false;
72
72
  }
73
+ if (/^code\([^()]+\)$/.test(normalizedRule)) {
74
+ return false;
75
+ }
73
76
  return item.trim().startsWith("$");
74
77
  }
75
78
  const normalizedType = item.type.trim().replace(/^\$/, "").toLowerCase();
@@ -336,6 +339,29 @@ function ExcelLayout({ initData, jsonValidator, isBalances = false, }) {
336
339
  }
337
340
  return validateDateByFormat(trimmedValue, stringRuleArg);
338
341
  }
342
+ const codeRuleMatch = rule.match(/^code\(([^()]+)\)$/);
343
+ if (codeRuleMatch) {
344
+ if (trimmedValue === "") {
345
+ return isOptional
346
+ ? { valid: true, message: "" }
347
+ : { valid: false, message: "Valor vacío" };
348
+ }
349
+ const isAlphanumeric = /^[a-zA-Z0-9]+$/.test(trimmedValue);
350
+ if (!isAlphanumeric) {
351
+ return {
352
+ valid: false,
353
+ message: "Solo se admiten letras y números",
354
+ };
355
+ }
356
+ const maxLength = Number(codeRuleMatch[1].trim());
357
+ const isWithinLength = trimmedValue.length <= maxLength;
358
+ return {
359
+ valid: isWithinLength,
360
+ message: isWithinLength
361
+ ? ""
362
+ : `Longitud máxima permitida: ${maxLength} caracteres`,
363
+ };
364
+ }
339
365
  return { valid: true, message: "" };
340
366
  };
341
367
  const filteredRows = matrix
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grafosoft/excel-validator",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "description": "React component to validate Excel files against configurable JSON rules.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",