diff options
Diffstat (limited to 'node_modules/typedoc/dist/lib/utils/validation.js')
-rw-r--r-- | node_modules/typedoc/dist/lib/utils/validation.js | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/node_modules/typedoc/dist/lib/utils/validation.js b/node_modules/typedoc/dist/lib/utils/validation.js new file mode 100644 index 0000000..274a9d5 --- /dev/null +++ b/node_modules/typedoc/dist/lib/utils/validation.js @@ -0,0 +1,56 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.isTagString = exports.optional = exports.validate = exports.additionalProperties = void 0; +const opt = Symbol(); +/** + * Symbol that may be placed on a schema object to define how additional properties are handled. + * By default, additional properties are not checked. + */ +exports.additionalProperties = Symbol(); +function validate(schema, obj) { + let type = schema; + if (opt in schema) { + if (obj == null) { + return true; + } + type = schema[opt]; + } + if (type === String) { + return typeof obj === "string"; + } + if (type === Number) { + return typeof obj === "number"; + } + if (type === Boolean) { + return typeof obj === "boolean"; + } + if (typeof type === "function") { + return type(obj); + } + if (Array.isArray(type)) { + if (type[0] === Array) { + return (Array.isArray(obj) && + obj.every((item) => validate(type[1], item))); + } + return type.includes(obj); + } + if (exports.additionalProperties in schema && + !schema[exports.additionalProperties]) { + if (Object.keys(obj).some((key) => !(key in schema))) { + return false; + } + } + return (!!obj && + typeof obj === "object" && + !Array.isArray(obj) && + Object.entries(type).every(([key, prop]) => validate(prop, obj[key]))); +} +exports.validate = validate; +function optional(x) { + return { [opt]: x }; +} +exports.optional = optional; +function isTagString(x) { + return typeof x === "string" && /^@[a-zA-Z][a-zA-Z0-9]*$/.test(x); +} +exports.isTagString = isTagString; |