Files
NapCatQQ/.pnpm-store/v3/files/a5/4325df568bf0c8ee651fa57ea3d41b684915a5a0c298f0bf58b9df99ee606450f8d52c5f8bc058192a469fdaabef37cf7c8722e6f3e687394509f85d9bd784
T
TanTan e311ca3275
Build NapCat Artifacts / Type Check & Test (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:25:58 +08:00

69 lines
1.3 KiB
Plaintext

/**
* @file wawoff2
* @author junmer
*/
/* eslint-env node */
var through = require('through2');
var replaceExt = require('replace-ext');
var _ = require('lodash');
var ttf2woff2 = require('ttf2woff2');
var isTtf = require('is-ttf');
/**
* wawoff2 fontmin plugin
*
* @param {Object} opts opts
* @return {Object} stream.Transform instance
* @api public
*/
module.exports = function (opts) {
opts = _.extend({clone: true}, opts);
return through.ctor({
objectMode: true
}, function (file, enc, cb) {
// check null
if (file.isNull()) {
cb(null, file);
return;
}
// check stream
if (file.isStream()) {
cb(new Error('Streaming is not supported'));
return;
}
// check ttf
if (!isTtf(file.contents)) {
cb(null, file);
return;
}
// clone
if (opts.clone) {
this.push(file.clone(false));
}
// ttf2woff2
var ouput;
try {
ouput = ttf2woff2(file.contents);
}
catch (ex) {
cb(ex, file);
}
if (ouput) {
file.path = replaceExt(file.path, '.woff2');
file.contents = ouput;
cb(null, file);
}
});
};