You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.0 KiB
47 lines
1.0 KiB
const { readFile } = require("fs"); |
|
const render = require("./render.js"); |
|
const { transform, encode, addXmlns } = require("./defaults.js"); |
|
const { |
|
removeFill, |
|
removeStroke, |
|
applyRootParams, |
|
applySelectedParams |
|
} = require("./processors.js"); |
|
|
|
function read(id) { |
|
return new Promise((resolve, reject) => { |
|
readFile(id, "utf-8", (err, data) => { |
|
if (err) { |
|
reject(Error(`Can't load '${id}'`)); |
|
} else { |
|
resolve(data); |
|
} |
|
}); |
|
}); |
|
} |
|
|
|
module.exports = function load(id, params, selectors, opts) { |
|
const processors = [ |
|
removeFill(id, opts), |
|
removeStroke(id,opts), |
|
applyRootParams(params), |
|
applySelectedParams(selectors) |
|
]; |
|
return read(id).then(data => { |
|
let code = render(data, ...processors); |
|
|
|
if (opts.xmlns !== false) { |
|
code = addXmlns(code); |
|
} |
|
|
|
if (opts.encode !== false) { |
|
code = (opts.encode || encode)(code); |
|
} |
|
|
|
if (opts.transform !== false) { |
|
code = (opts.transform || transform)(code, id); |
|
} |
|
|
|
return code; |
|
}); |
|
};
|
|
|