raw.cjs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. 'use strict';
  2. var vueDemi = require('vue-demi');
  3. function ownKeys(object, enumerableOnly) {
  4. var keys = Object.keys(object);
  5. if (Object.getOwnPropertySymbols) {
  6. var symbols = Object.getOwnPropertySymbols(object);
  7. enumerableOnly && (symbols = symbols.filter(function (sym) {
  8. return Object.getOwnPropertyDescriptor(object, sym).enumerable;
  9. })), keys.push.apply(keys, symbols);
  10. }
  11. return keys;
  12. }
  13. function _objectSpread2(target) {
  14. for (var i = 1; i < arguments.length; i++) {
  15. var source = null != arguments[i] ? arguments[i] : {};
  16. i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
  17. _defineProperty(target, key, source[key]);
  18. }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
  19. Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
  20. });
  21. }
  22. return target;
  23. }
  24. function _defineProperty(obj, key, value) {
  25. if (key in obj) {
  26. Object.defineProperty(obj, key, {
  27. value: value,
  28. enumerable: true,
  29. configurable: true,
  30. writable: true
  31. });
  32. } else {
  33. obj[key] = value;
  34. }
  35. return obj;
  36. }
  37. function isFunction(val) {
  38. return typeof val === 'function';
  39. }
  40. function isObject(o) {
  41. return o !== null && typeof o === 'object' && !Array.isArray(o);
  42. }
  43. function normalizeValidatorObject(validator) {
  44. return isFunction(validator.$validator) ? _objectSpread2({}, validator) : {
  45. $validator: validator
  46. };
  47. }
  48. function isPromise(object) {
  49. return isObject(object) && isFunction(object.then);
  50. }
  51. function unwrapValidatorResponse(result) {
  52. if (typeof result === 'object') return result.$valid;
  53. return result;
  54. }
  55. function unwrapNormalizedValidator(validator) {
  56. return validator.$validator || validator;
  57. }
  58. function withParams($params, $validator) {
  59. if (!isObject($params)) throw new Error(`[@vuelidate/validators]: First parameter to "withParams" should be an object, provided ${typeof $params}`);
  60. if (!isObject($validator) && !isFunction($validator)) throw new Error(`[@vuelidate/validators]: Validator must be a function or object with $validator parameter`);
  61. const validatorObj = normalizeValidatorObject($validator);
  62. validatorObj.$params = _objectSpread2(_objectSpread2({}, validatorObj.$params || {}), $params);
  63. return validatorObj;
  64. }
  65. function withMessage($message, $validator) {
  66. if (!isFunction($message) && typeof vueDemi.unref($message) !== 'string') throw new Error(`[@vuelidate/validators]: First parameter to "withMessage" should be string or a function returning a string, provided ${typeof $message}`);
  67. if (!isObject($validator) && !isFunction($validator)) throw new Error(`[@vuelidate/validators]: Validator must be a function or object with $validator parameter`);
  68. const validatorObj = normalizeValidatorObject($validator);
  69. validatorObj.$message = $message;
  70. return validatorObj;
  71. }
  72. function withAsync($validator) {
  73. let $watchTargets = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
  74. const validatorObj = normalizeValidatorObject($validator);
  75. return _objectSpread2(_objectSpread2({}, validatorObj), {}, {
  76. $async: true,
  77. $watchTargets
  78. });
  79. }
  80. function forEach(validators) {
  81. return {
  82. $validator(collection) {
  83. for (var _len = arguments.length, others = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  84. others[_key - 1] = arguments[_key];
  85. }
  86. return vueDemi.unref(collection).reduce((previous, collectionItem, index) => {
  87. const collectionEntryResult = Object.entries(collectionItem).reduce((all, _ref) => {
  88. let [property, $model] = _ref;
  89. const innerValidators = validators[property] || {};
  90. const propertyResult = Object.entries(innerValidators).reduce((all, _ref2) => {
  91. let [validatorName, currentValidator] = _ref2;
  92. const validatorFunction = unwrapNormalizedValidator(currentValidator);
  93. const $response = validatorFunction.call(this, $model, collectionItem, index, ...others);
  94. const $valid = unwrapValidatorResponse($response);
  95. all.$data[validatorName] = $response;
  96. all.$data.$invalid = !$valid || !!all.$data.$invalid;
  97. all.$data.$error = all.$data.$invalid;
  98. if (!$valid) {
  99. let $message = currentValidator.$message || '';
  100. const $params = currentValidator.$params || {};
  101. if (typeof $message === 'function') {
  102. $message = $message({
  103. $pending: false,
  104. $invalid: !$valid,
  105. $params,
  106. $model,
  107. $response
  108. });
  109. }
  110. all.$errors.push({
  111. $property: property,
  112. $message,
  113. $params,
  114. $response,
  115. $model,
  116. $pending: false,
  117. $validator: validatorName
  118. });
  119. }
  120. return {
  121. $valid: all.$valid && $valid,
  122. $data: all.$data,
  123. $errors: all.$errors
  124. };
  125. }, {
  126. $valid: true,
  127. $data: {},
  128. $errors: []
  129. });
  130. all.$data[property] = propertyResult.$data;
  131. all.$errors[property] = propertyResult.$errors;
  132. return {
  133. $valid: all.$valid && propertyResult.$valid,
  134. $data: all.$data,
  135. $errors: all.$errors
  136. };
  137. }, {
  138. $valid: true,
  139. $data: {},
  140. $errors: {}
  141. });
  142. return {
  143. $valid: previous.$valid && collectionEntryResult.$valid,
  144. $data: previous.$data.concat(collectionEntryResult.$data),
  145. $errors: previous.$errors.concat(collectionEntryResult.$errors)
  146. };
  147. }, {
  148. $valid: true,
  149. $data: [],
  150. $errors: []
  151. });
  152. },
  153. $message: _ref3 => {
  154. let {
  155. $response
  156. } = _ref3;
  157. return $response ? $response.$errors.map(context => {
  158. return Object.values(context).map(errors => errors.map(error => error.$message)).reduce((a, b) => a.concat(b), []);
  159. }) : [];
  160. }
  161. };
  162. }
  163. const req = value => {
  164. value = vueDemi.unref(value);
  165. if (Array.isArray(value)) return !!value.length;
  166. if (value === undefined || value === null) {
  167. return false;
  168. }
  169. if (value === false) {
  170. return true;
  171. }
  172. if (value instanceof Date) {
  173. return !isNaN(value.getTime());
  174. }
  175. if (typeof value === 'object') {
  176. for (let _ in value) return true;
  177. return false;
  178. }
  179. return !!String(value).length;
  180. };
  181. const len = value => {
  182. value = vueDemi.unref(value);
  183. if (Array.isArray(value)) return value.length;
  184. if (typeof value === 'object') {
  185. return Object.keys(value).length;
  186. }
  187. return String(value).length;
  188. };
  189. function regex() {
  190. for (var _len = arguments.length, expr = new Array(_len), _key = 0; _key < _len; _key++) {
  191. expr[_key] = arguments[_key];
  192. }
  193. return value => {
  194. value = vueDemi.unref(value);
  195. return !req(value) || expr.every(reg => {
  196. reg.lastIndex = 0;
  197. return reg.test(value);
  198. });
  199. };
  200. }
  201. var common = /*#__PURE__*/Object.freeze({
  202. __proto__: null,
  203. forEach: forEach,
  204. len: len,
  205. normalizeValidatorObject: normalizeValidatorObject,
  206. regex: regex,
  207. req: req,
  208. unwrap: vueDemi.unref,
  209. unwrapNormalizedValidator: unwrapNormalizedValidator,
  210. unwrapValidatorResponse: unwrapValidatorResponse,
  211. withAsync: withAsync,
  212. withMessage: withMessage,
  213. withParams: withParams
  214. });
  215. var alpha = regex(/^[a-zA-Z]*$/);
  216. var alphaNum = regex(/^[a-zA-Z0-9]*$/);
  217. var numeric = regex(/^\d*(\.\d+)?$/);
  218. function between (min, max) {
  219. return value => !req(value) || (!/\s/.test(value) || value instanceof Date) && +vueDemi.unref(min) <= +value && +vueDemi.unref(max) >= +value;
  220. }
  221. const emailRegex = /^(?:[A-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[A-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9]{2,}(?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/i;
  222. var email = regex(emailRegex);
  223. function ipAddress (value) {
  224. if (!req(value)) {
  225. return true;
  226. }
  227. if (typeof value !== 'string') {
  228. return false;
  229. }
  230. const nibbles = value.split('.');
  231. return nibbles.length === 4 && nibbles.every(nibbleValid);
  232. }
  233. const nibbleValid = nibble => {
  234. if (nibble.length > 3 || nibble.length === 0) {
  235. return false;
  236. }
  237. if (nibble[0] === '0' && nibble !== '0') {
  238. return false;
  239. }
  240. if (!nibble.match(/^\d+$/)) {
  241. return false;
  242. }
  243. const numeric = +nibble | 0;
  244. return numeric >= 0 && numeric <= 255;
  245. };
  246. function macAddress () {
  247. let separator = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ':';
  248. return value => {
  249. separator = vueDemi.unref(separator);
  250. if (!req(value)) {
  251. return true;
  252. }
  253. if (typeof value !== 'string') {
  254. return false;
  255. }
  256. const parts = typeof separator === 'string' && separator !== '' ? value.split(separator) : value.length === 12 || value.length === 16 ? value.match(/.{2}/g) : null;
  257. return parts !== null && (parts.length === 6 || parts.length === 8) && parts.every(hexValid);
  258. };
  259. }
  260. const hexValid = hex => hex.toLowerCase().match(/^[0-9a-f]{2}$/);
  261. function maxLength (length) {
  262. return value => !req(value) || len(value) <= vueDemi.unref(length);
  263. }
  264. function minLength (length) {
  265. return value => !req(value) || len(value) >= vueDemi.unref(length);
  266. }
  267. function required (value) {
  268. if (typeof value === 'string') {
  269. value = value.trim();
  270. }
  271. return req(value);
  272. }
  273. const validate$1 = (prop, val) => prop ? req(typeof val === 'string' ? val.trim() : val) : true;
  274. function requiredIf(propOrFunction) {
  275. return function (value, parentVM) {
  276. if (typeof propOrFunction !== 'function') {
  277. return validate$1(vueDemi.unref(propOrFunction), value);
  278. }
  279. const result = propOrFunction.call(this, value, parentVM);
  280. return validate$1(result, value);
  281. };
  282. }
  283. const validate = (prop, val) => !prop ? req(typeof val === 'string' ? val.trim() : val) : true;
  284. function requiredUnless(propOrFunction) {
  285. return function (value, parentVM) {
  286. if (typeof propOrFunction !== 'function') {
  287. return validate(vueDemi.unref(propOrFunction), value);
  288. }
  289. const result = propOrFunction.call(this, value, parentVM);
  290. return validate(result, value);
  291. };
  292. }
  293. function sameAs (equalTo) {
  294. return value => vueDemi.unref(value) === vueDemi.unref(equalTo);
  295. }
  296. const urlRegex = /^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9\u00a1-\uffff][a-z0-9\u00a1-\uffff_-]{0,62})?[a-z0-9\u00a1-\uffff]\.)+(?:[a-z\u00a1-\uffff]{2,}\.?))(?::\d{2,5})?(?:[/?#]\S*)?$/i;
  297. var url = regex(urlRegex);
  298. function syncOr(validators) {
  299. return function () {
  300. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  301. args[_key] = arguments[_key];
  302. }
  303. return validators.reduce((valid, fn) => {
  304. if (unwrapValidatorResponse(valid)) return valid;
  305. return unwrapNormalizedValidator(fn).apply(this, args);
  306. }, false);
  307. };
  308. }
  309. function asyncOr(validators) {
  310. return function () {
  311. for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  312. args[_key2] = arguments[_key2];
  313. }
  314. return validators.reduce(async (valid, fn) => {
  315. const r = await valid;
  316. if (unwrapValidatorResponse(r)) return r;
  317. return unwrapNormalizedValidator(fn).apply(this, args);
  318. }, Promise.resolve(false));
  319. };
  320. }
  321. function or() {
  322. for (var _len3 = arguments.length, validators = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
  323. validators[_key3] = arguments[_key3];
  324. }
  325. const $async = validators.some(v => v.$async);
  326. const $watchTargets = validators.reduce((all, v) => {
  327. if (!v.$watchTargets) return all;
  328. return all.concat(v.$watchTargets);
  329. }, []);
  330. let $validator = () => false;
  331. if (validators.length) $validator = $async ? asyncOr(validators) : syncOr(validators);
  332. return {
  333. $async,
  334. $validator,
  335. $watchTargets
  336. };
  337. }
  338. function syncAnd(validators) {
  339. return function () {
  340. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  341. args[_key] = arguments[_key];
  342. }
  343. return validators.reduce((valid, fn) => {
  344. if (!unwrapValidatorResponse(valid)) return valid;
  345. return unwrapNormalizedValidator(fn).apply(this, args);
  346. }, true);
  347. };
  348. }
  349. function asyncAnd(validators) {
  350. return function () {
  351. for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  352. args[_key2] = arguments[_key2];
  353. }
  354. return validators.reduce(async (valid, fn) => {
  355. const r = await valid;
  356. if (!unwrapValidatorResponse(r)) return r;
  357. return unwrapNormalizedValidator(fn).apply(this, args);
  358. }, Promise.resolve(true));
  359. };
  360. }
  361. function and() {
  362. for (var _len3 = arguments.length, validators = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
  363. validators[_key3] = arguments[_key3];
  364. }
  365. const $async = validators.some(v => v.$async);
  366. const $watchTargets = validators.reduce((all, v) => {
  367. if (!v.$watchTargets) return all;
  368. return all.concat(v.$watchTargets);
  369. }, []);
  370. let $validator = () => false;
  371. if (validators.length) $validator = $async ? asyncAnd(validators) : syncAnd(validators);
  372. return {
  373. $async,
  374. $validator,
  375. $watchTargets
  376. };
  377. }
  378. function not (validator) {
  379. return function (value, vm) {
  380. if (!req(value)) return true;
  381. const response = unwrapNormalizedValidator(validator).call(this, value, vm);
  382. if (!isPromise(response)) return !unwrapValidatorResponse(response);
  383. return response.then(r => !unwrapValidatorResponse(r));
  384. };
  385. }
  386. function minValue (min) {
  387. return value => !req(value) || (!/\s/.test(value) || value instanceof Date) && +value >= +vueDemi.unref(min);
  388. }
  389. function maxValue (max) {
  390. return value => !req(value) || (!/\s/.test(value) || value instanceof Date) && +value <= +vueDemi.unref(max);
  391. }
  392. var integer = regex(/(^[0-9]*$)|(^-[0-9]+$)/);
  393. var decimal = regex(/^[-]?\d*(\.\d+)?$/);
  394. exports.alpha = alpha;
  395. exports.alphaNum = alphaNum;
  396. exports.and = and;
  397. exports.between = between;
  398. exports.decimal = decimal;
  399. exports.email = email;
  400. exports.helpers = common;
  401. exports.integer = integer;
  402. exports.ipAddress = ipAddress;
  403. exports.macAddress = macAddress;
  404. exports.maxLength = maxLength;
  405. exports.maxValue = maxValue;
  406. exports.minLength = minLength;
  407. exports.minValue = minValue;
  408. exports.not = not;
  409. exports.numeric = numeric;
  410. exports.or = or;
  411. exports.required = required;
  412. exports.requiredIf = requiredIf;
  413. exports.requiredUnless = requiredUnless;
  414. exports.sameAs = sameAs;
  415. exports.url = url;