UNPKG

vue-types

Version:
217 lines (212 loc) 6.18 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); const sensibles = require('./shared/vue-types.D1zhuSli.cjs'); const dfn = Object.defineProperty; const isArray = Array.isArray; function deepClone(input) { if ("structuredClone" in globalThis) { return structuredClone(input); } if (Array.isArray(input)) { return [...input]; } if (sensibles.isPlainObject(input)) { return Object.assign({}, input); } return input; } function type(name, props = {}, validable = false) { const descriptors = { _vueTypes_name: { value: name, writable: true }, def: { value(v) { if (v === void 0) { if ("default" in this) { delete this.default; } return this; } if (isArray(v)) { this.default = () => deepClone(v); } else if (sensibles.isPlainObject(v)) { this.default = () => deepClone(v); } else { this.default = v; } return this; } }, isRequired: { get() { this.required = true; return this; } } }; if (validable) { descriptors.validate = { value() { } }; } if (!props.validator) { props.validator = () => true; } return Object.defineProperties(props, descriptors); } const any = () => type("any", {}, true); const func = () => type("func", { type: Function }, true); const bool = () => type("bool", { type: Boolean }, true); const string = () => type("string", { type: String }, true); const number = () => type("number", { type: Number }, true); const array = () => type("array", { type: Array }, true); const object = () => type("object", { type: Object }, true); const symbol = () => type("symbol"); const integer = () => type("integer", { type: Number }); const oneOf = (_a) => type("oneOf"); const custom = (_a) => type("custom"); const instanceOf = (Constr) => type("instanceOf", { type: Constr }); const oneOfType = (_a) => type("oneOfType"); const arrayOf = (_a) => type("arrayOf", { type: Array }); const objectOf = (_a) => type("objectOf", { type: Object }); const shape = (_a) => dfn(type("shape", { type: Object }), "loose", { get() { return this; } }); const nullable = () => ({ type: null }); function createValidator(root, name, props, getter = false, validable = false) { const prop = getter ? "get" : "value"; const descr = { [prop]: () => type(name, Object.assign({}, props), validable).def( getter ? root.defaults[name] : void 0 ) }; return dfn(root, name, descr); } function fromType(name, source, props = {}) { const t = type(name, Object.assign({}, source, props), !!source.validable); if (t.validator) { delete t.validator; } return t; } const toValidableType = (name, props) => type(name, props, true); const toType = (name, props) => type(name, props); const BaseVueTypes = /* @__PURE__ */ (() => ( // oxlint-disable-next-line no-shadow, typescript/no-extraneous-class class BaseVueTypes { static defaults = {}; static sensibleDefaults; static config = sensibles.config; static get any() { return any(); } static get func() { return func().def(this.defaults.func); } static get bool() { return bool().def(this.defaults.bool); } static get string() { return string().def(this.defaults.string); } static get number() { return number().def(this.defaults.number); } static get array() { return array().def(this.defaults.array); } static get object() { return object().def(this.defaults.object); } static get symbol() { return symbol(); } static get integer() { return integer().def(this.defaults.integer); } static get nullable() { return nullable(); } static oneOf = oneOf; static custom = custom; static instanceOf = instanceOf; static oneOfType = oneOfType; static arrayOf = arrayOf; static objectOf = objectOf; static shape = shape; static extend(props) { if (isArray(props)) { props.forEach((p) => this.extend(p)); return this; } const { name, validate, getter = false, type: _type = null } = props; const extType = sensibles.isPlainObject(_type) && _type.type ? null : _type; return createValidator(this, name, { type: extType }, getter, !!validate); } static utils = { toType: type, validate: (...args) => !!args }; } ))(); function createTypes(defs = sensibles.typeDefaults()) { return class extends BaseVueTypes { static defaults = Object.assign({}, defs); static get sensibleDefaults() { return Object.assign({}, this.defaults); } static set sensibleDefaults(v) { if (v === false) { this.defaults = {}; return; } if (v === true) { this.defaults = Object.assign({}, defs); return; } this.defaults = Object.assign({}, v); } }; } function validateType(_type, _value, _silent = false) { return true; } if (process.env.NODE_ENV !== "production") { !sensibles.config.silent && console.warn( "You are using the production shimmed version of VueTypes in a development build. Refer to https://vue-types.codeful.dev/guide/installation.html#production-build to learn how to configure VueTypes for usage in multiple environments." ); } class VueTypes extends createTypes() { } exports.config = sensibles.config; exports.any = any; exports.array = array; exports.arrayOf = arrayOf; exports.bool = bool; exports.createTypes = createTypes; exports.custom = custom; exports.default = VueTypes; exports.fromType = fromType; exports.func = func; exports.instanceOf = instanceOf; exports.integer = integer; exports.nullable = nullable; exports.number = number; exports.object = object; exports.objectOf = objectOf; exports.oneOf = oneOf; exports.oneOfType = oneOfType; exports.shape = shape; exports.string = string; exports.symbol = symbol; exports.toType = toType; exports.toValidableType = toValidableType; exports.validateType = validateType; //# sourceMappingURL=shim.cjs.map