UNPKG

zippa

Version:
35 lines (24 loc) 883 B
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.TreeZipper = exports.Node = undefined; var _index = require('../index'); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var Node = exports.Node = function Node(data) { var children = arguments.length <= 1 || arguments[1] === undefined ? [] : arguments[1]; _classCallCheck(this, Node); this.data = data; this.children = children; }; function getChildren(node) { return node.children; } function makeNode(node, children) { return new Node(node.data, children); } function isBranch(node) { return !!getChildren(node).length; } var TreeZipper = exports.TreeZipper = (0, _index.makeZipper)(isBranch, getChildren, makeNode); exports.default = TreeZipper;