@uxf/core 11.11.3 → 11.19.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 CHANGED
@@ -328,6 +328,58 @@ queryParamToNumber(ctx.query.id);
328
328
  queryParamToString(ctx.query.name);
329
329
  ```
330
330
 
331
+ ## Utils
332
+
333
+ ### cx, cxa
334
+ It is our fork of `clsx` library https://github.com/lukeed/clsx
335
+
336
+ We will mainly use `cx`, which is fork of `clsx/lite` – it accepts **ONLY** string values! Any non-string arguments are ignored!
337
+ ```tsx
338
+ import { cx } from "@uxf/core/utils/cx";
339
+
340
+ // string
341
+ cx("hello", true && "foo", false && "bar");
342
+ // => "hello foo"
343
+
344
+ // NOTE: Any non-string input(s) ignored
345
+ cx({ foo: true });
346
+ //=> ""
347
+ ```
348
+
349
+ The `cxa` function is full fork of `clsx` and can take *any* number of arguments, each of which can be an Object, Array, Boolean, or String.
350
+
351
+ **Important**: Any falsy values are discarded! Standalone Boolean values are discarded as well.
352
+ ```tsx
353
+ import { cxa } from "@uxf/core/utils/cxa";
354
+
355
+ cxa(true, false, "", null, undefined, 0, NaN);
356
+ //=> ""
357
+
358
+ // Strings (variadic)
359
+ cxa("foo", true && "bar", "baz");
360
+ //=> "foo bar baz"
361
+
362
+ // Objects
363
+ cxa({ foo:true, bar:false, baz:isTrue() });
364
+ //=> "foo baz"
365
+
366
+ // Objects (variadic)
367
+ cxa({ foo:true }, { bar:false }, null, { "--foobar":"hello" });
368
+ //=> "foo --foobar"
369
+
370
+ // Arrays
371
+ cxa(["foo", 0, false, "bar"]);
372
+ //=> "foo bar"
373
+
374
+ // Arrays (variadic)
375
+ cxa(["foo"], ["", 0, false, "bar"], [["baz", [["hello"], "there"]]]);
376
+ //=> "foo bar baz hello there"
377
+
378
+ // Kitchen sink (with nesting)
379
+ cxa("foo", [1 && "bar", { baz:false, bat:null }, ["hello", ["world"]]], "cya");
380
+ //=> "foo bar hello world cya"
381
+ ```
382
+
331
383
  ## Validators
332
384
  ```tsx
333
385
  import { Validator } from "@uxf/core";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxf/core",
3
- "version": "11.11.3",
3
+ "version": "11.19.0",
4
4
  "description": "UXF Core",
5
5
  "author": "Petr Vejvoda <vejvoda@uxf.cz>",
6
6
  "homepage": "https://gitlab.com/uxf-npm/core#readme",
package/utils/cx.d.ts CHANGED
@@ -1,3 +1,2 @@
1
- export type ClassArray = ClassValue[];
2
- export type ClassValue = ClassArray | Record<string, any> | string | number | null | boolean | undefined;
3
- export declare function cx(...classes: ClassValue[]): string;
1
+ export type CxClassValue = string | null | boolean | undefined;
2
+ export declare function cx(...classes: CxClassValue[]): string;
package/utils/cx.js CHANGED
@@ -1,51 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.cx = void 0;
4
- function toVal(mix) {
5
- let k;
6
- let y;
7
- let str = "";
8
- if (typeof mix === "string" || typeof mix === "number") {
9
- str += mix;
10
- }
11
- else if (typeof mix === "object") {
12
- if (Array.isArray(mix)) {
13
- for (k = 0; k < mix.length; k++) {
14
- if (mix[k]) {
15
- if ((y = toVal(mix[k]))) {
16
- if (str) {
17
- str += " ";
18
- }
19
- str += y;
20
- }
21
- }
22
- }
23
- }
24
- else {
25
- for (k in mix) {
26
- if (mix === null || mix === void 0 ? void 0 : mix[k]) {
27
- if (str) {
28
- str += " ";
29
- }
30
- str += k;
31
- }
32
- }
33
- }
34
- }
35
- return str;
36
- }
37
4
  function cx(...classes) {
38
- let i = 0;
39
- let tmp;
40
- let x;
41
- let str = "";
42
- while (i < classes.length) {
43
- if ((tmp = classes[i++])) {
44
- if ((x = toVal(tmp))) {
45
- if (str) {
46
- str += " ";
47
- }
48
- str += x;
5
+ let i = 0, tmp, str = "";
6
+ for (; i < classes.length; i++) {
7
+ if ((tmp = classes[i])) {
8
+ if (typeof tmp === "string") {
9
+ str += (str && " ") + tmp;
49
10
  }
50
11
  }
51
12
  }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ /* eslint-disable @typescript-eslint/no-unnecessary-condition,@typescript-eslint/ban-ts-comment */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const cx_1 = require("./cx");
5
+ test("strings", () => {
6
+ expect((0, cx_1.cx)("")).toBe("");
7
+ expect((0, cx_1.cx)("foo")).toBe("foo");
8
+ expect((0, cx_1.cx)(true && "foo")).toBe("foo");
9
+ expect((0, cx_1.cx)(false && "foo")).toBe("");
10
+ });
11
+ test("strings (variadic)", () => {
12
+ expect((0, cx_1.cx)("")).toBe("");
13
+ expect((0, cx_1.cx)("foo", "bar")).toBe("foo bar");
14
+ expect((0, cx_1.cx)(true && "foo", false && "bar", "baz")).toBe("foo baz");
15
+ expect((0, cx_1.cx)(false && "foo", "bar", "baz", "")).toBe("bar baz");
16
+ });
17
+ test("emptys", () => {
18
+ expect((0, cx_1.cx)("")).toBe("");
19
+ expect((0, cx_1.cx)(undefined)).toBe("");
20
+ expect((0, cx_1.cx)(null)).toBe("");
21
+ // @ts-ignore
22
+ expect((0, cx_1.cx)(0)).toBe("");
23
+ });
24
+ // lite ignores all non-strings
25
+ test("non-strings", () => {
26
+ // number
27
+ // @ts-ignore
28
+ expect((0, cx_1.cx)(1)).toBe("");
29
+ // @ts-ignore
30
+ expect((0, cx_1.cx)(1, 2)).toBe("");
31
+ // @ts-ignore
32
+ expect((0, cx_1.cx)(Infinity)).toBe("");
33
+ // @ts-ignore
34
+ expect((0, cx_1.cx)(NaN)).toBe("");
35
+ // @ts-ignore
36
+ expect((0, cx_1.cx)(0)).toBe("");
37
+ // objects
38
+ // @ts-ignore
39
+ expect((0, cx_1.cx)({})).toBe("");
40
+ // @ts-ignore
41
+ expect((0, cx_1.cx)(null)).toBe("");
42
+ // @ts-ignore
43
+ expect((0, cx_1.cx)({ a: 1 })).toBe("");
44
+ // @ts-ignore
45
+ expect((0, cx_1.cx)({ a: 1 }, { b: 2 })).toBe("");
46
+ // arrays
47
+ // @ts-ignore
48
+ expect((0, cx_1.cx)([])).toBe("");
49
+ // @ts-ignore
50
+ expect((0, cx_1.cx)(["foo"])).toBe("");
51
+ // @ts-ignore
52
+ expect((0, cx_1.cx)(["foo", "bar"])).toBe("");
53
+ // @ts-ignore
54
+ // functions
55
+ expect((0, cx_1.cx)(cx_1.cx)).toBe("");
56
+ // @ts-ignore
57
+ expect((0, cx_1.cx)(cx_1.cx, cx_1.cx)).toBe("");
58
+ });
package/utils/cxa.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export type CxaClassArray = CxaClassValue[];
2
+ export type CxaClassValue = CxaClassArray | Record<string, any> | string | number | null | boolean | undefined;
3
+ export declare function cxa(...classes: CxaClassValue[]): string;
package/utils/cxa.js ADDED
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cxa = void 0;
4
+ function toVal(mix) {
5
+ let k;
6
+ let y;
7
+ let str = "";
8
+ if (typeof mix === "string" || typeof mix === "number") {
9
+ str += mix;
10
+ }
11
+ else if (typeof mix === "object") {
12
+ if (Array.isArray(mix)) {
13
+ for (k = 0; k < mix.length; k++) {
14
+ if (mix[k]) {
15
+ if ((y = toVal(mix[k]))) {
16
+ if (str) {
17
+ str += " ";
18
+ }
19
+ str += y;
20
+ }
21
+ }
22
+ }
23
+ }
24
+ else {
25
+ for (k in mix) {
26
+ if (mix === null || mix === void 0 ? void 0 : mix[k]) {
27
+ if (str) {
28
+ str += " ";
29
+ }
30
+ str += k;
31
+ }
32
+ }
33
+ }
34
+ }
35
+ return str;
36
+ }
37
+ function cxa(...classes) {
38
+ let i = 0;
39
+ let tmp;
40
+ let x;
41
+ let str = "";
42
+ while (i < classes.length) {
43
+ if ((tmp = classes[i++])) {
44
+ if ((x = toVal(tmp))) {
45
+ if (str) {
46
+ str += " ";
47
+ }
48
+ str += x;
49
+ }
50
+ }
51
+ }
52
+ return str;
53
+ }
54
+ exports.cxa = cxa;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ /* eslint-disable @typescript-eslint/no-unnecessary-condition,no-empty-function */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const cxa_1 = require("./cxa");
5
+ test("strings", () => {
6
+ expect((0, cxa_1.cxa)("")).toBe("");
7
+ expect((0, cxa_1.cxa)("foo")).toBe("foo");
8
+ expect((0, cxa_1.cxa)(true && "foo")).toBe("foo");
9
+ expect((0, cxa_1.cxa)(false && "foo")).toBe("");
10
+ });
11
+ test("strings (variadic)", () => {
12
+ expect((0, cxa_1.cxa)("")).toBe("");
13
+ expect((0, cxa_1.cxa)("foo", "bar")).toBe("foo bar");
14
+ expect((0, cxa_1.cxa)(true && "foo", false && "bar", "baz")).toBe("foo baz");
15
+ expect((0, cxa_1.cxa)(false && "foo", "bar", "baz", "")).toBe("bar baz");
16
+ });
17
+ test("numbers", () => {
18
+ expect((0, cxa_1.cxa)(1)).toBe("1");
19
+ expect((0, cxa_1.cxa)(12)).toBe("12");
20
+ expect((0, cxa_1.cxa)(0.1)).toBe("0.1");
21
+ expect((0, cxa_1.cxa)(0)).toBe("");
22
+ expect((0, cxa_1.cxa)(Infinity)).toBe("Infinity");
23
+ expect((0, cxa_1.cxa)(NaN)).toBe("");
24
+ });
25
+ test("numbers (variadic)", () => {
26
+ expect((0, cxa_1.cxa)(0, 1)).toBe("1");
27
+ expect((0, cxa_1.cxa)(1, 2)).toBe("1 2");
28
+ });
29
+ test("objects", () => {
30
+ expect((0, cxa_1.cxa)({})).toBe("");
31
+ expect((0, cxa_1.cxa)({ foo: true })).toBe("foo");
32
+ expect((0, cxa_1.cxa)({ foo: true, bar: false })).toBe("foo");
33
+ expect((0, cxa_1.cxa)({ foo: "hiya", bar: 1 })).toBe("foo bar");
34
+ expect((0, cxa_1.cxa)({ foo: 1, bar: 0, baz: 1 })).toBe("foo baz");
35
+ expect((0, cxa_1.cxa)({ "-foo": 1, "--bar": 1 })).toBe("-foo --bar");
36
+ });
37
+ test("objects (variadic)", () => {
38
+ expect((0, cxa_1.cxa)({}, {})).toBe("");
39
+ expect((0, cxa_1.cxa)({ foo: 1 }, { bar: 2 })).toBe("foo bar");
40
+ expect((0, cxa_1.cxa)({ foo: 1 }, null, { baz: 1, bat: 0 })).toBe("foo baz");
41
+ expect((0, cxa_1.cxa)({ foo: 1 }, {}, {}, { bar: "a" }, { baz: null, bat: Infinity })).toBe("foo bar bat");
42
+ });
43
+ test("arrays", () => {
44
+ expect((0, cxa_1.cxa)([])).toBe("");
45
+ expect((0, cxa_1.cxa)(["foo"])).toBe("foo");
46
+ expect((0, cxa_1.cxa)(["foo", "bar"])).toBe("foo bar");
47
+ expect((0, cxa_1.cxa)(["foo", 0 && "bar", 1 && "baz"])).toBe("foo baz");
48
+ });
49
+ test("arrays (nested)", () => {
50
+ expect((0, cxa_1.cxa)([[[]]])).toBe("");
51
+ expect((0, cxa_1.cxa)([[["foo"]]])).toBe("foo");
52
+ expect((0, cxa_1.cxa)([true, [["foo"]]])).toBe("foo");
53
+ expect((0, cxa_1.cxa)(["foo", ["bar", ["", [["baz"]]]]])).toBe("foo bar baz");
54
+ });
55
+ test("arrays (variadic)", () => {
56
+ expect((0, cxa_1.cxa)([], [])).toBe("");
57
+ expect((0, cxa_1.cxa)(["foo"], ["bar"])).toBe("foo bar");
58
+ expect((0, cxa_1.cxa)(["foo"], null, ["baz", ""], true, "", [])).toBe("foo baz");
59
+ });
60
+ test("arrays (no `push` escape)", () => {
61
+ expect((0, cxa_1.cxa)({ push: 1 })).toBe("push");
62
+ expect((0, cxa_1.cxa)({ pop: true })).toBe("pop");
63
+ expect((0, cxa_1.cxa)({ push: true })).toBe("push");
64
+ expect((0, cxa_1.cxa)("hello", { world: 1, push: true })).toBe("hello world push");
65
+ });
66
+ test("functions", () => {
67
+ const foo = () => { };
68
+ expect((0, cxa_1.cxa)(foo, "hello")).toBe("hello");
69
+ expect((0, cxa_1.cxa)(foo, "hello", cxa_1.cxa)).toBe("hello");
70
+ expect((0, cxa_1.cxa)(foo, "hello", [[cxa_1.cxa], "world"])).toBe("hello world");
71
+ });
@@ -0,0 +1 @@
1
+ export declare function isNotEmpty(value: any[] | string): boolean;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isNotEmpty = void 0;
4
+ const is_empty_1 = require("./is-empty");
5
+ function isNotEmpty(value) {
6
+ return !(0, is_empty_1.isEmpty)(value);
7
+ }
8
+ exports.isNotEmpty = isNotEmpty;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const is_not_empty_1 = require("./is-not-empty");
4
+ test("is-not-empty", () => {
5
+ expect((0, is_not_empty_1.isNotEmpty)(["1"])).toBeTruthy();
6
+ expect((0, is_not_empty_1.isNotEmpty)([])).toBeFalsy();
7
+ expect((0, is_not_empty_1.isNotEmpty)("not-empty")).toBeTruthy();
8
+ expect((0, is_not_empty_1.isNotEmpty)("")).toBeFalsy();
9
+ });