Files
SDI 12e4f17b62
CI / lint (push) Failing after 49s
CI / format (push) Failing after 1m6s
CI / typecheck (push) Successful in 1m8s
CI / test (push) Failing after 1m8s
first commit
2026-07-15 18:05:12 +09:00

19 lines
524 B
JavaScript

export function commentParser(text) {
text = text.trim();
if (text.substr(0, 2) === '//') {
return [
'line',
text.split(/\r?\n/).map(function (line) {
return line.substr(2);
}),
];
} else if (text.substr(0, 2) === '/*' && text.substr(-2) === '*/') {
return ['block', text.substring(2, text.length - 2)];
} else {
throw new Error(
'Could not parse comment file: the file must contain either just line comments (//) or a single block comment (/* ... */)',
);
}
}