vest 4.0.0-dev-31f012 → 4.0.0-dev-e266d9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/CHANGELOG.md +70 -52
  2. package/README.md +2 -112
  3. package/dist/cjs/compose.js +7 -0
  4. package/dist/cjs/compounds.js +7 -0
  5. package/dist/cjs/enforce/compose.development.js +139 -0
  6. package/dist/cjs/enforce/compose.production.js +1 -0
  7. package/dist/cjs/enforce/compounds.development.js +132 -0
  8. package/dist/cjs/enforce/compounds.production.js +1 -0
  9. package/dist/cjs/enforce/package.json +1 -0
  10. package/dist/cjs/enforce/schema.development.js +144 -0
  11. package/dist/cjs/enforce/schema.production.js +1 -0
  12. package/dist/cjs/schema.js +7 -0
  13. package/dist/cjs/vest.development.js +504 -1034
  14. package/dist/cjs/vest.production.js +1 -1
  15. package/dist/es/enforce/compose.development.js +137 -0
  16. package/dist/es/enforce/compose.production.js +1 -0
  17. package/dist/es/enforce/compounds.development.js +130 -0
  18. package/dist/es/enforce/compounds.production.js +1 -0
  19. package/dist/es/enforce/package.json +1 -0
  20. package/dist/es/enforce/schema.development.js +140 -0
  21. package/dist/es/enforce/schema.production.js +1 -0
  22. package/dist/es/vest.development.js +497 -1033
  23. package/dist/es/vest.production.js +1 -1
  24. package/dist/umd/enforce/compose.development.js +143 -0
  25. package/dist/umd/enforce/compose.production.js +1 -0
  26. package/dist/umd/enforce/compounds.development.js +136 -0
  27. package/dist/umd/enforce/compounds.production.js +1 -0
  28. package/dist/umd/enforce/schema.development.js +148 -0
  29. package/dist/umd/enforce/schema.production.js +1 -0
  30. package/dist/umd/vest.development.js +1693 -2226
  31. package/dist/umd/vest.production.js +1 -1
  32. package/enforce/compose/package.json +7 -0
  33. package/enforce/compounds/package.json +7 -0
  34. package/enforce/schema/package.json +7 -0
  35. package/package.json +107 -13
  36. package/testUtils/mockThrowError.ts +16 -0
  37. package/types/enforce/compose.d.ts +134 -0
  38. package/types/enforce/compounds.d.ts +146 -0
  39. package/types/enforce/schema.d.ts +151 -0
  40. package/types/vest.d.ts +31 -203
package/CHANGELOG.md CHANGED
@@ -4,75 +4,93 @@ All notable changes to this project will be documented in this file.
4
4
 
5
5
  The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
6
 
7
- ## 4.0.0 - 2021-10-31
7
+ ## 4.0.0 - 2021-12-12
8
8
  ### Changed or removed
9
- - f5ba507 major(context): used named export in context (ealush)
10
- - eaed68f breaking(vest, enforce): prepare next major (ealush)
9
+ - b5a0108 breaking(vest): remove test.each (ealush)
10
+ - 7c43eab major(context): used named export in context (ealush)
11
+ - e8652bc breaking(vest, enforce): prepare next major (ealush)
12
+ - dab8e00 breaking(vest, enforce): prepare next major (ealush)
11
13
 
12
14
  ### Added
13
- - e0f0f91 feat(vest): support custom optional logic (ealush)
14
- - d4fecee feat(vest): Add a parser export (ealush)
15
- - e72498d feat(vest): isValid with field name (ealush)
16
- - f60d952 feat(vest): handle execution order state refill with memoized tests (ealush)
17
- - a2b60c4 feat(vest): Make the state rely on execution order. Make skipWhen set skipped context. (undefined)
18
- - ae5eb02 added(n4s): partial rule modifier (undefined)
19
- - 990c68f feat(n4s): context propagation within enforce (undefined)
15
+ - b0a9a14 feat(vest): use key prop to retain test state after reorder (#732) (Evyatar)
16
+ - d3e7613 feat(vest): support custom optional logic (ealush)
17
+ - be1cbf6 feat(vest): Add a parser export (ealush)
18
+ - 2553748 feat(vest): isValid with field name (ealush)
19
+ - ec5ceb9 feat(vest): handle execution order state refill with memoized tests (ealush)
20
+ - 4032bd8 feat(vest): Make the state rely on execution order. Make skipWhen set skipped context. (undefined)
21
+ - 220127b added(n4s): partial rule modifier (undefined)
22
+ - b5ce72d feat(n4s): context propagation within enforce (undefined)
20
23
 
21
24
  ### Fixed and improved
22
- - 31f0123 patch(vest): move creation functions to event bus (ealush)
23
- - d23641c patch: Some cleanups (ealush)
24
- - 7acb76f fix(vest): prevent pending tests from being marked as skipped (ealush)
25
- - 8851ff5 patch(vest): Add isolate module for containing re-orders (ealush)
26
- - 0593c0f patch(vest): refresh tests after cancel (ealush)
27
- - e915b53 patch: add cursor util (ealush)
28
- - f54ae8b patch(vest): move cursor into context (ealush)
29
- - fc7627e patch(vest): automatically purge not-found test results (ealush)
30
- - d68d990 vx: correctly pass cli options to build script (ealush)
31
- - 7c47b9a patch(vest): Throw error when tests are called in the wrong order (ealush)
32
- - 01be84e vx: add types to exports (ealush)
33
- - 7201170 organize vest state hooks (ealush)
34
- - e39bfd8 patch(vest): infer omitted optional fields (ealush)
35
- - 93014e3 vx: add dev bundle to exports (ealush)
36
- - 91df42e fix(vest): prevent changing test status once it was finalized (ealush)
37
- - 797df3e patch(vest): add cache invalidation for canceled tests (ealush)
38
- - 14ba6d9 types(vest): add safeguard around shouldUseErrorAsMessage (ealush)
39
- - 477ca00 patch(vest): some cleanups (ealush)
40
- - 58d5ed3 patch(vest): remove duplicate code handling perv test registration (ealush)
41
- - 6a98443 vx: use context directly from published package (ealush)
42
- - a79e479 patch: run done callbacks via event (ealush)
43
- - 01d32b7 patch(vest): removed state subscription (ealush)
25
+ - 1384c08 fix(vest): only.group works in conjunction with only (#734) (Evyatar)
26
+ - README.md
27
+ - 7daf6d2 rule(n4s): add isNullish rule, improve isBlank (ealush)
28
+ - c4a4140 chore: organize imports (ealush)
29
+ - 9f9b970 vx: improve package.json generation (ealush)
30
+ - 0370fc1 n4s: extract non-required modules (ealush)
31
+ - 03ba92c vx: support namespaced exports (ealush)
32
+ - 38a54ae vx: support installing of local packages (ealush)
33
+ - 7baedf2 n4s: use named export in entry (ealush)
34
+ - 366001b patch(vest): better handling of skipped async tests (ealush)
35
+ - 2380679 types(vest): allow unprovided suite name in tests (ealush)
36
+ - f721b2d patch(vest): replace warns boolean flag with enum (ealush)
37
+ - 0acb24d patch(vest): Pass draft result to skipWhen conditional (ealush)
38
+ - e84cd9d patch(vest): add back optional suite name argument (ealush)
39
+ - 8b30b66 patch(vest): make compose an external export (ealush)
40
+ - ddfa9fd patch(vest): move creation functions to event bus (ealush)
41
+ - fe83e88 patch: Some cleanups (ealush)
42
+ - 9275707 fix(vest): prevent pending tests from being marked as skipped (ealush)
43
+ - 94e00a8 patch(vest): Add isolate module for containing re-orders (ealush)
44
+ - 5bcc14a patch(vest): refresh tests after cancel (ealush)
45
+ - fd049e8 patch: add cursor util (ealush)
46
+ - 9380c09 patch(vest): move cursor into context (ealush)
47
+ - 49b72f4 patch(vest): automatically purge not-found test results (ealush)
48
+ - 2dfedaf vx: correctly pass cli options to build script (ealush)
49
+ - aae250a patch(vest): Throw error when tests are called in the wrong order (ealush)
50
+ - a87824b vx: add types to exports (ealush)
51
+ - cc9b4b0 organize vest state hooks (ealush)
52
+ - df84261 patch(vest): infer omitted optional fields (ealush)
53
+ - 2534cf6 vx: add dev bundle to exports (ealush)
54
+ - 4d450aa fix(vest): prevent changing test status once it was finalized (ealush)
55
+ - 8730e25 patch(vest): add cache invalidation for canceled tests (ealush)
56
+ - 4cb2c6c types(vest): add safeguard around shouldUseErrorAsMessage (ealush)
57
+ - c214a12 patch(vest): some cleanups (ealush)
58
+ - 858458d patch(vest): remove duplicate code handling perv test registration (ealush)
59
+ - ec69173 vx: use context directly from published package (ealush)
60
+ - 962bc06 patch: run done callbacks via event (ealush)
61
+ - d96f428 patch(vest): removed state subscription (ealush)
44
62
  - package.json
45
63
  - packages/anyone/package.json
46
64
  - packages/anyone/package.json
47
65
  - packages/vast/types/vast.d.ts
48
- - b10b98b patch(vest): remove pending and lagging state (ealush)
49
- - dfd2cc3 patch(vest): convert boolean flags to a single status key (ealush)
50
- - 1c9da6c patch: simplify fieldname comparison (ealush)
51
- - 43c75a4 patch(vest): add useAllIncomplete hook (ealush)
52
- - 2dfdc97 patch(vest): invalid accounts for warning tests as well (ealush)
53
- - 4033cca patch(vest): isValid counts all required tests per field (ealush)
54
- - 02b28a6 chore: cleanups (ealush)
66
+ - e4e1746 patch(vest): remove pending and lagging state (ealush)
67
+ - 9d8fd21 patch(vest): convert boolean flags to a single status key (ealush)
68
+ - dbb836e patch: simplify fieldname comparison (ealush)
69
+ - 5a78179 patch(vest): add useAllIncomplete hook (ealush)
70
+ - b5ae658 patch(vest): invalid accounts for warning tests as well (ealush)
71
+ - 4563b8d patch(vest): isValid counts all required tests per field (ealush)
72
+ - 3fe2f21 chore: cleanups (ealush)
55
73
  - .eslintrc.js
56
- - afa16e9 add(n4s): enforce.condition (ealush)
74
+ - 149aab3 add(n4s): enforce.condition (ealush)
57
75
  - package.json
58
76
  - packages/anyone/package.json
59
- - d452e26 chore: cleanup residue (undefined)
60
- - 5982183 chore: remove duplicate types (undefined)
77
+ - 40ef071 chore: cleanup residue (undefined)
78
+ - eeac20e chore: remove duplicate types (undefined)
61
79
  - packages/anyone/package.json
62
- - 52ac8e0 patch: add nodejs exports (undefined)
63
- - f9c4b3e patch: remove unused exports (undefined)
80
+ - 4d88c04 patch: add nodejs exports (undefined)
81
+ - 6e57aa1 patch: remove unused exports (undefined)
64
82
  - packages/anyone/package.json
65
- - db0253b chore: reduce complexity, remove all lint errors (undefined)
83
+ - 26af06b chore: reduce complexity, remove all lint errors (undefined)
66
84
  - packages/anyone/.npmignore
67
85
  - .github/PULL_REQUEST_TEMPLATE.md
68
- - be9c776 chore: cleanup unused code (ealush)
69
- - c5eb2de lint: handling lint of all packages (ealush)
86
+ - 5be986d chore: cleanup unused code (ealush)
87
+ - ba68539 lint: handling lint of all packages (ealush)
70
88
  - .gitignore
71
- - d388fdc patch(n4s): add ruleReturn default values (ealush)
72
- - be91b7e fix(n4s): make enforce compound runners fall back to correct response (ealush)
73
- - 7e8f25c fix(n4s): make enforce chaining work (ealush)
74
- - e60ce3b chore: some lint fixes (ealush)
75
- - fc8e2d8 add cli options support (ealush)
89
+ - cca5130 patch(n4s): add ruleReturn default values (ealush)
90
+ - 75306ff fix(n4s): make enforce compound runners fall back to correct response (ealush)
91
+ - 4751584 fix(n4s): make enforce chaining work (ealush)
92
+ - 73b28a1 chore: some lint fixes (ealush)
93
+ - 4135ce3 add cli options support (ealush)
76
94
 
77
95
  ## 3.2.7 - 2021-07-17
78
96
 
package/README.md CHANGED
@@ -1,113 +1,3 @@
1
- ![Vest](https://cdn.jsdelivr.net/gh/ealush/vest@assets/vest-logo.png 'Vest')
1
+ # Vest
2
2
 
3
- # Vest 🦺 Declarative Validation Testing
4
-
5
- ![Github Stars](https://githubbadges.com/star.svg?user=ealush&repo=vest&style=flat)
6
- ![Npm downloads](https://img.shields.io/npm/dt/vest?label=Downloads&logo=npm)
7
-
8
- [![npm version](https://badge.fury.io/js/vest.svg)](https://badge.fury.io/js/vest) [![Build Status](https://travis-ci.org/ealush/vest.svg?branch=latest)](https://travis-ci.org/ealush/vest) [![Known Vulnerabilities](https://snyk.io/test/npm/vest/badge.svg)](https://snyk.io/test/npm/vest)
9
- ![minifiedSize](https://img.shields.io/bundlephobia/min/vest?color=blue&logo=npm)
10
-
11
- [![Join discord](https://img.shields.io/discord/757686103292641312?label=Join%20Discord&logo=discord&logoColor=green)](https://discord.gg/WmADZpJnSe)
12
-
13
- - [Documentation homepage](https://vestjs.dev)
14
- - **Try vest live**
15
- - [Vanilla JS Example](https://stackblitz.com/edit/vest-vanilla-support-example?file=validation.js)
16
- - ReactJS Examples:
17
- - [Example 1 (groups)](https://codesandbox.io/s/ecstatic-waterfall-4i2ne?file=/src/validate.js)
18
- - [Example 2 (Async)](https://codesandbox.io/s/youthful-williamson-loijb?file=/src/validate.js)
19
- - [Example 3](https://stackblitz.com/edit/vest-react-support-example?file=validation.js)
20
- - [Example 4](https://stackblitz.com/edit/vest-react-registration?file=validate.js)
21
- - [Example 5 (Password validator)](https://codesandbox.io/s/password-validator-example-6puvy?file=/src/validate.js)
22
- - [VueJS Example](https://codesandbox.io/s/vest-vue-example-1j6r8?file=/src/validations.js)
23
- - [Svelte Example](https://codesandbox.io/s/vestdocssvelteexample-k87t7?file=/validate.js)
24
-
25
- ## Tutorials
26
-
27
- [Step By Step React Tutorial](https://dev.to/ealush/dead-simple-form-validation-with-vest-5gf8)
28
-
29
- ## [Release Notes](https://github.com/ealush/vest/releases)
30
-
31
- ## 🦺 What is Vest?
32
-
33
- Vest is a validations library for JS apps that derives its syntax from modern JS unit testing frameworks such as Mocha or Jest. It is easy to learn due to its use of already common declarative patterns.
34
- It works great with user-input validation and with validating upon user interaction to provide the best possible user experience.
35
-
36
- The idea behind Vest is that your validations can be described as a 'spec' or a contract that reflects your form or feature structure. Your validations run in production, and they are framework agnostic - meaning Vest works well with React, Angular, Vue, or even without a framework at all.
37
-
38
- Using Vest for form validation can reduce bloat, improve feature readability and maintainability.
39
-
40
- **Basic Example**
41
- ![full](https://cdn.jsdelivr.net/gh/ealush/vest@assets/demos/full_3.gif 'full')
42
-
43
- **Memoized async test**
44
- ![memo](https://cdn.jsdelivr.net/gh/ealush/vest@assets/demos/memo.gif 'memo')
45
-
46
- ## ✅ Motivation
47
-
48
- Writing forms is an integral part of building web apps, and even though it may seem trivial at first - as your feature grows over time, so does your validation logic grows in complexity.
49
-
50
- Vest tries to remediate this by separating validation logic from feature logic so it is easier to maintain over time and refactor when needed.
51
-
52
- ## ✨ Vest's features
53
-
54
- - 🎨 Framework agnostic (BYOUI)
55
- - ⚡️ Rich, extendable, assertions library (enforce) ([doc](http://vestjs.dev/#/enforce))
56
- - 🚥 Multiple validations for the same field
57
- - ⚠️ Warning (non failing) tests ([doc](http://vestjs.dev/#/warn))
58
- - 📝 Validate only the fields the user interacted with ([doc](http://vestjs.dev/#/exclusion))
59
- - ⏳ Memoize async validations to reduce calls to the server ([doc](http://vestjs.dev/#/test?id=testmemo-for-memoized-tests))
60
- - 🚦 Test grouping ([doc](http://vestjs.dev/#/group))
61
-
62
- ## Example code ([Run in sandbox](https://codesandbox.io/s/vest-react-tutorial-finished-ztt8t?file=/src/validate.js))
63
-
64
- ```js
65
- import { create, only, test, enforce, warn, skipWhen } from 'vest';
66
-
67
- export default create((data = {}, currentField) => {
68
- only(currentField);
69
-
70
- test('username', 'Username is required', () => {
71
- enforce(data.username).isNotEmpty();
72
- });
73
-
74
- test('username', 'Username is too short', () => {
75
- enforce(data.username).longerThanOrEquals(3);
76
- });
77
-
78
- test('password', 'Password is required', () => {
79
- enforce(data.password).isNotEmpty();
80
- });
81
-
82
- test('password', 'Password must be at least 6 chars long', () => {
83
- enforce(data.password).longerThanOrEquals(6);
84
- });
85
-
86
- test('password', 'Password is weak, Maybe add a number?', () => {
87
- warn();
88
- enforce(data.password).matches(/[0-9]/);
89
- });
90
-
91
- skipWhen(!data.password, () => {
92
- test('confirm_password', 'Passwords do not match', () => {
93
- enforce(data.confirm_password).equals(data.password);
94
- });
95
- });
96
-
97
- test('email', 'Email Address is not valid', () => {
98
- enforce(data.email).isEmail();
99
- });
100
-
101
- test('tos', () => {
102
- enforce(data.tos).isTruthy();
103
- });
104
- });
105
- ```
106
-
107
- ## Why Vest?
108
-
109
- - 🧠 Vest is really easy to learn. You can take your existing knowledge of unit tests and transfer it to validations.
110
- - ✏️ Vest takes into account user interaction and warn only validations.
111
- - 🧱 Your validations are structured, making it very simple to read and write. All validation files look the same.
112
- - 🖇 Your validation logic is separate from your feature logic, preventing the spaghetti code that's usually involved with writing validations.
113
- - 🧩 Validation logic is easy to share and reuse across features.
3
+ Home of the Vest source code.
@@ -0,0 +1,7 @@
1
+ 'use strict'
2
+
3
+ if (process.env.NODE_ENV === 'production') {
4
+ module.exports = require('./compose.production.js');
5
+ } else {
6
+ module.exports = require('./compose.development.js');
7
+ }
@@ -0,0 +1,7 @@
1
+ 'use strict'
2
+
3
+ if (process.env.NODE_ENV === 'production') {
4
+ module.exports = require('./compounds.production.js');
5
+ } else {
6
+ module.exports = require('./compounds.development.js');
7
+ }
@@ -0,0 +1,139 @@
1
+ 'use strict';
2
+
3
+ var n4s = require('n4s');
4
+
5
+ function mapFirst(array, callback) {
6
+ var broke = false;
7
+ var breakoutValue = null;
8
+ for (var i = 0; i < array.length; i++) {
9
+ callback(array[i], breakout, i);
10
+ if (broke) {
11
+ return breakoutValue;
12
+ }
13
+ }
14
+ function breakout(value) {
15
+ broke = true;
16
+ breakoutValue = value;
17
+ }
18
+ }
19
+
20
+ function isFunction(value) {
21
+ return typeof value === 'function';
22
+ }
23
+
24
+ function optionalFunctionValue(value) {
25
+ var args = [];
26
+ for (var _i = 1; _i < arguments.length; _i++) {
27
+ args[_i - 1] = arguments[_i];
28
+ }
29
+ return isFunction(value) ? value.apply(void 0, args) : value;
30
+ }
31
+
32
+ function defaultTo(callback, defaultValue) {
33
+ var _a;
34
+ return (_a = optionalFunctionValue(callback)) !== null && _a !== void 0 ? _a : defaultValue;
35
+ }
36
+
37
+ /**
38
+ * Throws a timed out error.
39
+ */
40
+ function throwError(devMessage, productionMessage) {
41
+ throw new Error(devMessage );
42
+ }
43
+
44
+ /**
45
+ * A safe hasOwnProperty access
46
+ */
47
+ function hasOwnProperty(obj, key) {
48
+ return Object.prototype.hasOwnProperty.call(obj, key);
49
+ }
50
+
51
+ function isNumber(value) {
52
+ return Boolean(typeof value === 'number');
53
+ }
54
+
55
+ function lengthEquals(value, arg1) {
56
+ return value.length === Number(arg1);
57
+ }
58
+
59
+ function isEmpty(value) {
60
+ if (!value) {
61
+ return true;
62
+ }
63
+ else if (isNumber(value)) {
64
+ return value === 0;
65
+ }
66
+ else if (hasOwnProperty(value, 'length')) {
67
+ return lengthEquals(value, 0);
68
+ }
69
+ else if (typeof value === 'object') {
70
+ return lengthEquals(Object.keys(value), 0);
71
+ }
72
+ return true;
73
+ }
74
+
75
+ function ruleReturn(pass, message) {
76
+ var output = { pass: pass };
77
+ if (message) {
78
+ output.message = message;
79
+ }
80
+ return output;
81
+ }
82
+ function failing() {
83
+ return ruleReturn(false);
84
+ }
85
+ function passing() {
86
+ return ruleReturn(true);
87
+ }
88
+ function defaultToPassing(callback) {
89
+ return defaultTo(callback, passing());
90
+ }
91
+
92
+ function runLazyRule(lazyRule, currentValue) {
93
+ try {
94
+ return lazyRule.run(currentValue);
95
+ }
96
+ catch (_a) {
97
+ return failing();
98
+ }
99
+ }
100
+
101
+ /* eslint-disable max-lines-per-function */
102
+ function compose() {
103
+ var composites = [];
104
+ for (var _i = 0; _i < arguments.length; _i++) {
105
+ composites[_i] = arguments[_i];
106
+ }
107
+ return Object.assign(function (value) {
108
+ var res = run(value);
109
+ if (!res.pass) {
110
+ if (isEmpty(res.message)) {
111
+ throwError();
112
+ }
113
+ else {
114
+ // Explicitly throw a string so that vest.test can pick it up as the validation error message
115
+ throw res.message;
116
+ }
117
+ }
118
+ }, {
119
+ run: run,
120
+ test: function (value) { return run(value).pass; }
121
+ });
122
+ function run(value) {
123
+ return n4s.ctx.run({ value: value }, function () {
124
+ return defaultToPassing(mapFirst(composites, function (composite, breakout) {
125
+ /* HACK: Just a small white lie. ~~HELP WANTED~~.
126
+ The ideal is that instead of `TLazyRuleRunners` We would simply use `TLazy` to begin with.
127
+ The problem is that lazy rules can't really be passed to this function due to some generic hell
128
+ so we're limiting it to a small set of functions.
129
+ */
130
+ var res = runLazyRule(composite, value);
131
+ if (!res.pass) {
132
+ breakout(res);
133
+ }
134
+ }));
135
+ });
136
+ }
137
+ }
138
+
139
+ module.exports = compose;
@@ -0,0 +1 @@
1
+ "use strict";var n=require("n4s");function r(n,r){function t(n){u=!0,e=n}for(var u=!1,e=null,o=0;o<n.length;o++)if(r(n[o],t,o),u)return e}function t(n){return"function"==typeof n}function u(n,r){var u;return null!==(u=function(n){for(var r=[],u=1;u<arguments.length;u++)r[u-1]=arguments[u];return t(n)?n.apply(void 0,r):n}(n))&&void 0!==u?u:r}function e(n,r){throw Error(u(r,n))}function o(n,r){return n.length===Number(r)}function f(n){if(n){if(function(n){return"number"==typeof n}(n))return 0===n;if(function(n,r){return Object.prototype.hasOwnProperty.call(n,r)}(n,"length"))return o(n,0);if("object"==typeof n)return o(Object.keys(n),0)}return!0}function i(n,r){return n={pass:n},r&&(n.message=r),n}function c(n){return u(n,i(!0))}function s(n,r){try{return n.run(r)}catch(n){return i(!1)}}module.exports=function(){function t(t){return n.ctx.run({value:t},(function(){return c(r(u,(function(n,r){(n=s(n,t)).pass||r(n)})))}))}for(var u=[],o=0;o<arguments.length;o++)u[o]=arguments[o];return Object.assign((function(n){if(!(n=t(n)).pass){if(!f(n.message))throw n.message;e()}}),{run:t,test:function(n){return t(n).pass}})};
@@ -0,0 +1,132 @@
1
+ 'use strict';
2
+
3
+ var n4s = require('n4s');
4
+
5
+ function mapFirst(array, callback) {
6
+ var broke = false;
7
+ var breakoutValue = null;
8
+ for (var i = 0; i < array.length; i++) {
9
+ callback(array[i], breakout, i);
10
+ if (broke) {
11
+ return breakoutValue;
12
+ }
13
+ }
14
+ function breakout(value) {
15
+ broke = true;
16
+ breakoutValue = value;
17
+ }
18
+ }
19
+
20
+ function isFunction(value) {
21
+ return typeof value === 'function';
22
+ }
23
+
24
+ function optionalFunctionValue(value) {
25
+ var args = [];
26
+ for (var _i = 1; _i < arguments.length; _i++) {
27
+ args[_i - 1] = arguments[_i];
28
+ }
29
+ return isFunction(value) ? value.apply(void 0, args) : value;
30
+ }
31
+
32
+ function defaultTo(callback, defaultValue) {
33
+ var _a;
34
+ return (_a = optionalFunctionValue(callback)) !== null && _a !== void 0 ? _a : defaultValue;
35
+ }
36
+
37
+ function ruleReturn(pass, message) {
38
+ var output = { pass: pass };
39
+ if (message) {
40
+ output.message = message;
41
+ }
42
+ return output;
43
+ }
44
+ function failing() {
45
+ return ruleReturn(false);
46
+ }
47
+ function passing() {
48
+ return ruleReturn(true);
49
+ }
50
+ function defaultToFailing(callback) {
51
+ return defaultTo(callback, failing());
52
+ }
53
+ function defaultToPassing(callback) {
54
+ return defaultTo(callback, passing());
55
+ }
56
+
57
+ function runLazyRule(lazyRule, currentValue) {
58
+ try {
59
+ return lazyRule.run(currentValue);
60
+ }
61
+ catch (_a) {
62
+ return failing();
63
+ }
64
+ }
65
+
66
+ function allOf(value) {
67
+ var rules = [];
68
+ for (var _i = 1; _i < arguments.length; _i++) {
69
+ rules[_i - 1] = arguments[_i];
70
+ }
71
+ return defaultToPassing(mapFirst(rules, function (rule, breakout) {
72
+ var res = runLazyRule(rule, value);
73
+ if (!res.pass) {
74
+ breakout(res);
75
+ }
76
+ }));
77
+ }
78
+
79
+ function anyOf(value) {
80
+ var rules = [];
81
+ for (var _i = 1; _i < arguments.length; _i++) {
82
+ rules[_i - 1] = arguments[_i];
83
+ }
84
+ return defaultToFailing(mapFirst(rules, function (rule, breakout) {
85
+ var res = runLazyRule(rule, value);
86
+ if (res.pass) {
87
+ breakout(res);
88
+ }
89
+ }));
90
+ }
91
+
92
+ function noneOf(value) {
93
+ var rules = [];
94
+ for (var _i = 1; _i < arguments.length; _i++) {
95
+ rules[_i - 1] = arguments[_i];
96
+ }
97
+ return defaultToPassing(mapFirst(rules, function (rule, breakout) {
98
+ var res = runLazyRule(rule, value);
99
+ if (res.pass) {
100
+ breakout(failing());
101
+ }
102
+ }));
103
+ }
104
+
105
+ function lengthEquals(value, arg1) {
106
+ return value.length === Number(arg1);
107
+ }
108
+
109
+ function longerThan(value, arg1) {
110
+ return value.length > Number(arg1);
111
+ }
112
+
113
+ var REQUIRED_COUNT = 1;
114
+ function oneOf(value) {
115
+ var rules = [];
116
+ for (var _i = 1; _i < arguments.length; _i++) {
117
+ rules[_i - 1] = arguments[_i];
118
+ }
119
+ var passing = [];
120
+ rules.some(function (rule) {
121
+ if (longerThan(passing, REQUIRED_COUNT)) {
122
+ return false;
123
+ }
124
+ var res = runLazyRule(rule, value);
125
+ if (res.pass) {
126
+ passing.push(res);
127
+ }
128
+ });
129
+ return ruleReturn(lengthEquals(passing, REQUIRED_COUNT));
130
+ }
131
+
132
+ n4s.enforce.extend({ allOf: allOf, anyOf: anyOf, noneOf: noneOf, oneOf: oneOf });
@@ -0,0 +1 @@
1
+ "use strict";var n=require("n4s");function r(n,r){function t(n){u=!0,e=n}for(var u=!1,e=null,f=0;f<n.length;f++)if(r(n[f],t,f),u)return e}function t(n){return"function"==typeof n}function u(n,r){var u;return null!==(u=function(n){for(var r=[],u=1;u<arguments.length;u++)r[u-1]=arguments[u];return t(n)?n.apply(void 0,r):n}(n))&&void 0!==u?u:r}function e(n,r){return n={pass:n},r&&(n.message=r),n}function f(){return e(!1)}function o(n){return u(n,f())}function i(n){return u(n,e(!0))}function c(n,r){try{return n.run(r)}catch(n){return f()}}function a(n,r){return n.length===Number(r)}function s(n,r){return n.length>Number(r)}n.enforce.extend({allOf:function(n){for(var t=[],u=1;u<arguments.length;u++)t[u-1]=arguments[u];return i(r(t,(function(r,t){(r=c(r,n)).pass||t(r)})))},anyOf:function(n){for(var t=[],u=1;u<arguments.length;u++)t[u-1]=arguments[u];return o(r(t,(function(r,t){(r=c(r,n)).pass&&t(r)})))},noneOf:function(n){for(var t=[],u=1;u<arguments.length;u++)t[u-1]=arguments[u];return i(r(t,(function(r,t){c(r,n).pass&&t(f())})))},oneOf:function(n){for(var r=[],t=1;t<arguments.length;t++)r[t-1]=arguments[t];var u=[];return r.some((function(r){if(s(u,1))return!1;(r=c(r,n)).pass&&u.push(r)})),e(a(u,1))}});
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}