Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const pathModule = require('path')
const UglifyJS = require('uglify-js')
const { js_beautify, css_beautify } = require('js-beautify')
const { execSync } = require('child_process')
const mkdirp = require('mkdirp')
// const source = fs.readFileSync('src/models/tag.js', 'utf8')
const source = `
var a = function() {
return (c, b), a
}
`
const foo = fs.readFileSync('./raw/owl-web-a5a29e830e828ff1f7445e23dc456e2e.js', 'utf8')
const bar = js_beautify(foo, { indent_size: 2 })
const idx = bar.indexOf('{')
const injection = 'console.log(JSON.stringify(Object.entries(t).map(([id,[fn,deps]])=>({id:Number(id),source:fn.toString(),deps:deps})))); return;\n'
fs.writeFileSync('./flowdock.js', bar.slice(0, idx + 1) + injection + bar.slice(idx + 1))
const output = execSync('node ./flowdock.js')
const modules = JSON.parse(output)
const node2statement = (node) => {
if (node.TYPE == 'SimpleStatement' || node instanceof UglifyJS.AST_Statement) {
return node
}
return new UglifyJS.AST_SimpleStatement({body: node})
if (base) {
_.extend(obj.props, base.props)
}
baseKey = _.keys(base.base)[0]
}
// sorting
obj.props = utils.sortByKey(obj.props)
obj.methods = utils.sortByKey(obj.methods)
obj.events = utils.sortByKey(obj.events)
}
})
json = utils.sortByKey(json)
file.contents = new Buffer(beautify(JSON.stringify(json), { indent_size: 2 }))
cb(null, file)
}))
.pipe(gulp.dest('./doc'))
lineDom.appendChild(logLine)
}
})
} else {
// render the value like a JSON object
// for now, we just render it as raw JSON, TODO: some sort of fancier key-value pair visualization?
if (field === 'parameters' || field === 'annotations') {
// special case here: the parameters field is really a map, but stored as an array of key-value pairs
value = value.reduce((M, kv) => {
M[kv.key] = kv.value;
return M
}, {})
}
const beautify = require('js-beautify').js_beautify
container.innerText = beautify(JSON.stringify(value))
// apply the syntax highlighter to the JSON
setTimeout(() => hljs.highlightBlock(container), 0)
}
}
documentjs(files, function (error, data, search) {
var writers = [];
var rootItem = utils.menuTree(data, configuration.parent);
writers.push(function(callback) {
var filename = path.join(configuration.out, 'searchdata.json');
fs.writeFile(filename, JSON.stringify(search), function(error) {
callback(error, filename);
});
});
if(options.debug) {
fs.writeFileSync(path.join(configuration.out, 'documentjs-debug.json'), beautify(JSON.stringify(data)));
fs.writeFileSync(path.join(configuration.out, 'rootItem-debug.json'), beautify(JSON.stringify(rootItem)));
}
_.each(data, function (docData, name) {
if (!configuration.ignore(docData, name)) {
writers.push(function (callback) {
// Set the active item from the given name
utils.activateItems(rootItem, name);
var filename = path.join(configuration.out, (name === configuration.parent ? 'index.html' : utils.docsFilename(name)));
var data = _.extend({
menu: rootItem
}, configuration.data, docData);
if(options.debug) {
data.debug = beautify(JSON.stringify(docData));
}
let webPackVarStr = "";
const webPackVarKeys = Object.keys(Vars);
webPackVarKeys.map( (wKey, wIndex) => {
webPackVarStr = webPackVarStr +`const ${wKey} = "${Vars[wKey]}";\n`
})
const webPackConcat = webPackVarStr + '\n' + webPackConfigStrWrap;
fs.writeFileSync(mergeFile, webPackConcat, 'utf-8');
const mergeData = fs.readFileSync(mergeFile, "utf-8")
.replace(/"@(\/\\)(\\)(\S*)"/g, "$1$3")
.replace(/\\\?/g,"\?") // 处理字体双斜杠/\.(eot|ttf|woff|woff2|svg|svgz)(\\?.+)?$/
.replace(/"@(\/\S*)"/g, "$1") // 处理"@/node_modules/"
.replace(/"<%/g, '')
.replace(/%>"/g, '');
const beautifyData = beautify(mergeData, { indent_size: 4 });
fs.writeFileSync(mergeFile, beautifyData, 'utf-8');
}
exports.run = function(api) {
if ((/javascript/i).test(api.getResponseInfo().headers['content-type'])) {
var js = api.getResponseBody();
try {
var beautifulJs = beautify(js, { indent_size: 2 });
if (js !== beautifulJs && beautifulJs.indexOf('function') != -1) {
api.setResponseBody(beautifulJs);
}
api.notify();
} catch (ex) {
api.notify(ex);
}
} else {
api.notify();
}
};
var transpile = function(source) {
var parser = require('./parser').parser;
parser.yy = require('./scope');
var transpiled = parser.parse(source);
var output = beautify(transpiled, { indent_size: 2, max_preserve_newlines: -1, end_with_newline: true, space_before_conditional: 0 });
return output;
};
code.push(me.parseExpression(ast.limit[0]));
}else{
code.push(me.parseExpression(ast.limit[0]) + ',' + me.parseExpression(ast.limit[0]) + '+' + me.parseExpression(ast.limit[1]));
}
code.push(')');
}
//5. get value .value();
code.push('.value()');
code.unshift('function (params){');
code.push('return res;');
code.push('}');
return jsbeautify.js_beautify(code.join('\n'));
};
function saveInfo(id,url,summary,body){
var infoFile = path.join(userSavePath, id + "_summary_" + summary.host),
bodyFile = path.join(userSavePath, id + "_body_" + summary.host);
fs.writeFileSync(infoFile , beautify(JSON.stringify(summary), { indent_size: 4 }));
fs.writeFileSync(bodyFile , body);
}
getInitialState: function () {
return {
value: beautify(this.props.defaultValue||'', { indent_size: 2 }) || ''
};
},
getValue: function () {