Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
each(comments, function(comment) {
let lines = trim(comment).split('\n');
if (trim(lines[0]) !== 'module') return;
lines.shift();
each(lines, function(line) {
let splitterPos = line.indexOf(':');
let name = trim(line.slice(0, splitterPos));
let val = trim(line.slice(splitterPos + 1));
if (name === 'env') {
if (val === 'all') {
val = ['node', 'browser', 'miniprogram'];
} else {
val = val.split(/\s+/g);
}
}
if (name === 'test') {
if (val === 'manual') {
val = [];
} else if (val === 'all') {
return doc.map(str => {
str = str.split(/\n/);
const name = str.shift().trim();
return {
name,
content: trim(str.join('\n'))
};
});
}
function extractDependencies(data) {
let dependencies = regDependency.exec(data);
dependencies = dependencies ? trim(dependencies[1]).split(/\s+/) : [];
return dependencies;
}
each(comments, function(comment) {
let lines = trim(comment).split('\n');
if (trim(lines[0]) !== 'module') return;
lines.shift();
each(lines, function(line) {
let splitterPos = line.indexOf(':');
let name = trim(line.slice(0, splitterPos));
let val = trim(line.slice(splitterPos + 1));
if (name === 'env') {
if (val === 'all') {
val = ['node', 'browser', 'miniprogram'];
} else {
val = val.split(/\s+/g);
}
}
if (name === 'test') {
if (val === 'manual') {
val = [];
each(lines, function(line) {
let splitterPos = line.indexOf(':');
let name = trim(line.slice(0, splitterPos));
let val = trim(line.slice(splitterPos + 1));
if (name === 'env') {
if (val === 'all') {
val = ['node', 'browser', 'miniprogram'];
} else {
val = val.split(/\s+/g);
}
}
if (name === 'test') {
if (val === 'manual') {
val = [];
} else if (val === 'all') {
val = ['node', 'browser'];
} else {
val = [val];
}
}
comments.forEach(comment => {
comment = trim(comment);
if (startWith(comment, 'example')) {
example = comment.replace(/^example/, '');
example = outdentOneSpace(example);
example = example.replace(regTsIgnore, '');
example = '```javascript\n' + trim(example) + '\n```';
}
});
doc = splitH2(doc);
comments.forEach(comment => {
comment = trim(comment);
if (startWith(comment, 'example')) {
example = comment.replace(/^example/, '');
example = outdentOneSpace(example);
example = example.replace(regTsIgnore, '');
example = '```javascript\n' + trim(example) + '\n```';
}
});
doc = splitH2(doc);
function transToCommonjs(data, dependencies, isEs5) {
data = trim(data);
data += '\n\nmodule.exports = exports;\n';
if (!dependencies) return data;
let requires = '';
const len = dependencies.length;
each(dependencies, (val, i) => {
requires +=
(isEs5 ? 'var ' : 'const ') + val + " = require('./" + val + "');";
if (i !== len - 1) requires += '\n';
});
if (requires) {
requires = '\n\n' + requires;