pols-validator 2.1.2 → 2.2.1

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;AA2C3D,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
@@ -4,6 +4,7 @@ exports.PRules = void 0;
4
4
  const pols_utils_1 = require("pols-utils");
5
5
  const rulesEngine_1 = require("./rulesEngine");
6
6
  const pols_date_1 = require("pols-date");
7
+ const isomorphic_dompurify_1 = require("isomorphic-dompurify");
7
8
  const isObject = (context, wrapper, schema) => {
8
9
  const message = `'${wrapper.label}' debe ser un objeto`;
9
10
  if (typeof wrapper.value == 'string') {
@@ -416,5 +417,10 @@ class PRules extends rulesEngine_1.PRulesEngine {
416
417
  wrapper.value = Math.ceil(wrapper.value);
417
418
  });
418
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
+ }
419
425
  }
420
426
  exports.PRules = PRules;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pols-validator",
3
- "version": "2.1.2",
3
+ "version": "2.2.1",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -9,6 +9,12 @@
9
9
  "test": "npx ts-node-dev -r tsconfig-paths/register --project tsconfig.json",
10
10
  "export": "npm run build && npm publish"
11
11
  },
12
+ "exports": {
13
+ ".": {
14
+ "import": "./dist/index.js",
15
+ "require": "./dist/index.js"
16
+ }
17
+ },
12
18
  "author": "Jean Paul Sánchez mendoza",
13
19
  "license": "ISC",
14
20
  "description": "",
@@ -22,6 +28,7 @@
22
28
  "typescript-eslint": "^8.11.0"
23
29
  },
24
30
  "dependencies": {
31
+ "isomorphic-dompurify": "^2.21.0",
25
32
  "pols-date": "^1.0.1",
26
33
  "pols-utils": "^4.1.0"
27
34
  }
package/src/rules.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { PUtils } from "pols-utils"
2
2
  import { PRulesEngine, PRulesWrapper } from "./rulesEngine"
3
3
  import { PDate } from "pols-date"
4
+ import { sanitize } from 'isomorphic-dompurify'
4
5
 
5
6
  const isObject = (context: PRules, wrapper: PRulesWrapper, schema?: Record<string, PRules>) => {
6
7
  const message = `'${wrapper.label}' debe ser un objeto`
@@ -414,4 +415,10 @@ export class PRules extends PRulesEngine {
414
415
  wrapper.value = Math.ceil(wrapper.value)
415
416
  })
416
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
+ }
417
424
  }