n4s 3.1.0 → 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 (63) hide show
  1. package/CHANGELOG.md +129 -0
  2. package/LICENSE +1 -2
  3. package/README.md +2 -5
  4. package/compose/package.json +7 -0
  5. package/compounds/package.json +7 -0
  6. package/dist/cjs/compose.development.js +139 -0
  7. package/dist/cjs/compose.js +7 -0
  8. package/dist/cjs/compose.production.js +1 -0
  9. package/dist/cjs/compounds.development.js +132 -0
  10. package/dist/cjs/compounds.js +7 -0
  11. package/dist/cjs/compounds.production.js +1 -0
  12. package/dist/cjs/n4s.development.js +602 -0
  13. package/dist/cjs/n4s.js +7 -0
  14. package/dist/cjs/n4s.production.js +1 -0
  15. package/dist/cjs/package.json +1 -0
  16. package/dist/cjs/schema.development.js +144 -0
  17. package/dist/cjs/schema.js +7 -0
  18. package/dist/cjs/schema.production.js +1 -0
  19. package/dist/es/compose.development.js +137 -0
  20. package/dist/es/compose.production.js +1 -0
  21. package/dist/es/compounds.development.js +130 -0
  22. package/dist/es/compounds.production.js +1 -0
  23. package/dist/es/n4s.development.js +597 -0
  24. package/dist/es/n4s.production.js +1 -0
  25. package/dist/es/package.json +1 -0
  26. package/dist/es/schema.development.js +140 -0
  27. package/dist/es/schema.production.js +1 -0
  28. package/dist/umd/compose.development.js +143 -0
  29. package/dist/umd/compose.production.js +1 -0
  30. package/dist/umd/compounds.development.js +136 -0
  31. package/dist/umd/compounds.production.js +1 -0
  32. package/dist/umd/n4s.development.js +606 -0
  33. package/dist/umd/n4s.production.js +1 -0
  34. package/dist/umd/schema.development.js +148 -0
  35. package/dist/umd/schema.production.js +1 -0
  36. package/docs/README.md +2 -5
  37. package/docs/_sidebar.md +0 -1
  38. package/docs/external.md +1 -28
  39. package/package.json +129 -53
  40. package/schema/package.json +7 -0
  41. package/tsconfig.json +8 -0
  42. package/types/compose.d.ts +134 -0
  43. package/types/compounds.d.ts +146 -0
  44. package/types/n4s.d.ts +167 -0
  45. package/types/schema.d.ts +151 -0
  46. package/config/jest/jest.setup.js +0 -14
  47. package/config/rollup/enforce.js +0 -8
  48. package/config/rollup/rollup.config.js +0 -3
  49. package/docs/compound.md +0 -187
  50. package/docs/custom.md +0 -52
  51. package/docs/template.md +0 -53
  52. package/esm/n4s.es.development.js +0 -1142
  53. package/esm/n4s.es.production.js +0 -1142
  54. package/esm/n4s.es.production.min.js +0 -1
  55. package/esm/package.json +0 -1
  56. package/jest.config.js +0 -3
  57. package/n4s.cjs.development.js +0 -1144
  58. package/n4s.cjs.production.js +0 -1144
  59. package/n4s.cjs.production.min.js +0 -1
  60. package/n4s.js +0 -7
  61. package/n4s.umd.development.js +0 -1231
  62. package/n4s.umd.production.js +0 -1231
  63. package/n4s.umd.production.min.js +0 -1
package/docs/custom.md DELETED
@@ -1,52 +0,0 @@
1
- # Creating Custom Rules
2
-
3
- To make it easier to reuse logic across your application, sometimes you would want to encapsulate bits of logic in rules that you can use later on, for example, "what's considered a valid email".
4
-
5
- Rules are called with the argument passed to enforce(x) followed by the arguments passed to `.yourRule(y, z)`.
6
-
7
- ```js
8
- enforce.extend({
9
- yourRule(x, y, z) {
10
- return {
11
- pass: true,
12
- message: () => '',
13
- };
14
- },
15
- });
16
- ```
17
-
18
- ```js
19
- enforce.extend({
20
- isValidEmail: value => value.indexOf('@') > -1,
21
- hasKey: (value, key) => value.hasOwnProperty(key),
22
- passwordsMatch: (passConfirm, options) =>
23
- passConfirm === options.passConfirm && options.passIsValid,
24
- });
25
-
26
- enforce(user.email).isValidEmail();
27
- ```
28
-
29
- ## Custom rules return value
30
-
31
- Rules can either return boolean indicating success or failure, or an object with two keys. `pass` indicates whether the validation is successful or not, and message provides a function with no arguments that return an error message in case of failure. Thus, when pass is false, message should return the error message for when enforce(x).yourRule() fails.
32
-
33
- ```js
34
- enforce.extend({
35
- isWithinRange(received, floor, ceiling) {
36
- const pass = received >= floor && received <= ceiling;
37
- if (pass) {
38
- return {
39
- message: () =>
40
- `expected ${received} not to be within range ${floor} - ${ceiling}`,
41
- pass: true,
42
- };
43
- } else {
44
- return {
45
- message: () =>
46
- `expected ${received} to be within range ${floor} - ${ceiling}`,
47
- pass: false,
48
- };
49
- }
50
- },
51
- });
52
- ```
package/docs/template.md DELETED
@@ -1,53 +0,0 @@
1
- # Enforce templates
2
-
3
- When you have common patterns you need to repeat in multiple places, it might be simpler to store them as templates.
4
-
5
- For example, let's assume that all across our systems, a username must be a non-numeric string that's longer than 3 characters.
6
-
7
- ```js
8
- enforce(username).isString().isNotEmpty().isNotNumeric().longerThan(3);
9
- ```
10
-
11
- This is quite simple to understand, but if you have to keep it up-to-date in every place you validate a username, you may eventually have inconsistent or out-of-date validations.
12
-
13
- It can be beneficial in that case to keep this enforcement as a template for later use:
14
-
15
- ```js
16
- const Username = enforce.template(
17
- enforce.isString().isNotEmpty().isNotNumeric().longerThan(3)
18
- );
19
- ```
20
-
21
- And then, anywhere else you can use your new `Username` template to validate usernames all across your application:
22
-
23
- ```js
24
- Username('myUsername'); // passes
25
- Username('1234'); // throws
26
- Username('ab'); // throws
27
- ```
28
-
29
- You can also use templates inside other compound rules, such as `shape`, `isArrayOf` ,`anyOf` or `allOf`.
30
-
31
- ```js
32
- enforce({
33
- username: 'someusername',
34
- }).shape({ username: Username });
35
-
36
- enforce(['user1', 'user2']).isArrayOf(Username);
37
- ```
38
-
39
- Templates can also be nested and composited:
40
-
41
- ```js
42
- const RequiredField = enforce.template(enforce.isNotEmpty());
43
- const NumericString = enforce.template(enforce.isNumeric().isString());
44
-
45
- const EvenNumeric = enforce.template(
46
- RequiredField,
47
- NumericString,
48
- enforce.isEven()
49
- );
50
-
51
- EvenNumeric('10'); // pases
52
- EvenNumeric('1'); // throws
53
- ```