query-parse.js 525 Bytes
const _ = require('lodash');
const fp = require('lodash/fp');

const splits = ['**', '$$', '::'];
const flow = fp.map(fp.fromPairs);

const resolveStr = (str, level = 0) => {
    let sp = [];
    const tp = _.split(str, splits[level]);

    _.each(tp, child => {
        if (child.indexOf(splits[level + 1]) >= 0) {
            sp.push(resolveStr(child, level + 1));
        }
    });
    return sp.length ? sp : tp;
};

const parse = (str) => {
    return fp.pipe(resolveStr, flow)(str);
};

module.exports = {
    parse
};