async function convert (source, options) {
  const { safeMode, specFormat, format } = options
  let spec = JSON.parse(source)
  if (specFormat === 'lite') {
    spec = vegaLite.compile(spec, { logger: nullLogger }).spec
  }
  if (safeMode === 'secure' && spec && spec.data && Array.isArray(spec.data)) {
    const dataWithUrlAttribute = spec.data.filter((item) => item.url)
    if (dataWithUrlAttribute && dataWithUrlAttribute.length > 0) {
      throw new UnsafeIncludeError(`Unable to load data from an URL while running in secure mode.
Please include your data set as 'values' or run Kroki in unsafe mode using the KROKI_SAFE_MODE environment variable.`)
    }
  }
  const view = new vega.View(vega.parse(spec), { renderer: 'none' }).finalize()
  if (format === 'svg') {
    return await view.toSVG()
  }
  if (format === 'png') {
    const canvas = await view.toCanvas()
    const data = []
    return new Promise((resolve, reject) => {
      const stream = canvas.createPNGStream()
      stream.on('data', (chunk) => data.push(chunk))
      stream.on('end', () => resolve(Buffer.concat(data)))
      stream.on('error', (error) => reject(error))
    })
  }
  if (format === 'pdf') {
    const canvas = await view.toCanvas(undefined, { type: 'pdf', context: { textDrawingMode: 'glyph' } })
    const data = []
    return new Promise((resolve, reject) => {
      const stream = canvas.createPDFStream()
      stream.on('data', (chunk) => data.push(chunk))
      stream.on('end', () => resolve(Buffer.concat(data)))
      stream.on('error', (error) => reject(error))
    })
  }
  throw new IllegalArgumentError(`Unknown output format: ${format}. Must be one of: svg, png or pdf.`)
}
@param source
@param options
@returns {Promise<string|Buffer>}