/**
 * A utility function for creating GraphQL descriptions out of a multiline
 * template string.
 *
 * It trims whitespace from the beginning and end of the string in addition to
 * removing indentation.
 */ export function trimDescription ( description ) { return description . replace ( /^ +/gm , '' ) . trim ( ) ; } /**
 * Runs `trimDescription` on all properties named `description` deeply in a
 * config object.
 *
 * Creates a new config object instead of mutating the config object passed in.
 *
 * We only trim descriptions on plain JavaScript objects.
 */ export function trimDescriptionsInConfig < T extends { [ key ] : any ; } > ( config ) { const nextConfig = { } ; for ( const key of Object . keys ( config ) ) { const value = config [ key ] ; if ( value !== null && typeof value === 'object' && Object . getPrototypeOf ( value ) === Object . prototype ) { nextConfig [ key ] = trimDescriptionsInConfig ( value ) ; } else if ( key === 'description' && typeof value === 'string' ) { nextConfig [ key ] = trimDescription ( value ) ; } else { nextConfig [ key ] = value ; } } return nextConfig as T ; }