1- /* eslint-disable max-len, no-control-regex */
2- import errors from "./errors" ;
31import validUrl from "valid-url" ;
42import { parse as parseIdnEmail } from "smtp-address-parser" ;
53// referenced
@@ -28,7 +26,7 @@ const formatValidators = {
2826 // full-date from http://tools.ietf.org/html/rfc3339#section-5.6
2927 const matches = value . match ( matchDate ) ;
3028 if ( ! matches ) {
31- return errors . formatDateTimeError ( { value, pointer, schema } ) ;
29+ return draft . errors . formatDateTimeError ( { value, pointer, schema } ) ;
3230 }
3331 const year = + matches [ 1 ] ;
3432 const month = + matches [ 2 ] ;
@@ -41,40 +39,40 @@ const formatValidators = {
4139 day <= ( month == 2 && isLeapYear ? 29 : DAYS [ month ] ) ) {
4240 return undefined ;
4341 }
44- return errors . formatDateError ( { value, pointer, schema } ) ;
42+ return draft . errors . formatDateError ( { value, pointer, schema } ) ;
4543 } ,
4644 "date-time" : ( draft , schema , value , pointer ) => {
4745 if ( typeof value !== "string" || value === "" ) {
4846 return undefined ;
4947 }
5048 if ( value === "" || isValidDateTime . test ( value ) ) {
5149 if ( new Date ( value ) . toString ( ) === "Invalid Date" ) {
52- return errors . formatDateTimeError ( { value, pointer, schema } ) ;
50+ return draft . errors . formatDateTimeError ( { value, pointer, schema } ) ;
5351 }
5452 return undefined ;
5553 }
56- return errors . formatDateTimeError ( { value, pointer, schema } ) ;
54+ return draft . errors . formatDateTimeError ( { value, pointer, schema } ) ;
5755 } ,
5856 email : ( draft , schema , value , pointer ) => {
5957 if ( typeof value !== "string" || value === "" ) {
6058 return undefined ;
6159 }
6260 // taken from https://github.com/ExodusMovement/schemasafe/blob/master/src/formats.js
6361 if ( value [ 0 ] === '"' ) {
64- return errors . formatEmailError ( { value, pointer, schema } ) ;
62+ return draft . errors . formatEmailError ( { value, pointer, schema } ) ;
6563 }
6664 const [ name , host , ...rest ] = value . split ( "@" ) ;
6765 if ( ! name || ! host || rest . length !== 0 || name . length > 64 || host . length > 253 ) {
68- return errors . formatEmailError ( { value, pointer, schema } ) ;
66+ return draft . errors . formatEmailError ( { value, pointer, schema } ) ;
6967 }
7068 if ( name [ 0 ] === "." || name . endsWith ( "." ) || name . includes ( ".." ) ) {
71- return errors . formatEmailError ( { value, pointer, schema } ) ;
69+ return draft . errors . formatEmailError ( { value, pointer, schema } ) ;
7270 }
7371 if ( ! / ^ [ a - z 0 - 9 . - ] + $ / i. test ( host ) || ! / ^ [ a - z 0 - 9 . ! # $ % & ' * + / = ? ^ _ ` { | } ~ - ] + $ / i. test ( name ) ) {
74- return errors . formatEmailError ( { value, pointer, schema } ) ;
72+ return draft . errors . formatEmailError ( { value, pointer, schema } ) ;
7573 }
7674 if ( ! host . split ( "." ) . every ( ( part ) => / ^ [ a - z 0 - 9 ] ( [ a - z 0 - 9 - ] { 0 , 61 } [ a - z 0 - 9 ] ) ? $ / i. test ( part ) ) ) {
77- return errors . formatEmailError ( { value, pointer, schema } ) ;
75+ return draft . errors . formatEmailError ( { value, pointer, schema } ) ;
7876 }
7977 return undefined ;
8078 } ,
@@ -91,7 +89,7 @@ const formatValidators = {
9189 return undefined ;
9290 }
9391 catch ( e ) {
94- return errors . formatEmailError ( { value, pointer, schema } ) ;
92+ return draft . errors . formatEmailError ( { value, pointer, schema } ) ;
9593 }
9694 } ,
9795 hostname : ( draft , schema , value , pointer ) => {
@@ -101,33 +99,33 @@ const formatValidators = {
10199 if ( value === "" || isValidHostname . test ( value ) ) {
102100 return undefined ;
103101 }
104- return errors . formatHostnameError ( { value, pointer, schema } ) ;
102+ return draft . errors . formatHostnameError ( { value, pointer, schema } ) ;
105103 } ,
106104 ipv4 : ( draft , schema , value , pointer ) => {
107105 if ( typeof value !== "string" || value === "" ) {
108106 return undefined ;
109107 }
110108 if ( value && value [ 0 ] === "0" ) {
111109 // leading zeroes should be rejected, as they are treated as octals
112- return errors . formatIPV4LeadingZeroError ( { value, pointer, schema } ) ;
110+ return draft . errors . formatIPV4LeadingZeroError ( { value, pointer, schema } ) ;
113111 }
114112 if ( value . length <= 15 && isValidIPV4 . test ( value ) ) {
115113 return undefined ;
116114 }
117- return errors . formatIPV4Error ( { value, pointer, schema } ) ;
115+ return draft . errors . formatIPV4Error ( { value, pointer, schema } ) ;
118116 } ,
119117 ipv6 : ( draft , schema , value , pointer ) => {
120118 if ( typeof value !== "string" || value === "" ) {
121119 return undefined ;
122120 }
123121 if ( value && value [ 0 ] === "0" ) {
124122 // leading zeroes should be rejected, as they are treated as octals
125- return errors . formatIPV6LeadingZeroError ( { value, pointer, schema } ) ;
123+ return draft . errors . formatIPV6LeadingZeroError ( { value, pointer, schema } ) ;
126124 }
127125 if ( value . length <= 45 && isValidIPV6 . test ( value ) ) {
128126 return undefined ;
129127 }
130- return errors . formatIPV6Error ( { value, pointer, schema } ) ;
128+ return draft . errors . formatIPV6Error ( { value, pointer, schema } ) ;
131129 } ,
132130 "json-pointer" : ( draft , schema , value , pointer ) => {
133131 if ( typeof value !== "string" || value === "" ) {
@@ -136,7 +134,7 @@ const formatValidators = {
136134 if ( isValidJsonPointer . test ( value ) ) {
137135 return undefined ;
138136 }
139- return errors . formatJsonPointerError ( { value, pointer, schema } ) ;
137+ return draft . errors . formatJsonPointerError ( { value, pointer, schema } ) ;
140138 } ,
141139 "relative-json-pointer" : ( draft , schema , value , pointer ) => {
142140 if ( typeof value !== "string" || value === "" ) {
@@ -145,7 +143,7 @@ const formatValidators = {
145143 if ( isValidRelativeJsonPointer . test ( value ) ) {
146144 return undefined ;
147145 }
148- return errors . formatJsonPointerError ( { value, pointer, schema } ) ;
146+ return draft . errors . formatJsonPointerError ( { value, pointer, schema } ) ;
149147 } ,
150148 regex : ( draft , schema , value , pointer ) => {
151149 if ( typeof value === "string" && / \\ Z $ / . test ( value ) === false ) {
@@ -154,13 +152,13 @@ const formatValidators = {
154152 return undefined ;
155153 }
156154 catch ( e ) { } // eslint-disable-line no-empty
157- return errors . formatRegExError ( { value, pointer, schema } ) ;
155+ return draft . errors . formatRegExError ( { value, pointer, schema } ) ;
158156 }
159157 // v7 tests, ignore non-regex values
160158 if ( typeof value === "object" || typeof value === "number" || Array . isArray ( value ) ) {
161159 return undefined ;
162160 }
163- return errors . formatRegExError ( { value, pointer, schema } ) ;
161+ return draft . errors . formatRegExError ( { value, pointer, schema } ) ;
164162 } ,
165163 // hh:mm:ss.sTZD
166164 // https://opis.io/json-schema/2.x/formats.html
@@ -171,7 +169,7 @@ const formatValidators = {
171169 }
172170 // https://github.com/cfworker/cfworker/blob/main/packages/json-schema/src/format.ts
173171 const matches = value . match ( matchTime ) ;
174- return matches ? undefined : errors . formatDateTimeError ( { value, pointer, schema } ) ;
172+ return matches ? undefined : draft . errors . formatDateTimeError ( { value, pointer, schema } ) ;
175173 // if (!matches) {
176174 // return errors.formatDateTimeError({ value, pointer, schema });
177175 // }
@@ -195,7 +193,7 @@ const formatValidators = {
195193 if ( validUrl . isUri ( value ) ) {
196194 return undefined ;
197195 }
198- return errors . formatURIError ( { value, pointer, schema } ) ;
196+ return draft . errors . formatURIError ( { value, pointer, schema } ) ;
199197 } ,
200198 "uri-reference" : ( draft , schema , value , pointer ) => {
201199 if ( typeof value !== "string" || value === "" ) {
@@ -204,7 +202,7 @@ const formatValidators = {
204202 if ( isValidURIRef . test ( value ) ) {
205203 return undefined ;
206204 }
207- return errors . formatURIReferenceError ( { value, pointer, schema } ) ;
205+ return draft . errors . formatURIReferenceError ( { value, pointer, schema } ) ;
208206 } ,
209207 "uri-template" : ( draft , schema , value , pointer ) => {
210208 if ( typeof value !== "string" || value === "" ) {
@@ -213,13 +211,13 @@ const formatValidators = {
213211 if ( isValidURITemplate . test ( value ) ) {
214212 return undefined ;
215213 }
216- return errors . formatURITemplateError ( { value, pointer, schema } ) ;
214+ return draft . errors . formatURITemplateError ( { value, pointer, schema } ) ;
217215 } ,
218216 url : ( draft , schema , value , pointer ) => {
219217 if ( value === "" || validUrl . isWebUri ( value ) ) {
220218 return undefined ;
221219 }
222- return errors . formatURLError ( { value, pointer, schema } ) ;
220+ return draft . errors . formatURLError ( { value, pointer, schema } ) ;
223221 }
224222} ;
225223export default formatValidators ;
0 commit comments