UNPKG

ts-to-mongo-schema

Version:

Using the Typescript Compiler API, this program parses through Typescript, to generate a JSON Schema that conforms to MongoDB's bson format. Useful when generating large schemas, and being unable to use a javascript or typescript library like Moongoose.

26 lines (25 loc) 888 B
"use strict"; var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); ar[i] = from[i]; } } return to.concat(ar || Array.prototype.slice.call(from)); }; Object.defineProperty(exports, "__esModule", { value: true }); function grabSubNodes(node, condition) { if (!node) return []; var array = []; if (condition(node)) array.push(node); node.forEachChild(function (node) { if (condition(node)) array.push(node); array = __spreadArray(__spreadArray([], array, true), grabSubNodes(node, condition), true); }); return array; } exports.default = grabSubNodes;