Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function sassInlineImage(file) {
var
filePath = path.resolve(process.cwd(), file.getValue()),
ext = filePath.split('.').pop(),
data = fs.readFileSync(filePath),
buffer = new Buffer(data),
str = '"data:image/' + ext + ';base64,' + buffer.toString('base64') + '"';
return sassTypes.String(str);
}
function encode(content, opts) {
if (opts.encodingFormat === 'uri') {
return new types.String('url("' + svgToDataUri(content.toString('UTF-8')) + '")');
}
if (opts.encodingFormat === 'base64') {
return new types.String('url("data:image/svg+xml;base64,' + content.toString('base64') + '")');
}
throw new Error('encodingFormat ' + opts.encodingFormat + ' is not supported');
}
fs.readFile(file, function(err, data) {
if (err) return done(err);
data = new Buffer(data);
data = data.toString('base64');
data = 'url(data:image/' + ext + ';base64,' + data +')';
data = types.String(data);
done(data);
});
};
function encode(content, opts) {
if (opts.encodingFormat === 'uri') {
return new types.String('url("' + svgToDataUri(content.toString('UTF-8')) + '")');
}
if (opts.encodingFormat === 'base64') {
return new types.String('url("data:image/svg+xml;base64,' + content.toString('base64') + '")');
}
throw new Error('encodingFormat ' + opts.encodingFormat + ' is not supported');
}
'twemoji-url': function(emoji) {
const codePoint = twemoji.convert.toCodePoint(emoji.getValue());
return sassTypes.String(`url(${twemoji.base}svg/${codePoint}.svg)`);
}
}