-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsvg2datauri.js
More file actions
25 lines (22 loc) · 759 Bytes
/
Copy pathsvg2datauri.js
File metadata and controls
25 lines (22 loc) · 759 Bytes
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
const fs = require('fs')
const path = require('path')
const { promisify } = require('util')
const svgToMiniDataURI = require('mini-svg-data-uri')
const readFileAsync = promisify(fs.readFile)
const readdirAsync = promisify(fs.readdir)
const svg2datauri = async (folder = './assets/icons') => {
let svgs = []
const filePath = path.join(__dirname, folder)
const files = await readdirAsync(filePath)
const filtered = files.filter(file => path.extname(file) === '.svg')
for (const file of filtered) {
const data = await readFileAsync(path.resolve(filePath, file))
const svg = {
name: file,
datauri: svgToMiniDataURI(data.toString())
}
svgs = [...svgs, svg]
}
return Promise.resolve(svgs)
}
module.exports = svg2datauri