2
0
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:
Nikolay Kostyurin
2018-09-09 23:55:28 +02:00
committed by GitHub
parent d22a2895a4
commit 32a7fb51da
76 changed files with 930 additions and 10174 deletions
+50
View File
@@ -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,
};
},
};
}