FLUJOS/VISUALIZACION/node_modules/ngraph.forcelayout/inline-transform.js
2025-11-07 00:06:12 +01:00

23 lines
No EOL
1,003 B
JavaScript
Executable file

var through = require('through2');
module.exports = function (file) {
return through(function (buf, enc, next) {
let originalContent = buf.toString('utf8');
let dimensions = 2; // change this if you need different number of dimensions
if (file.match(/codeGenerators\/generate/)) {
let content = require(file);
let matches = originalContent.match(/^\/\/ InlineTransform: (.+)$/gm);
let additionalTransform = matches ? matches.map(name => {
let f = name.substr('// InlineTransform: '.length);
return content[f](dimensions);
}).join('\n') : '';
let exportCodeMatch = originalContent.match(/^\/\/ InlineTransformExport: (.+)$/m);
let codeExport = exportCodeMatch ? exportCodeMatch[1] :
`module.exports = function() { return ${content(dimensions).toString()} }`;
this.push(`${additionalTransform}\n${codeExport}`);
} else {
this.push(originalContent);
}
next();
});
};