@@ -15,8 +15,8 @@ import {
1515 ResponseSchemas ,
1616 ValidationFormatter ,
1717 Validations
18- } from './interfaces'
19- import { get } from './utils'
18+ } from './interfaces.js '
19+ import { get } from './utils.js '
2020
2121export interface ValidationResult extends FastifyValidationResult {
2222 dataPath : any
@@ -32,7 +32,7 @@ export function niceJoin(array: Array<string>, lastSeparator: string = ' and ',
3232 case 2 :
3333 return array . join ( lastSeparator )
3434 default :
35- return array . slice ( 0 , array . length - 1 ) . join ( separator ) + lastSeparator + array [ array . length - 1 ]
35+ return array . slice ( 0 , - 1 ) . join ( separator ) + lastSeparator + array . at ( - 1 ) !
3636 }
3737}
3838
@@ -87,7 +87,7 @@ export const validationMessagesFormatters: { [key: string]: ValidationFormatter
8787 values . map ( ( f : string ) => `"${ f } "` ) ,
8888 ' or '
8989 ) } `,
90- pattern : pattern => `must match pattern "${ pattern . replace ( / \( \? : / g , '(' ) } "` ,
90+ pattern : pattern => `must match pattern "${ pattern . replaceAll ( '(?:' , '(' ) } "` ,
9191 invalidResponseCode : code => `This endpoint cannot respond with HTTP status ${ code } .` ,
9292 invalidResponse : code =>
9393 `The response returned from the endpoint violates its specification for the HTTP status ${ code } .` ,
@@ -116,13 +116,13 @@ export function convertValidationErrors(
116116 let key = e . dataPath ?? e . instancePath /* c8 ignore next */ ?? ''
117117
118118 if ( key . startsWith ( '.' ) ) {
119- key = key . substring ( 1 )
119+ key = key . slice ( 1 )
120120 }
121121
122122 // Remove useless quotes
123123 /* c8 ignore next 3 */
124124 if ( key . startsWith ( '[' ) && key . endsWith ( ']' ) ) {
125- key = key . substring ( 1 , key . length - 1 )
125+ key = key . slice ( 1 , - 1 )
126126 }
127127
128128 // Depending on the type
@@ -165,11 +165,10 @@ export function convertValidationErrors(
165165 pattern = e . params . pattern as string
166166 value = get < string > ( data , key )
167167
168- if ( pattern === '.+' && ! value ) {
169- message = validationMessagesFormatters . presentString ( )
170- } else {
171- message = validationMessagesFormatters . pattern ( e . params . pattern )
172- }
168+ message =
169+ pattern === '.+' && ! value
170+ ? validationMessagesFormatters . presentString ( )
171+ : validationMessagesFormatters . pattern ( e . params . pattern )
173172
174173 break
175174 case 'format' :
@@ -192,8 +191,8 @@ export function convertValidationErrors(
192191
193192 // Remove useless quotes
194193 /* c8 ignore next 3 */
195- if ( key . match ( / (?: ^ [ ' " ] ) (?: [ ^ . ] + ) (?: [ ' " ] $ ) / ) ) {
196- key = key . substring ( 1 , key . length - 1 )
194+ if ( / ^ [ " ' ] [ ^ . ] + [ " ' ] $ / . test ( key ) ) {
195+ key = key . slice ( 1 , - 1 )
197196 }
198197
199198 // Fix empty properties
0 commit comments