@uxf/core 11.127.0 → 11.129.0
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.
- package/README.md +49 -4
- package/package.json +1 -1
- package/utils/resizer.js +1 -1
- package/utils/resizer.test.js +1 -1
- package/index.d.ts +0 -2
- package/index.js +0 -19
package/README.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# UXF Core
|
|
2
2
|
|
|
3
|
+
Framework-agnostic helpers shared by every `@uxf/*` package: constants, value helpers (money, dates, QR, cookies), a large set of small utils and validators.
|
|
4
|
+
|
|
5
|
+
There is no root entry point – every symbol is imported from its own deep path, e.g. `import { isNil } from "@uxf/core/utils/is-nil";`. Import paths in this document are the ones to copy.
|
|
6
|
+
|
|
3
7
|
## Constants
|
|
4
8
|
|
|
5
9
|
- common modifier classnames for interactive elements (eg. `CLASSES.IS_HOVERABLE` for is-hoverable classname)
|
|
@@ -26,7 +30,7 @@
|
|
|
26
30
|
```json
|
|
27
31
|
[
|
|
28
32
|
{
|
|
29
|
-
"route": "/generated/static/:width(\\d+|x)_:height(\\d+|x)_:fit([a-z]+)_:position([a-z]+)_:background([a-z]+)_:trim([a-z]+)_:quality(\\d+|x)/:version/:filename(
|
|
33
|
+
"route": "/generated/static/:width(\\d+|x)_:height(\\d+|x)_:fit([a-z]+)_:position([a-z]+)_:background([a-z]+)_:trim([a-z]+)_:quality(\\d+|x)/:version/:filename(.*).:extension.:toFormat",
|
|
30
34
|
"source": "https://uxf-base.uxf.dev/:filename+.:extension"
|
|
31
35
|
},
|
|
32
36
|
{
|
|
@@ -821,9 +825,50 @@ const example = trimTrailingZeros("120,450"); /* returns "120,45" */
|
|
|
821
825
|
|
|
822
826
|
## Validators
|
|
823
827
|
|
|
828
|
+
Predicates returning a plain `boolean`.
|
|
829
|
+
|
|
824
830
|
```tsx
|
|
825
|
-
import { Validator } from "@uxf/core";
|
|
831
|
+
import { Validator } from "@uxf/core/validators/validator";
|
|
826
832
|
|
|
827
|
-
Validator.isEmail("
|
|
828
|
-
Validator.isPhone("
|
|
833
|
+
Validator.isEmail("dev@uxf.cz"); /* returns true */
|
|
834
|
+
Validator.isPhone("777 888 999"); /* returns true */
|
|
829
835
|
```
|
|
836
|
+
|
|
837
|
+
| Validator | Signature | Accepts |
|
|
838
|
+
| ------------------- | ---------------------------- | ---------------------------------------------------------------------------- |
|
|
839
|
+
| `Validator.isEmail` | `(email: string) => boolean` | `local@domain.tld` |
|
|
840
|
+
| `Validator.isPhone` | `(phone: string) => boolean` | 9 digits, optional spaces, optional `+420` / `00420` prefix (1–3 digit code) |
|
|
841
|
+
|
|
842
|
+
### FormValidator
|
|
843
|
+
|
|
844
|
+
Field-level validators built on top of `Validator`. Each one takes an optional error message and
|
|
845
|
+
returns a validation function that yields the message when the value is invalid, or `undefined`
|
|
846
|
+
when it passes – the shape a `@uxf/form` field validator expects.
|
|
847
|
+
|
|
848
|
+
```tsx
|
|
849
|
+
import { FormValidator } from "@uxf/core/validators/form-validator";
|
|
850
|
+
|
|
851
|
+
FormValidator.required()(""); /* returns "Vyplňte." */
|
|
852
|
+
FormValidator.isEmail("Zadejte e-mail.")("dev@uxfcz"); /* returns "Zadejte e-mail." */
|
|
853
|
+
FormValidator.isLessThan(10)("9.9"); /* returns undefined */
|
|
854
|
+
```
|
|
855
|
+
|
|
856
|
+
| Validator | Signature | Passes when |
|
|
857
|
+
| ---------------------- | ------------------------------------------------------ | --------------------------------------------------------- |
|
|
858
|
+
| `required` | `(errorMessage?) => (value: unknown)` | value is not `null`, `undefined` or `""` |
|
|
859
|
+
| `isEmail` | `(errorMessage?) => (value: string)` | value is empty, or `Validator.isEmail` accepts it |
|
|
860
|
+
| `isPhone` | `(errorMessage?) => (value: string)` | value is empty, or `Validator.isPhone` accepts it |
|
|
861
|
+
| `isLessThan` | `(maxValue: number, errorMessage?) => (value: string)` | value is `""`, or `Number.parseFloat(value) < maxValue` |
|
|
862
|
+
| `isLessOrEqualThan` | `(maxValue: number, errorMessage?) => (value: string)` | value is `""`, or `Number.parseFloat(value) <= maxValue` |
|
|
863
|
+
| `isGreaterThan` | `(minValue: number, errorMessage?) => (value: string)` | value is empty, or `Number.parseFloat(value) > minValue` |
|
|
864
|
+
| `isGreaterOrEqualThan` | `(minValue: number, errorMessage?) => (value: string)` | value is empty, or `Number.parseFloat(value) >= minValue` |
|
|
865
|
+
|
|
866
|
+
Gotchas:
|
|
867
|
+
|
|
868
|
+
- Every validator except `required` treats an empty value as valid. Combine them with `required` to
|
|
869
|
+
enforce presence.
|
|
870
|
+
- `required` only rejects `null`, `undefined` and `""` – `0` and `false` pass.
|
|
871
|
+
- The numeric validators compare `Number.parseFloat(value)`, and every comparison against `NaN` is
|
|
872
|
+
`false`, so a non-numeric string such as `"abc"` passes all four.
|
|
873
|
+
- The default error messages are Czech (`"Vyplňte."`, `"E-mail není validní"`, …). Pass your own
|
|
874
|
+
message for any other language.
|
package/package.json
CHANGED
package/utils/resizer.js
CHANGED
|
@@ -83,7 +83,7 @@ function resizerImageUrl(source, width = "auto", height = "auto", props = {}, ve
|
|
|
83
83
|
function resizerGetDefaultConfig(generatedFilesUrl, staticFilesUrl) {
|
|
84
84
|
return [
|
|
85
85
|
{
|
|
86
|
-
route: "/generated/static/:width(\\d+|x)_:height(\\d+|x)_:fit([a-z]+)_:position([a-z]+)_:background([a-z]+)_:trim([a-z]+)_:quality(\\d+|x)/:version/:filename(
|
|
86
|
+
route: "/generated/static/:width(\\d+|x)_:height(\\d+|x)_:fit([a-z]+)_:position([a-z]+)_:background([a-z]+)_:trim([a-z]+)_:quality(\\d+|x)/:version/:filename(.*).:extension.:toFormat",
|
|
87
87
|
source: `${staticFilesUrl}/:filename+.:extension`,
|
|
88
88
|
},
|
|
89
89
|
{
|
package/utils/resizer.test.js
CHANGED
|
@@ -71,7 +71,7 @@ describe("resizerGetDefaultConfig", () => {
|
|
|
71
71
|
const staticFilesUrl = "http://example.com/static";
|
|
72
72
|
const expectedConfig = [
|
|
73
73
|
{
|
|
74
|
-
route: "/generated/static/:width(\\d+|x)_:height(\\d+|x)_:fit([a-z]+)_:position([a-z]+)_:background([a-z]+)_:trim([a-z]+)_:quality(\\d+|x)/:version/:filename(
|
|
74
|
+
route: "/generated/static/:width(\\d+|x)_:height(\\d+|x)_:fit([a-z]+)_:position([a-z]+)_:background([a-z]+)_:trim([a-z]+)_:quality(\\d+|x)/:version/:filename(.*).:extension.:toFormat",
|
|
75
75
|
source: `${staticFilesUrl}/:filename+.:extension`,
|
|
76
76
|
},
|
|
77
77
|
{
|
package/index.d.ts
DELETED
package/index.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
// TODO @vejvis - remove me
|
|
18
|
-
__exportStar(require("./validators/form-validator"), exports);
|
|
19
|
-
__exportStar(require("./validators/validator"), exports);
|