pols-validator 2.1.0 → 2.1.2

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
@@ -35,5 +35,7 @@ export declare class PRules extends PRulesEngine {
35
35
  replace(search: string | RegExp, replace: string | ((substring: string, ...args: any[]) => string)): this;
36
36
  capitalize(): this;
37
37
  split(separator: string | RegExp): this;
38
+ floor(): this;
39
+ ceil(): this;
38
40
  }
39
41
  //# 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;IA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IAMxC,SAAS;IA+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;CAKJ"}
package/dist/rules.js CHANGED
@@ -3,6 +3,7 @@ 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");
6
7
  const isObject = (context, wrapper, schema) => {
7
8
  const message = `'${wrapper.label}' debe ser un objeto`;
8
9
  if (typeof wrapper.value == 'string') {
@@ -66,8 +67,8 @@ class PRules extends rulesEngine_1.PRulesEngine {
66
67
  isDateTime() {
67
68
  this.add(this.isDateTime.name, (wrapper) => {
68
69
  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);
70
+ if (typeof wrapper.value == 'string' || typeof wrapper.value == 'number' || wrapper.value instanceof Date || wrapper.value instanceof pols_date_1.PDate) {
71
+ const newDate = new pols_date_1.PDate(wrapper.value);
71
72
  if (newDate.isInvalidDate)
72
73
  return message;
73
74
  wrapper.value = newDate;
@@ -284,7 +285,7 @@ class PRules extends rulesEngine_1.PRulesEngine {
284
285
  }
285
286
  beforeOrSameAsNow() {
286
287
  return this.isDateTime().add(this.beforeOrSameAsNow.name, (wrapper) => {
287
- const now = new pols_utils_1.PDate;
288
+ const now = new pols_date_1.PDate;
288
289
  if (wrapper.value.time > now.time)
289
290
  return `'${wrapper.label}' debe ser anterior o igual a 'ahora'`;
290
291
  });
@@ -405,5 +406,15 @@ class PRules extends rulesEngine_1.PRulesEngine {
405
406
  wrapper.value = wrapper.value.split(separator);
406
407
  });
407
408
  }
409
+ floor() {
410
+ return this.isNumber().add(this.floor.name, (wrapper) => {
411
+ wrapper.value = Math.floor(wrapper.value);
412
+ });
413
+ }
414
+ ceil() {
415
+ return this.isNumber().add(this.ceil.name, (wrapper) => {
416
+ wrapper.value = Math.ceil(wrapper.value);
417
+ });
418
+ }
408
419
  }
409
420
  exports.PRules = PRules;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pols-validator",
3
- "version": "2.1.0",
3
+ "version": "2.1.2",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -22,6 +22,7 @@
22
22
  "typescript-eslint": "^8.11.0"
23
23
  },
24
24
  "dependencies": {
25
- "pols-utils": "^1.3.5"
25
+ "pols-date": "^1.0.1",
26
+ "pols-utils": "^4.1.0"
26
27
  }
27
28
  }
package/src/rules.ts CHANGED
@@ -1,5 +1,6 @@
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"
3
4
 
4
5
  const isObject = (context: PRules, wrapper: PRulesWrapper, schema?: Record<string, PRules>) => {
5
6
  const message = `'${wrapper.label}' debe ser un objeto`
@@ -397,8 +398,20 @@ export class PRules extends PRulesEngine {
397
398
  }
398
399
 
399
400
  split(separator: string | RegExp) {
400
- return this.isAlphanumeric().add(this.split.name, (wrapper: PRulesWrapper) => {
401
- wrapper.value = (wrapper.value as any).split(separator)
401
+ return this.isAlphanumeric().add(this.split.name, (wrapper: PRulesWrapper<string>) => {
402
+ wrapper.value = wrapper.value.split(separator) as any
403
+ })
404
+ }
405
+
406
+ floor() {
407
+ return this.isNumber().add(this.floor.name, (wrapper: PRulesWrapper<number>) => {
408
+ wrapper.value = Math.floor(wrapper.value)
409
+ })
410
+ }
411
+
412
+ ceil() {
413
+ return this.isNumber().add(this.ceil.name, (wrapper: PRulesWrapper<number>) => {
414
+ wrapper.value = Math.ceil(wrapper.value)
402
415
  })
403
416
  }
404
417
  }
@@ -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)