Node.js helper functions to convert heropatterns to JPEGs, PNGs, SVGs, and ZIPs
Install with NPM.
npm install heropatterns-helper sharp
Install with Yarn.
yarn add heropatterns-helper sharp
Please note that Sharp.js is a peer dependency for toJpeg
, toPng
, and toZip
.
const heropatterns = require('heropatterns-helper');
const {
toJpeg,
toPng,
toSvg,
toZip,
getMetadata,
FileType,
} = require('heropatterns-helper');
// returns object { width, height, backgroundColor, foregroundColor, svg, }
getMetadata(cssString);
// returns buffer with jpeg
toJpeg(heroPatternSvg);
// returns buffer with png
toPng(heroPatternSvg);
// returns buffer with svg
toSvg(heroPatternSvg);
// The FileType as imported above
export const FileType = {
JPEG: 'JPEG',
PNG: 'PNG',
SVG: 'SVG',
ZIP: 'ZIP',
};
// if you have already created file buffers
// the zip function can reuse them
const files = {
[FileType.JPEG]: await toJpeg(heroPatternSvg),
};
// returns buffer with zip
toZip(heroPatternSvg, files, fileName, licenseText);
Heropatterns Helper Code: MIT (see license.md)