@uxf/core 11.87.0 → 11.88.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
@@ -285,6 +285,20 @@ import { filterNullish } from "@uxf/core/utils/filter-nullish";
285
285
  filterNullish([0, "text", null, undefined, [], {}]); /* returns [0, "text", [], {}] */
286
286
  ```
287
287
 
288
+ ## filterNullishObjectValues
289
+
290
+ Filters out all properties with `null` or `undefined` values from an object, returning a new object with only non-nullish values.
291
+
292
+ ```tsx
293
+ import { filterNullishObjectValues } from "@uxf/core/utils/filter-nullish-object-values";
294
+
295
+ filterNullishObjectValues({ a: 1, b: null, c: "test", d: undefined });
296
+ /* returns { a: 1, c: "test" } */
297
+
298
+ filterNullishObjectValues({ a: 0, b: "", c: false });
299
+ /* returns { a: 0, b: "", c: false } - keeps falsy values that are not nullish */
300
+ ```
301
+
288
302
  ## filterAriaAndDataAttrs
289
303
 
290
304
  Filters an object to return only properties that start with `aria-` or `data-` prefixes. This utility is useful when you need to pass accessibility and data attributes to HTML elements while excluding other props like event handlers or component-specific props.
@@ -340,6 +354,36 @@ isEmpty(["1"]); /* returns false */
340
354
  isEmpty([]); /* returns true */
341
355
  ```
342
356
 
357
+ ## isEven
358
+
359
+ Checks if a number is even.
360
+
361
+ ```tsx
362
+ import { isEven } from "@uxf/core/utils/is-even";
363
+
364
+ isEven(2); /* returns true */
365
+ isEven(4); /* returns true */
366
+ isEven(1); /* returns false */
367
+ isEven(3); /* returns false */
368
+ isEven(0); /* returns true */
369
+ isEven(-2); /* returns true */
370
+ ```
371
+
372
+ ## isOdd
373
+
374
+ Checks if a number is odd.
375
+
376
+ ```tsx
377
+ import { isOdd } from "@uxf/core/utils/is-odd";
378
+
379
+ isOdd(1); /* returns true */
380
+ isOdd(3); /* returns true */
381
+ isOdd(2); /* returns false */
382
+ isOdd(4); /* returns false */
383
+ isOdd(0); /* returns false */
384
+ isOdd(-1); /* returns true */
385
+ ```
386
+
343
387
  ## isBrowser / isServer
344
388
 
345
389
  ```tsx
@@ -378,6 +422,8 @@ isNotNil([]); /* returns true */
378
422
  isNotNil("string"); /* returns true */
379
423
  ```
380
424
 
425
+ ## last
426
+
381
427
  ```tsx
382
428
  import { last } from "@uxf/core/utils/last";
383
429
 
@@ -385,6 +431,63 @@ last([1, 2]); /* returns 2 */
385
431
  last([]); /* returns undefined */
386
432
  ```
387
433
 
434
+ ## nonEmptyArrayOrNull
435
+
436
+ Converts empty arrays, `null`, or `undefined` values to `null`, leaving all non-empty arrays unchanged. Useful for normalizing form inputs or API data where empty arrays should be treated as `null`.
437
+
438
+ ```tsx
439
+ import { nonEmptyArrayOrNull } from "@uxf/core/utils/non-empty-array-or-null";
440
+
441
+ nonEmptyArrayOrNull([]); /* returns null */
442
+ nonEmptyArrayOrNull(null); /* returns null */
443
+ nonEmptyArrayOrNull(undefined); /* returns null */
444
+ nonEmptyArrayOrNull([1, 2, 3]); /* returns [1, 2, 3] */
445
+ nonEmptyArrayOrNull(["a", "b"]); /* returns ["a", "b"] */
446
+ ```
447
+
448
+ ## nonEmptyStringOrNull
449
+
450
+ Converts empty strings and `undefined` values to `null`, leaving all other strings unchanged. Useful for normalizing form inputs or API data where empty strings should be treated as `null`.
451
+
452
+ ```tsx
453
+ import { nonEmptyStringOrNull } from "@uxf/core/utils/non-empty-string-or-null";
454
+
455
+ nonEmptyStringOrNull(""); /* returns null */
456
+ nonEmptyStringOrNull(undefined); /* returns null */
457
+ nonEmptyStringOrNull(null); /* returns null */
458
+ nonEmptyStringOrNull("test"); /* returns "test" */
459
+ nonEmptyStringOrNull(" "); /* returns " " - non-empty string */
460
+ ```
461
+
462
+ ## nullishToEmptyString
463
+
464
+ Converts `null` or `undefined` values to an empty string, leaving all other strings unchanged. Useful for safely displaying nullable string values in UI components.
465
+
466
+ ```tsx
467
+ import { nullishToEmptyString } from "@uxf/core/utils/nullish-to-empty-string";
468
+
469
+ nullishToEmptyString(null); /* returns "" */
470
+ nullishToEmptyString(undefined); /* returns "" */
471
+ nullishToEmptyString(""); /* returns "" */
472
+ nullishToEmptyString("hello world"); /* returns "hello world" */
473
+ ```
474
+
475
+ ## numberOrNull
476
+
477
+ Converts `NaN`, `null`, or `undefined` values to `null`, leaving all valid numbers unchanged. Useful for normalizing numeric inputs or API data where invalid numbers should be treated as `null`.
478
+
479
+ ```tsx
480
+ import { numberOrNull } from "@uxf/core/utils/number-or-null";
481
+
482
+ numberOrNull(0); /* returns 0 */
483
+ numberOrNull(42); /* returns 42 */
484
+ numberOrNull(-1); /* returns -1 */
485
+ numberOrNull(3.14); /* returns 3.14 */
486
+ numberOrNull(NaN); /* returns null */
487
+ numberOrNull(null); /* returns null */
488
+ numberOrNull(undefined); /* returns null */
489
+ ```
490
+
388
491
  ## slugify
389
492
 
390
493
  ```tsx
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxf/core",
3
- "version": "11.87.0",
3
+ "version": "11.88.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/types/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export type Nullish = null | undefined;
2
2
  export type Noop = () => void;
3
+ export type AnyObject = Partial<Record<string, any>>;
3
4
  export interface FileResponse {
4
5
  id: number;
5
6
  name: string;
@@ -0,0 +1,3 @@
1
+ export declare function filterNullishObjectValues(obj: Record<string, any>): {
2
+ [k: string]: any;
3
+ };
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.filterNullishObjectValues = filterNullishObjectValues;
4
+ const is_not_nil_1 = require("@uxf/core/utils/is-not-nil");
5
+ function filterNullishObjectValues(obj) {
6
+ return Object.fromEntries(Object.entries(obj).filter(([, value]) => (0, is_not_nil_1.isNotNil)(value)));
7
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const filter_nullish_object_values_1 = require("./filter-nullish-object-values");
4
+ test("filter-nullish-object-values", () => {
5
+ expect((0, filter_nullish_object_values_1.filterNullishObjectValues)({ a: 1, b: null, c: "test", d: undefined })).toStrictEqual({
6
+ a: 1,
7
+ c: "test",
8
+ });
9
+ expect((0, filter_nullish_object_values_1.filterNullishObjectValues)({ a: 0, b: "", c: false, d: NaN })).toStrictEqual({
10
+ a: 0,
11
+ b: "",
12
+ c: false,
13
+ d: NaN,
14
+ });
15
+ expect((0, filter_nullish_object_values_1.filterNullishObjectValues)({ a: [], b: {} })).toStrictEqual({ a: [], b: {} });
16
+ expect((0, filter_nullish_object_values_1.filterNullishObjectValues)({})).toStrictEqual({});
17
+ expect((0, filter_nullish_object_values_1.filterNullishObjectValues)({ a: null, b: undefined })).toStrictEqual({});
18
+ });
@@ -1 +1,2 @@
1
- export declare function filterNullish<T>(val: Array<T | null | undefined>): T[];
1
+ import { Nullish } from "../types";
2
+ export declare function filterNullish<T>(val: Array<T | Nullish>): T[];
@@ -0,0 +1 @@
1
+ export declare function isEven(n: number): boolean;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isEven = isEven;
4
+ function isEven(n) {
5
+ return n % 2 === 0;
6
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const is_even_1 = require("./is-even");
4
+ test("is-even", () => {
5
+ [0, 2, 4, 10, 100, -2, -4].map((value) => expect((0, is_even_1.isEven)(value)).toBeTruthy());
6
+ [1, 3, 5, 11, 101, -1, -3].map((value) => expect((0, is_even_1.isEven)(value)).toBeFalsy());
7
+ });
@@ -0,0 +1 @@
1
+ export declare function isOdd(n: number): boolean;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isOdd = isOdd;
4
+ const is_even_1 = require("./is-even");
5
+ function isOdd(n) {
6
+ return !(0, is_even_1.isEven)(n);
7
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const is_odd_1 = require("./is-odd");
4
+ test("is-odd", () => {
5
+ [1, 3, 5, 11, 101, -1, -3].map((value) => expect((0, is_odd_1.isOdd)(value)).toBeTruthy());
6
+ [0, 2, 4, 10, 100, -2, -4].map((value) => expect((0, is_odd_1.isOdd)(value)).toBeFalsy());
7
+ });
@@ -0,0 +1,2 @@
1
+ import { Nullish } from "@uxf/core/types";
2
+ export declare function nonEmptyArrayOrNull<T>(value: Nullish | T[]): T[] | null;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.nonEmptyArrayOrNull = nonEmptyArrayOrNull;
4
+ const is_empty_1 = require("@uxf/core/utils/is-empty");
5
+ const is_nil_1 = require("@uxf/core/utils/is-nil");
6
+ function nonEmptyArrayOrNull(value) {
7
+ return (0, is_nil_1.isNil)(value) || (0, is_empty_1.isEmpty)(value) ? null : value;
8
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const non_empty_array_or_null_1 = require("./non-empty-array-or-null");
4
+ test("non-empty-array-or-null", () => {
5
+ expect((0, non_empty_array_or_null_1.nonEmptyArrayOrNull)([])).toBe(null);
6
+ expect((0, non_empty_array_or_null_1.nonEmptyArrayOrNull)(undefined)).toBe(null);
7
+ expect((0, non_empty_array_or_null_1.nonEmptyArrayOrNull)(null)).toBe(null);
8
+ expect((0, non_empty_array_or_null_1.nonEmptyArrayOrNull)([1, 2, 3])).toStrictEqual([1, 2, 3]);
9
+ expect((0, non_empty_array_or_null_1.nonEmptyArrayOrNull)(["a", "b"])).toStrictEqual(["a", "b"]);
10
+ expect((0, non_empty_array_or_null_1.nonEmptyArrayOrNull)([0])).toStrictEqual([0]);
11
+ expect((0, non_empty_array_or_null_1.nonEmptyArrayOrNull)([false])).toStrictEqual([false]);
12
+ expect((0, non_empty_array_or_null_1.nonEmptyArrayOrNull)([null])).toStrictEqual([null]);
13
+ expect((0, non_empty_array_or_null_1.nonEmptyArrayOrNull)([{}])).toStrictEqual([{}]);
14
+ });
@@ -0,0 +1,2 @@
1
+ import { Nullish } from "../types";
2
+ export declare function nonEmptyStringOrNull(value: string | Nullish): string | null;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.nonEmptyStringOrNull = nonEmptyStringOrNull;
4
+ function nonEmptyStringOrNull(value) {
5
+ return value === "" || value === undefined ? null : value;
6
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const non_empty_string_or_null_1 = require("./non-empty-string-or-null");
4
+ test("nullish-empty-string-to-nullable", () => {
5
+ expect((0, non_empty_string_or_null_1.nonEmptyStringOrNull)("")).toBe(null);
6
+ expect((0, non_empty_string_or_null_1.nonEmptyStringOrNull)(undefined)).toBe(null);
7
+ expect((0, non_empty_string_or_null_1.nonEmptyStringOrNull)(null)).toBe(null);
8
+ expect((0, non_empty_string_or_null_1.nonEmptyStringOrNull)("test")).toBe("test");
9
+ expect((0, non_empty_string_or_null_1.nonEmptyStringOrNull)("hello world")).toBe("hello world");
10
+ expect((0, non_empty_string_or_null_1.nonEmptyStringOrNull)(" ")).toBe(" ");
11
+ });
@@ -0,0 +1,2 @@
1
+ import { Nullish } from "../types";
2
+ export declare function nullishToEmptyString(value: string | Nullish): string;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.nullishToEmptyString = nullishToEmptyString;
4
+ function nullishToEmptyString(value) {
5
+ return value !== null && value !== void 0 ? value : "";
6
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const nullish_to_empty_string_1 = require("./nullish-to-empty-string");
4
+ test("nullish-to-empty-string", () => {
5
+ expect((0, nullish_to_empty_string_1.nullishToEmptyString)(null)).toBe("");
6
+ expect((0, nullish_to_empty_string_1.nullishToEmptyString)(undefined)).toBe("");
7
+ expect((0, nullish_to_empty_string_1.nullishToEmptyString)("")).toBe("");
8
+ expect((0, nullish_to_empty_string_1.nullishToEmptyString)("test")).toBe("test");
9
+ expect((0, nullish_to_empty_string_1.nullishToEmptyString)("hello world")).toBe("hello world");
10
+ });
@@ -0,0 +1,2 @@
1
+ import { Nullish } from "../types";
2
+ export declare function numberOrNull(value: number | Nullish): number | null;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.numberOrNull = numberOrNull;
4
+ const is_not_nil_1 = require("./is-not-nil");
5
+ function numberOrNull(value) {
6
+ return (0, is_not_nil_1.isNotNil)(value) && !isNaN(value) ? value : null;
7
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const number_or_null_1 = require("./number-or-null");
4
+ test("number-or-null", () => {
5
+ // Valid numbers should return the number
6
+ expect((0, number_or_null_1.numberOrNull)(0)).toBe(0);
7
+ expect((0, number_or_null_1.numberOrNull)(1)).toBe(1);
8
+ expect((0, number_or_null_1.numberOrNull)(-1)).toBe(-1);
9
+ expect((0, number_or_null_1.numberOrNull)(42)).toBe(42);
10
+ expect((0, number_or_null_1.numberOrNull)(3.14)).toBe(3.14);
11
+ expect((0, number_or_null_1.numberOrNull)(-99.99)).toBe(-99.99);
12
+ // null should return null
13
+ expect((0, number_or_null_1.numberOrNull)(null)).toBe(null);
14
+ // undefined should return null
15
+ expect((0, number_or_null_1.numberOrNull)(undefined)).toBe(null);
16
+ // NaN should return null
17
+ expect((0, number_or_null_1.numberOrNull)(NaN)).toBe(null);
18
+ });