Skip to content

Commit f8e19c7

Browse files
committed
1.5.0 build
1 parent 6a6df38 commit f8e19c7

File tree

8 files changed

+917
-741
lines changed

8 files changed

+917
-741
lines changed

dist/index.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ var _sensibles = require("./sensibles");
1111

1212
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1313

14+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
15+
1416
var VueTypes = {
1517
get any() {
1618
return (0, _utils.toType)('any', {
@@ -72,6 +74,51 @@ var VueTypes = {
7274
}, true);
7375
},
7476

77+
extend: function extend(props) {
78+
if (props === void 0) {
79+
props = {};
80+
}
81+
82+
var _props = props,
83+
name = _props.name,
84+
_props$validate = _props.validate,
85+
validate = _props$validate === void 0 ? false : _props$validate,
86+
_props$getter = _props.getter,
87+
getter = _props$getter === void 0 ? false : _props$getter,
88+
type = _objectWithoutPropertiesLoose(_props, ["name", "validate", "getter"]);
89+
90+
var descriptor;
91+
92+
if (getter) {
93+
descriptor = {
94+
get: function get() {
95+
return (0, _utils.toType)(name, type, validate);
96+
},
97+
enumerable: true,
98+
configurable: false
99+
};
100+
} else {
101+
var validator = type.validator;
102+
descriptor = {
103+
value: function value() {
104+
if (validator) {
105+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
106+
args[_key] = arguments[_key];
107+
}
108+
109+
type.validator = validator.bind.apply(validator, [this].concat(args));
110+
}
111+
112+
return (0, _utils.toType)(name, type, validate);
113+
},
114+
writable: false,
115+
enumerable: true,
116+
configurable: false
117+
};
118+
}
119+
120+
return Object.defineProperty(this, name, descriptor);
121+
},
75122
custom: function custom(validatorFn, warnMsg) {
76123
if (warnMsg === void 0) {
77124
warnMsg = 'custom validation failed';

dist/shim.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,16 @@ Object.defineProperty(vueTypes, 'shape', {
6666
});
6767
}
6868
});
69+
70+
vueTypes.extend = function (props) {
71+
var name = props.name,
72+
validate = props.validate,
73+
_props$getter = props.getter,
74+
getter = _props$getter === void 0 ? false : _props$getter;
75+
return createValidator(vueTypes, name, getter, validate && {
76+
validate: function validate() {}
77+
});
78+
};
79+
6980
var _default = vueTypes;
7081
exports.default = _default;

es/index.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
2+
13
import isPlainObject from 'lodash/isPlainObject';
24
import { toType, getType, isFunction, validateType, isInteger, isArray, warn } from './utils';
35
import { setDefaults } from './sensibles';
@@ -62,6 +64,51 @@ var VueTypes = {
6264
}, true);
6365
},
6466

67+
extend: function extend(props) {
68+
if (props === void 0) {
69+
props = {};
70+
}
71+
72+
var _props = props,
73+
name = _props.name,
74+
_props$validate = _props.validate,
75+
validate = _props$validate === void 0 ? false : _props$validate,
76+
_props$getter = _props.getter,
77+
getter = _props$getter === void 0 ? false : _props$getter,
78+
type = _objectWithoutPropertiesLoose(_props, ["name", "validate", "getter"]);
79+
80+
var descriptor;
81+
82+
if (getter) {
83+
descriptor = {
84+
get: function get() {
85+
return toType(name, type, validate);
86+
},
87+
enumerable: true,
88+
configurable: false
89+
};
90+
} else {
91+
var validator = type.validator;
92+
descriptor = {
93+
value: function value() {
94+
if (validator) {
95+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
96+
args[_key] = arguments[_key];
97+
}
98+
99+
type.validator = validator.bind.apply(validator, [this].concat(args));
100+
}
101+
102+
return toType(name, type, validate);
103+
},
104+
writable: false,
105+
enumerable: true,
106+
configurable: false
107+
};
108+
}
109+
110+
return Object.defineProperty(this, name, descriptor);
111+
},
65112
custom: function custom(validatorFn, warnMsg) {
66113
if (warnMsg === void 0) {
67114
warnMsg = 'custom validation failed';

es/shim.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,15 @@ Object.defineProperty(vueTypes, 'shape', {
6161
});
6262
}
6363
});
64+
65+
vueTypes.extend = function (props) {
66+
var name = props.name,
67+
validate = props.validate,
68+
_props$getter = props.getter,
69+
getter = _props$getter === void 0 ? false : _props$getter;
70+
return createValidator(vueTypes, name, getter, validate && {
71+
validate: function validate() {}
72+
});
73+
};
74+
6475
export default vueTypes;

0 commit comments

Comments
 (0)