pols-validator 2.1.1 → 2.2.0

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/rules.d.ts CHANGED
@@ -37,5 +37,6 @@ export declare class PRules extends PRulesEngine {
37
37
  split(separator: string | RegExp): this;
38
38
  floor(): this;
39
39
  ceil(): this;
40
+ sanitize(...allowedTags: string[]): this;
40
41
  }
41
42
  //# sourceMappingURL=rules.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../src/rules.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAiB,MAAM,eAAe,CAAA;AA0C3D,qBAAa,MAAO,SAAQ,YAAY;IACvC,cAAc;IAWd,cAAc;IAQd,UAAU;IAcV,MAAM;IAMN,MAAM;IA4BN,KAAK,CAAC,OAAO,EAAE,MAAM;IAQrB,QAAQ;IAUR,SAAS;IAQT,SAAS;IAIT,eAAe;IAIf,WAAW;IAQX,SAAS,CAAC,KAAK,EAAE,MAAM;IAYvB,SAAS,CAAC,KAAK,EAAE,MAAM;IAYvB,cAAc,CAAC,KAAK,EAAE,MAAM;IAY5B,IAAI,CAAC,KAAK,EAAE,MAAM;IAMlB,OAAO,CAAC,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM;IA+BlD,IAAI,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE;IAY3B,OAAO,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE;IAM9B,WAAW;IAMX,EAAE,CAAC,KAAK,EAAE,MAAM;IAMhB,GAAG,CAAC,KAAK,EAAE,MAAM;IAMjB,EAAE,CAAC,KAAK,EAAE,MAAM;IAMhB,GAAG,CAAC,KAAK,EAAE,MAAM;IAMjB,iBAAiB;IAOjB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAMxC,SAAS;IA+CT,KAAK;IAQL,KAAK;IAQ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+CT,KAAK;IAQL,KAAK;IAQL,SAAS;IAQT,KAAK,CAAC,QAAQ,EAAE,MAAM;IAStB,iBAAiB;IAQjB,QAAQ;IASR,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,CAAC,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,MAAM,CAAC;IAMlG,UAAU;IAQV,KAAK,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM;IAMhC,KAAK;IAML,IAAI;IAMJ,QAAQ,CAAC,GAAG,WAAW,EAAE,MAAM,EAAE;CAKjC"}
package/dist/rules.js CHANGED
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PRules = void 0;
4
4
  const pols_utils_1 = require("pols-utils");
5
5
  const rulesEngine_1 = require("./rulesEngine");
6
+ const pols_date_1 = require("pols-date");
7
+ const isomorphic_dompurify_1 = require("isomorphic-dompurify");
6
8
  const isObject = (context, wrapper, schema) => {
7
9
  const message = `'${wrapper.label}' debe ser un objeto`;
8
10
  if (typeof wrapper.value == 'string') {
@@ -66,8 +68,8 @@ class PRules extends rulesEngine_1.PRulesEngine {
66
68
  isDateTime() {
67
69
  this.add(this.isDateTime.name, (wrapper) => {
68
70
  const message = `'${wrapper.label}' tiene un formato de fecha y hora no válido`;
69
- if (typeof wrapper.value == 'string' || typeof wrapper.value == 'number' || wrapper.value instanceof Date || wrapper.value instanceof pols_utils_1.PDate) {
70
- const newDate = new pols_utils_1.PDate(wrapper.value);
71
+ if (typeof wrapper.value == 'string' || typeof wrapper.value == 'number' || wrapper.value instanceof Date || wrapper.value instanceof pols_date_1.PDate) {
72
+ const newDate = new pols_date_1.PDate(wrapper.value);
71
73
  if (newDate.isInvalidDate)
72
74
  return message;
73
75
  wrapper.value = newDate;
@@ -284,7 +286,7 @@ class PRules extends rulesEngine_1.PRulesEngine {
284
286
  }
285
287
  beforeOrSameAsNow() {
286
288
  return this.isDateTime().add(this.beforeOrSameAsNow.name, (wrapper) => {
287
- const now = new pols_utils_1.PDate;
289
+ const now = new pols_date_1.PDate;
288
290
  if (wrapper.value.time > now.time)
289
291
  return `'${wrapper.label}' debe ser anterior o igual a 'ahora'`;
290
292
  });
@@ -415,5 +417,10 @@ class PRules extends rulesEngine_1.PRulesEngine {
415
417
  wrapper.value = Math.ceil(wrapper.value);
416
418
  });
417
419
  }
420
+ sanitize(...allowedTags) {
421
+ return this.isAlphanumeric().add(this.sanitize.name, (wrapper) => {
422
+ wrapper.value = (0, isomorphic_dompurify_1.sanitize)(wrapper.value.trim(), { ALLOWED_TAGS: allowedTags });
423
+ });
424
+ }
418
425
  }
419
426
  exports.PRules = PRules;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pols-validator",
3
- "version": "2.1.1",
3
+ "version": "2.2.0",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -22,6 +22,8 @@
22
22
  "typescript-eslint": "^8.11.0"
23
23
  },
24
24
  "dependencies": {
25
- "pols-utils": "^1.3.5"
25
+ "isomorphic-dompurify": "^2.21.0",
26
+ "pols-date": "^1.0.1",
27
+ "pols-utils": "^4.1.0"
26
28
  }
27
29
  }
package/src/rules.ts CHANGED
@@ -1,5 +1,7 @@
1
- import { PDate, PUtils } from "pols-utils"
1
+ import { PUtils } from "pols-utils"
2
2
  import { PRulesEngine, PRulesWrapper } from "./rulesEngine"
3
+ import { PDate } from "pols-date"
4
+ import { sanitize } from 'isomorphic-dompurify'
3
5
 
4
6
  const isObject = (context: PRules, wrapper: PRulesWrapper, schema?: Record<string, PRules>) => {
5
7
  const message = `'${wrapper.label}' debe ser un objeto`
@@ -413,4 +415,10 @@ export class PRules extends PRulesEngine {
413
415
  wrapper.value = Math.ceil(wrapper.value)
414
416
  })
415
417
  }
418
+
419
+ sanitize(...allowedTags: string[]) {
420
+ return this.isAlphanumeric().add(this.sanitize.name, (wrapper: PRulesWrapper) => {
421
+ wrapper.value = sanitize((wrapper.value as string).trim(), { ALLOWED_TAGS: allowedTags })
422
+ })
423
+ }
416
424
  }
@@ -1,30 +0,0 @@
1
- import { rules } from '../src/index'
2
-
3
- const original = {
4
- uno: 'hola',
5
- dos: 'er',
6
- tres: '67',
7
- cuatro: {
8
- aaa: '2024-10-28 23:56:00',
9
- bbb: 'fgh'
10
- },
11
- cinco: [23, {
12
- ccc: 'asd'
13
- }]
14
- }
15
-
16
- const otro = 56
17
-
18
- const resultados = rules({ label: 'Body' }).isObject({
19
- uno: rules({ label: 'Uno', required: true }).isNatural(),
20
- dos: rules().isBoolean(),
21
- tres: rules({ required: true }).isNaturalNoZero(),
22
- cuatro: rules({ label: 'Cuatro', default: {} }).isObject({
23
- aaa: rules().isDateTime()
24
- }),
25
- cinco: rules().isArray(i => rules({ label: `Elem ${i + 1}` }).isObject({
26
- ccc: rules().isNumber()
27
- }))
28
- }).validate<typeof original>(original)
29
-
30
- console.log(original, resultados)