@@ -430,7 +430,36 @@ const parseListOfTexts = (value:any)=>{
430430 }
431431 return value ;
432432}
433-
433+ function createHelpfulJsonError ( e : any , trimmedValue : string ) {
434+ const errorMessage = e . message || 'Invalid JSON'
435+
436+ // Extract position info if available
437+ const positionMatch = errorMessage . match ( / p o s i t i o n \s + ( \d + ) / i)
438+ const position = positionMatch ? parseInt ( positionMatch [ 1 ] , 10 ) : null
439+
440+ let helpfulMessage = 'Invalid JSON: '
441+
442+ // Check for common mistakes
443+ if ( trimmedValue . includes ( "'" ) && ! trimmedValue . includes ( '"' ) ) {
444+ helpfulMessage += "Use double quotes (\") instead of single quotes (') for strings."
445+ } else if ( / , \s * [ } \] ] / . test ( trimmedValue ) ) {
446+ helpfulMessage += "Trailing comma found. Remove the comma before the closing bracket."
447+ } else if ( errorMessage . includes ( 'Unexpected token' ) ) {
448+ if ( position !== null ) {
449+ const contextStart = Math . max ( 0 , position - 10 )
450+ const contextEnd = Math . min ( trimmedValue . length , position + 10 )
451+ const context = trimmedValue . substring ( contextStart , contextEnd )
452+ helpfulMessage += `Unexpected character near position ${ position } : "...${ context } ..."`
453+ } else {
454+ helpfulMessage += errorMessage
455+ }
456+ } else if ( errorMessage . includes ( 'Unexpected end' ) ) {
457+ helpfulMessage += "JSON is incomplete. Check for missing closing brackets or quotes."
458+ } else {
459+ helpfulMessage += errorMessage
460+ }
461+ return helpfulMessage
462+ }
434463function parseJSON ( value : any ) : { parsed : any ; error : string | null } {
435464 if ( typeof value !== 'string' ) {
436465 return { parsed : value , error : null } ;
@@ -446,33 +475,7 @@ function parseJSON(value: any): { parsed: any; error: string | null } {
446475 return { parsed, error : null } ;
447476 } catch ( e : any ) {
448477 // Provide helpful error messages based on common JSON mistakes
449- const errorMessage = e . message || 'Invalid JSON' ;
450-
451- // Extract position info if available
452- const positionMatch = errorMessage . match ( / p o s i t i o n \s + ( \d + ) / i) ;
453- const position = positionMatch ? parseInt ( positionMatch [ 1 ] , 10 ) : null ;
454-
455- let helpfulMessage = 'Invalid JSON: ' ;
456-
457- // Check for common mistakes
458- if ( trimmedValue . includes ( "'" ) && ! trimmedValue . includes ( '"' ) ) {
459- helpfulMessage += "Use double quotes (\") instead of single quotes (') for strings." ;
460- } else if ( / , \s * [ } \] ] / . test ( trimmedValue ) ) {
461- helpfulMessage += "Trailing comma found. Remove the comma before the closing bracket." ;
462- } else if ( errorMessage . includes ( 'Unexpected token' ) ) {
463- if ( position !== null ) {
464- const contextStart = Math . max ( 0 , position - 10 ) ;
465- const contextEnd = Math . min ( trimmedValue . length , position + 10 ) ;
466- const context = trimmedValue . substring ( contextStart , contextEnd ) ;
467- helpfulMessage += `Unexpected character near position ${ position } : "...${ context } ..."` ;
468- } else {
469- helpfulMessage += errorMessage ;
470- }
471- } else if ( errorMessage . includes ( 'Unexpected end' ) ) {
472- helpfulMessage += "JSON is incomplete. Check for missing closing brackets or quotes." ;
473- } else {
474- helpfulMessage += errorMessage ;
475- }
478+ let helpfulMessage = createHelpfulJsonError ( e , trimmedValue )
476479
477480 return { parsed : null , error : helpfulMessage } ;
478481 }
@@ -1204,7 +1207,6 @@ private parse(data: any) {
12041207 }
12051208}
12061209
1207-
12081210function isInvalidFileType ( file : any , acceptedFileTypes : any ) {
12091211 const fileExtension = file . name . split ( "." ) . pop ( ) ?. toLowerCase ( )
12101212 return ! acceptedFileTypes . includes ( fileExtension )
@@ -1250,4 +1252,5 @@ function createControls(input_js: string | Function) {
12501252}
12511253
12521254
1253- export { Controls , createControls , FileTypes }
1255+ export { Controls , createControls , FileTypes }
1256+
0 commit comments