Merging this separately so the commit with the tooling change is readable. This is a follow-on to #1167 which turned prettier on.
21 lines
389 B
JavaScript
21 lines
389 B
JavaScript
'use strict'
|
|
|
|
function isDataUri(s) {
|
|
return s !== undefined && /^(data:)([^;]+);([^,]+),(.+)$/.test(s)
|
|
}
|
|
|
|
function svg2base64(svg) {
|
|
if (typeof svg !== 'string') {
|
|
return undefined
|
|
}
|
|
// Check if logo is already base64
|
|
return isDataUri(svg)
|
|
? svg
|
|
: 'data:image/svg+xml;base64,' + Buffer.from(svg).toString('base64')
|
|
}
|
|
|
|
module.exports = {
|
|
svg2base64,
|
|
isDataUri,
|
|
}
|