@gram-data/gram-ops
Version:
gram data graph operations
3 lines (2 loc) • 1.25 kB
JavaScript
;Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@gram-data/gram-ast"),r=require("@gram-data/gram-builder"),n=function e(r){return void 0===r.children||0===r.children.length?r:e(r.children[0])},i=function e(r){return void 0===r.children||0===r.children.length?r:e(r.children[r.children.length-1])};exports.count=function e(r){return r.children.reduce((function(r,n){return r+e(n)}),1)},exports.edges=function e(t){return void 0===t||void 0===t.children||0===t.children.length?[]:2===t.children.length?[].concat(e(t.children[0]),void 0!==t.kind&&"pair"!==t.kind?[r.edge([i(t.children[0]),n(t.children[1])],t.kind,t.id,t.labels,t.record)]:[],e(t.children[1])):t.children.reduce((function(r,n){return[].concat(r,e(n))}),[])},exports.head=n,exports.identity=function(e){return e.id},exports.merge=function(e,r){return r},exports.nodes=function r(n){if(e.isGramNode(n))return[n];if(e.isGramSeq(n))return r(n.children);if(Array.isArray(n)){var i=[],t=n.map(r).flat().reduce((function(e,r){return r.id?e.has(r.id)?e.set(r.id,Object.assign(e.get(r.id),r)):e.set(r.id,r):i.push(r),e}),new Map);return Array.from(t.values()).concat(i)}return r(n.children)},exports.tail=i;
//# sourceMappingURL=gram-ops.cjs.production.min.js.map