UNPKG

dilswer

Version:

Blazingly fast data validation library with TypeScript integration.

92 lines (90 loc) 2.79 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/validation-algorithms/approximate-complexity.ts var approximate_complexity_exports = {}; __export(approximate_complexity_exports, { approximateComplexity: () => approximateComplexity }); module.exports = __toCommonJS(approximate_complexity_exports); function approximateComplexity(t) { return t._acceptVisitor({ visit(t2, children) { var _a, _b, _c, _d, _e, _f, _g, _h; switch (t2.kind) { case "literal": case "instanceOf": case "enumMember": case "simple": { return 1; } case "stringMatching": { return 2; } case "set": case "array": { return 10 + ((_a = children.reduce( (c, next) => next + c, 0 )) != null ? _a : 0); } case "tuple": { return 1 + ((_b = children.reduce( (c, next) => next + c, 0 )) != null ? _b : 0); } case "circularRef": case "circular": { return 0; } case "custom": { return 1; } case "dictionary": { return 3 + ((_c = children.reduce( (c, next) => next + c, 0 )) != null ? _c : 0); } case "enumUnion": { return (_d = children == null ? void 0 : children.length) != null ? _d : 1; } case "union": { return (_e = children.reduce( (c, next) => next + c, 0 )) != null ? _e : 0; } case "intersection": { return Math.floor(((_f = children == null ? void 0 : children.length) != null ? _f : 0) / 2) + ((_g = children.reduce( (c, next) => next + c, 0 )) != null ? _g : 0); } case "record": { return 2 + ((_h = children.reduce( (c, next) => next.child + c, 0 )) != null ? _h : 0); } } return 0; } }); }