-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
37 lines (30 loc) · 918 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const types = require('node-sass').types
const path = require('path')
const fs = require('fs')
const packageVersion = require('./package.json')['version']
const base64encode = string => {
const stringBuffer = Buffer.from(string.getValue())
return types.String(stringBuffer.toString('base64'))
}
const inlineSVG = source => {
const sourcePath = path.join(__dirname, 'vendor', 'assets', 'images', source.getValue())
let svg = ''
try {
svg = fs.readFileSync(sourcePath).toString()
} catch (err) {
console.error('Error inlining SVG file', err)
}
const dataUrl = `url('data:image/svg+xml;charset=utf-8,${encodeURIComponent(svg)}')`
return types.String(dataUrl)
}
const version = function () {
return types.String(packageVersion)
}
const SassHelpers = {
'base64encode($string)': base64encode,
'inline-svg($source)': inlineSVG,
'version': version
}
module.exports = {
SassHelpers
}