How to use the fxjs.deep_flat function in fxjs

To help you get started, we’ve selected a few fxjs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github marpple / FxSQL / src / index.js View on Github external
function ASSOCIATE_MODULE(strs, ...tails) {
    strs = strs.slice();
    strs.push(strs.pop() + '\n');
    var [strs2, tails2] = import_module(strs, tails);

    const splited = deep_flat(strs.map(str => str.split('\n')))
      .filter(str => str.match(/^\s*/)[0])
      .filter(str => str.trim());

    const min = min_by(str => str.match(/^\s*/)[0].length, splited);
    const a = '\n' + min.match(/^\s*/)[0];

    return [strs2.map(str => str.split(a).join('\n')), tails2];
  }
github marpple / FxSQL / src / index.js View on Github external
function import_module(strs, tails) {
    if (!tails.some(tail => typeof tail == 'function' && !is_tag(tail))) return [strs, tails];

    var strs2 = [...strs];
    var j = 0;
    var tails2 = tails.map(function(tail, i) {
      if (typeof tail != 'function' || is_tag(tail)) return tail;
      var k = i + j++;
      var spaces = last(strs2[k].split('\n')).match(/^\s*/)[0];
      var [strs3, tails3] = tail();
      strs2.splice(k+1, 0, strs3.map(str => str.replace(/\n/g, '\n' + spaces)));
      return tails3;
    });

    return [
      deep_flat(strs2).filter(str => str.trim()).reduce((strs, str, i) => {
        if (i == 0) return strs.push(str), strs;
        const splited = last(strs).split('\n');
        if (!last(splited).trim()) {
          splited[splited.length-1] = str.substr(1);
          strs[strs.length-1] = splited.join('\n');
        } else {
          strs.push(str);
        }
        return strs;
      }, []),
      deep_flat(tails2)];
  }
github marpple / FxSQL / src / index.js View on Github external
return tails3;
    });

    return [
      deep_flat(strs2).filter(str => str.trim()).reduce((strs, str, i) => {
        if (i == 0) return strs.push(str), strs;
        const splited = last(strs).split('\n');
        if (!last(splited).trim()) {
          splited[splited.length-1] = str.substr(1);
          strs[strs.length-1] = splited.join('\n');
        } else {
          strs.push(str);
        }
        return strs;
      }, []),
      deep_flat(tails2)];
  }
github marpple / FxSQL / src / index.js View on Github external
function BASE_IN(key, operator, values) {
    values = uniq(values);

    var keys_text = COLUMN(...wrap_arr(key))().text;
    return {
      text: `${Array.isArray(key) ? `(${keys_text})` : keys_text} ${operator} (${values.map(
        Array.isArray(key) ? v => `(${v.map(to_q).join(', ')})` : to_q
      ).join(', ')})`,
      values: deep_flat(values)
    };
  }