mirror of
https://github.com/tenrok/BBob.git
synced 2026-06-17 19:21:20 +03:00
refactor(*): convert to babel and generation to lib, es, dist folders (#2)
* refactor(*): convert to babel and generation to lib, es, dist * chore(*): remove generated files * fix(*): lint run command
This commit is contained in:
committed by
GitHub
parent
d22a2895a4
commit
32a7fb51da
@@ -0,0 +1,50 @@
|
||||
import { parse } from '@bbob/parser';
|
||||
import { iterate, match } from './utils';
|
||||
|
||||
function walk(cb) {
|
||||
return iterate(this, cb);
|
||||
}
|
||||
|
||||
export default function bbob(plugs) {
|
||||
const plugins = typeof plugs === 'function' ? [plugs] : plugs || [];
|
||||
|
||||
let options = {
|
||||
skipParse: false,
|
||||
};
|
||||
|
||||
return {
|
||||
process(input, opts) {
|
||||
options = opts || {};
|
||||
|
||||
const parseFn = options.parser || parse;
|
||||
const renderFn = options.render;
|
||||
|
||||
let tree = options.skipParse
|
||||
? input || []
|
||||
: parseFn(input, options);
|
||||
|
||||
tree.walk = walk;
|
||||
tree.match = match;
|
||||
|
||||
plugins.forEach((plugin) => {
|
||||
tree = plugin(tree, {
|
||||
parse: parseFn,
|
||||
render: renderFn,
|
||||
iterate,
|
||||
match,
|
||||
}) || tree;
|
||||
});
|
||||
|
||||
return {
|
||||
get html() {
|
||||
if (typeof renderFn !== 'function') {
|
||||
throw new Error('"render" function not defined, please pass to "process(input, { render })"');
|
||||
}
|
||||
return renderFn(tree, tree.options);
|
||||
},
|
||||
tree,
|
||||
messages: tree.messages,
|
||||
};
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user