valgen 6.2.0 → 6.2.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/constants.js CHANGED
@@ -1,4 +1,4 @@
1
- export const version = '6.2.0';
1
+ export const version = '6.2.2';
2
2
  export const postValidation = Symbol('postValidation');
3
3
  export const preValidation = Symbol('preValidation');
4
4
  export const VALIDATE_METADATA = Symbol('VALIDATE_METADATA');
package/index.d.ts CHANGED
@@ -65,6 +65,7 @@ declare const toBoolean: Validator<boolean | undefined, unknown, ExecutionOption
65
65
  declare const toDate: Validator<Date, string | number | Date, ExecutionOptions>;
66
66
  declare const toDateString: (input: Date | string | number, options?: ExecutionOptions & {
67
67
  trim?: vg.isDateString.Precision;
68
+ separators?: boolean;
68
69
  }, ctx?: Context) => any;
69
70
  declare const toInteger: Validator<number, unknown, ExecutionOptions>;
70
71
  declare const toNumber: Validator<number, unknown, ExecutionOptions>;
package/index.js CHANGED
@@ -79,6 +79,7 @@ const toDateString = (input, options, ctx) => {
79
79
  coerce: true,
80
80
  precisionMax,
81
81
  trim: true,
82
+ separators: options?.separators,
82
83
  });
83
84
  toDateStringValidators.set(precisionMax, validator);
84
85
  }
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "valgen",
3
3
  "description": "Fast runtime type validator, converter and io (encoding/decoding) library",
4
- "version": "6.2.0",
4
+ "version": "6.2.2",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
7
7
  "dependencies": {
8
8
  "@browsery/validator": "^13.15.35",
9
- "@jsopen/objects": "^2.2.1",
10
- "date-fns": "^4.1.0",
9
+ "@jsopen/objects": "^2.2.2",
10
+ "date-fns": "^4.2.1",
11
11
  "reflect-metadata": "^0.2.2",
12
12
  "ts-gems": "^3.12.0",
13
13
  "tslib": "^2.8.1"
@@ -23,6 +23,6 @@ export declare namespace isDateString {
23
23
  precisionMin?: Precision;
24
24
  precisionMax?: Precision;
25
25
  trim?: boolean;
26
- timeZone?: boolean | number;
26
+ separators?: boolean;
27
27
  }
28
28
  }
@@ -46,7 +46,10 @@ export function isDateString(options) {
46
46
  precisionMin = (PRECISION_INDEX_KEYS[PRECISION_INDEX_VALUES.indexOf(precisionMinIdx)] || precisionMin);
47
47
  return validator(isDateString.name, (input, context, _this) => {
48
48
  const coerce = options?.coerce ?? context.coerce;
49
- const parsed = coerceDateString(input, trim ? precisionMax : undefined);
49
+ const parsed = coerceDateString(input, {
50
+ trimPrecision: trim ? precisionMax : undefined,
51
+ separators: options?.separators,
52
+ });
50
53
  if (parsed) {
51
54
  if (parsed.precision < precisionMinIdx) {
52
55
  context.fail(_this, `Minimum date precision should be ${precisionMin}`, input, options);
@@ -62,7 +65,9 @@ export function isDateString(options) {
62
65
  // noinspection RegExpUnnecessaryNonCapturingGroup
63
66
  const DATE_PATTERN = /^(\d{4})(?:-(0[0-9]|1[0-2]))?(?:-([0-2][0-9]|3[0-1]))?(?:[T ](?:([0-1][0-9]|2[0-4]):([0-5][0-9])(?::([0-5][0-9]))?(?:\.(\d{0,6}))?)?((?:[+-](0[0-9]|1[0-2])(?::(\d{2}))?)|Z)?)?$/;
64
67
  const DATE_PATTERN2 = /^(\d{4,14})(?:\.(\d{1,6}))?(?:(?:([+-])(0[0-9]|1[0-2])(\d{2})?)|Z)?$/;
65
- function coerceDateString(input, trimPrecision) {
68
+ function coerceDateString(input, options = {}) {
69
+ const { trimPrecision } = options;
70
+ const separators = options.separators ?? true;
66
71
  const precisionIndex = (trimPrecision ? PRECISION_INDEX[trimPrecision] : 9) || 9;
67
72
  let dateParts;
68
73
  let detectedPrecision;
@@ -122,15 +127,15 @@ function coerceDateString(input, trimPrecision) {
122
127
  detectedPrecision = Math.min(dateParts.length, 8);
123
128
  let value = dateParts[0] || '0000';
124
129
  if (precisionIndex > 1)
125
- value += '-' + (dateParts[1] || '01');
130
+ value += (separators ? '-' : '') + (dateParts[1] || '01');
126
131
  if (precisionIndex > 2)
127
- value += '-' + (dateParts[2] || '01');
132
+ value += (separators ? '-' : '') + (dateParts[2] || '01');
128
133
  if (precisionIndex > 3)
129
- value += 'T' + (dateParts[3] || '00');
134
+ value += (separators ? 'T' : '') + (dateParts[3] || '00');
130
135
  if (precisionIndex > 4)
131
- value += ':' + (dateParts[4] || '00');
136
+ value += (separators ? ':' : '') + (dateParts[4] || '00');
132
137
  if (precisionIndex > 5)
133
- value += ':' + (dateParts[5] || '00');
138
+ value += (separators ? ':' : '') + (dateParts[5] || '00');
134
139
  if (precisionIndex > 6)
135
140
  value += dateParts[6] ? '.' + dateParts[6] : '';
136
141
  if (precisionIndex > 7)