├── .babelrc ├── .eslintignore ├── .eslintrc.js ├── .gitignore ├── LICENSE.txt ├── changelog.md ├── docs ├── index.html ├── index.js.html ├── module-svelte-form.html ├── module-svelte-form_rule_between.html ├── module-svelte-form_rule_email.html ├── module-svelte-form_rule_equal.html ├── module-svelte-form_rule_exclude.html ├── module-svelte-form_rule_ignore.html ├── module-svelte-form_rule_include.html ├── module-svelte-form_rule_max.html ├── module-svelte-form_rule_min.html ├── module-svelte-form_rule_required.html ├── module-svelte-form_rule_rx.html ├── module-svelte-form_rule_url.html ├── rule_between.js.html ├── rule_email.js.html ├── rule_equal.js.html ├── rule_exclude.js.html ├── rule_ignoreEmpty.js.html ├── rule_include.js.html ├── rule_max.js.html ├── rule_min.js.html ├── rule_required.js.html ├── rule_rx.js.html ├── rule_url.js.html ├── scripts │ ├── collapse.js │ ├── linenumber.js │ ├── nav.js │ ├── polyfill.js │ ├── prettify │ │ ├── Apache-License-2.0.txt │ │ ├── lang-css.js │ │ └── prettify.js │ └── search.js └── styles │ ├── jsdoc.css │ └── prettify.css ├── jsdoc.json ├── package.json ├── readme.md ├── rollup.config.js └── src ├── index.js ├── index.test.js └── rule ├── between.js ├── email.js ├── equal.js ├── exclude.js ├── ignoreEmpty.js ├── include.js ├── index.test.js ├── max.js ├── min.js ├── required.js ├── rx.js └── url.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "@babel/env" 4 | ] 5 | } -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | # Lib 2 | lib/*.js -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | parser: 'babel-eslint', 3 | rules: { 4 | strict: 0, 5 | 'linebreak-style': ['error', 'unix'], 6 | }, 7 | extends: ['google'] 8 | }; -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Output 2 | lib 3 | 4 | # NPM, YARN 5 | node_modules 6 | yarn.lock 7 | yarn-error.log 8 | package-lock.json 9 | npm-debug.log 10 | 11 | # VS Code 12 | *.vscode 13 | *.code-workspace 14 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright 2019 David Horak 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. -------------------------------------------------------------------------------- /changelog.md: -------------------------------------------------------------------------------- 1 | # Svelte Form changelog 2 | 3 | ## 1.0.4 4 | 5 | * New validation rules: Exclude, Include. 6 | 7 | ## 1.0.3 8 | 9 | * New feature: Validation breaking rule for empty values. 10 | 11 | ## 1.0.2 12 | 13 | * New feature: Add new function to trigger validation on all fields. 14 | 15 | ## 1.0.1 16 | 17 | * Updated email validation rule. 18 | * Updated documentation. 19 | 20 | ## 1.0.0 21 | 22 | * First release. 23 | -------------------------------------------------------------------------------- /docs/index.js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | index.js - Documentation 7 | 8 | 9 | 10 | 11 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 25 | 26 | 27 | 28 | 32 | 33 |
34 | 35 |

index.js

36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 |
44 |
45 |
/**
 46 |  * Svelte Form module.
 47 |  * @module svelte-form
 48 |  */
 49 | 
 50 | import tc from '@spaceavocado/type-check';
 51 | import {writable, derived, get} from 'svelte/store';
 52 | import {BREAK_FLAG} from './rule/ignoreEmpty';
 53 | 
 54 | // Rules
 55 | import required from './rule/required';
 56 | import email from './rule/email';
 57 | import url from './rule/url';
 58 | import equal from './rule/equal';
 59 | import min from './rule/min';
 60 | import max from './rule/max';
 61 | import between from './rule/between';
 62 | import rx from './rule/rx';
 63 | import ignoreEmpty from './rule/ignoreEmpty';
 64 | 
 65 | export {
 66 |   ignoreEmpty,
 67 |   required,
 68 |   email,
 69 |   url,
 70 |   equal,
 71 |   min,
 72 |   max,
 73 |   between,
 74 |   rx,
 75 | };
 76 | 
 77 | /**
 78 |  * Get input validation rules
 79 |  * @private
 80 |  * @param {string} key input key.
 81 |  * @param {object} validation rules.
 82 |  * @return {function[]} validation rules.
 83 |  */
 84 | export function validationRules(key, validation) {
 85 |   validation = validation || {};
 86 |   if (tc.isNullOrUndefined(validation[key])) {
 87 |     return [];
 88 |   }
 89 |   if (tc.isArray(validation[key])) {
 90 |     return validation[key];
 91 |   }
 92 |   return [validation[key]];
 93 | }
 94 | 
 95 | /**
 96 |  * Validate field
 97 |  * @private
 98 |  * @param {mixed} value field value.
 99 |  * @param {function[]} rules filed validation rules.
100 |  * @return {boolean|string} true = no error, string = error message.
101 |  */
102 | export function validate(value, rules) {
103 |   for (let i = 0; i < rules.length; i++) {
104 |     const err = rules[i](value);
105 |     if (err === BREAK_FLAG) {
106 |       return true;
107 |     } else if (err !== true) {
108 |       return err;
109 |     }
110 |   }
111 |   return true;
112 | }
113 | 
114 | /**
115 |  * Form object
116 |  * @typedef Form
117 |  * @property {function} subscribe Svelte store, context {valid: boolean}.
118 |  * @property {function} field Get form field observable value and state.
119 |  * Signature fn(key), returns {module:svelte-form~FormField}.
120 |  * @property {function} validate Trigger all fields validation.
121 |  * @property {function} data Get all form fields data. Signature fn().
122 |  */
123 | 
124 | /**
125 |  * FormField object
126 |  * @typedef FormField
127 |  * @property {function} value Writeable Svelte store, context: mixed value.
128 |  * @property {function} state Readonly Svelte store,
129 |  * context: {valid: boolean, error: string}.
130 |  */
131 | 
132 | /**
133 |  * Create a new form store
134 |  * @param {object} fields Form fields.
135 |  * @param {object} validation Validation rules mapping.
136 |  * Where each key is a fn(val)->boolean validation function or
137 |  * an array of fn(val)->boolean validation functions.
138 |  * @param {object} opts Form options.
139 |  * @param {boolean} opts.onCreateValidation Validate form fields
140 |  * when the form is created. Defaults to false.
141 |  * @return {module:svelte-form~Form}
142 |  */
143 | export default function(fields, validation, opts) {
144 |   opts = opts || {};
145 |   opts.onCreateValidation = opts.onCreateValidation || false;
146 |   const _fields = {};
147 |   const form = writable(Date.now());
148 | 
149 |   // Field wrapper structure
150 |   const field = (key, rules) => {
151 |     let firstPass = true;
152 |     const value = writable(fields[key]);
153 |     const state = derived(
154 |         [value, form],
155 |         ([$value]) => {
156 |           if (firstPass) {
157 |             firstPass = false;
158 |             if (opts.onCreateValidation === false) {
159 |               return {
160 |                 valid: true,
161 |                 error: '',
162 |               };
163 |             }
164 |           }
165 |           const res = validate($value, rules);
166 |           return {
167 |             valid: res === true,
168 |             error: res === true ? '' : res,
169 |           };
170 |         }
171 |     );
172 |     return {
173 |       value,
174 |       state,
175 |     };
176 |   };
177 | 
178 |   // Convert all inputs into field wrappers
179 |   let key;
180 |   for (key in fields) {
181 |     if (fields.hasOwnProperty(key)) {
182 |       _fields[key] = field(key, validationRules(key, validation));
183 |     }
184 |   }
185 | 
186 |   // Overall valid state
187 |   const {subscribe} = derived(
188 |       Object.values(_fields).map((f) => f.state),
189 |       ($states) => {
190 |         return {
191 |           valid: $states.every((s) => s.valid === true),
192 |         };
193 |       }
194 |   );
195 | 
196 |   return {
197 |     subscribe,
198 |     field: (key) => {
199 |       if (tc.isNullOrUndefined(_fields[key])) {
200 |         return undefined;
201 |       }
202 |       return {
203 |         value: _fields[key].value,
204 |         state: _fields[key].state,
205 |       };
206 |     },
207 |     validate: () => {
208 |       form.set(Date.now());
209 |     },
210 |     data: () => {
211 |       const data = {};
212 |       let key;
213 |       for (key in _fields) {
214 |         if (_fields.hasOwnProperty(key)) {
215 |           data[key] = get(_fields[key].value);
216 |         }
217 |       }
218 |       return data;
219 |     },
220 |   };
221 | }
222 | 
223 |
224 |
225 | 226 | 227 | 228 | 229 | 230 | 231 |
232 | 233 |
234 | 235 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | -------------------------------------------------------------------------------- /docs/module-svelte-form.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | svelte-form - Documentation 7 | 8 | 9 | 10 | 11 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 25 | 26 | 27 | 28 | 32 | 33 |
34 | 35 |

svelte-form

36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 |
44 | 45 |
46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 |
54 | 55 |
56 | 57 |
58 | 59 | 60 |

Svelte Form module.

61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 |
70 | 71 | 72 |
Source:
73 |
76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 |
108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 |

(require("svelte-form"))(fields, validation, opts) → {module:svelte-form~Form}

146 | 147 | 148 | 149 | 150 | 151 | 152 |
153 | 154 | 155 |
Source:
156 |
159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 |
191 | 192 | 193 | 194 | 195 | 196 |
197 |

Create a new form store

198 |
199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 |
Parameters:
211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 269 | 270 | 271 | 272 | 273 | 274 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 294 | 295 | 296 | 297 | 298 | 299 | 350 | 351 | 352 | 353 | 354 |
NameTypeDescription
fields 239 | 240 | 241 | object 242 | 243 | 244 | 245 |

Form fields.

validation 262 | 263 | 264 | object 265 | 266 | 267 | 268 |

Validation rules mapping. 275 | Where each key is a fn(val)->boolean validation function or 276 | an array of fn(val)->boolean validation functions.

opts 287 | 288 | 289 | object 290 | 291 | 292 | 293 |

Form options.

300 |
Properties
301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 336 | 337 | 338 | 339 | 340 | 341 | 343 | 344 | 345 | 346 | 347 |
NameTypeDescription
onCreateValidation 329 | 330 | 331 | boolean 332 | 333 | 334 | 335 |

Validate form fields 342 | when the form is created. Defaults to false.

348 | 349 |
355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 |
Returns:
372 | 373 | 374 | 375 | 376 |
377 |
378 | Type 379 |
380 |
381 | 382 | module:svelte-form~Form 383 | 384 | 385 |
386 |
387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 |
395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 |

Type Definitions

415 | 416 | 417 | 418 |

Form

419 | 420 | 421 | 422 | 423 | 424 |
425 | 426 | 427 |
Source:
428 |
431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 |
463 | 464 | 465 | 466 |
Properties:
467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 526 | 527 | 528 | 529 | 530 | 531 | 533 | 534 | 535 | 536 | 537 | 538 | 539 | 540 | 541 | 542 | 550 | 551 | 552 | 553 | 554 | 555 | 556 | 557 | 558 | 559 | 560 | 561 | 562 | 563 | 564 | 565 | 573 | 574 | 575 | 576 | 577 | 578 | 579 | 580 | 581 | 582 | 583 |
NameTypeDescription
subscribe 496 | 497 | 498 | function 499 | 500 | 501 | 502 |

Svelte store, context {valid: boolean}.

field 519 | 520 | 521 | function 522 | 523 | 524 | 525 |

Get form field observable value and state. 532 | Signature fn(key), returns {module:svelte-form~FormField}.

validate 543 | 544 | 545 | function 546 | 547 | 548 | 549 |

Trigger all fields validation.

data 566 | 567 | 568 | function 569 | 570 | 571 | 572 |

Get all form fields data. Signature fn().

584 | 585 | 586 | 587 | 588 | 589 | 590 |
591 |

Form object

592 |
593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 |

FormField

604 | 605 | 606 | 607 | 608 | 609 |
610 | 611 | 612 |
Source:
613 |
616 | 617 | 618 | 619 | 620 | 621 | 622 | 623 | 624 | 625 | 626 | 627 | 628 | 629 | 630 | 631 | 632 | 633 | 634 | 635 | 636 | 637 | 638 | 639 | 640 | 641 | 642 | 643 | 644 | 645 | 646 | 647 |
648 | 649 | 650 | 651 |
Properties:
652 | 653 | 654 | 655 | 656 | 657 | 658 | 659 | 660 | 661 | 662 | 663 | 664 | 665 | 666 | 667 | 668 | 669 | 670 | 671 | 672 | 673 | 674 | 675 | 676 | 677 | 678 | 679 | 680 | 688 | 689 | 690 | 691 | 692 | 693 | 694 | 695 | 696 | 697 | 698 | 699 | 700 | 701 | 702 | 703 | 711 | 712 | 713 | 714 | 715 | 716 | 718 | 719 | 720 | 721 | 722 |
NameTypeDescription
value 681 | 682 | 683 | function 684 | 685 | 686 | 687 |

Writeable Svelte store, context: mixed value.

state 704 | 705 | 706 | function 707 | 708 | 709 | 710 |

Readonly Svelte store, 717 | context: {valid: boolean, error: string}.

723 | 724 | 725 | 726 | 727 | 728 | 729 |
730 |

FormField object

731 |
732 | 733 | 734 | 735 | 736 | 737 | 738 | 739 | 740 | 741 | 742 | 743 | 744 |
745 | 746 |
747 | 748 | 749 | 750 | 751 | 752 | 753 |
754 | 755 |
756 | 757 | 760 | 761 | 762 | 763 | 764 | 765 | 766 | 767 | 768 | -------------------------------------------------------------------------------- /docs/module-svelte-form_rule_between.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | svelte-form/rule/between - Documentation 7 | 8 | 9 | 10 | 11 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 25 | 26 | 27 | 28 | 32 | 33 |
34 | 35 |

svelte-form/rule/between

36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 |
44 | 45 |
46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 |
54 | 55 |
56 | 57 |
58 | 59 | 60 |

Svelte Form validation rules module.

61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 |
70 | 71 | 72 |
Source:
73 |
76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 |
108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 |

(require("svelte-form/rule/between"))(msg, arg1, arg2) → {boolean|string}

146 | 147 | 148 | 149 | 150 | 151 | 152 |
153 | 154 | 155 |
Source:
156 |
159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 |
191 | 192 | 193 | 194 | 195 | 196 |
197 |

Between numbers rule

198 |
199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 |
Parameters:
211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 |
NameTypeDescription
msg 239 | 240 | 241 | string 242 | 243 | 244 | 245 |

error message.

arg1 262 | 263 | 264 | number 265 | 266 | 267 | 268 |

min number.

arg2 285 | 286 | 287 | number 288 | 289 | 290 | 291 |

max number.

303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 |
Returns:
320 | 321 | 322 |
323 |

true when valid, error message otherwise.

324 |
325 | 326 | 327 | 328 |
329 |
330 | Type 331 |
332 |
333 | 334 | boolean 335 | | 336 | 337 | string 338 | 339 | 340 |
341 |
342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 |
350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 |
372 | 373 |
374 | 375 | 376 | 377 | 378 | 379 | 380 |
381 | 382 |
383 | 384 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | -------------------------------------------------------------------------------- /docs/module-svelte-form_rule_email.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | svelte-form/rule/email - Documentation 7 | 8 | 9 | 10 | 11 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 25 | 26 | 27 | 28 | 32 | 33 |
34 | 35 |

svelte-form/rule/email

36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 |
44 | 45 |
46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 |
54 | 55 |
56 | 57 |
58 | 59 | 60 |

Svelte Form validation rules module.

61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 |
70 | 71 | 72 |
Source:
73 |
76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 |
108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 |

(require("svelte-form/rule/email"))(msg) → {boolean|string}

146 | 147 | 148 | 149 | 150 | 151 | 152 |
153 | 154 | 155 |
Source:
156 |
159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 |
191 | 192 | 193 | 194 | 195 | 196 |
197 |

Email rule

198 |
199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 |
Parameters:
211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 |
NameTypeDescription
msg 239 | 240 | 241 | string 242 | 243 | 244 | 245 |

error message.

257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 |
Returns:
274 | 275 | 276 |
277 |

true when valid, error message otherwise.

278 |
279 | 280 | 281 | 282 |
283 |
284 | Type 285 |
286 |
287 | 288 | boolean 289 | | 290 | 291 | string 292 | 293 | 294 |
295 |
296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 |
304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 |
326 | 327 |
328 | 329 | 330 | 331 | 332 | 333 | 334 |
335 | 336 |
337 | 338 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | -------------------------------------------------------------------------------- /docs/module-svelte-form_rule_equal.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | svelte-form/rule/equal - Documentation 7 | 8 | 9 | 10 | 11 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 25 | 26 | 27 | 28 | 32 | 33 |
34 | 35 |

svelte-form/rule/equal

36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 |
44 | 45 |
46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 |
54 | 55 |
56 | 57 |
58 | 59 | 60 |

Svelte Form validation rules module.

61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 |
70 | 71 | 72 |
Source:
73 |
76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 |
108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 |

(require("svelte-form/rule/equal"))(msg, arg) → {boolean|string}

146 | 147 | 148 | 149 | 150 | 151 | 152 |
153 | 154 | 155 |
Source:
156 |
159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 |
191 | 192 | 193 | 194 | 195 | 196 |
197 |

Equal rule.

198 |
199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 |
Parameters:
211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 272 | 273 | 274 | 275 | 276 | 277 | 279 | 280 | 281 | 282 | 283 |
NameTypeDescription
msg 239 | 240 | 241 | string 242 | 243 | 244 | 245 |

error message.

arg 262 | 263 | 264 | mixed 265 | | 266 | 267 | function 268 | 269 | 270 | 271 |

a matcher object or 278 | matcher function = fn(val) returning true|false.

284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 |
Returns:
301 | 302 | 303 |
304 |

true when valid, error message otherwise.

305 |
306 | 307 | 308 | 309 |
310 |
311 | Type 312 |
313 |
314 | 315 | boolean 316 | | 317 | 318 | string 319 | 320 | 321 |
322 |
323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 |
331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 |
353 | 354 |
355 | 356 | 357 | 358 | 359 | 360 | 361 |
362 | 363 |
364 | 365 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | -------------------------------------------------------------------------------- /docs/module-svelte-form_rule_exclude.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | svelte-form/rule/exclude - Documentation 7 | 8 | 9 | 10 | 11 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 25 | 26 | 27 | 28 | 32 | 33 |
34 | 35 |

svelte-form/rule/exclude

36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 |
44 | 45 |
46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 |
54 | 55 |
56 | 57 |
58 | 59 | 60 |

Svelte Form validation rules module.

61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 |
70 | 71 | 72 |
Source:
73 |
76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 |
108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 |

(require("svelte-form/rule/exclude"))(msg, arg) → {boolean|string}

146 | 147 | 148 | 149 | 150 | 151 | 152 |
153 | 154 | 155 |
Source:
156 |
159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 |
191 | 192 | 193 | 194 | 195 | 196 |
197 |

Max rule

198 |
199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 |
Parameters:
211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 |
NameTypeDescription
msg 239 | 240 | 241 | string 242 | 243 | 244 | 245 |

error message.

arg 262 | 263 | 264 | Array.<number> 265 | | 266 | 267 | Array.<string> 268 | 269 | 270 | 271 |

exclusion list.

283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 |
Returns:
300 | 301 | 302 |
303 |

true when valid, error message otherwise.

304 |
305 | 306 | 307 | 308 |
309 |
310 | Type 311 |
312 |
313 | 314 | boolean 315 | | 316 | 317 | string 318 | 319 | 320 |
321 |
322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 |
330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 |
352 | 353 |
354 | 355 | 356 | 357 | 358 | 359 | 360 |
361 | 362 |
363 | 364 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | -------------------------------------------------------------------------------- /docs/module-svelte-form_rule_ignore.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | svelte-form/rule/ignore - Documentation 7 | 8 | 9 | 10 | 11 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 25 | 26 | 27 | 28 | 32 | 33 |
34 | 35 |

svelte-form/rule/ignore

36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 |
44 | 45 |
46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 |
54 | 55 |
56 | 57 |
58 | 59 | 60 |

Svelte Form validation rules module.

61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 |
70 | 71 | 72 |
Source:
73 |
76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 |
108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 |

(require("svelte-form/rule/ignore"))() → {boolean|string}

146 | 147 | 148 | 149 | 150 | 151 | 152 |
153 | 154 | 155 |
Source:
156 |
159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 |
191 | 192 | 193 | 194 | 195 | 196 |
197 |

Ignore empty rule 198 | This rule causes to break the validation chain for empty values.

199 |
200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 |
Returns:
226 | 227 | 228 |
229 |

true when valid, error message otherwise.

230 |
231 | 232 | 233 | 234 |
235 |
236 | Type 237 |
238 |
239 | 240 | boolean 241 | | 242 | 243 | string 244 | 245 | 246 |
247 |
248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 |
256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 |
278 | 279 |
280 | 281 | 282 | 283 | 284 | 285 | 286 |
287 | 288 |
289 | 290 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | -------------------------------------------------------------------------------- /docs/module-svelte-form_rule_include.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | svelte-form/rule/include - Documentation 7 | 8 | 9 | 10 | 11 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 25 | 26 | 27 | 28 | 32 | 33 |
34 | 35 |

svelte-form/rule/include

36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 |
44 | 45 |
46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 |
54 | 55 |
56 | 57 |
58 | 59 | 60 |

Svelte Form validation rules module.

61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 |

(require("svelte-form/rule/include"))(msg, arg) → {boolean|string}

69 | 70 | 71 | 72 | 73 | 74 | 75 |
76 | 77 | 78 |
Source:
79 |
82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 |
114 | 115 | 116 | 117 | 118 | 119 |
120 |

Include rule

121 |
122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 |
Parameters:
134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 |
NameTypeDescription
msg 162 | 163 | 164 | string 165 | 166 | 167 | 168 |

error message.

arg 185 | 186 | 187 | Array.<number> 188 | | 189 | 190 | Array.<string> 191 | 192 | 193 | 194 |

inclusion list.

206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 |
Returns:
223 | 224 | 225 |
226 |

true when valid, error message otherwise.

227 |
228 | 229 | 230 | 231 |
232 |
233 | Type 234 |
235 |
236 | 237 | boolean 238 | | 239 | 240 | string 241 | 242 | 243 |
244 |
245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 |
257 | 258 | 259 |
Source:
260 |
263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 |
295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 |
330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 |
352 | 353 |
354 | 355 | 356 | 357 | 358 | 359 | 360 |
361 | 362 |
363 | 364 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | -------------------------------------------------------------------------------- /docs/module-svelte-form_rule_max.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | svelte-form/rule/max - Documentation 7 | 8 | 9 | 10 | 11 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 25 | 26 | 27 | 28 | 32 | 33 |
34 | 35 |

svelte-form/rule/max

36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 |
44 | 45 |
46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 |
54 | 55 |
56 | 57 |
58 | 59 | 60 |

Svelte Form validation rules module.

61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 |
70 | 71 | 72 |
Source:
73 |
76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 |
108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 |

(require("svelte-form/rule/max"))(msg, arg) → {boolean|string}

146 | 147 | 148 | 149 | 150 | 151 | 152 |
153 | 154 | 155 |
Source:
156 |
159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 |
191 | 192 | 193 | 194 | 195 | 196 |
197 |

Max rule

198 |
199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 |
Parameters:
211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 |
NameTypeDescription
msg 239 | 240 | 241 | string 242 | 243 | 244 | 245 |

error message.

arg 262 | 263 | 264 | number 265 | 266 | 267 | 268 |

max number.

280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 |
Returns:
297 | 298 | 299 |
300 |

true when valid, error message otherwise.

301 |
302 | 303 | 304 | 305 |
306 |
307 | Type 308 |
309 |
310 | 311 | boolean 312 | | 313 | 314 | string 315 | 316 | 317 |
318 |
319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 |
327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 |
349 | 350 |
351 | 352 | 353 | 354 | 355 | 356 | 357 |
358 | 359 |
360 | 361 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | -------------------------------------------------------------------------------- /docs/module-svelte-form_rule_min.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | svelte-form/rule/min - Documentation 7 | 8 | 9 | 10 | 11 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 25 | 26 | 27 | 28 | 32 | 33 |
34 | 35 |

svelte-form/rule/min

36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 |
44 | 45 |
46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 |
54 | 55 |
56 | 57 |
58 | 59 | 60 |

Svelte Form validation rules module.

61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 |

(require("svelte-form/rule/min"))(msg, arg) → {boolean|string}

69 | 70 | 71 | 72 | 73 | 74 | 75 |
76 | 77 | 78 |
Source:
79 |
82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 |
114 | 115 | 116 | 117 | 118 | 119 |
120 |

Min rule

121 |
122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 |
Parameters:
134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 |
NameTypeDescription
msg 162 | 163 | 164 | string 165 | 166 | 167 | 168 |

error message.

arg 185 | 186 | 187 | number 188 | 189 | 190 | 191 |

min number.

203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 |
Returns:
220 | 221 | 222 |
223 |

true when valid, error message otherwise.

224 |
225 | 226 | 227 | 228 |
229 |
230 | Type 231 |
232 |
233 | 234 | boolean 235 | | 236 | 237 | string 238 | 239 | 240 |
241 |
242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 |
254 | 255 | 256 |
Source:
257 |
260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 |
292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 |
327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 |
349 | 350 |
351 | 352 | 353 | 354 | 355 | 356 | 357 |
358 | 359 |
360 | 361 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | -------------------------------------------------------------------------------- /docs/module-svelte-form_rule_required.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | svelte-form/rule/required - Documentation 7 | 8 | 9 | 10 | 11 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 25 | 26 | 27 | 28 | 32 | 33 |
34 | 35 |

svelte-form/rule/required

36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 |
44 | 45 |
46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 |
54 | 55 |
56 | 57 |
58 | 59 | 60 |

Svelte Form validation rules module.

61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 |
70 | 71 | 72 |
Source:
73 |
76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 |
108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 |

(require("svelte-form/rule/required"))(msg) → {boolean|string}

146 | 147 | 148 | 149 | 150 | 151 | 152 |
153 | 154 | 155 |
Source:
156 |
159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 |
191 | 192 | 193 | 194 | 195 | 196 |
197 |

Required rule

198 |
199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 |
Parameters:
211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 |
NameTypeDescription
msg 239 | 240 | 241 | string 242 | 243 | 244 | 245 |

error message.

257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 |
Returns:
274 | 275 | 276 |
277 |

true when valid, error message otherwise.

278 |
279 | 280 | 281 | 282 |
283 |
284 | Type 285 |
286 |
287 | 288 | boolean 289 | | 290 | 291 | string 292 | 293 | 294 |
295 |
296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 |
304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 |
326 | 327 |
328 | 329 | 330 | 331 | 332 | 333 | 334 |
335 | 336 |
337 | 338 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | -------------------------------------------------------------------------------- /docs/module-svelte-form_rule_rx.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | svelte-form/rule/rx - Documentation 7 | 8 | 9 | 10 | 11 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 25 | 26 | 27 | 28 | 32 | 33 |
34 | 35 |

svelte-form/rule/rx

36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 |
44 | 45 |
46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 |
54 | 55 |
56 | 57 |
58 | 59 | 60 |

Svelte Form validation rules module.

61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 |
70 | 71 | 72 |
Source:
73 |
76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 |
108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 |

(require("svelte-form/rule/rx"))(msg, arg) → {boolean|string}

146 | 147 | 148 | 149 | 150 | 151 | 152 |
153 | 154 | 155 |
Source:
156 |
159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 |
191 | 192 | 193 | 194 | 195 | 196 |
197 |

Custom regex rule.

198 |
199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 |
Parameters:
211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 |
NameTypeDescription
msg 239 | 240 | 241 | string 242 | 243 | 244 | 245 |

error message.

arg 262 | 263 | 264 | number 265 | 266 | 267 | 268 |

Regular expression.

280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 |
Returns:
297 | 298 | 299 |
300 |

true when valid, error message otherwise.

301 |
302 | 303 | 304 | 305 |
306 |
307 | Type 308 |
309 |
310 | 311 | boolean 312 | | 313 | 314 | string 315 | 316 | 317 |
318 |
319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 |
327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 |
349 | 350 |
351 | 352 | 353 | 354 | 355 | 356 | 357 |
358 | 359 |
360 | 361 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | -------------------------------------------------------------------------------- /docs/module-svelte-form_rule_url.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | svelte-form/rule/url - Documentation 7 | 8 | 9 | 10 | 11 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 25 | 26 | 27 | 28 | 32 | 33 |
34 | 35 |

svelte-form/rule/url

36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 |
44 | 45 |
46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 |
54 | 55 |
56 | 57 |
58 | 59 | 60 |

Svelte Form validation rules module.

61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 |

(require("svelte-form/rule/url"))(msg) → {boolean|string}

69 | 70 | 71 | 72 | 73 | 74 | 75 |
76 | 77 | 78 |
Source:
79 |
82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 |
114 | 115 | 116 | 117 | 118 | 119 |
120 |

URL rule

121 |
122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 |
Parameters:
134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 |
NameTypeDescription
msg 162 | 163 | 164 | string 165 | 166 | 167 | 168 |

error message.

180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 |
Returns:
197 | 198 | 199 |
200 |

true when valid, error message otherwise.

201 |
202 | 203 | 204 | 205 |
206 |
207 | Type 208 |
209 |
210 | 211 | boolean 212 | | 213 | 214 | string 215 | 216 | 217 |
218 |
219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 |
231 | 232 | 233 |
Source:
234 |
237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 |
269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 |
304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 |
326 | 327 |
328 | 329 | 330 | 331 | 332 | 333 | 334 |
335 | 336 |
337 | 338 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | -------------------------------------------------------------------------------- /docs/rule_between.js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | rule/between.js - Documentation 7 | 8 | 9 | 10 | 11 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 25 | 26 | 27 | 28 | 32 | 33 |
34 | 35 |

rule/between.js

36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 |
44 |
45 |
/**
46 |  * Svelte Form validation rules module.
47 |  * @module svelte-form/rule/between
48 |  */
49 | 
50 | import min from './min';
51 | import max from './max';
52 | 
53 | /**
54 |  * Between numbers rule
55 |  * @param {string} msg error message.
56 |  * @param {number} arg1 min number.
57 |  * @param {number} arg2 max number.
58 |  * @return {boolean|string} true when valid, error message otherwise.
59 |  */
60 | export default (msg, arg1, arg2) => (value) => {
61 |   if (min('', arg1)(value) !== true || max('', arg2)(value) !== true) {
62 |     return msg;
63 |   }
64 |   return true;
65 | };
66 | 
67 | 
68 |
69 |
70 | 71 | 72 | 73 | 74 | 75 | 76 |
77 | 78 |
79 | 80 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /docs/rule_email.js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | rule/email.js - Documentation 7 | 8 | 9 | 10 | 11 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 25 | 26 | 27 | 28 | 32 | 33 |
34 | 35 |

rule/email.js

36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 |
44 |
45 |
/**
46 |  * Svelte Form validation rules module.
47 |  * @module svelte-form/rule/email
48 |  */
49 | 
50 | import tc from '@spaceavocado/type-check';
51 | 
52 | /**
53 |  * Email rule
54 |  * @param {string} msg error message.
55 |  * @return {boolean|string} true when valid, error message otherwise.
56 |  */
57 | export default (msg) => (value) => {
58 |   if (tc.isNullOrUndefined(value) || tc.not.isString(value)) {
59 |     return msg;
60 |   }
61 |   const rule = /^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$/;
62 |   if (value.match(rule) == null) {
63 |     return msg;
64 |   }
65 |   return true;
66 | };
67 | 
68 |
69 |
70 | 71 | 72 | 73 | 74 | 75 | 76 |
77 | 78 |
79 | 80 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /docs/rule_equal.js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | rule/equal.js - Documentation 7 | 8 | 9 | 10 | 11 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 25 | 26 | 27 | 28 | 32 | 33 |
34 | 35 |

rule/equal.js

36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 |
44 |
45 |
/**
 46 |  * Svelte Form validation rules module.
 47 |  * @module svelte-form/rule/equal
 48 |  */
 49 | 
 50 | import tc from '@spaceavocado/type-check';
 51 | 
 52 | /**
 53 |  * Equal rule.
 54 |  * @param {string} msg error message.
 55 |  * @param {mixed|function} arg a matcher object or
 56 |  * matcher function = fn(val) returning true|false.
 57 |  * @return {boolean|string} true when valid, error message otherwise.
 58 |  */
 59 | export default (msg, arg) => {
 60 |   const customMatcher = tc.isFunction(arg);
 61 |   return (value) => {
 62 |     if (customMatcher === false && tc.isNullOrUndefined(value)) {
 63 |       return msg;
 64 |     }
 65 |     if (customMatcher) {
 66 |       if (arg(value) === false) {
 67 |         return msg;
 68 |       }
 69 |     } else if (value !== arg) {
 70 |       return msg;
 71 |     }
 72 |     return true;
 73 |   };
 74 | };
 75 | 
76 |
77 |
78 | 79 | 80 | 81 | 82 | 83 | 84 |
85 | 86 |
87 | 88 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /docs/rule_exclude.js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | rule/exclude.js - Documentation 7 | 8 | 9 | 10 | 11 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 25 | 26 | 27 | 28 | 32 | 33 |
34 | 35 |

rule/exclude.js

36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 |
44 |
45 |
/**
46 |  * Svelte Form validation rules module.
47 |  * @module svelte-form/rule/exclude
48 |  */
49 | 
50 | import tc from '@spaceavocado/type-check';
51 | 
52 | /**
53 |  * Max rule
54 |  * @param {string} msg error message.
55 |  * @param {number[]|string[]} arg exclusion list.
56 |  * @return {boolean|string} true when valid, error message otherwise.
57 |  */
58 | export default (msg, arg) => (value) => {
59 |   if (tc.isNullOrUndefined(value)
60 |   || (tc.not.isString(value) && tc.not.isNumber(value))
61 |   || tc.isNullOrUndefined(arg)) {
62 |     return msg;
63 |   }
64 |   if (arg.indexOf(value) > -1) {
65 |     return msg;
66 |   }
67 |   return true;
68 | };
69 | 
70 |
71 |
72 | 73 | 74 | 75 | 76 | 77 | 78 |
79 | 80 |
81 | 82 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /docs/rule_ignoreEmpty.js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | rule/ignoreEmpty.js - Documentation 7 | 8 | 9 | 10 | 11 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 25 | 26 | 27 | 28 | 32 | 33 |
34 | 35 |

rule/ignoreEmpty.js

36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 |
44 |
45 |
/**
46 |  * Svelte Form validation rules module.
47 |  * @module svelte-form/rule/ignore
48 |  */
49 | 
50 | import required from './required';
51 | 
52 | // Break validation symbol
53 | export const BREAK_FLAG = Symbol('Break Validation');
54 | 
55 | /**
56 |  * Ignore empty rule
57 |  * This rule causes to break the validation chain for empty values.
58 |  * @return {boolean|string} true when valid, error message otherwise.
59 |  */
60 | export default () => {
61 |   const req = required('');
62 |   return (value) => {
63 |     if (req(value) !== true) {
64 |       return BREAK_FLAG;
65 |     }
66 |     return true;
67 |   };
68 | };
69 | 
70 |
71 |
72 | 73 | 74 | 75 | 76 | 77 | 78 |
79 | 80 |
81 | 82 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /docs/rule_include.js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | rule/include.js - Documentation 7 | 8 | 9 | 10 | 11 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 25 | 26 | 27 | 28 | 32 | 33 |
34 | 35 |

rule/include.js

36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 |
44 |
45 |
/**
46 |  * Svelte Form validation rules module.
47 |  * @module svelte-form/rule/include
48 |  */
49 | 
50 | import tc from '@spaceavocado/type-check';
51 | 
52 | /**
53 |  * Include rule
54 |  * @param {string} msg error message.
55 |  * @param {number[]|string[]} arg inclusion list.
56 |  * @return {boolean|string} true when valid, error message otherwise.
57 |  */
58 | export default (msg, arg) => (value) => {
59 |   if (tc.isNullOrUndefined(value)
60 |   || (tc.not.isString(value) && tc.not.isNumber(value))
61 |   || tc.isNullOrUndefined(arg)) {
62 |     return msg;
63 |   }
64 |   if (arg.indexOf(value) == -1) {
65 |     return msg;
66 |   }
67 |   return true;
68 | };
69 | 
70 |
71 |
72 | 73 | 74 | 75 | 76 | 77 | 78 |
79 | 80 |
81 | 82 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /docs/rule_max.js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | rule/max.js - Documentation 7 | 8 | 9 | 10 | 11 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 25 | 26 | 27 | 28 | 32 | 33 |
34 | 35 |

rule/max.js

36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 |
44 |
45 |
/**
46 |  * Svelte Form validation rules module.
47 |  * @module svelte-form/rule/max
48 |  */
49 | 
50 | import tc from '@spaceavocado/type-check';
51 | 
52 | /**
53 |  * Max rule
54 |  * @param {string} msg error message.
55 |  * @param {number} arg max number.
56 |  * @return {boolean|string} true when valid, error message otherwise.
57 |  */
58 | export default (msg, arg) => (value) => {
59 |   if (tc.isNullOrUndefined(value) || tc.not.isNumber(value)
60 |   || tc.isNullOrUndefined(arg)) {
61 |     return msg;
62 |   }
63 |   if (value > arg) {
64 |     return msg;
65 |   }
66 |   return true;
67 | };
68 | 
69 |
70 |
71 | 72 | 73 | 74 | 75 | 76 | 77 |
78 | 79 |
80 | 81 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /docs/rule_min.js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | rule/min.js - Documentation 7 | 8 | 9 | 10 | 11 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 25 | 26 | 27 | 28 | 32 | 33 |
34 | 35 |

rule/min.js

36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 |
44 |
45 |
/**
46 |  * Svelte Form validation rules module.
47 |  * @module svelte-form/rule/min
48 |  */
49 | 
50 | import tc from '@spaceavocado/type-check';
51 | 
52 | /**
53 |  * Min rule
54 |  * @param {string} msg error message.
55 |  * @param {number} arg min number.
56 |  * @return {boolean|string} true when valid, error message otherwise.
57 |  */
58 | export default (msg, arg) => (value) => {
59 |   if (tc.isNullOrUndefined(value) || tc.not.isNumber(value)
60 |   || tc.isNullOrUndefined(arg)) {
61 |     return msg;
62 |   }
63 |   if (value < arg) {
64 |     return msg;
65 |   }
66 |   return true;
67 | };
68 | 
69 |
70 |
71 | 72 | 73 | 74 | 75 | 76 | 77 |
78 | 79 |
80 | 81 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /docs/rule_required.js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | rule/required.js - Documentation 7 | 8 | 9 | 10 | 11 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 25 | 26 | 27 | 28 | 32 | 33 |
34 | 35 |

rule/required.js

36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 |
44 |
45 |
/**
46 |  * Svelte Form validation rules module.
47 |  * @module svelte-form/rule/required
48 |  */
49 | 
50 | import tc from '@spaceavocado/type-check';
51 | 
52 | /**
53 |  * Required rule
54 |  * @param {string} msg error message.
55 |  * @return {boolean|string} true when valid, error message otherwise.
56 |  */
57 | export default (msg) => (value) => {
58 |   if (tc.isNullOrUndefined(value)
59 |   || tc.isObject(value)
60 |   || tc.isFunction(value)) {
61 |     return msg;
62 |   }
63 |   if (tc.isString(value)) {
64 |     value = value.trim();
65 |     if (value.length == 0) {
66 |       return msg;
67 |     }
68 |   }
69 |   return true;
70 | };
71 | 
72 |
73 |
74 | 75 | 76 | 77 | 78 | 79 | 80 |
81 | 82 |
83 | 84 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /docs/rule_rx.js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | rule/rx.js - Documentation 7 | 8 | 9 | 10 | 11 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 25 | 26 | 27 | 28 | 32 | 33 |
34 | 35 |

rule/rx.js

36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 |
44 |
45 |
/**
46 |  * Svelte Form validation rules module.
47 |  * @module svelte-form/rule/rx
48 |  */
49 | 
50 | import tc from '@spaceavocado/type-check';
51 | 
52 | /**
53 |  * Custom regex rule.
54 |  * @param {string} msg error message.
55 |  * @param {number} arg Regular expression.
56 |  * @return {boolean|string} true when valid, error message otherwise.
57 |  */
58 | export default (msg, arg) => (value) => {
59 |   if (tc.isNullOrUndefined(value) || tc.not.isString(value)) {
60 |     return msg;
61 |   }
62 |   if (value.match(arg) == null) {
63 |     return msg;
64 |   }
65 |   return true;
66 | };
67 | 
68 |
69 |
70 | 71 | 72 | 73 | 74 | 75 | 76 |
77 | 78 |
79 | 80 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /docs/rule_url.js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | rule/url.js - Documentation 7 | 8 | 9 | 10 | 11 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 25 | 26 | 27 | 28 | 32 | 33 |
34 | 35 |

rule/url.js

36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 |
44 |
45 |
/**
46 |  * Svelte Form validation rules module.
47 |  * @module svelte-form/rule/url
48 |  */
49 | 
50 | import tc from '@spaceavocado/type-check';
51 | 
52 | /**
53 |  * URL rule
54 |  * @param {string} msg error message.
55 |  * @return {boolean|string} true when valid, error message otherwise.
56 |  */
57 | export default (msg) => (value) => {
58 |   if (tc.isNullOrUndefined(value) || tc.not.isString(value)) {
59 |     return msg;
60 |   }
61 |   if (value.match(/^https?:\/\/[^\s]*/i) == null) {
62 |     return msg;
63 |   }
64 |   return true;
65 | };
66 | 
67 |
68 |
69 | 70 | 71 | 72 | 73 | 74 | 75 |
76 | 77 |
78 | 79 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /docs/scripts/collapse.js: -------------------------------------------------------------------------------- 1 | function hideAllButCurrent(){ 2 | //by default all submenut items are hidden 3 | //but we need to rehide them for search 4 | document.querySelectorAll("nav > ul > li > ul li").forEach(function(parent) { 5 | parent.style.display = "none"; 6 | }); 7 | 8 | //only current page (if it exists) should be opened 9 | var file = window.location.pathname.split("/").pop().replace(/\.html/, ''); 10 | document.querySelectorAll("nav > ul > li > a").forEach(function(parent) { 11 | var href = parent.attributes.href.value.replace(/\.html/, ''); 12 | if (file === href) { 13 | parent.parentNode.querySelectorAll("ul li").forEach(function(elem) { 14 | elem.style.display = "block"; 15 | }); 16 | } 17 | }); 18 | } 19 | 20 | hideAllButCurrent(); -------------------------------------------------------------------------------- /docs/scripts/linenumber.js: -------------------------------------------------------------------------------- 1 | /*global document */ 2 | (function() { 3 | var source = document.getElementsByClassName('prettyprint source linenums'); 4 | var i = 0; 5 | var lineNumber = 0; 6 | var lineId; 7 | var lines; 8 | var totalLines; 9 | var anchorHash; 10 | 11 | if (source && source[0]) { 12 | anchorHash = document.location.hash.substring(1); 13 | lines = source[0].getElementsByTagName('li'); 14 | totalLines = lines.length; 15 | 16 | for (; i < totalLines; i++) { 17 | lineNumber++; 18 | lineId = 'line' + lineNumber; 19 | lines[i].id = lineId; 20 | if (lineId === anchorHash) { 21 | lines[i].className += ' selected'; 22 | } 23 | } 24 | } 25 | })(); 26 | -------------------------------------------------------------------------------- /docs/scripts/nav.js: -------------------------------------------------------------------------------- 1 | function scrollToNavItem() { 2 | var path = window.location.href.split('/').pop().replace(/\.html/, ''); 3 | document.querySelectorAll('nav a').forEach(function(link) { 4 | var href = link.attributes.href.value.replace(/\.html/, ''); 5 | if (path === href) { 6 | link.scrollIntoView({block: 'center'}); 7 | return; 8 | } 9 | }) 10 | } 11 | 12 | scrollToNavItem(); 13 | -------------------------------------------------------------------------------- /docs/scripts/polyfill.js: -------------------------------------------------------------------------------- 1 | //IE Fix, src: https://www.reddit.com/r/programminghorror/comments/6abmcr/nodelist_lacks_foreach_in_internet_explorer/ 2 | if (typeof(NodeList.prototype.forEach)!==typeof(alert)){ 3 | NodeList.prototype.forEach=Array.prototype.forEach; 4 | } -------------------------------------------------------------------------------- /docs/scripts/prettify/Apache-License-2.0.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /docs/scripts/prettify/lang-css.js: -------------------------------------------------------------------------------- 1 | PR.registerLangHandler(PR.createSimpleLexer([["pln",/^[\t\n\f\r ]+/,null," \t\r\n "]],[["str",/^"(?:[^\n\f\r"\\]|\\(?:\r\n?|\n|\f)|\\[\S\s])*"/,null],["str",/^'(?:[^\n\f\r'\\]|\\(?:\r\n?|\n|\f)|\\[\S\s])*'/,null],["lang-css-str",/^url\(([^"')]*)\)/i],["kwd",/^(?:url|rgb|!important|@import|@page|@media|@charset|inherit)(?=[^\w-]|$)/i,null],["lang-css-kw",/^(-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*)\s*:/i],["com",/^\/\*[^*]*\*+(?:[^*/][^*]*\*+)*\//],["com", 2 | /^(?:<\!--|--\>)/],["lit",/^(?:\d+|\d*\.\d+)(?:%|[a-z]+)?/i],["lit",/^#[\da-f]{3,6}/i],["pln",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i],["pun",/^[^\s\w"']+/]]),["css"]);PR.registerLangHandler(PR.createSimpleLexer([],[["kwd",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i]]),["css-kw"]);PR.registerLangHandler(PR.createSimpleLexer([],[["str",/^[^"')]+/]]),["css-str"]); 3 | -------------------------------------------------------------------------------- /docs/scripts/prettify/prettify.js: -------------------------------------------------------------------------------- 1 | var q=null;window.PR_SHOULD_USE_CONTINUATION=!0; 2 | (function(){function L(a){function m(a){var f=a.charCodeAt(0);if(f!==92)return f;var b=a.charAt(1);return(f=r[b])?f:"0"<=b&&b<="7"?parseInt(a.substring(1),8):b==="u"||b==="x"?parseInt(a.substring(2),16):a.charCodeAt(1)}function e(a){if(a<32)return(a<16?"\\x0":"\\x")+a.toString(16);a=String.fromCharCode(a);if(a==="\\"||a==="-"||a==="["||a==="]")a="\\"+a;return a}function h(a){for(var f=a.substring(1,a.length-1).match(/\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\[0-3][0-7]{0,2}|\\[0-7]{1,2}|\\[\S\s]|[^\\]/g),a= 3 | [],b=[],o=f[0]==="^",c=o?1:0,i=f.length;c122||(d<65||j>90||b.push([Math.max(65,j)|32,Math.min(d,90)|32]),d<97||j>122||b.push([Math.max(97,j)&-33,Math.min(d,122)&-33]))}}b.sort(function(a,f){return a[0]-f[0]||f[1]-a[1]});f=[];j=[NaN,NaN];for(c=0;ci[0]&&(i[1]+1>i[0]&&b.push("-"),b.push(e(i[1])));b.push("]");return b.join("")}function y(a){for(var f=a.source.match(/\[(?:[^\\\]]|\\[\S\s])*]|\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\\d+|\\[^\dux]|\(\?[!:=]|[()^]|[^()[\\^]+/g),b=f.length,d=[],c=0,i=0;c=2&&a==="["?f[c]=h(j):a!=="\\"&&(f[c]=j.replace(/[A-Za-z]/g,function(a){a=a.charCodeAt(0);return"["+String.fromCharCode(a&-33,a|32)+"]"}));return f.join("")}for(var t=0,s=!1,l=!1,p=0,d=a.length;p=5&&"lang-"===b.substring(0,5))&&!(o&&typeof o[1]==="string"))c=!1,b="src";c||(r[f]=b)}i=d;d+=f.length;if(c){c=o[1];var j=f.indexOf(c),k=j+c.length;o[2]&&(k=f.length-o[2].length,j=k-c.length);b=b.substring(5);B(l+i,f.substring(0,j),e,p);B(l+i+j,c,C(b,c),p);B(l+i+k,f.substring(k),e,p)}else p.push(l+i,b)}a.e=p}var h={},y;(function(){for(var e=a.concat(m), 9 | l=[],p={},d=0,g=e.length;d=0;)h[n.charAt(k)]=r;r=r[1];n=""+r;p.hasOwnProperty(n)||(l.push(r),p[n]=q)}l.push(/[\S\s]/);y=L(l)})();var t=m.length;return e}function u(a){var m=[],e=[];a.tripleQuotedStrings?m.push(["str",/^(?:'''(?:[^'\\]|\\[\S\s]|''?(?=[^']))*(?:'''|$)|"""(?:[^"\\]|\\[\S\s]|""?(?=[^"]))*(?:"""|$)|'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$))/,q,"'\""]):a.multiLineStrings?m.push(["str",/^(?:'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$)|`(?:[^\\`]|\\[\S\s])*(?:`|$))/, 10 | q,"'\"`"]):m.push(["str",/^(?:'(?:[^\n\r'\\]|\\.)*(?:'|$)|"(?:[^\n\r"\\]|\\.)*(?:"|$))/,q,"\"'"]);a.verbatimStrings&&e.push(["str",/^@"(?:[^"]|"")*(?:"|$)/,q]);var h=a.hashComments;h&&(a.cStyleComments?(h>1?m.push(["com",/^#(?:##(?:[^#]|#(?!##))*(?:###|$)|.*)/,q,"#"]):m.push(["com",/^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\b|[^\n\r]*)/,q,"#"]),e.push(["str",/^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/,q])):m.push(["com",/^#[^\n\r]*/, 11 | q,"#"]));a.cStyleComments&&(e.push(["com",/^\/\/[^\n\r]*/,q]),e.push(["com",/^\/\*[\S\s]*?(?:\*\/|$)/,q]));a.regexLiterals&&e.push(["lang-regex",/^(?:^^\.?|[!+-]|!=|!==|#|%|%=|&|&&|&&=|&=|\(|\*|\*=|\+=|,|-=|->|\/|\/=|:|::|;|<|<<|<<=|<=|=|==|===|>|>=|>>|>>=|>>>|>>>=|[?@[^]|\^=|\^\^|\^\^=|{|\||\|=|\|\||\|\|=|~|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\s*(\/(?=[^*/])(?:[^/[\\]|\\[\S\s]|\[(?:[^\\\]]|\\[\S\s])*(?:]|$))+\/)/]);(h=a.types)&&e.push(["typ",h]);a=(""+a.keywords).replace(/^ | $/g, 12 | "");a.length&&e.push(["kwd",RegExp("^(?:"+a.replace(/[\s,]+/g,"|")+")\\b"),q]);m.push(["pln",/^\s+/,q," \r\n\t\xa0"]);e.push(["lit",/^@[$_a-z][\w$@]*/i,q],["typ",/^(?:[@_]?[A-Z]+[a-z][\w$@]*|\w+_t\b)/,q],["pln",/^[$_a-z][\w$@]*/i,q],["lit",/^(?:0x[\da-f]+|(?:\d(?:_\d+)*\d*(?:\.\d*)?|\.\d\+)(?:e[+-]?\d+)?)[a-z]*/i,q,"0123456789"],["pln",/^\\[\S\s]?/,q],["pun",/^.[^\s\w"-$'./@\\`]*/,q]);return x(m,e)}function D(a,m){function e(a){switch(a.nodeType){case 1:if(k.test(a.className))break;if("BR"===a.nodeName)h(a), 13 | a.parentNode&&a.parentNode.removeChild(a);else for(a=a.firstChild;a;a=a.nextSibling)e(a);break;case 3:case 4:if(p){var b=a.nodeValue,d=b.match(t);if(d){var c=b.substring(0,d.index);a.nodeValue=c;(b=b.substring(d.index+d[0].length))&&a.parentNode.insertBefore(s.createTextNode(b),a.nextSibling);h(a);c||a.parentNode.removeChild(a)}}}}function h(a){function b(a,d){var e=d?a.cloneNode(!1):a,f=a.parentNode;if(f){var f=b(f,1),g=a.nextSibling;f.appendChild(e);for(var h=g;h;h=g)g=h.nextSibling,f.appendChild(h)}return e} 14 | for(;!a.nextSibling;)if(a=a.parentNode,!a)return;for(var a=b(a.nextSibling,0),e;(e=a.parentNode)&&e.nodeType===1;)a=e;d.push(a)}var k=/(?:^|\s)nocode(?:\s|$)/,t=/\r\n?|\n/,s=a.ownerDocument,l;a.currentStyle?l=a.currentStyle.whiteSpace:window.getComputedStyle&&(l=s.defaultView.getComputedStyle(a,q).getPropertyValue("white-space"));var p=l&&"pre"===l.substring(0,3);for(l=s.createElement("LI");a.firstChild;)l.appendChild(a.firstChild);for(var d=[l],g=0;g=0;){var h=m[e];A.hasOwnProperty(h)?window.console&&console.warn("cannot override language handler %s",h):A[h]=a}}function C(a,m){if(!a||!A.hasOwnProperty(a))a=/^\s*=o&&(h+=2);e>=c&&(a+=2)}}catch(w){"console"in window&&console.log(w&&w.stack?w.stack:w)}}var v=["break,continue,do,else,for,if,return,while"],w=[[v,"auto,case,char,const,default,double,enum,extern,float,goto,int,long,register,short,signed,sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"], 18 | "catch,class,delete,false,import,new,operator,private,protected,public,this,throw,true,try,typeof"],F=[w,"alignof,align_union,asm,axiom,bool,concept,concept_map,const_cast,constexpr,decltype,dynamic_cast,explicit,export,friend,inline,late_check,mutable,namespace,nullptr,reinterpret_cast,static_assert,static_cast,template,typeid,typename,using,virtual,where"],G=[w,"abstract,boolean,byte,extends,final,finally,implements,import,instanceof,null,native,package,strictfp,super,synchronized,throws,transient"], 19 | H=[G,"as,base,by,checked,decimal,delegate,descending,dynamic,event,fixed,foreach,from,group,implicit,in,interface,internal,into,is,lock,object,out,override,orderby,params,partial,readonly,ref,sbyte,sealed,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort,var"],w=[w,"debugger,eval,export,function,get,null,set,undefined,var,with,Infinity,NaN"],I=[v,"and,as,assert,class,def,del,elif,except,exec,finally,from,global,import,in,is,lambda,nonlocal,not,or,pass,print,raise,try,with,yield,False,True,None"], 20 | J=[v,"alias,and,begin,case,class,def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo,rescue,retry,self,super,then,true,undef,unless,until,when,yield,BEGIN,END"],v=[v,"case,done,elif,esac,eval,fi,function,in,local,set,then,until"],K=/^(DIR|FILE|vector|(de|priority_)?queue|list|stack|(const_)?iterator|(multi)?(set|map)|bitset|u?(int|float)\d*)/,N=/\S/,O=u({keywords:[F,H,w,"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END"+ 21 | I,J,v],hashComments:!0,cStyleComments:!0,multiLineStrings:!0,regexLiterals:!0}),A={};k(O,["default-code"]);k(x([],[["pln",/^[^]*(?:>|$)/],["com",/^<\!--[\S\s]*?(?:--\>|$)/],["lang-",/^<\?([\S\s]+?)(?:\?>|$)/],["lang-",/^<%([\S\s]+?)(?:%>|$)/],["pun",/^(?:<[%?]|[%?]>)/],["lang-",/^]*>([\S\s]+?)<\/xmp\b[^>]*>/i],["lang-js",/^]*>([\S\s]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\S\s]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i]]), 22 | ["default-markup","htm","html","mxml","xhtml","xml","xsl"]);k(x([["pln",/^\s+/,q," \t\r\n"],["atv",/^(?:"[^"]*"?|'[^']*'?)/,q,"\"'"]],[["tag",/^^<\/?[a-z](?:[\w-.:]*\w)?|\/?>$/i],["atn",/^(?!style[\s=]|on)[a-z](?:[\w:-]*\w)?/i],["lang-uq.val",/^=\s*([^\s"'>]*(?:[^\s"'/>]|\/(?=\s)))/],["pun",/^[/<->]+/],["lang-js",/^on\w+\s*=\s*"([^"]+)"/i],["lang-js",/^on\w+\s*=\s*'([^']+)'/i],["lang-js",/^on\w+\s*=\s*([^\s"'>]+)/i],["lang-css",/^style\s*=\s*"([^"]+)"/i],["lang-css",/^style\s*=\s*'([^']+)'/i],["lang-css", 23 | /^style\s*=\s*([^\s"'>]+)/i]]),["in.tag"]);k(x([],[["atv",/^[\S\s]+/]]),["uq.val"]);k(u({keywords:F,hashComments:!0,cStyleComments:!0,types:K}),["c","cc","cpp","cxx","cyc","m"]);k(u({keywords:"null,true,false"}),["json"]);k(u({keywords:H,hashComments:!0,cStyleComments:!0,verbatimStrings:!0,types:K}),["cs"]);k(u({keywords:G,cStyleComments:!0}),["java"]);k(u({keywords:v,hashComments:!0,multiLineStrings:!0}),["bsh","csh","sh"]);k(u({keywords:I,hashComments:!0,multiLineStrings:!0,tripleQuotedStrings:!0}), 24 | ["cv","py"]);k(u({keywords:"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END",hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["perl","pl","pm"]);k(u({keywords:J,hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["rb"]);k(u({keywords:w,cStyleComments:!0,regexLiterals:!0}),["js"]);k(u({keywords:"all,and,by,catch,class,else,extends,false,finally,for,if,in,is,isnt,loop,new,no,not,null,of,off,on,or,return,super,then,true,try,unless,until,when,while,yes", 25 | hashComments:3,cStyleComments:!0,multilineStrings:!0,tripleQuotedStrings:!0,regexLiterals:!0}),["coffee"]);k(x([],[["str",/^[\S\s]+/]]),["regex"]);window.prettyPrintOne=function(a,m,e){var h=document.createElement("PRE");h.innerHTML=a;e&&D(h,e);E({g:m,i:e,h:h});return h.innerHTML};window.prettyPrint=function(a){function m(){for(var e=window.PR_SHOULD_USE_CONTINUATION?l.now()+250:Infinity;p=0){var k=k.match(g),f,b;if(b= 26 | !k){b=n;for(var o=void 0,c=b.firstChild;c;c=c.nextSibling)var i=c.nodeType,o=i===1?o?b:c:i===3?N.test(c.nodeValue)?b:o:o;b=(f=o===b?void 0:o)&&"CODE"===f.tagName}b&&(k=f.className.match(g));k&&(k=k[1]);b=!1;for(o=n.parentNode;o;o=o.parentNode)if((o.tagName==="pre"||o.tagName==="code"||o.tagName==="xmp")&&o.className&&o.className.indexOf("prettyprint")>=0){b=!0;break}b||((b=(b=n.className.match(/\blinenums\b(?::(\d+))?/))?b[1]&&b[1].length?+b[1]:!0:!1)&&D(n,b),d={g:k,h:n,i:b},E(d))}}p ul > li:not(.level-hide)").forEach(function(elem) { 16 | elem.style.display = "block"; 17 | }); 18 | 19 | if (typeof hideAllButCurrent === "function"){ 20 | //let's do what ever collapse wants to do 21 | hideAllButCurrent(); 22 | } else { 23 | //menu by default should be opened 24 | document.querySelectorAll("nav > ul > li > ul li").forEach(function(elem) { 25 | elem.style.display = "block"; 26 | }); 27 | } 28 | } else { 29 | //we are searching 30 | document.documentElement.setAttribute(searchAttr, ''); 31 | 32 | //show all parents 33 | document.querySelectorAll("nav > ul > li").forEach(function(elem) { 34 | elem.style.display = "block"; 35 | }); 36 | //hide all results 37 | document.querySelectorAll("nav > ul > li > ul li").forEach(function(elem) { 38 | elem.style.display = "none"; 39 | }); 40 | //show results matching filter 41 | document.querySelectorAll("nav > ul > li > ul a").forEach(function(elem) { 42 | if (!contains(elem.parentNode, search)) { 43 | return; 44 | } 45 | elem.parentNode.style.display = "block"; 46 | }); 47 | //hide parents without children 48 | document.querySelectorAll("nav > ul > li").forEach(function(parent) { 49 | var countSearchA = 0; 50 | parent.querySelectorAll("a").forEach(function(elem) { 51 | if (contains(elem, search)) { 52 | countSearchA++; 53 | } 54 | }); 55 | 56 | var countUl = 0; 57 | var countUlVisible = 0; 58 | parent.querySelectorAll("ul").forEach(function(ulP) { 59 | // count all elements that match the search 60 | if (contains(ulP, search)) { 61 | countUl++; 62 | } 63 | 64 | // count all visible elements 65 | var children = ulP.children 66 | for (i=0; i ul { 227 | padding: 0 10px; 228 | } 229 | 230 | nav > ul > li > a { 231 | color: #606; 232 | margin-top: 10px; 233 | } 234 | 235 | nav ul ul a { 236 | color: hsl(207, 1%, 60%); 237 | border-left: 1px solid hsl(207, 10%, 86%); 238 | } 239 | 240 | nav ul ul a, 241 | nav ul ul a:active { 242 | padding-left: 20px 243 | } 244 | 245 | nav h2 { 246 | font-size: 13px; 247 | margin: 10px 0 0 0; 248 | padding: 0; 249 | } 250 | 251 | nav > h2 > a { 252 | margin: 10px 0 -10px; 253 | color: #606 !important; 254 | } 255 | 256 | footer { 257 | color: hsl(0, 0%, 28%); 258 | margin-left: 250px; 259 | display: block; 260 | padding: 15px; 261 | font-style: italic; 262 | font-size: 90%; 263 | } 264 | 265 | .ancestors { 266 | color: #999 267 | } 268 | 269 | .ancestors a { 270 | color: #999 !important; 271 | } 272 | 273 | .clear { 274 | clear: both 275 | } 276 | 277 | .important { 278 | font-weight: bold; 279 | color: #950B02; 280 | } 281 | 282 | .yes-def { 283 | text-indent: -1000px 284 | } 285 | 286 | .type-signature { 287 | color: #CA79CA 288 | } 289 | 290 | .type-signature:last-child { 291 | color: #eee; 292 | } 293 | 294 | .name, .signature { 295 | font-family: Consolas, Monaco, 'Andale Mono', monospace 296 | } 297 | 298 | .signature { 299 | color: #fc83ff; 300 | } 301 | 302 | .details { 303 | margin-top: 6px; 304 | border-left: 2px solid #DDD; 305 | line-height: 20px; 306 | font-size: 14px; 307 | } 308 | 309 | .details dt { 310 | width: auto; 311 | float: left; 312 | padding-left: 10px; 313 | } 314 | 315 | .details dd { 316 | margin-left: 70px; 317 | margin-top: 6px; 318 | margin-bottom: 6px; 319 | } 320 | 321 | .details ul { 322 | margin: 0 323 | } 324 | 325 | .details ul { 326 | list-style-type: none 327 | } 328 | 329 | .details pre.prettyprint { 330 | margin: 0 331 | } 332 | 333 | .details .object-value { 334 | padding-top: 0 335 | } 336 | 337 | .description { 338 | margin-bottom: 1em; 339 | margin-top: 1em; 340 | } 341 | 342 | .code-caption { 343 | font-style: italic; 344 | font-size: 107%; 345 | margin: 0; 346 | } 347 | 348 | .prettyprint { 349 | font-size: 14px; 350 | overflow: auto; 351 | } 352 | 353 | .prettyprint.source { 354 | width: inherit; 355 | line-height: 18px; 356 | display: block; 357 | background-color: #0d152a; 358 | color: #aeaeae; 359 | } 360 | 361 | .prettyprint code { 362 | line-height: 18px; 363 | display: block; 364 | background-color: #0d152a; 365 | color: #4D4E53; 366 | } 367 | 368 | .prettyprint > code { 369 | padding: 15px; 370 | } 371 | 372 | .prettyprint .linenums code { 373 | padding: 0 15px 374 | } 375 | 376 | .prettyprint .linenums li:first-of-type code { 377 | padding-top: 15px 378 | } 379 | 380 | .prettyprint code span.line { 381 | display: inline-block 382 | } 383 | 384 | .prettyprint.linenums { 385 | padding-left: 70px; 386 | -webkit-user-select: none; 387 | -moz-user-select: none; 388 | -ms-user-select: none; 389 | user-select: none; 390 | } 391 | 392 | .prettyprint.linenums ol { 393 | padding-left: 0 394 | } 395 | 396 | .prettyprint.linenums li { 397 | border-left: 3px #34446B solid; 398 | } 399 | 400 | .prettyprint.linenums li.selected, .prettyprint.linenums li.selected * { 401 | background-color: #34446B; 402 | } 403 | 404 | .prettyprint.linenums li * { 405 | -webkit-user-select: text; 406 | -moz-user-select: text; 407 | -ms-user-select: text; 408 | user-select: text; 409 | } 410 | 411 | table { 412 | border-spacing: 0; 413 | border: 1px solid #ddd; 414 | border-collapse: collapse; 415 | border-radius: 3px; 416 | box-shadow: 0 1px 3px rgba(0,0,0,0.1); 417 | width: 100%; 418 | font-size: 14px; 419 | margin: 1em 0; 420 | } 421 | 422 | td, th { 423 | margin: 0px; 424 | text-align: left; 425 | vertical-align: top; 426 | padding: 10px; 427 | display: table-cell; 428 | } 429 | 430 | thead tr, thead tr { 431 | background-color: #fff; 432 | font-weight: bold; 433 | border-bottom: 1px solid #ddd; 434 | } 435 | 436 | .params .type { 437 | white-space: nowrap; 438 | } 439 | 440 | .params code { 441 | white-space: pre; 442 | } 443 | 444 | .params td, .params .name, .props .name, .name code { 445 | color: #4D4E53; 446 | font-family: Consolas, Monaco, 'Andale Mono', monospace; 447 | font-size: 100%; 448 | } 449 | 450 | .params td { 451 | border-top: 1px solid #eee 452 | } 453 | 454 | .params td.description > p:first-child, .props td.description > p:first-child { 455 | margin-top: 0; 456 | padding-top: 0; 457 | } 458 | 459 | .params td.description > p:last-child, .props td.description > p:last-child { 460 | margin-bottom: 0; 461 | padding-bottom: 0; 462 | } 463 | 464 | span.param-type, .params td .param-type, .param-type dd { 465 | color: #606; 466 | font-family: Consolas, Monaco, 'Andale Mono', monospace 467 | } 468 | 469 | .param-type dt, .param-type dd { 470 | display: inline-block 471 | } 472 | 473 | .param-type { 474 | margin: 14px 0; 475 | } 476 | 477 | .disabled { 478 | color: #454545 479 | } 480 | 481 | /* navicon button */ 482 | .navicon-button { 483 | display: none; 484 | position: relative; 485 | padding: 2.0625rem 1.5rem; 486 | transition: 0.25s; 487 | cursor: pointer; 488 | -webkit-user-select: none; 489 | -moz-user-select: none; 490 | -ms-user-select: none; 491 | user-select: none; 492 | opacity: .8; 493 | } 494 | .navicon-button .navicon:before, .navicon-button .navicon:after { 495 | transition: 0.25s; 496 | } 497 | .navicon-button:hover { 498 | transition: 0.5s; 499 | opacity: 1; 500 | } 501 | .navicon-button:hover .navicon:before, .navicon-button:hover .navicon:after { 502 | transition: 0.25s; 503 | } 504 | .navicon-button:hover .navicon:before { 505 | top: .825rem; 506 | } 507 | .navicon-button:hover .navicon:after { 508 | top: -.825rem; 509 | } 510 | 511 | /* navicon */ 512 | .navicon { 513 | position: relative; 514 | width: 2.5em; 515 | height: .3125rem; 516 | background: #000; 517 | transition: 0.3s; 518 | border-radius: 2.5rem; 519 | } 520 | .navicon:before, .navicon:after { 521 | display: block; 522 | content: ""; 523 | height: .3125rem; 524 | width: 2.5rem; 525 | background: #000; 526 | position: absolute; 527 | z-index: -1; 528 | transition: 0.3s 0.25s; 529 | border-radius: 1rem; 530 | } 531 | .navicon:before { 532 | top: .625rem; 533 | } 534 | .navicon:after { 535 | top: -.625rem; 536 | } 537 | 538 | /* open */ 539 | .nav-trigger:checked + label:not(.steps) .navicon:before, 540 | .nav-trigger:checked + label:not(.steps) .navicon:after { 541 | top: 0 !important; 542 | } 543 | 544 | .nav-trigger:checked + label .navicon:before, 545 | .nav-trigger:checked + label .navicon:after { 546 | transition: 0.5s; 547 | } 548 | 549 | /* Minus */ 550 | .nav-trigger:checked + label { 551 | -webkit-transform: scale(0.75); 552 | transform: scale(0.75); 553 | } 554 | 555 | /* × and + */ 556 | .nav-trigger:checked + label.plus .navicon, 557 | .nav-trigger:checked + label.x .navicon { 558 | background: transparent; 559 | } 560 | 561 | .nav-trigger:checked + label.plus .navicon:before, 562 | .nav-trigger:checked + label.x .navicon:before { 563 | -webkit-transform: rotate(-45deg); 564 | transform: rotate(-45deg); 565 | background: #FFF; 566 | } 567 | 568 | .nav-trigger:checked + label.plus .navicon:after, 569 | .nav-trigger:checked + label.x .navicon:after { 570 | -webkit-transform: rotate(45deg); 571 | transform: rotate(45deg); 572 | background: #FFF; 573 | } 574 | 575 | .nav-trigger:checked + label.plus { 576 | -webkit-transform: scale(0.75) rotate(45deg); 577 | transform: scale(0.75) rotate(45deg); 578 | } 579 | 580 | .nav-trigger:checked ~ nav { 581 | left: 0 !important; 582 | } 583 | 584 | .nav-trigger:checked ~ .overlay { 585 | display: block; 586 | } 587 | 588 | .nav-trigger { 589 | position: fixed; 590 | top: 0; 591 | clip: rect(0, 0, 0, 0); 592 | } 593 | 594 | .overlay { 595 | display: none; 596 | position: fixed; 597 | top: 0; 598 | bottom: 0; 599 | left: 0; 600 | right: 0; 601 | width: 100%; 602 | height: 100%; 603 | background: hsla(0, 0%, 0%, 0.5); 604 | z-index: 1; 605 | } 606 | 607 | /* nav level */ 608 | .level-hide { 609 | display: none; 610 | } 611 | html[data-search-mode] .level-hide { 612 | display: block; 613 | } 614 | 615 | 616 | @media only screen and (min-width: 320px) and (max-width: 680px) { 617 | body { 618 | overflow-x: hidden; 619 | } 620 | 621 | nav { 622 | background: #FFF; 623 | width: 250px; 624 | height: 100%; 625 | position: fixed; 626 | top: 0; 627 | right: 0; 628 | bottom: 0; 629 | left: -250px; 630 | z-index: 3; 631 | padding: 0 10px; 632 | transition: left 0.2s; 633 | } 634 | 635 | .navicon-button { 636 | display: inline-block; 637 | position: fixed; 638 | top: 1.5em; 639 | right: 0; 640 | z-index: 2; 641 | } 642 | 643 | #main { 644 | width: 100%; 645 | min-width: 360px; 646 | } 647 | 648 | #main h1.page-title { 649 | margin: 1em 0; 650 | } 651 | 652 | #main section { 653 | padding: 0; 654 | } 655 | 656 | footer { 657 | margin-left: 0; 658 | } 659 | } 660 | 661 | /** Add a '#' to static members */ 662 | [data-type="member"] a::before { 663 | content: '#'; 664 | display: inline-block; 665 | margin-left: -14px; 666 | margin-right: 5px; 667 | } 668 | 669 | #disqus_thread{ 670 | margin-left: 30px; 671 | } 672 | -------------------------------------------------------------------------------- /docs/styles/prettify.css: -------------------------------------------------------------------------------- 1 | .pln { 2 | color: #ddd; 3 | } 4 | 5 | /* string content */ 6 | .str { 7 | color: #61ce3c; 8 | } 9 | 10 | /* a keyword */ 11 | .kwd { 12 | color: #fbde2d; 13 | } 14 | 15 | /* a comment */ 16 | .com { 17 | color: #aeaeae; 18 | } 19 | 20 | /* a type name */ 21 | .typ { 22 | color: #8da6ce; 23 | } 24 | 25 | /* a literal value */ 26 | .lit { 27 | color: #fbde2d; 28 | } 29 | 30 | /* punctuation */ 31 | .pun { 32 | color: #ddd; 33 | } 34 | 35 | /* lisp open bracket */ 36 | .opn { 37 | color: #000000; 38 | } 39 | 40 | /* lisp close bracket */ 41 | .clo { 42 | color: #000000; 43 | } 44 | 45 | /* a markup tag name */ 46 | .tag { 47 | color: #8da6ce; 48 | } 49 | 50 | /* a markup attribute name */ 51 | .atn { 52 | color: #fbde2d; 53 | } 54 | 55 | /* a markup attribute value */ 56 | .atv { 57 | color: #ddd; 58 | } 59 | 60 | /* a declaration */ 61 | .dec { 62 | color: #EF5050; 63 | } 64 | 65 | /* a variable name */ 66 | .var { 67 | color: #c82829; 68 | } 69 | 70 | /* a function name */ 71 | .fun { 72 | color: #4271ae; 73 | } 74 | 75 | /* Specify class=linenums on a pre to get line numbering */ 76 | ol.linenums { 77 | margin-top: 0; 78 | margin-bottom: 0; 79 | } 80 | -------------------------------------------------------------------------------- /jsdoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": ["plugins/markdown"], 3 | "opts": { 4 | "template": "node_modules/docdash" 5 | }, 6 | "source": { 7 | "exclude": ["node_modules", "lib"], 8 | "excludePattern": ".*test.*" 9 | } 10 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@spaceavocado/svelte-form", 3 | "version": "1.0.4", 4 | "description": "Simple Svelte form model handler and input validations.", 5 | "main": "lib/svelte-form.js", 6 | "module": "lib/svelte-form.esm.js", 7 | "files": [ 8 | "/lib", 9 | "changelog.md" 10 | ], 11 | "author": "David Horak ", 12 | "license": "MIT", 13 | "scripts": { 14 | "build": "rollup -c", 15 | "test": "jest --verbose /src/*", 16 | "docs": "jsdoc . -r -d docs -c jsdoc.json -R readme.md", 17 | "prepare": "npm run build", 18 | "license-check": "license-checker --summary --excludePrivatePackages --onlyAllow 'MIT;MIT OR X11;BSD;ISC;Apache-2.0;MPL-2.0;Apache 2.0;WTFPL;CC0-1.0;CC-BY-3.0;CC-BY-4.0;Unlicense;Zlib;Apache*'" 19 | }, 20 | "repository": { 21 | "type": "git", 22 | "url": "git@github.com:spaceavocado/svelte-form.git" 23 | }, 24 | "bugs": { 25 | "url": "https://github.com/spaceavocado/svelte-form/issues" 26 | }, 27 | "homepage": "https://github.com/spaceavocado/svelte-form", 28 | "keywords": [ 29 | "svelte", 30 | "form", 31 | "validation", 32 | "plugins" 33 | ], 34 | "dependencies": { 35 | "@spaceavocado/type-check": "^1.0.1" 36 | }, 37 | "peerDependencies": { 38 | "svelte": "^3.8.1" 39 | }, 40 | "devDependencies": { 41 | "@babel/core": "^7.5.5", 42 | "@babel/preset-env": "^7.5.5", 43 | "babel-eslint": "^10.0.2", 44 | "docdash": "^1.1.1", 45 | "eslint": "^6.2.1", 46 | "eslint-config-google": "^0.13.0", 47 | "jest": "^24.8.0", 48 | "license-checker": "^25.0.1", 49 | "rollup": "^1.20.0", 50 | "rollup-plugin-babel": "^4.3.3", 51 | "rollup-plugin-commonjs": "^10.0.2", 52 | "rollup-plugin-eslint": "^7.0.0", 53 | "rollup-plugin-node-resolve": "^5.2.0", 54 | "rollup-plugin-replace": "^2.2.0", 55 | "svelte": "^3.8.1" 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Svelte Form 2 | Simple [Svelte](#https://svelte.dev) Form model handler and form fields validation library. It is designed to give maximum freedom in the actual input component construction, i.e. there are not actual build-in input components, rather examples how to build one. 3 | 4 | To see the details code documentation, please read the [Code Documentation](https://spaceavocado.github.io/svelte-form/). 5 | 6 | **Quick Links** 7 | * [Webpack Setup](#webpack-setup) 8 | * [Rollup Setup](#rollup-setup) 9 | 10 | **Table of Content** 11 | - [Svelte Form](#svelte-form) 12 | - [Installation via NPM or Yarn](#installation-via-npm-or-yarn) 13 | - [Webpack Setup](#webpack-setup) 14 | - [Rollup Setup](#rollup-setup) 15 | - [Essentials](#essentials) 16 | - [Create the Form](#create-the-form) 17 | - [Input Binding](#input-binding) 18 | - [Form State](#form-state) 19 | - [Form Data](#form-data) 20 | - [Form Field Validation](#form-field-validation) 21 | - [Builtin Validation Rules](#builtin-validation-rules) 22 | - [Required](#required) 23 | - [Equal](#equal) 24 | - [Email](#email) 25 | - [URL](#url) 26 | - [Min](#min) 27 | - [Max](#max) 28 | - [Between](#between) 29 | - [Regular Expression](#regular-expression) 30 | - [Exclude](#exclude) 31 | - [Include](#include) 32 | - [Ignore Empty](#ignore-empty) 33 | - [Custom Validation Rule](#custom-validation-rule) 34 | - [Trigger Form Validation](#trigger-form-validation) 35 | - [API](#api) 36 | - [Create Form](#create-form) 37 | - [Form Options](#form-options) 38 | - [Form Object](#form-object) 39 | - [Form Field Object](#form-field-object) 40 | - [Changes](#changes) 41 | - [About](#about) 42 | - [Contributing](#contributing) 43 | - [Pull Request Process](#pull-request-process) 44 | - [License](#license) 45 | 46 | ## Installation via NPM or Yarn 47 | ```sh 48 | npm install -D @spaceavocado/svelte-form 49 | ``` 50 | ```sh 51 | yarn add @spaceavocado/svelte-form -D 52 | ``` 53 | 54 | ## Webpack Setup 55 | Please see the [Svelte Webpack Template](https://github.com/sveltejs/template-webpack). 56 | Important setup in the **webpack.config.js**: 57 | ```javascript 58 | resolve: { 59 | // This alias is important to prevent svelte mismatch 60 | // between your code, and the 3rd party components. 61 | alias: { 62 | svelte: path.resolve('node_modules', 'svelte') 63 | }, 64 | extensions: ['.mjs', '.js', '.svelte'], 65 | mainFields: ['svelte', 'browser', 'module', 'main'] 66 | }, 67 | 68 | module: { 69 | rules: [ 70 | { 71 | test: /\.svelte$/, 72 | // Do not exclude: /(node_modules)/ since the router 73 | // components are located in the node_modules 74 | use: { 75 | loader: 'svelte-loader', 76 | options: { 77 | emitCss: true, 78 | hotReload: true 79 | } 80 | } 81 | } 82 | ] 83 | } 84 | ``` 85 | 86 | ## Rollup Setup 87 | rollup.config.js: 88 | ```javascript 89 | import babel from 'rollup-plugin-babel'; 90 | import resolve from 'rollup-plugin-node-resolve'; 91 | import commonjs from 'rollup-plugin-commonjs'; 92 | import svelte from 'rollup-plugin-svelte'; 93 | 94 | export default { 95 | input: './src/index.js', 96 | output: { 97 | file: './dist/bundle.js', 98 | format: 'iife' 99 | }, 100 | plugins: [ 101 | resolve(), 102 | commonjs({ 103 | include: 'node_modules/**', 104 | }), 105 | svelte(), 106 | babel({ 107 | exclude: 'node_modules/**', 108 | }), 109 | ] 110 | } 111 | ``` 112 | 113 | ## Essentials 114 | Note: All code below uses ES2015+. 115 | 116 | ### Create the Form 117 | form.svelte: 118 | ```javascript 119 | import createForm from '@spaceavocado/svelte-form'; 120 | 121 | // An example of a form without validation 122 | const form = createForm({ 123 | username: '', 124 | password: '', 125 | }); 126 | ``` 127 | > To get more details about the createForm method, please see [Create Form](#create-form). 128 | 129 | ### Input Binding 130 | form.svelte: 131 | ```html 132 | 142 | 143 | 144 | ``` 145 | text.svelte: 146 | ```html 147 | 159 | 160 |
161 | 162 |

{$state.error}

163 |
164 | 165 | 177 | ``` 178 | * The state store is a derived store based on the value store, performing the input validation each time the value changes. 179 | * The **form.field(name)** method gets the field stores, for more details see [Form Field Object](#form-field-object). 180 | 181 | ### Form State 182 | The form state is a svelte store holding the form validation state. 183 | 184 | form.svelte: 185 | ```javascript 186 | import createForm from '@spaceavocado/svelte-form'; 187 | 188 | // An example of a form without validation 189 | const form = createForm({ 190 | username: '', 191 | password: '', 192 | }); 193 | 194 | // You can directly subscribe to form state change 195 | form.subscribe((f) => console.log(f.valid)); 196 | // or shorthand access. 197 | console.log($form.valid) 198 | ``` 199 | 200 | > To get more details about the form, please see [Form Object](#form-object). 201 | 202 | ### Form Data 203 | You can get the current form date anytime by calling: 204 | ```javascript 205 | import createForm from '@spaceavocado/svelte-form'; 206 | 207 | // An example of a form without validation 208 | const form = createForm({ 209 | username: '', 210 | password: '', 211 | }); 212 | 213 | // Get the form current data 214 | const data = form.data(); 215 | ``` 216 | 217 | ### Form Field Validation 218 | Validation functions could be passed for individual form fields: 219 | 220 | ```javascript 221 | import createForm from '@spaceavocado/svelte-form'; 222 | import {required, email} from '@spaceavocado/svelte-form'; 223 | 224 | // An example of a form without validation 225 | const form = createForm( 226 | // Form fields 227 | { 228 | username: '', 229 | password: '', 230 | }, 231 | // Form validation - optional 232 | // Collection of validation rules or single rule. 233 | { 234 | username: [ 235 | required('This field is required'), 236 | email('Invalid email format') 237 | ], 238 | password: required('This field is required'), 239 | } 240 | ); 241 | ``` 242 | 243 | **More information:** 244 | * [Builtin Validation Rules](#builtin-validation-rules). 245 | * [Custom Validation Rule](#custom-validation-rule). 246 | 247 | ### Builtin Validation Rules 248 | 249 | #### Required 250 | ```javascript 251 | import {required} from '@spaceavocado/svelte-form'; 252 | 253 | // Create new rule 254 | const rule = required('Error message'); 255 | ``` 256 | 257 | #### Equal 258 | ```javascript 259 | import {equal} from '@spaceavocado/svelte-form'; 260 | 261 | // The value must be equal to 5 262 | const rule = equal('Error message', 5); 263 | 264 | // Equal can accept fn(val)->boolean as an argument for a custom 265 | // equality matching. 266 | const customMatcherRule = equal('Error message', (val) => { 267 | return val === 5; 268 | }); 269 | ``` 270 | 271 | #### Email 272 | ```javascript 273 | import {email} from '@spaceavocado/svelte-form'; 274 | 275 | // Create new rule 276 | const rule = email('Error message'); 277 | ``` 278 | 279 | #### URL 280 | ```javascript 281 | import {url} from '@spaceavocado/svelte-form'; 282 | 283 | // Create new rule 284 | const rule = url('Error message'); 285 | ``` 286 | 287 | #### Min 288 | ```javascript 289 | import {min} from '@spaceavocado/svelte-form'; 290 | 291 | // The value must be 5 and more. 292 | const rule = min('Error message', 5); 293 | ``` 294 | 295 | #### Max 296 | ```javascript 297 | import {max} from '@spaceavocado/svelte-form'; 298 | 299 | // The value must be 5 and less. 300 | const rule = max('Error message', 5); 301 | ``` 302 | 303 | #### Between 304 | ```javascript 305 | import {between} from '@spaceavocado/svelte-form'; 306 | 307 | // The value must be between 5 and 10 inclusively. 308 | const rule = between('Error message', 5, 10); 309 | ``` 310 | 311 | #### Regular Expression 312 | ```javascript 313 | import {rx} from '@spaceavocado/svelte-form'; 314 | 315 | // The value must match custom regular expression. 316 | const rule = rx('Error message', /\d+\.\d+/); 317 | ``` 318 | 319 | #### Exclude 320 | ```javascript 321 | import {exclude} from '@spaceavocado/svelte-form'; 322 | 323 | // The value must not be present in the exclusion array. 324 | const ruleA = exclude('Error message', [1, 2]); 325 | const ruleB = exclude('Error message', ['toronto', 'new-york']); 326 | ``` 327 | 328 | #### Include 329 | ```javascript 330 | import {include} from '@spaceavocado/svelte-form'; 331 | 332 | // The value must be present in the inclusion array. 333 | const ruleA = include('Error message', [1, 2]); 334 | const ruleB = include('Error message', ['toronto', 'new-york']); 335 | ``` 336 | 337 | #### Ignore Empty 338 | This is a special rule which might be used to the ignore empty fields, i.e. any other validation rules will be tested only if the value in not empty. 339 | ```javascript 340 | import {ignoreEmpty, url} from '@spaceavocado/svelte-form'; 341 | 342 | // An example usage 343 | const form = createForm( 344 | // Form fields 345 | { 346 | website: '', 347 | }, 348 | // URL validation will be tested only if the website in not empty. 349 | { 350 | website: [ 351 | ignoreEmpty(), 352 | url('Invalid URL'), 353 | ], 354 | } 355 | ); 356 | 357 | ``` 358 | 359 | ### Custom Validation Rule 360 | Custom validation rule must be a function accepting a tested value, and expected to return true when valid, or error message string in not valid, e.g.: 361 | ```javascript 362 | const invoice = (msg) => (value) => { 363 | if (value.match(/inv-\d+/) === null) { 364 | return msg; 365 | } 366 | return true; 367 | } 368 | 369 | // The actual rule expected by the form field, e.g. fn(val)->true|string 370 | const rule = invoice('Invalid invoice number'); 371 | ``` 372 | 373 | ### Trigger Form Validation 374 | Validation could be trigger all fields in this manner: 375 | 376 | ```javascript 377 | import createForm from '@spaceavocado/svelte-form'; 378 | import {required, email} from '@spaceavocado/svelte-form'; 379 | 380 | // An example of a form without validation 381 | const form = createForm( 382 | // Form fields 383 | { 384 | username: '', 385 | password: '', 386 | }, 387 | // Form validation - optional 388 | // Collection of validation rules or single rule. 389 | { 390 | username: [ 391 | required('This field is required'), 392 | email('Invalid email format') 393 | ], 394 | password: required('This field is required'), 395 | } 396 | ); 397 | 398 | // Trigger validation of all fields 399 | form.validate(); 400 | ``` 401 | 402 | ## API 403 | To see the details code documentation, please read the [Code Documentation](https://spaceavocado.github.io/svelte-form/) 404 | 405 | ### Create Form 406 | ```javascript 407 | import createForm from '@spaceavocado/svelte-form'; 408 | 409 | // Please see the opts below. 410 | const formOpts = {}; 411 | 412 | // Please see the Form object for details on returned object 413 | const form = createForm( 414 | // Form fields 415 | { 416 | username: '', 417 | password: '', 418 | }, 419 | // Form validation - optional 420 | // Collection of validation rules or single rule. 421 | { 422 | username: [ 423 | required('This field is required'), 424 | email('Invalid email format') 425 | ], 426 | password: required('This field is required'), 427 | }, 428 | // Form options - optional 429 | formOpts, 430 | ); 431 | ``` 432 | 433 | #### Form Options 434 | | Property | Description | Type | 435 | | :----------------- | :---------------------------------------------------------------- | :------ | 436 | | onCreateValidation | Validate form fields when the form is created. Defaults to false. | boolean | 437 | 438 | 439 | ### Form Object 440 | | Property | Description | Type | 441 | | :-------- | :------------------------------------------------------------------------------------------------------------- | :------- | 442 | | subscribe | Svelte store, context {valid: boolean}. | function | 443 | | field | Get form field observable value and state. Signature fn(key), returns [Form Field Object](#form-field-object). | function | 444 | | data | Get all form fields data. Signature fn(). | function | 445 | 446 | ### Form Field Object 447 | | Property | Description | Type | 448 | | :------- | :------------------------------------------------------ | :------- | 449 | | value | Svelte store, context: mixed value. | function | 450 | | state | Svelte store, context: {valid: boolean, error: string}. | function | 451 | 452 | ## Changes 453 | To see the changes that were made in a given release, please lookup the tag on the releases page. The full changelog could be seen here [changelog.md](https://github.com/spaceavocado/svelte-form/blob/master/changelog.md) 454 | 455 | ## About 456 | This project is mainly to explore and test [Svelte](#https://svelte.dev) in SPA realm. Any feedback, contribution to this project is welcomed. 457 | 458 | The project is in a beta phase, therefore there might be major changes in near future, the annotation should stay the same, though. 459 | 460 | ## Contributing 461 | When contributing to this repository, please first discuss the change you wish to make via issue, email, or any other method with the owners of this repository before making a change. 462 | 463 | ### Pull Request Process 464 | 1. Fork it 465 | 2. Create your feature branch (git checkout -b ft/new-feature-name) 466 | 3. Commit your changes (git commit -am 'Add some feature') 467 | 4. Push to the branch (git push origin ft/new-feature-name) 468 | 5. Create new Pull Request 469 | > Please make an issue first if the change is likely to increase. 470 | 471 | ## License 472 | Svelte Router is released under the MIT license. See [LICENSE.txt](https://github.com/spaceavocado/svelte-router/blob/master/LICENSE.txt). -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | import babel from 'rollup-plugin-babel'; 2 | import resolve from 'rollup-plugin-node-resolve'; 3 | import commonjs from 'rollup-plugin-commonjs'; 4 | import replace from 'rollup-plugin-replace'; 5 | import {eslint} from 'rollup-plugin-eslint'; 6 | 7 | const libraryName = 'svelte-form'; 8 | const input = './src/index.js'; 9 | const plugins = [ 10 | resolve(), 11 | commonjs(), 12 | eslint(), 13 | babel({ 14 | exclude: 'node_modules/**', 15 | }), 16 | replace({ 17 | 'process.env.NODE_ENV': JSON.stringify('production'), 18 | }), 19 | ]; 20 | 21 | export default 22 | { 23 | input, 24 | output: [ 25 | { 26 | file: './lib/'+ libraryName +'.esm.js', 27 | format: 'esm', 28 | }, 29 | { 30 | file: './lib/'+ libraryName +'.js', 31 | format: 'cjs', 32 | exports: 'named', 33 | }, 34 | ], 35 | plugins, 36 | external: [ 37 | '@spaceavocado/type-check', 38 | 'svelte', 39 | 'svelte/store', 40 | ], 41 | }; 42 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Svelte Form module. 3 | * @module svelte-form 4 | */ 5 | 6 | import tc from '@spaceavocado/type-check'; 7 | import {writable, derived, get} from 'svelte/store'; 8 | import {BREAK_FLAG} from './rule/ignoreEmpty'; 9 | 10 | // Rules 11 | import required from './rule/required'; 12 | import email from './rule/email'; 13 | import url from './rule/url'; 14 | import equal from './rule/equal'; 15 | import min from './rule/min'; 16 | import max from './rule/max'; 17 | import between from './rule/between'; 18 | import rx from './rule/rx'; 19 | import exclude from './rule/exclude'; 20 | import include from './rule/include'; 21 | import ignoreEmpty from './rule/ignoreEmpty'; 22 | 23 | export { 24 | ignoreEmpty, 25 | required, 26 | email, 27 | url, 28 | equal, 29 | min, 30 | max, 31 | between, 32 | rx, 33 | exclude, 34 | include, 35 | }; 36 | 37 | /** 38 | * Get input validation rules 39 | * @private 40 | * @param {string} key input key. 41 | * @param {object} validation rules. 42 | * @return {function[]} validation rules. 43 | */ 44 | export function validationRules(key, validation) { 45 | validation = validation || {}; 46 | if (tc.isNullOrUndefined(validation[key])) { 47 | return []; 48 | } 49 | if (tc.isArray(validation[key])) { 50 | return validation[key]; 51 | } 52 | return [validation[key]]; 53 | } 54 | 55 | /** 56 | * Validate field 57 | * @private 58 | * @param {mixed} value field value. 59 | * @param {function[]} rules filed validation rules. 60 | * @return {boolean|string} true = no error, string = error message. 61 | */ 62 | export function validate(value, rules) { 63 | for (let i = 0; i < rules.length; i++) { 64 | const err = rules[i](value); 65 | if (err === BREAK_FLAG) { 66 | return true; 67 | } else if (err !== true) { 68 | return err; 69 | } 70 | } 71 | return true; 72 | } 73 | 74 | /** 75 | * Form object 76 | * @typedef Form 77 | * @property {function} subscribe Svelte store, context {valid: boolean}. 78 | * @property {function} field Get form field observable value and state. 79 | * Signature fn(key), returns {module:svelte-form~FormField}. 80 | * @property {function} validate Trigger all fields validation. 81 | * @property {function} data Get all form fields data. Signature fn(). 82 | */ 83 | 84 | /** 85 | * FormField object 86 | * @typedef FormField 87 | * @property {function} value Writeable Svelte store, context: mixed value. 88 | * @property {function} state Readonly Svelte store, 89 | * context: {valid: boolean, error: string}. 90 | */ 91 | 92 | /** 93 | * Create a new form store 94 | * @param {object} fields Form fields. 95 | * @param {object} validation Validation rules mapping. 96 | * Where each key is a fn(val)->boolean validation function or 97 | * an array of fn(val)->boolean validation functions. 98 | * @param {object} opts Form options. 99 | * @param {boolean} opts.onCreateValidation Validate form fields 100 | * when the form is created. Defaults to false. 101 | * @return {module:svelte-form~Form} 102 | */ 103 | export default function(fields, validation, opts) { 104 | opts = opts || {}; 105 | opts.onCreateValidation = opts.onCreateValidation || false; 106 | const _fields = {}; 107 | const form = writable(Date.now()); 108 | 109 | // Field wrapper structure 110 | const field = (key, rules) => { 111 | let firstPass = true; 112 | const value = writable(fields[key]); 113 | const state = derived( 114 | [value, form], 115 | ([$value]) => { 116 | if (firstPass) { 117 | firstPass = false; 118 | if (opts.onCreateValidation === false) { 119 | return { 120 | valid: true, 121 | error: '', 122 | }; 123 | } 124 | } 125 | const res = validate($value, rules); 126 | return { 127 | valid: res === true, 128 | error: res === true ? '' : res, 129 | }; 130 | } 131 | ); 132 | return { 133 | value, 134 | state, 135 | }; 136 | }; 137 | 138 | // Convert all inputs into field wrappers 139 | let key; 140 | for (key in fields) { 141 | if (fields.hasOwnProperty(key)) { 142 | _fields[key] = field(key, validationRules(key, validation)); 143 | } 144 | } 145 | 146 | // Overall valid state 147 | const {subscribe} = derived( 148 | Object.values(_fields).map((f) => f.state), 149 | ($states) => { 150 | return { 151 | valid: $states.every((s) => s.valid === true), 152 | }; 153 | } 154 | ); 155 | 156 | return { 157 | subscribe, 158 | field: (key) => { 159 | if (tc.isNullOrUndefined(_fields[key])) { 160 | return undefined; 161 | } 162 | return { 163 | value: _fields[key].value, 164 | state: _fields[key].state, 165 | }; 166 | }, 167 | validate: () => { 168 | form.set(Date.now()); 169 | }, 170 | data: () => { 171 | const data = {}; 172 | let key; 173 | for (key in _fields) { 174 | if (_fields.hasOwnProperty(key)) { 175 | data[key] = get(_fields[key].value); 176 | } 177 | } 178 | return data; 179 | }, 180 | }; 181 | } 182 | -------------------------------------------------------------------------------- /src/index.test.js: -------------------------------------------------------------------------------- 1 | import {validate} from './index'; 2 | import url from './rule/url'; 3 | import ignore from './rule/ignoreEmpty'; 4 | 5 | describe('Break rule', () => { 6 | const rules = [ignore(), url('invalid')]; 7 | const tests = [ 8 | {cond: undefined, res: true}, 9 | {cond: null, res: true}, 10 | {cond: {}, res: true}, 11 | {cond: '', res: true}, 12 | {cond: 'some', res: 'invalid'}, 13 | {cond: 'http://domain.com', res: true}, 14 | ]; 15 | 16 | for (const t of tests) { 17 | test(`Cond: ${t.cond}`, () => { 18 | expect(validate(t.cond, rules)).toBe(t.res); 19 | }); 20 | } 21 | }); 22 | -------------------------------------------------------------------------------- /src/rule/between.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Svelte Form validation rules module. 3 | * @module svelte-form/rule/between 4 | */ 5 | 6 | import min from './min'; 7 | import max from './max'; 8 | 9 | /** 10 | * Between numbers rule 11 | * @param {string} msg error message. 12 | * @param {number} arg1 min number. 13 | * @param {number} arg2 max number. 14 | * @return {boolean|string} true when valid, error message otherwise. 15 | */ 16 | export default (msg, arg1, arg2) => (value) => { 17 | if (min('', arg1)(value) !== true || max('', arg2)(value) !== true) { 18 | return msg; 19 | } 20 | return true; 21 | }; 22 | 23 | -------------------------------------------------------------------------------- /src/rule/email.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Svelte Form validation rules module. 3 | * @module svelte-form/rule/email 4 | */ 5 | 6 | import tc from '@spaceavocado/type-check'; 7 | 8 | /** 9 | * Email rule 10 | * @param {string} msg error message. 11 | * @return {boolean|string} true when valid, error message otherwise. 12 | */ 13 | export default (msg) => (value) => { 14 | if (tc.isNullOrUndefined(value) || tc.not.isString(value)) { 15 | return msg; 16 | } 17 | const rule = /^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$/; 18 | if (value.match(rule) == null) { 19 | return msg; 20 | } 21 | return true; 22 | }; 23 | -------------------------------------------------------------------------------- /src/rule/equal.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Svelte Form validation rules module. 3 | * @module svelte-form/rule/equal 4 | */ 5 | 6 | import tc from '@spaceavocado/type-check'; 7 | 8 | /** 9 | * Equal rule. 10 | * @param {string} msg error message. 11 | * @param {mixed|function} arg a matcher object or 12 | * matcher function = fn(val) returning true|false. 13 | * @return {boolean|string} true when valid, error message otherwise. 14 | */ 15 | export default (msg, arg) => { 16 | const customMatcher = tc.isFunction(arg); 17 | return (value) => { 18 | if (customMatcher === false && tc.isNullOrUndefined(value)) { 19 | return msg; 20 | } 21 | if (customMatcher) { 22 | if (arg(value) === false) { 23 | return msg; 24 | } 25 | } else if (value !== arg) { 26 | return msg; 27 | } 28 | return true; 29 | }; 30 | }; 31 | -------------------------------------------------------------------------------- /src/rule/exclude.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Svelte Form validation rules module. 3 | * @module svelte-form/rule/exclude 4 | */ 5 | 6 | import tc from '@spaceavocado/type-check'; 7 | 8 | /** 9 | * Max rule 10 | * @param {string} msg error message. 11 | * @param {number[]|string[]} arg exclusion list. 12 | * @return {boolean|string} true when valid, error message otherwise. 13 | */ 14 | export default (msg, arg) => (value) => { 15 | if (tc.isNullOrUndefined(value) 16 | || (tc.not.isString(value) && tc.not.isNumber(value)) 17 | || tc.isNullOrUndefined(arg)) { 18 | return msg; 19 | } 20 | if (arg.indexOf(value) > -1) { 21 | return msg; 22 | } 23 | return true; 24 | }; 25 | -------------------------------------------------------------------------------- /src/rule/ignoreEmpty.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Svelte Form validation rules module. 3 | * @module svelte-form/rule/ignore 4 | */ 5 | 6 | import required from './required'; 7 | 8 | // Break validation symbol 9 | export const BREAK_FLAG = Symbol('Break Validation'); 10 | 11 | /** 12 | * Ignore empty rule 13 | * This rule causes to break the validation chain for empty values. 14 | * @return {boolean|string} true when valid, error message otherwise. 15 | */ 16 | export default () => { 17 | const req = required(''); 18 | return (value) => { 19 | if (req(value) !== true) { 20 | return BREAK_FLAG; 21 | } 22 | return true; 23 | }; 24 | }; 25 | -------------------------------------------------------------------------------- /src/rule/include.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Svelte Form validation rules module. 3 | * @module svelte-form/rule/include 4 | */ 5 | 6 | import tc from '@spaceavocado/type-check'; 7 | 8 | /** 9 | * Include rule 10 | * @param {string} msg error message. 11 | * @param {number[]|string[]} arg inclusion list. 12 | * @return {boolean|string} true when valid, error message otherwise. 13 | */ 14 | export default (msg, arg) => (value) => { 15 | if (tc.isNullOrUndefined(value) 16 | || (tc.not.isString(value) && tc.not.isNumber(value)) 17 | || tc.isNullOrUndefined(arg)) { 18 | return msg; 19 | } 20 | if (arg.indexOf(value) == -1) { 21 | return msg; 22 | } 23 | return true; 24 | }; 25 | -------------------------------------------------------------------------------- /src/rule/index.test.js: -------------------------------------------------------------------------------- 1 | import required from './required'; 2 | import email from './email'; 3 | import url from './url'; 4 | import equal from './equal'; 5 | import min from './min'; 6 | import max from './max'; 7 | import between from './between'; 8 | import rx from './rx'; 9 | import exclude from './exclude'; 10 | import include from './include'; 11 | import ignore, {BREAK_FLAG} from './ignoreEmpty'; 12 | 13 | /** 14 | * Rur rule tests 15 | * @param {function} rule fn(value) 16 | * @param {object[]} tests 17 | */ 18 | function runTests(rule, tests) { 19 | for (const t of tests) { 20 | test(`Cond: ${t.cond}`, () => { 21 | expect(rule(t.cond)).toBe(t.res); 22 | }); 23 | } 24 | } 25 | 26 | describe('Required', () => { 27 | const tests = [ 28 | {cond: undefined, res: 'invalid'}, 29 | {cond: null, res: 'invalid'}, 30 | {cond: {}, res: 'invalid'}, 31 | {cond: '', res: 'invalid'}, 32 | {cond: 'some', res: true}, 33 | ]; 34 | runTests(required('invalid'), tests); 35 | }); 36 | 37 | describe('Equal', () => { 38 | const tests = [ 39 | {cond: undefined, res: 'invalid'}, 40 | {cond: null, res: 'invalid'}, 41 | {cond: {}, res: 'invalid'}, 42 | {cond: '5', res: 'invalid'}, 43 | {cond: 5, res: true}, 44 | ]; 45 | runTests(equal('invalid', 5), tests); 46 | runTests(equal('invalid', (val) => val === 5), tests); 47 | }); 48 | 49 | describe('Email', () => { 50 | const tests = [ 51 | {cond: undefined, res: 'invalid'}, 52 | {cond: null, res: 'invalid'}, 53 | {cond: {}, res: 'invalid'}, 54 | {cond: '', res: 'invalid'}, 55 | {cond: 'emaildomain.com', res: 'invalid'}, 56 | {cond: 'email@domaincom', res: 'invalid'}, 57 | {cond: '@domain.com', res: 'invalid'}, 58 | {cond: 'email@domain.com', res: true}, 59 | ]; 60 | runTests(email('invalid'), tests); 61 | }); 62 | 63 | describe('URL', () => { 64 | const tests = [ 65 | {cond: undefined, res: 'invalid'}, 66 | {cond: null, res: 'invalid'}, 67 | {cond: {}, res: 'invalid'}, 68 | {cond: '', res: 'invalid'}, 69 | {cond: 'domain.com', res: 'invalid'}, 70 | {cond: 'http://domain.com', res: true}, 71 | {cond: 'https://domain.com', res: true}, 72 | {cond: 'http://www.example.com/products?id=1&page=2', res: true}, 73 | {cond: 'http://255.255.255.255', res: true}, 74 | ]; 75 | runTests(url('invalid'), tests); 76 | }); 77 | 78 | describe('Min', () => { 79 | const tests = [ 80 | {cond: undefined, res: 'invalid'}, 81 | {cond: null, res: 'invalid'}, 82 | {cond: {}, res: 'invalid'}, 83 | {cond: '', res: 'invalid'}, 84 | {cond: 4, res: 'invalid'}, 85 | {cond: 5, res: true}, 86 | {cond: 10, res: true}, 87 | ]; 88 | runTests(min('invalid', 5), tests); 89 | }); 90 | 91 | describe('Max', () => { 92 | const tests = [ 93 | {cond: undefined, res: 'invalid'}, 94 | {cond: null, res: 'invalid'}, 95 | {cond: {}, res: 'invalid'}, 96 | {cond: '', res: 'invalid'}, 97 | {cond: 6, res: 'invalid'}, 98 | {cond: 5, res: true}, 99 | {cond: 1, res: true}, 100 | ]; 101 | runTests(max('invalid', 5), tests); 102 | }); 103 | 104 | describe('Between', () => { 105 | const tests = [ 106 | {cond: undefined, res: 'invalid'}, 107 | {cond: null, res: 'invalid'}, 108 | {cond: {}, res: 'invalid'}, 109 | {cond: '', res: 'invalid'}, 110 | {cond: 4, res: 'invalid'}, 111 | {cond: 11, res: 'invalid'}, 112 | {cond: 5, res: true}, 113 | {cond: 7, res: true}, 114 | {cond: 10, res: true}, 115 | ]; 116 | runTests(between('invalid', 5, 10), tests); 117 | }); 118 | 119 | describe('Rx', () => { 120 | const tests = [ 121 | {cond: undefined, res: 'invalid'}, 122 | {cond: null, res: 'invalid'}, 123 | {cond: {}, res: 'invalid'}, 124 | {cond: '', res: 'invalid'}, 125 | {cond: 5, res: 'invalid'}, 126 | {cond: '5.', res: 'invalid'}, 127 | {cond: '5.5', res: true}, 128 | ]; 129 | runTests(rx('invalid', /\d+\.\d+/), tests); 130 | }); 131 | 132 | describe('Ignore', () => { 133 | const tests = [ 134 | {cond: undefined, res: BREAK_FLAG}, 135 | {cond: null, res: BREAK_FLAG}, 136 | {cond: {}, res: BREAK_FLAG}, 137 | {cond: '', res: BREAK_FLAG}, 138 | {cond: 5, res: true}, 139 | {cond: '5.', res: true}, 140 | {cond: '5.5', res: true}, 141 | ]; 142 | runTests(ignore(), tests); 143 | }); 144 | 145 | describe('Exclude', () => { 146 | let tests = [ 147 | {cond: undefined, res: 'invalid'}, 148 | {cond: null, res: 'invalid'}, 149 | {cond: {}, res: 'invalid'}, 150 | {cond: 1, res: 'invalid'}, 151 | {cond: '3', res: true}, 152 | {cond: 3, res: true}, 153 | ]; 154 | runTests(exclude('invalid', [1,2]), tests); 155 | 156 | tests = [ 157 | {cond: undefined, res: 'invalid'}, 158 | {cond: null, res: 'invalid'}, 159 | {cond: {}, res: 'invalid'}, 160 | {cond: '1', res: 'invalid'}, 161 | {cond: '3', res: true}, 162 | {cond: 3, res: true}, 163 | ]; 164 | runTests(exclude('invalid', ['1','2']), tests); 165 | }); 166 | 167 | describe('Include', () => { 168 | let tests = [ 169 | {cond: undefined, res: 'invalid'}, 170 | {cond: null, res: 'invalid'}, 171 | {cond: {}, res: 'invalid'}, 172 | {cond: 3, res: 'invalid'}, 173 | {cond: '1', res: 'invalid'}, 174 | {cond: 1, res: true}, 175 | ]; 176 | runTests(include('invalid', [1,2]), tests); 177 | 178 | tests = [ 179 | {cond: undefined, res: 'invalid'}, 180 | {cond: null, res: 'invalid'}, 181 | {cond: {}, res: 'invalid'}, 182 | {cond: '3', res: 'invalid'}, 183 | {cond: 1, res: 'invalid'}, 184 | {cond: '1', res: true}, 185 | ]; 186 | runTests(include('invalid', ['1','2']), tests); 187 | }); -------------------------------------------------------------------------------- /src/rule/max.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Svelte Form validation rules module. 3 | * @module svelte-form/rule/max 4 | */ 5 | 6 | import tc from '@spaceavocado/type-check'; 7 | 8 | /** 9 | * Max rule 10 | * @param {string} msg error message. 11 | * @param {number} arg max number. 12 | * @return {boolean|string} true when valid, error message otherwise. 13 | */ 14 | export default (msg, arg) => (value) => { 15 | if (tc.isNullOrUndefined(value) || tc.not.isNumber(value) 16 | || tc.isNullOrUndefined(arg)) { 17 | return msg; 18 | } 19 | if (value > arg) { 20 | return msg; 21 | } 22 | return true; 23 | }; 24 | -------------------------------------------------------------------------------- /src/rule/min.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Svelte Form validation rules module. 3 | * @module svelte-form/rule/min 4 | */ 5 | 6 | import tc from '@spaceavocado/type-check'; 7 | 8 | /** 9 | * Min rule 10 | * @param {string} msg error message. 11 | * @param {number} arg min number. 12 | * @return {boolean|string} true when valid, error message otherwise. 13 | */ 14 | export default (msg, arg) => (value) => { 15 | if (tc.isNullOrUndefined(value) || tc.not.isNumber(value) 16 | || tc.isNullOrUndefined(arg)) { 17 | return msg; 18 | } 19 | if (value < arg) { 20 | return msg; 21 | } 22 | return true; 23 | }; 24 | -------------------------------------------------------------------------------- /src/rule/required.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Svelte Form validation rules module. 3 | * @module svelte-form/rule/required 4 | */ 5 | 6 | import tc from '@spaceavocado/type-check'; 7 | 8 | /** 9 | * Required rule 10 | * @param {string} msg error message. 11 | * @return {boolean|string} true when valid, error message otherwise. 12 | */ 13 | export default (msg) => (value) => { 14 | if (tc.isNullOrUndefined(value) 15 | || tc.isObject(value) 16 | || tc.isFunction(value)) { 17 | return msg; 18 | } 19 | if (tc.isString(value)) { 20 | value = value.trim(); 21 | if (value.length == 0) { 22 | return msg; 23 | } 24 | } 25 | return true; 26 | }; 27 | -------------------------------------------------------------------------------- /src/rule/rx.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Svelte Form validation rules module. 3 | * @module svelte-form/rule/rx 4 | */ 5 | 6 | import tc from '@spaceavocado/type-check'; 7 | 8 | /** 9 | * Custom regex rule. 10 | * @param {string} msg error message. 11 | * @param {number} arg Regular expression. 12 | * @return {boolean|string} true when valid, error message otherwise. 13 | */ 14 | export default (msg, arg) => (value) => { 15 | if (tc.isNullOrUndefined(value) || tc.not.isString(value)) { 16 | return msg; 17 | } 18 | if (value.match(arg) == null) { 19 | return msg; 20 | } 21 | return true; 22 | }; 23 | -------------------------------------------------------------------------------- /src/rule/url.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Svelte Form validation rules module. 3 | * @module svelte-form/rule/url 4 | */ 5 | 6 | import tc from '@spaceavocado/type-check'; 7 | 8 | /** 9 | * URL rule 10 | * @param {string} msg error message. 11 | * @return {boolean|string} true when valid, error message otherwise. 12 | */ 13 | export default (msg) => (value) => { 14 | if (tc.isNullOrUndefined(value) || tc.not.isString(value)) { 15 | return msg; 16 | } 17 | if (value.match(/^https?:\/\/[^\s]*/i) == null) { 18 | return msg; 19 | } 20 | return true; 21 | }; 22 | --------------------------------------------------------------------------------